-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.php
More file actions
154 lines (132 loc) · 6 KB
/
submit.php
File metadata and controls
154 lines (132 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
include_once "password-generator.php";
include_once "rrmdir.php";
include "config.php";
// Sanitize the domain string
$clean_domain = preg_replace("/[^a-zA-Z0-9]+/", "", $_POST['domain_name']);
// Declare errors variable
$errors = [];
// Check if domain name is taken
if (file_exists($subdomains . $clean_domain)) {
$errors[] = "Domain name <strong>" . $clean_domain . "</strong> is already taken";
}
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
$errors[] = "Failed to connect to the database, please try again later...";
}
// Generate FTP password
$generated_password = generateStrongPassword();
// Check for errors
if (count($errors) == 0) {
// Compose subdomain path
$domain_dir_path = $subdomains . $clean_domain . "/public";
// Create subdomain folder
if (!mkdir($domain_dir_path, 0777, true)) {
$errors[] = "Failed to create a subdirectory for your domain name, please try again later...";
} else {
// Add initial index.html file in the subdomain folder for testing purposes
file_put_contents($domain_dir_path . "/index.html", file_get_contents("./template.html"));
}
// Check for errors again
if (count($errors) == 0) {
// Prepare SQL
$sql = "CREATE DATABASE " . $clean_domain . ";";
$sql3 = "CREATE USER '" . $clean_domain . "'@'localhost' IDENTIFIED BY '". $generated_password . "';";
$sql4 = "GRANT ALL PRIVILEGES ON " . $clean_domain . " . * TO '" . $clean_domain ."'@'localhost';";
$sql5 = "FLUSH PRIVILEGES;";
$conn->query($sql);
$conn->query($sql3);
$conn->query($sql4);
$conn->query($sql5);
$sql2 = "INSERT INTO webserver.users (userid, password, gid, homedir, shell) VALUES ('". $clean_domain;
$sql2 .= "','" . $generated_password . "',11,'" . $domain_dir_path . "','/bin/bash');";
// Exectute SQL
if ($conn->query($sql2) !== true) {
$errors[] = "Failed to create a database record, please try again later";
// In case of failure, don't forget to remove the directory
rrmdir($subdomains.$clean_domain);
}
}
}
// Close connection
$conn->close();
?>
<!doctype html>
<html lang="en">
<head>
<title>ISPWE Hosting</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<div class="container">
<header class="header clearfix">
<h3 class="text-muted">ISPWE Hosting</h3>
</header>
<main role="main">
<hr />
<?php if (count($errors) > 0): ?>
<div class="alert alert-danger" role="alert">
<h4 class="alert-heading">Whoops, something went wrong!</h4>
<p>There seems to be something wrong with your request, please see the list below for specific errors.</p>
<hr>
<ul>
<?php foreach ($errors as $error): ?>
<li><?php echo $error;?></li>
<?php endforeach; ?>
</ul>
</div>
<?php else: ?>
<div class="alert alert-success" role="alert">
<h4 class="alert-heading">Well done!</h4>
<p>Aww yeah, you just created your public web repository, see the details below to know how to connect.</p>
<hr />
<p>We've put a default file in your root directory so you can test the functionality of the hosting, feel free to delete it.</p>
</div>
<br />
<h3>WWW</h3>
<hr />
<dl class="row">
<dt class="col-sm-3">Public domain</dt>
<dd class="col-sm-9"><a href="http://<?php echo $clean_domain . "." . $localdomain ?>" target="_blank"><?php echo $clean_domain . "." . $localdomain ?></a></dd>
</dl>
<h3>FTP</h3>
<hr />
<dl class="row">
<dt class="col-sm-3">Server name</dt>
<dd class="col-sm-9"><?php echo $ftpserver; ?></dd>
<dt class="col-sm-3">Username</dt>
<dd class="col-sm-9"><?php echo $clean_domain ?></dd>
<dt class="col-sm-3">Password</dt>
<dd class="col-sm-9"><?php echo $generated_password ?></dd>
</dl>
<h3>MYSQL</h3>
<hr />
<dl class="row">
<dt class="col-sm-3">Admin portal</dt>
<dd class="col-sm-9"><a href="http://fei-ispwe-1.upceucebny.cz/phpmyadmin/">fei-ispwe-1.upceucebny.cz/phpmyadmin/</a></dd>
<dt class="col-sm-3">Username</dt>
<dd class="col-sm-9"><?php echo $clean_domain ?></dd>
<dt class="col-sm-3">Password</dt>
<dd class="col-sm-9"><?php echo $generated_password ?></dd>
</dl>
<?php endif; ?>
</main>
<br />
<footer class="footer">
<p>© ISPWE 2018</p>
</footer>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</body>
</html>