-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
120 lines (109 loc) · 4.62 KB
/
install.php
File metadata and controls
120 lines (109 loc) · 4.62 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
<?PHP
/*
--------------------------------------------------------
ChiliStats(Revived) is based on the original code from Adam Pawlita (https://pawlita.de)
Currently maintained by KuJoe (https://github.com/KuJoe/ChiliStats/)
--------------------------------------------------------
Original Copyright Notice:
The script is protected by copyright law. All rights and
copyrights are held by the author: Adam Pawlita
This script may be freely used and redistributed so long
the stated copyright notices in all parts of the script before-
hands remain. For correct operation, or damage caused by
the operation of this script is made only if the author has no
Warranty. Commissioning is carried out in each case
at their own risk of the operator.
-------------------------------------------------------
*/
$filename = 'LOCKED';
if (file_exists($filename)) {
die("The directory is locked. Please delete the LOCKED file if you are sure you need to run the install.php file (this might overwrite existing data in the database if it exists).");
}
require_once('config.php');
function generateRandomString($length = 16) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$username = "admin";
$password = generateRandomString();
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
try {
$conn = new PDO("sqlite:$db_file_path");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "<font color=\"#00CC00\">- The SQLite database connection was established successfully!</font><br>";
$tables = [
'days' => "CREATE TABLE days (
day_id INTEGER PRIMARY KEY AUTOINCREMENT,
day TEXT NOT NULL DEFAULT '',
user INTEGER NOT NULL DEFAULT 0,
view INTEGER NOT NULL DEFAULT 0
)",
'visitors' => "CREATE TABLE visitors (
visitor_id INTEGER PRIMARY KEY AUTOINCREMENT,
ipaddr TEXT NOT NULL DEFAULT '',
time INTEGER NOT NULL DEFAULT 0,
online INTEGER NOT NULL DEFAULT 0
)",
'languages' => "CREATE TABLE languages (
lang_id INTEGER PRIMARY KEY AUTOINCREMENT,
day TEXT NOT NULL DEFAULT '',
language TEXT NOT NULL DEFAULT '',
view INTEGER NOT NULL DEFAULT 0
)",
'pages' => "CREATE TABLE pages (
page_id INTEGER PRIMARY KEY AUTOINCREMENT,
day TEXT NOT NULL DEFAULT '',
page TEXT NOT NULL DEFAULT '',
view INTEGER NOT NULL DEFAULT 0
)",
'staff' => "CREATE TABLE staff (
staff_id INTEGER PRIMARY KEY AUTOINCREMENT,
staff_username TEXT NOT NULL DEFAULT '',
staff_email TEXT NOT NULL DEFAULT '',
staff_password TEXT NOT NULL DEFAULT 0,
staff_active INTEGER NOT NULL DEFAULT 0,
staff_rememberme_token TEXT NOT NULL DEFAULT 0,
seckey TEXT NOT NULL DEFAULT '',
staff_ip TEXT NOT NULL DEFAULT 0,
staff_lastlogin TEXT NULL DEFAULT NULL,
staff_failed_logins INTEGER NOT NULL DEFAULT 0,
staff_locked DATETIME NOT NULL DEFAULT '1970-01-01 00:00:01',
unique_token TEXT NULL DEFAULT NULL
)"
];
foreach ($tables as $name => $sql) {
$stmt = $conn->prepare($sql);
$stmt->execute();
echo "<font color=\"#00CC00\">- Table ".$name." was created successfully!<br>";
}
$sql = "INSERT INTO staff (staff_username, staff_password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $hashedPassword);
$stmt->execute();
echo "Username: " . $username . "<br />";
echo "Password: " . $password . "<br />";
} catch(PDOException $e) {
echo "<font color=\"#CC0000\">- " . $e->getMessage() . "</font><br>";
}
$file = fopen('LOCKED', 'w');
if ($file == false) {
echo "<font color=\"#CC0000\">- Unable to lock the directory to prevent the install.php script from being run again. Either manually create a file named <strong>LOCKED</strong> in this directory or delete the install.php to be safe.</font><br>";
} else {
echo "<font color=\"#00CC00\">- Lock file created to prevent the install.php file from being run again. You can delete the install.php file just to safe.<br>";
fclose($file);
}
?>
<p>
Copy and Paste: <br />
<textarea name="textfield" cols="80" rows="5" wrap="off" readonly="readonly"><script type="text/javascript">
document.write('<img src="chilistats/counter.php?ref=' + escape(document.referrer) + '">')
</script>
<noscript><img src="chilistats/counter.php" /></noscript></textarea>
</p>
<div id="footer"><a href="https://github.com/KuJoe/ChiliStats/" target="_blank" ><img src="github.svg" width="24" height="24" alt="GitHub Logo" title="ChiliStats(Revived)" /></a></div>