-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.php
179 lines (117 loc) · 4.94 KB
/
setup.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?
//error_reporting(-1);
//ini_set('display_errors',1);
//ini_set('display_startup_errors',1);
error_reporting (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
// Turnoff all error reporting
//error_reporting(0);
//ini_set('display_errors', 0);
//ini_set('log_errors', 0);
require('config.php');
printf("<BR><BR>=== STAMMTISCH SETUP ====<BR><BR>");
function opendb() {
global $WEBMASTER;
global $DBUSER;
global $DBPWD;
global $DBURL;
$dbs = @mysql_connect($DBURL,$DBUSER,$DBPWD);
if(!$dbs) { echo '-CANNOT ACCESS DATABASESERVER, PLEASE CONTACT THE SYSTEM ADMINISTARTOR AT '.$WEBMASTER; exit;}
return $dbs;
}
$connection = opendb();
$db = 0;
if ($connection) $db = mysql_select_db($DBNAME,$connection);
if($db) {
echo '-SETUP HAS ALREADY RUN, PLEASE CONTACT THE SYSTEM ADMINISTARTOR AT '.$WEBMASTER;
exit;
}
// Create database
$sql = "CREATE DATABASE ".$DBNAME;
echo "Creating Database... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED, DO MANUALLY:<BR>".htmlentities($sql)."<BR>";}
//$success = mysql_query($sql);
if ($connection) $db = mysql_select_db($DBNAME,$connection);
if(!$db) {
echo "Error creating database. Is the db already created? Has user '".$DBUSER."' enough rights to create a DB? Is the password correct?";
exit;
} else {
echo "Database created successfully.<BR>";
}
echo "<BR><BR>Now creating tables...<BR><BR>";
$sql = 'CREATE TABLE IF NOT EXISTS `confirm` ('
. ' `uid` INT NOT NULL, '
. ' `mid` INT NOT NULL, '
. ' `confirmed` VARCHAR(50) NOT NULL, '
. ' `phone` INT NOT NULL, '
. ' `comment` VARCHAR(200) NOT NULL '
. ' )';
echo "confirm... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED, DO MANUALLY:<BR>".htmlentities($sql)."<BR>";}
$sql = 'CREATE TABLE IF NOT EXISTS `rating` ('
. ' `mid` INT NOT NULL, '
. ' `uid` INT NOT NULL, '
. ' `rating` INT NOT NULL, '
. ' `timestamp` VARCHAR(50) NOT NULL '
. ' )';
echo "rating... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED, DO MANUALLY:<BR>".htmlentities($sql)."<BR>";}
$sql = 'CREATE TABLE IF NOT EXISTS `meeting` ('
. ' `mid` INT NOT NULL AUTO_INCREMENT, '
. ' `date` VARCHAR(50) NOT NULL, '
. ' `sid` INT NOT NULL, '
. ' `invited` VARCHAR(50) NOT NULL, '
. ' `reminded` VARCHAR(50) NOT NULL, '
. ' PRIMARY KEY (`mid`)'
. ' )';
echo "meeting... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED, DO MANUALLY:<BR>".htmlentities($sql)."<BR>";}
$sql = 'CREATE TABLE IF NOT EXISTS `session` ('
. ' `uid` INT NOT NULL, '
. ' `sessionid` VARCHAR(200) NOT NULL, '
. ' `created` VARCHAR(50) NOT NULL, '
. ' `ip` VARCHAR(20) NOT NULL, '
. ' `browser` VARCHAR(200) NOT NULL '
. ' )';
echo "session... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED, DO MANUALLY:<BR>".htmlentities($sql)."<BR>";}
$sql = 'CREATE TABLE IF NOT EXISTS `suggestion` ('
. ' `sid` INT NOT NULL AUTO_INCREMENT, '
. ' `name` VARCHAR(50) NOT NULL, '
. ' `address` VARCHAR(200) NOT NULL, '
. ' `uid` INT NOT NULL, '
. ' `suggested` VARCHAR(50) NOT NULL, '
. ' `chosen` VARCHAR(50) NOT NULL, '
. ' PRIMARY KEY (`sid`)'
. ' )';
echo "suggestion... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED, DO MANUALLY:<BR>".htmlentities($sql)."<BR>";}
$sql = 'CREATE TABLE IF NOT EXISTS `user` ('
. ' `uid` INT NOT NULL AUTO_INCREMENT, '
. ' `name` VARCHAR(50) NOT NULL, '
. ' `pwd` VARCHAR(100) NOT NULL, '
. ' `email` VARCHAR(50) NOT NULL, '
. ' `registered` VARCHAR(50) NOT NULL, '
. ' `lastseen` VARCHAR(50) NOT NULL, '
. ' `invited` INT NOT NULL, '
. ' `admin` INT NOT NULL, '
. ' PRIMARY KEY (`uid`)'
. ' )';
echo "user... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED, DO MANUALLY:<BR>".htmlentities($sql)."<BR>";}
$sql = 'CREATE TABLE IF NOT EXISTS `knowndevices` ('
. ' `created` VARCHAR(20) NOT NULL, '
. ' `uid` INT NOT NULL, '
. ' `device` VARCHAR(4) NOT NULL'
. ' )';
$sql = 'CREATE TABLE IF NOT EXISTS `vote` ('
. ' `sid` INT NOT NULL, '
. ' `uid` INT NOT NULL, '
. ' `voted` VARCHAR(50) NOT NULL '
. ' )';
echo "vote... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED, DO MANUALLY:<BR>".htmlentities($sql)."<BR>";}
$sql = "GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , INDEX , ALTER ON `".$DBNAME."` . * TO '".$DBUSER."'@'".$DBURL."';";
echo "<BR>Granting permissions... ";
if (mysql_query($sql)) {echo "OK<BR>";} else {echo "FAILED<BR>".htmlentities($sql)."<BR>";}
printf("<BR><BR>Setup completed. You should delete the file 'setup.php' immediately.");
?>