-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
100 lines (87 loc) · 2.7 KB
/
setup.php
File metadata and controls
100 lines (87 loc) · 2.7 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
<?php
$DB_host = "";
$DB_user = "";
$DB_pass = "";
$DB_name = "";
$charset = "utf8";
try
{
$DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name};charset={$charset}",$DB_user,$DB_pass);
$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "setup.php: Connected successfully to database.";
}
catch(PDOException $e)
{
echo "setup.php: Connection to database failed: " . $e->getMessage();
}
$createuserstable = "
CREATE TABLE `Users` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Username` varchar(255) NOT NULL,
`DiscordName` varchar(255) DEFAULT NULL,
`Password` varchar(255) NOT NULL,
`Role` enum('Admin','Moderator','User') NOT NULL DEFAULT 'User',
`Reputation` int(11) DEFAULT NULL,
`Last_Login` datetime NOT NULL,
`ExpireDate` date NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `Username` (`Username`)
) ENGINE=MyISAM AUTO_INCREMENT=37 DEFAULT CHARSET=latin1
";
$createiptable = "
CREATE TABLE `HackersIP` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`IP` varchar(15) NOT NULL,
`Name` varchar(255) NOT NULL,
`Added_By` varchar(255) DEFAULT NULL,
`Reputation` int(11) DEFAULT NULL,
`Clan` varchar(10) DEFAULT NULL,
`Last_Updated` date NOT NULL,
`Miners` int(11) DEFAULT NULL,
`Description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=36 DEFAULT CHARSET=latin1
";
$createapitokentable = "
CREATE TABLE `APIToken` (
`UserID` int(11) NOT NULL,
`Token` varchar(50) NOT NULL,
PRIMARY KEY (`Token`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
";
$createfavoritetable = "
CREATE TABLE `IPUserFav` (
`UserID` int(11) NOT NULL,
`IPID` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
";
$createreporttable = "
CREATE TABLE `IPUserReport` (
`UserID` int(11) NOT NULL,
`IPID` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
";
$stmt = $DB_con->prepare($createuserstable);
$stmt->execute();
$stmt = $DB_con->prepare($createiptable);
$stmt->execute();
$stmt = $DB_con->prepare($createfavoritetable);
$stmt->execute();
$stmt = $DB_con->prepare($createreporttable);
$stmt->execute();
$stmt = $DB_con->prepare($createapitokentable);
$stmt->execute();
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$password = '';
for ($i = 0; $i < 10; $i++) {
$password .= $characters[rand(0, $charactersLength - 1)];
}
$new_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $DB_con->prepare("INSERT INTO `Users`(Username, Password, Role) VALUES(:uname, :upass, 'Admin')");
$admin = "admin";
$stmt->bindparam(":uname", $admin);
$stmt->bindparam(":upass", $new_password);
$stmt->execute();
echo "Ein Admin-Account wurde erstellt! <br> Name: admin <br> Password: {$password}";
return $stmt;