This repository was archived by the owner on Jan 14, 2022. It is now read-only.
forked from sayakb/sticky-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
executable file
·136 lines (115 loc) · 5.09 KB
/
install.php
File metadata and controls
executable file
·136 lines (115 loc) · 5.09 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* Sticky Notes pastebin
* @ver 0.3
* @license BSD License - www.opensource.org/licenses/bsd-license.php
*
* Copyright (c) 2012 Sayak Banerjee <sayakb@kde.org>
* All rights reserved. Do not remove this copyright notice.
*/
// Define constants
define('IN_INSTALL', true);
// Include necessary files
include_once('init.php');
/* COMMENT OUT WHEN INSTALLING */
/* UNCOMMENT ONCE INSTALLING IS COMPLETED */
$gsod->trigger('Install file locked. Check out the README file for installation instructions.');
// Check is config file is present
if (!file_exists(realpath('config.php')))
{
$gsod->trigger('Config file not found. Please rename config.sample.php to ' .
'config.php and make it writable.');
}
// Check if the config file is writable
if (!is_writable(realpath('config.php')))
{
$gsod->trigger('Config file is not writable. Please adjust the permissions ' .
'to start installation.');
}
// Check if DB data is set
$db_fields = array($config->db_host, $config->db_name, $config->db_username,
$config->db_password, $config->db_prefix);
foreach ($db_fields as $field)
{
if (empty($field))
{
$gsod->trigger('One or more database options have not been set in the config file.');
}
}
// Check if the tables already exist
$sql = "SHOW TABLES LIKE '{$db->prefix}%'";
$rows = $db->query($sql);
if (!empty($rows) && count($rows) > 0)
{
$gsod->trigger('One or more tables already exist in the specified database. '.
'Please drop them to start installation.');
}
// Create the config file
$config->create($config->db_host, $config->db_port, $config->db_name,
$config->db_username, $config->db_password, $config->db_prefix);
// Create the table structure
$db->query("CREATE TABLE IF NOT EXISTS {$db->prefix}main (" .
"id INT(12) UNSIGNED NOT NULL AUTO_INCREMENT, " .
"author VARCHAR(50) DEFAULT '', " .
"project VARCHAR(50) DEFAULT '', " .
"timestamp INT(11) UNSIGNED NOT NULL, " .
"expire INT(11) UNSIGNED NOT NULL, " .
"data MEDIUMTEXT NOT NULL, " .
"language VARCHAR(50) NOT NULL DEFAULT 'php', " .
"password VARCHAR(40) NOT NULL, " .
"salt VARCHAR(5) NOT NULL, " .
"private TINYINT(1) NOT NULL DEFAULT 0, " .
"hash INT(12) UNSIGNED NOT NULL, " .
"ip VARCHAR(50) NOT NULL, " .
"PRIMARY KEY(id))");
$db->query("CREATE TABLE IF NOT EXISTS {$db->prefix}session (" .
"sid VARCHAR(40) NOT NULL, " .
"timestamp INT(11) UNSIGNED NOT NULL, " .
"PRIMARY KEY(sid))");
$db->query("CREATE TABLE IF NOT EXISTS {$db->prefix}cron (" .
"timestamp INT(11) UNSIGNED NOT NULL DEFAULT 0, " .
"locked TINYINT(1) NOT NULL DEFAULT 0)");
$db->query("CREATE TABLE IF NOT EXISTS {$db->prefix}users (" .
"id INT(12) UNSIGNED NOT NULL AUTO_INCREMENT, " .
"username VARCHAR(50) NOT NULL, " .
"password VARCHAR(40) NOT NULL, " .
"salt VARCHAR(5) NOT NULL, " .
"email VARCHAR(100) NOT NULL, " .
"dispname VARCHAR(100) DEFAULT '', " .
"sid VARCHAR(40) DEFAULT '', " .
"lastlogin INT(11) UNSIGNED DEFAULT 0, " .
"PRIMARY KEY(id))");
$db->query("CREATE TABLE IF NOT EXISTS {$db->prefix}ipbans (" .
"ip VARCHAR(50) NOT NULL, " .
"PRIMARY KEY(ip))");
// Add index and charset data
$db->query("ALTER TABLE {$db->prefix}main DEFAULT CHARACTER SET utf8");
$db->query("ALTER TABLE {$db->prefix}main CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
$db->query("ALTER TABLE {$db->prefix}main AUTO_INCREMENT = 1000");
$db->query("CREATE INDEX {$db->prefix}idx_private ON {$db->prefix}main(id, private)");
$db->query("CREATE INDEX {$db->prefix}idx_author ON {$db->prefix}main(id, author)");
$db->query("CREATE INDEX {$db->prefix}idx_project ON {$db->prefix}main(id, project)");
$db->query("CREATE INDEX {$db->prefix}idx_data ON {$db->prefix}main(id, data)");
$db->query("CREATE INDEX {$db->prefix}idx_sid ON {$db->prefix}session(sid)");
$db->query("CREATE INDEX {$db->prefix}idx_adminuser ON {$db->prefix}users(username)");
$db->query("CREATE INDEX {$db->prefix}idx_adminsid ON {$db->prefix}users(sid)");
// Fill in empty values to cron table
$db->query("INSERT INTO {$db->prefix}cron VALUES (0, 0)");
// Generate a salt and password
$salt = substr(sha1(time()), rand(0, 34), 5);
$password = substr(sha1(sha1(time())), rand(0, 31), 8);
$hash = sha1($password . $salt);
// Add the default admin user
$sql = "INSERT INTO {$db->prefix}users " .
"(username, password, salt, email) " .
"VALUES ('admin', '{$hash}', '{$salt}', 'admin@sticky.notes')";
$db->query($sql);
// Done!
$gsod->trigger(
"Successfully installed! You can log in to the admin panel with the following credentials:" .
"<ul><li>Username: <b>admin</b></li>" .
"<li>Password: <b>{$password}</b></li></ul>" .
"Please make a note of this password. You can change it from the User Management section of " .
"the <a href=\"../admin/\">admin panel</a>."
);
?>