-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
89 lines (69 loc) · 2.36 KB
/
start.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require __DIR__.'/bootstrap/autoload.php';
$servername = 'localhost';
$username = $_POST['db_user'];
$password = $_POST['db_pass'];
$dbname = $_POST['db_name'];
$app_name = $_POST['app_name'];
$email = $_POST['email'];
$hash = password_hash($_POST["password"], PASSWORD_BCRYPT,
array('cost' => 10));
// $content = [
// 29 => "'default' => 'mysql',",
// 74 => "'host' => 'localhost',",
// 75 => "'database' => '$dbname',",
// 76 => "'username' => '$username',",
// 77 => "'password' => '$password',",
// ];
$content = [
7 => "DB_DATABASE=$dbname",
8 => "DB_USERNAME=$username",
9 => "DB_PASSWORD=$password"
];
function edit($content){
$filename = __DIR__.'/.env';
// chmod($filename, 0777);
foreach($content as $line => $modifiedContent ) {
$line_i_am_looking_for = $line-1;
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
$lines[$line_i_am_looking_for] = $modifiedContent;
file_put_contents( $filename , implode( "\n", $lines ) );
}
}
edit($content);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to create table
$sql = "devless_production.sql";
$templine = '';
$lines = file($sql);
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
if ($conn->query($templine) != TRUE) {
echo "Error creating tables: " . $conn->error;
}
$templine = '';
}
}
$db = "INSERT INTO users (email, password, role, status)
VALUES ('$email', '$hash', 1, 0);";
$db .= "INSERT INTO apps (name)
VALUES ('$app_name');";
$conn->multi_query($db);
$conn->close();
header("Location: http://".$_SERVER["HTTP_HOST"].'/'
.str_replace("/start.php", "", $_SERVER["REQUEST_URI"]).'/index.php');
unlink('index.html');
unlink('start.php');