· 7 years ago · Oct 20, 2018, 05:40 PM
1<?PHP
2define('INITIALIZED', true);
3define('ONLY_PAGE', false);
4
5
6$time_start = microtime(true);
7session_start();
8
9function autoLoadClass($className)
10{
11 if(!class_exists($className))
12 if(file_exists('./classes/' . strtolower($className) . '.php'))
13 include_once('./classes/' . strtolower($className) . '.php');
14 else
15 new Error_Critic('#E-7', 'Cannot load class <b>' . $className . '</b>, file <b>./classes/class.' . strtolower($className) . '.php</b> doesn\'t exist');
16}
17spl_autoload_register('autoLoadClass');
18
19//load acc. maker config to $config['site']
20$config = array();
21include('./config/config.php');
22if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
23{
24 $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
25 while(list($key, $val) = each($process))
26 {
27 foreach ($val as $k => $v)
28 {
29 unset($process[$key][$k]);
30 if(is_array($v))
31 {
32 $process[$key][stripslashes($k)] = $v;
33 $process[] = &$process[$key][stripslashes($k)];
34 }
35 else
36 $process[$key][stripslashes($k)] = stripslashes($v);
37 }
38 }
39 unset($process);
40}
41
42
43
44$page = '';
45if(isset($_REQUEST['page']))
46 $page = $_REQUEST['page'];
47$step = 'start';
48if(isset($_REQUEST['step']))
49 $step = $_REQUEST['step'];
50// load server path
51function getServerPath()
52{
53 $config = array();
54 include('./config/config.php');
55 return $config['site']['serverPath'];
56}
57// save server path
58function setServerPath($newPath)
59{
60 $file = fopen("./config/config.php", "r");
61 $lines = array();
62 while (!feof($file)) {
63 $lines[] = fgets($file);
64 }
65 fclose($file);
66
67 $newConfig = array();
68 foreach ($lines as $i => $line)
69 {
70 if(substr($line, 0, strlen('$config[\'site\'][\'serverPath\']')) == '$config[\'site\'][\'serverPath\']')
71 $newConfig[] = '$config[\'site\'][\'serverPath\'] = "' . str_replace('"', '\"' , $newPath) . '";' . PHP_EOL; // do something with each line from text file here
72 else
73 $newConfig[] = $line;
74 }
75 Website::putFileContents("./config/config.php", implode('', $newConfig));
76}
77if($page == '')
78{
79 echo '<html>
80 <head>
81 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
82 <title>Installation of account maker</title>
83 </head>
84 <frameset cols="230,*">
85 <frame name="menu" src="install.php?page=menu" />
86 <frame name="step" src="install.php?page=step&step=start" />
87 <noframes><body>Frames don\'t work. Install Firefox :P</body></noframes>
88 </frameset>
89 </html>';
90}
91elseif($page == 'menu')
92{
93 echo '<h2>MENU</h2><br>
94 <b>IF NOT INSTALLED:</b><br>
95 <a href="install.php?page=step&step=start" target="step">0. Informations</a><br>
96 <a href="install.php?page=step&step=1" target="step">1. Set server path</a><br>
97 <a href="install.php?page=step&step=2" target="step">2. Check DataBase connection</a><br>
98 <a href="install.php?page=step&step=3" target="step">3. Add tables and columns to DB</a><br>
99 <a href="install.php?page=step&step=4" target="step">4. Add samples to DB</a><br>
100 <a href="install.php?page=step&step=5" target="step">5. Set Admin Account</a><br>
101 <b>Author:</b><br>
102 Gesior<br>
103 Compatible with TFS 0.4 rev. 3703+</a>';
104}
105elseif($page == 'step')
106{
107 if($step >= 2 && $step <= 5)
108 {
109 //load server config $config['server']
110 if(Website::getWebsiteConfig()->getValue('useServerConfigCache'))
111 {
112 // use cache to make website load faster
113 if(Website::fileExists('./config/server.config.php'))
114 {
115 $tmp_php_config = new ConfigPHP('./config/server.config.php');
116 $config['server'] = $tmp_php_config->getConfig();
117 }
118 else
119 {
120 // if file isn't cache we should load .lua file and make .php cache
121 $tmp_lua_config = new ConfigLUA(Website::getWebsiteConfig()->getValue('serverPath') . 'config.lua');
122 $config['server'] = $tmp_lua_config->getConfig();
123 $tmp_php_config = new ConfigPHP();
124 $tmp_php_config->setConfig($tmp_lua_config->getConfig());
125 $tmp_php_config->saveToFile('./config/server.config.php');
126 }
127 }
128 else
129 {
130 $tmp_lua_config = new ConfigLUA(Website::getWebsiteConfig()->getValue('serverPath') . 'config.lua');
131 $config['server'] = $tmp_lua_config->getConfig();
132 }
133 if(Website::getServerConfig()->isSetKey('mysqlHost'))
134 {
135 define('SERVERCONFIG_SQL_TYPE', 'sqlType');
136 define('SERVERCONFIG_SQL_HOST', 'mysqlHost');
137 define('SERVERCONFIG_SQL_PORT', 'mysqlPort');
138 define('SERVERCONFIG_SQL_USER', 'mysqlUser');
139 define('SERVERCONFIG_SQL_PASS', 'mysqlPass');
140 define('SERVERCONFIG_SQL_DATABASE', 'mysqlDatabase');
141 define('SERVERCONFIG_SQLITE_FILE', 'sqlFile');
142 }
143 elseif(Website::getServerConfig()->isSetKey('sqlHost'))
144 {
145 define('SERVERCONFIG_SQL_TYPE', 'sqlType');
146 define('SERVERCONFIG_SQL_HOST', 'sqlHost');
147 define('SERVERCONFIG_SQL_PORT', 'sqlPort');
148 define('SERVERCONFIG_SQL_USER', 'sqlUser');
149 define('SERVERCONFIG_SQL_PASS', 'sqlPass');
150 define('SERVERCONFIG_SQL_DATABASE', 'sqlDatabase');
151 define('SERVERCONFIG_SQLITE_FILE', 'sqlFile');
152 }
153 else
154 new Error_Critic('#E-3', 'There is no key <b>sqlHost</b> or <b>mysqlHost</b> in server config', array(new Error('INFO', 'use server config cache: <b>' . (Website::getWebsiteConfig()->getValue('useServerConfigCache') ? 'true' : 'false') . '</b>')));
155 if(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_TYPE) == 'mysql')
156 {
157 Website::setDatabaseDriver(Database::DB_MYSQL);
158 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_HOST))
159 Website::getDBHandle()->setDatabaseHost(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_HOST));
160 else
161 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_HOST . '</b> in server config file.');
162 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PORT))
163 Website::getDBHandle()->setDatabasePort(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PORT));
164 else
165 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_PORT . '</b> in server config file.');
166 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_DATABASE))
167 Website::getDBHandle()->setDatabaseName(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_DATABASE));
168 else
169 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_DATABASE . '</b> in server config file.');
170 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_USER))
171 Website::getDBHandle()->setDatabaseUsername(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_USER));
172 else
173 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_USER . '</b> in server config file.');
174 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PASS))
175 Website::getDBHandle()->setDatabasePassword(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PASS));
176 else
177 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_PASS . '</b> in server config file.');
178 }
179 elseif(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_TYPE) == 'sqlite')
180 {
181 Website::setDatabaseDriver(Database::DB_SQLITE);
182 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQLITE_FILE))
183 Website::getDBHandle()->setDatabaseFile(Website::getServerConfig()->getValue(SERVERCONFIG_SQLITE_FILE));
184 else
185 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQLITE_FILE . '</b> in server config file.');
186 }
187 elseif(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_TYPE) == 'pgsql')
188 {
189 // does pgsql use 'port' parameter? I don't know
190 Website::setDatabaseDriver(Database::DB_PGSQL);
191 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_HOST))
192 Website::getDBHandle()->setDatabaseHost(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_HOST));
193 else
194 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_HOST . '</b> in server config file.');
195 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_DATABASE))
196 Website::getDBHandle()->setDatabaseName(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_DATABASE));
197 else
198 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_DATABASE . '</b> in server config file.');
199 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_USER))
200 Website::getDBHandle()->setDatabaseUsername(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_USER));
201 else
202 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_USER . '</b> in server config file.');
203 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PASS))
204 Website::getDBHandle()->setDatabasePassword(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PASS));
205 else
206 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_PASS . '</b> in server config file.');
207 }
208 else
209 new Error_Critic('#E-6', 'Database error. Unknown database type in <b>server config</b> . Must be equal to: "<b>mysql</b>", "<b>sqlite</b>" or "<b>pgsql</b>" . Now is: "<b>' . Website::getServerConfig()->getValue(SERVERCONFIG_SQL_TYPE) . '</b>"');
210 Website::setPasswordsEncryption(Website::getServerConfig()->getValue('encryptionType'));
211 $SQL = Website::getDBHandle();
212 }
213
214 if($step == 'start')
215 {
216 echo '<h1>STEP '.$step.'</h1>Informations<br>';
217 echo 'Welcome to Gesior Account Maker installer. <b>After 5 simple steps account maker will be ready to use!</b><br />';
218 // check access to write files
219 $writeable = array('config/config.php', 'cache', 'cache/flags', 'cache/DONT_EDIT_usercounter.txt', 'cache/DONT_EDIT_serverstatus.txt', 'custom_scripts', 'install.txt');
220 foreach($writeable as $fileToWrite)
221 {
222 if(is_writable($fileToWrite))
223 echo '<span style="color:green">CAN WRITE TO FILE: <b>' . $fileToWrite . '</b></span><br />';
224 else
225 echo '<span style="color:red">CANNOT WRITE TO FILE: <b>' . $fileToWrite . '</b> - edit file access for PHP [on linux: chmod]</span><br />';
226 }
227 }
228 elseif($step == 1)
229 {
230 if(isset($_REQUEST['server_path']))
231 {
232 echo '<h1>STEP '.$step.'</h1>Check server configuration<br>';
233 $path = $_REQUEST['server_path'];
234 $path = trim($path)."\\";
235 $path = str_replace("\\\\", "/", $path);
236 $path = str_replace("\\", "/", $path);
237 $path = str_replace("//", "/", $path);
238 setServerPath($path);
239 $tmp_lua_config = new ConfigLUA($path . 'config.lua');
240 $config['server'] = $tmp_lua_config->getConfig();
241 if(isset($config['server']['sqlType']))
242 {
243 echo 'File <b>config.lua</b> loaded from <font color="red"><i>'.$path.'config.lua</i></font>. It looks like fine server config file. Now you can check database('.$config['server']['sqlType'].') connection: <a href="install.php?page=step&step=2">STEP 2 - check database connection</a>';
244 }
245 else
246 {
247 echo 'File <b>config.lua</b> loaded from <font color="red"><i>'.$path.'config.lua</i></font> and it\'s not valid TFS config.lua file. <a href="install.php?page=step&step=1">Go to STEP 1 - select other directory.</a> If it\'s your config.lua file from TFS contact with acc. maker author.';
248 }
249 }
250 else
251 {
252 echo 'Please write you TFS directory below. Like: <i>C:\Documents and Settings\Gesior\Desktop\TFS 0.2.9\</i><form action="install.php">
253 <input type="text" name="server_path" size="90" value="'.htmlspecialchars(getServerPath()).'" /><input type="hidden" name="page" value="step" /><input type="hidden" name="step" value="1" /><input type="submit" value="Set server path" />
254 </form>';
255 }
256 }
257 elseif($step == 2)
258 {
259 echo '<h1>STEP '.$step.'</h1>Check database connection<br>';
260 echo 'If you don\'t see any errors press <a href="install.php?page=step&step=3">link to STEP 3 - Add tables and columns to DB</a>. If you see some errors it mean server has wrong configuration. Check FAQ or ask author of acc. maker.<br />';
261 $SQL->connect(); // show errors if can't connect
262 }
263 elseif($step == 3)
264 {
265 echo '<h1>STEP '.$step.'</h1>Add tables and columns to DB<br>';
266 echo 'Installer try to add new tables and columns to database.<br>';
267 $columns = array();
268 //$columns[] = array('table', 'name_of_column', 'type', 'length', 'default');
269 $columns[] = array('accounts', 'key', 'VARCHAR', '20', '0');
270 $columns[] = array('accounts', 'email_new', 'VARCHAR', '255', '');
271 $columns[] = array('accounts', 'email_new_time', 'INT', '11', '0');
272 $columns[] = array('accounts', 'rlname', 'VARCHAR', '255', '');
273 $columns[] = array('accounts', 'location', 'VARCHAR', '255', '');
274 $columns[] = array('accounts', 'page_access', 'INT', '11', '0');
275 $columns[] = array('accounts', 'email_code', 'VARCHAR', '255', '');
276 $columns[] = array('accounts', 'next_email', 'INT', '11', '0');
277 $columns[] = array('accounts', 'premium_points', 'INT', '11', '0');
278 $columns[] = array('accounts', 'create_date', 'INT', '11', '0');
279 $columns[] = array('accounts', 'create_ip', 'INT', '11', '0');
280 $columns[] = array('accounts', 'last_post', 'INT', '11', '0');
281 $columns[] = array('accounts', 'flag', 'VARCHAR', '80', '');
282
283 $columns[] = array('guilds', 'description', 'TEXT', '', '');
284 $columns[] = array('guilds', 'guild_logo', 'MEDIUMBLOB', '', NULL);
285 $columns[] = array('guilds', 'create_ip', 'INT', '11', '0');
286 $columns[] = array('guilds', 'balance', 'BIGINT UNSIGNED', '', '0');
287 $columns[] = array('killers', 'war', 'INT', '11', '0');
288
289 $columns[] = array('players', 'deleted', 'TINYINT', '1', '0');
290 $columns[] = array('players', 'description', 'VARCHAR', '255', '');
291 $columns[] = array('players', 'comment', 'TEXT', '', '');
292 $columns[] = array('players', 'create_ip', 'INT', '11', '0');
293 $columns[] = array('players', 'create_date', 'INT', '11', '0');
294 $columns[] = array('players', 'hide_char', 'INT', '11', '0');
295
296 $tables = array();
297 // mysql tables
298 $tables[Database::DB_MYSQL]['z_ots_comunication'] = "CREATE TABLE `z_ots_comunication` (
299 `id` int(11) NOT NULL auto_increment,
300 `name` varchar(255) NOT NULL,
301 `type` varchar(255) NOT NULL,
302 `action` varchar(255) NOT NULL,
303 `param1` varchar(255) NOT NULL,
304 `param2` varchar(255) NOT NULL,
305 `param3` varchar(255) NOT NULL,
306 `param4` varchar(255) NOT NULL,
307 `param5` varchar(255) NOT NULL,
308 `param6` varchar(255) NOT NULL,
309 `param7` varchar(255) NOT NULL,
310 `delete_it` int(2) NOT NULL default '1',
311 PRIMARY KEY (`id`)
312 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
313 $tables[Database::DB_MYSQL]['z_shop_offer'] = "CREATE TABLE `z_shop_offer` (
314 `id` int(11) NOT NULL auto_increment,
315 `points` int(11) NOT NULL default '0',
316 `itemid1` int(11) NOT NULL default '0',
317 `count1` int(11) NOT NULL default '0',
318 `itemid2` int(11) NOT NULL default '0',
319 `count2` int(11) NOT NULL default '0',
320 `offer_type` varchar(255) default NULL,
321 `offer_description` text NOT NULL,
322 `offer_name` varchar(255) NOT NULL,
323 PRIMARY KEY (`id`)
324 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
325 $tables[Database::DB_MYSQL]['z_shop_history_item'] = "CREATE TABLE `z_shop_history_item` (
326 `id` int(11) NOT NULL auto_increment,
327 `to_name` varchar(255) NOT NULL default '0',
328 `to_account` int(11) NOT NULL default '0',
329 `from_nick` varchar(255) NOT NULL,
330 `from_account` int(11) NOT NULL default '0',
331 `price` int(11) NOT NULL default '0',
332 `offer_id` varchar(255) NOT NULL default '',
333 `trans_state` varchar(255) NOT NULL,
334 `trans_start` int(11) NOT NULL default '0',
335 `trans_real` int(11) NOT NULL default '0',
336 PRIMARY KEY (`id`)
337 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
338 $tables[Database::DB_MYSQL]['z_forum'] = "CREATE TABLE `z_forum` (
339 `id` int(11) NOT NULL auto_increment,
340 `first_post` int(11) NOT NULL default '0',
341 `last_post` int(11) NOT NULL default '0',
342 `section` int(3) NOT NULL default '0',
343 `replies` int(20) NOT NULL default '0',
344 `views` int(20) NOT NULL default '0',
345 `author_aid` int(20) NOT NULL default '0',
346 `author_guid` int(20) NOT NULL default '0',
347 `post_text` text NOT NULL,
348 `post_topic` varchar(255) NOT NULL,
349 `post_smile` tinyint(1) NOT NULL default '0',
350 `post_date` int(20) NOT NULL default '0',
351 `last_edit_aid` int(20) NOT NULL default '0',
352 `edit_date` int(20) NOT NULL default '0',
353 `post_ip` varchar(15) NOT NULL default '0.0.0.0',
354 PRIMARY KEY (`id`),
355 KEY `section` (`section`)
356 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
357 $tables[Database::DB_MYSQL]['guild_wars'] = "CREATE TABLE `guild_wars` (
358 `id` INT NOT NULL AUTO_INCREMENT,
359 `guild_id` INT NOT NULL,
360 `enemy_id` INT NOT NULL,
361 `begin` BIGINT NOT NULL DEFAULT '0',
362 `end` BIGINT NOT NULL DEFAULT '0',
363 `frags` INT UNSIGNED NOT NULL DEFAULT '0',
364 `payment` BIGINT UNSIGNED NOT NULL DEFAULT '0',
365 `guild_kills` INT UNSIGNED NOT NULL DEFAULT '0',
366 `enemy_kills` INT UNSIGNED NOT NULL DEFAULT '0',
367 `status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
368 PRIMARY KEY (`id`),
369 KEY `status` (`status`),
370 KEY `guild_id` (`guild_id`),
371 KEY `enemy_id` (`enemy_id`)
372 ) ENGINE=InnoDB;";
373 $tables[Database::DB_MYSQL]['guild_wars_table_references'] = "ALTER TABLE `guild_wars`
374 ADD CONSTRAINT `guild_wars_ibfk_1` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE,
375 ADD CONSTRAINT `guild_wars_ibfk_2` FOREIGN KEY (`enemy_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE;";
376 $tables[Database::DB_MYSQL]['guild_kills'] = "CREATE TABLE `guild_kills` (
377 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
378 `guild_id` INT NOT NULL,
379 `war_id` INT NOT NULL,
380 `death_id` INT NOT NULL
381 ) ENGINE = InnoDB;";
382 $tables[Database::DB_MYSQL]['guild_kills_table_references'] = "ALTER TABLE `guild_kills`
383 ADD CONSTRAINT `guild_kills_ibfk_1` FOREIGN KEY (`war_id`) REFERENCES `guild_wars` (`id`) ON DELETE CASCADE,
384 ADD CONSTRAINT `guild_kills_ibfk_2` FOREIGN KEY (`death_id`) REFERENCES `player_deaths` (`id`) ON DELETE CASCADE,
385 ADD CONSTRAINT `guild_kills_ibfk_3` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE;";
386 // sqlite tables
387 $tables[Database::DB_SQLITE]['z_ots_comunication'] = 'CREATE TABLE "z_ots_comunication" (
388 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
389 "name" varchar(255) NOT NULL,
390 "type" varchar(255) NOT NULL,
391 "action" varchar(255) NOT NULL,
392 "param1" varchar(255) NOT NULL,
393 "param2" varchar(255) NOT NULL,
394 "param3" varchar(255) NOT NULL,
395 "param4" varchar(255) NOT NULL,
396 "param5" varchar(255) NOT NULL,
397 "param6" varchar(255) NOT NULL,
398 "param7" varchar(255) NOT NULL,
399 "delete_it" int(2) NOT NULL default 1);';
400 $tables[Database::DB_SQLITE]['z_shop_offer'] = 'CREATE TABLE "z_shop_offer" (
401 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
402 "points" int(11) NOT NULL default 0,
403 "itemid1" int(11) NOT NULL default 0,
404 "count1" int(11) NOT NULL default 0,
405 "itemid2" int(11) NOT NULL default 0,
406 "count2" int(11) NOT NULL default 0,
407 "offer_type" varchar(255) default NULL,
408 "offer_description" text NOT NULL,
409 "offer_name" varchar(255) NOT NULL);';
410 $tables[Database::DB_SQLITE]['z_shop_history_item'] = 'CREATE TABLE "z_shop_history_item" (
411 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
412 "to_name" varchar(255) NOT NULL default 0,
413 "to_account" int(11) NOT NULL default 0,
414 "from_nick" varchar(255) NOT NULL,
415 "from_account" int(11) NOT NULL default 0,
416 "price" int(11) NOT NULL default 0,
417 "offer_id" varchar(255) NOT NULL default "",
418 "trans_state" varchar(255) NOT NULL,
419 "trans_start" int(11) NOT NULL default 0,
420 "trans_real" int(11) NOT NULL default 0);';
421 $tables[Database::DB_SQLITE]['z_forum'] = 'CREATE TABLE "z_forum" (
422 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
423 "first_post" int(11) NOT NULL default 0,
424 "last_post" int(11) NOT NULL default 0,
425 "section" int(3) NOT NULL default 0,
426 "replies" int(20) NOT NULL default 0,
427 "views" int(20) NOT NULL default 0,
428 "author_aid" int(20) NOT NULL default 0,
429 "author_guid" int(20) NOT NULL default 0,
430 "post_text" text NOT NULL,
431 "post_topic" varchar(255) NOT NULL,
432 "post_smile" tinyint(1) NOT NULL default 0,
433 "post_date" int(20) NOT NULL default 0,
434 "last_edit_aid" int(20) NOT NULL default 0,
435 "edit_date" int(20) NOT NULL default 0,
436 "post_ip" varchar(15) NOT NULL default "0.0.0.0");';
437 foreach($columns as $column)
438 {
439 if($column[4] === NULL && $SQL->query('ALTER TABLE ' . $SQL->tableName($column[0]) . ' ADD ' . $SQL->fieldName($column[1]) . ' ' . $column[2] . ' NULL DEFAULT NULL') !== false)
440 echo "<span style=\"color:green\">Column <b>" . $column[1] . "</b> added to table <b>" . $column[0] . "</b>.</span><br />";
441 elseif($SQL->query('ALTER TABLE ' . $SQL->tableName($column[0]) . ' ADD ' . $SQL->fieldName($column[1]) . ' ' . $column[2] . '' . (($column[3] == '') ? '' : '(' . $column[3] . ')') . ' NOT NULL DEFAULT \'' . $column[4] . '\'') !== false)
442 echo "<span style=\"color:green\">Column <b>" . $column[1] . "</b> added to table <b>" . $column[0] . "</b>.</span><br />";
443 else
444 echo "Could not add column <b>" . $column[1] . "</b> to table <b>" . $column[0] . "</b>. Already exist?<br />";
445 }
446 foreach($tables[$SQL->getDatabaseDriver()] as $tableName => $tableQuery)
447 {
448 if($SQL->query($tableQuery) !== false)
449 echo "<span style=\"color:green\">Table <b>" . $tableName . "</b> created.</span><br />";
450 else
451 echo "Could not create table <b>" . $tableName . "</b>. Already exist?<br />";
452 }
453 echo 'Tables and columns added to database.<br>Go to <a href="install.php?page=step&step=4">STEP 4 - Add samples</a>';
454 }
455 elseif($step == 4)
456 {
457 echo '<h1>STEP '.$step.'</h1>Add samples to DB:<br>';
458
459 $samplePlayers = array();
460 $samplePlayers[0] = 'Rook Sample';
461 $samplePlayers[1] = 'Sorcerer Sample';
462 $samplePlayers[2] = 'Druid Sample';
463 $samplePlayers[3] = 'Paladin Sample';
464 $samplePlayers[4] = 'Knight Sample';
465 $newPlayer = new Player('Account Manager', Player::LOADTYPE_NAME);
466 if($newPlayer->isLoaded())
467 {
468 foreach($samplePlayers as $vocationID => $name)
469 {
470 $samplePlayer = new Player($name, Player::LOADTYPE_NAME);
471 if(!$samplePlayer->isLoaded())
472 {
473 $samplePlayer = new Player('Account Manager', Player::LOADTYPE_NAME);
474 $samplePlayer->setID(null); // save as new player, not edited
475 $samplePlayer->setName($name);
476 $samplePlayer->setVocation($vocationID);
477 $samplePlayer->setGroupID(1);
478 $samplePlayer->setLookType(128);
479 $samplePlayer->save();
480 echo '<span style="color:green">Added sample character: </span><span style="color:green;font-weight:bold">' . $name . '</span><br/>';
481 }
482 else
483 echo 'Sample character: <span style="font-weight:bold">' . $name . '</span> already exist in database<br/>';
484 }
485 }
486 else
487 new Error_Critic('', 'Character <i>Account Manager</i> does not exist. Cannot install sample characters!');
488 }
489 elseif($step == 5)
490 {
491 echo '<h1>STEP '.$step.'</h1>Set Admin Account<br>';
492 if(empty($_REQUEST['saveaccpassword']))
493 {
494 echo 'Admin account login is: <b>1</b><br/>Set new password to this account.<br>';
495 echo 'New password: <form action="install.php" method=POST><input type="text" name="newpass" size="35">(Don\'t give it password to anyone!)';
496 echo '<input type="hidden" name="saveaccpassword" value="yes"><input type="hidden" name="page" value="step"><input type="hidden" name="step" value="5"><input type="submit" value="SET"></form><br>If account with login 1 doesn\'t exist installator will create it and set your password.';
497 }
498 else
499 {
500 include_once('./system/load.compat.php');
501 $newpass = trim($_POST['newpass']);
502 if(!check_password($newpass))
503 echo 'Password contains illegal characters. Please use only a-Z and 0-9. <a href="install.php?page=step&step=5">GO BACK</a> and write other password.';
504 else
505 {
506 //create / set pass to admin account
507 $account = new Account(1, Account::LOADTYPE_NAME);
508 if($account->isLoaded())
509 {
510 $account->setPassword($newpass); // setPassword encrypt it to ots encryption
511 $account->setPageAccess(3);
512 $account->setFlag('unknown');
513 $account->save();
514 }
515 else
516 {
517 $newAccount = new Account();
518 $newAccount->setName(1);
519 $newAccount->setPassword($newpass); // setPassword encrypt it to ots encryption
520 $newAccount->setMail(rand(0,999999) . '@gmail.com');
521 $newAccount->setPageAccess(3);
522 $newAccount->setGroupID(1);
523 $newAccount->setFlag('unknown');
524 $newAccount->setCreateIP(Visitor::getIP());
525 $newAccount->setCreateDate(time());
526 }
527 $_SESSION['account'] = 1;
528 $_SESSION['password'] = $newpass;
529 $logged = TRUE;
530 echo '<h1>Admin account login: 1<br>Admin account password: '.$newpass.'</h1><br/><h3>It\'s end of installation. Installation is blocked!</h3>';
531 if(!unlink('install.txt'))
532 new Error_Critic('', 'Cannot remove file <i>install.txt</i>. You must remove it to disable installer. I recommend you to go to step <i>0</i> and check if any other file got problems with WRITE permission.');
533 }
534 }
535 }
536}