-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddUser.php
executable file
·60 lines (47 loc) · 1.25 KB
/
addUser.php
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
#!/usr/bin/php
<?php
$appDir = dirname(__FILE__);
require_once($appDir.'/config.php');
print "User / Servername: ";
$user = trim(fgets(STDIN));
print "Password: ";
system('stty -echo');
$password = password_hash(trim(fgets(STDIN)), PASSWORD_BCRYPT);
// Alternative: htpasswd -nB
system('stty echo');
// add a new line since the users CR didn't echo
print "\n";
$upload = -1;
while ($upload < 0 or $upload > 1) {
print "Upload (1 for yes, 0 for no): ";
$input = trim(fgets(STDIN));
if (is_numeric($input)) {
$upload = intval($input);
}
}
$view = -1;
while ($view < 0 or $view > 1) {
print "View (1 for yes, 0 for no): ";
$input = trim(fgets(STDIN));
if (is_numeric($input)) {
$view = intval($input);
}
}
$query = <<<SQL
INSERT INTO user (user, hash, upload, view)
VALUES ('$user', '$password', $upload, $view);
SQL;
print "$query\n\n";
// Create connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DB);
// Check connection
if ($conn->connect_error) {
print 'MySQL connection failed: ' . $conn->connect_error . "\n\n";
die();
}
$result = $conn->query($query);
if (!$result) {
print 'MySQL INSERT error message: ' . $conn->error . "\n" . $query . "\n\n");
die();
}
print "User added!\n\n";