-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate1.php
executable file
·73 lines (56 loc) · 2.27 KB
/
create1.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php session_start();
$db_config = array(
'server' => 'localhost',
'username' => $_POST["rootuser"],
'password' => $_POST["rootpwd"]
);
$conn = new mysqli($db_config['server'], $db_config['username'], $db_config['password']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sqlScript = file('ospota.sql');
foreach ($sqlScript as $line) {
$startWith = substr(trim($line), 0 ,2);
$endWith = substr(trim($line), -1 ,1);
if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') {
continue;
}
$query = $query . $line;
if ($endWith == ';') {
mysqli_query($conn,$query) or die('<div class="error-response sql-import-response">Problem in executing the SQL query <b>' . $query. '</b></div>');
$query= '';
}
}
$query = "DROP USER IF EXISTS '" . $_POST["logginguser"] ."'@'%';";
mysqli_query($conn,$query);
$query = "CREATE USER '" . $_POST["logginguser"] . "'@'%' IDENTIFIED BY '" . $_POST["loggingpwd"] . "';";
mysqli_query($conn,$query);
$query = "GRANT ALL PRIVILEGES ON ospotalog.* TO '" . $_POST["logginguser"] ."'@'%';";
mysqli_query($conn,$query);
$query = "FLUSH PRIVILEGES;";
mysqli_query($conn,$query);
//print "Database created";
$linefeed = "\n";
$text = "<?php session_start();" . $linefeed;
$text .= $linefeed;
$text .= '$db_config = array(' . $linefeed;
$text .= " 'server' => 'localhost'," . $linefeed;
$text .= " 'username' => '" . $_POST["logginguser"] . "'," . $linefeed;
$text .= " 'password' => '" . $_POST["loggingpwd"] . "'," . $linefeed;
$text .= " 'dbname' => 'ospotalog'" . $linefeed;
$text .= ");" . $linefeed;
$text .= $linefeed;
$text .= '$conn' . " = new mysqli(" . '$db_config' . "['server'], " . '$db_config' . "['username'], " . '$db_config' . "['password'], " . '$db_config' . "['dbname']);" . $linefeed;
$text .= $linefeed;
$text .= "if (" . '$conn' . "->connect_error) {" . $linefeed;
$text .= ' die("Connection failed: " . $conn->connect_error);' . $linefeed;
$text .= "}" . $linefeed;
$text .= $linefeed;
$text .= "?>" . $linefeed;
$dir = getcwd() . "/";
$filename = "db_config.php";
$myfile = fopen($dir . $filename, "w") or die("Unable to open file!");
fwrite($myfile, $text);
fclose($myfile);
header("location: index.php");
?>