· 7 years ago · Oct 18, 2018, 05:12 AM
1<?PHP
2define('INITIALIZED', true);
3define('ONLY_PAGE', false);
4if(!file_exists('install.txt'))
5{
6 echo('AAC installation is disabled. To enable it make file <b>install.php</b> in main AAC directory and put there your IP.');
7 exit;
8}
9$installIP = trim(file_get_contents('install.txt'));
10if($installIP != $_SERVER['REMOTE_ADDR'])
11{
12 echo('In file <b>install.txt</b> must be your IP!<br />In file is:<br /><b>' . $installIP . '</b><br />Your IP is:<br /><b>' . $_SERVER['REMOTE_ADDR'] . '</b>');
13 exit;
14}
15
16$time_start = microtime(true);
17session_start();
18
19function autoLoadClass($className)
20{
21 if(!class_exists($className))
22 if(file_exists('./classes/' . strtolower($className) . '.php'))
23 include_once('./classes/' . strtolower($className) . '.php');
24 else
25 new Error_Critic('#E-7', 'Cannot load class <b>' . $className . '</b>, file <b>./classes/class.' . strtolower($className) . '.php</b> doesn\'t exist');
26}
27spl_autoload_register('autoLoadClass');
28
29//load acc. maker config to $config['site']
30$config = array();
31include('./config/config.php');
32if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
33{
34 $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
35 while(list($key, $val) = each($process))
36 {
37 foreach ($val as $k => $v)
38 {
39 unset($process[$key][$k]);
40 if(is_array($v))
41 {
42 $process[$key][stripslashes($k)] = $v;
43 $process[] = &$process[$key][stripslashes($k)];
44 }
45 else
46 $process[$key][stripslashes($k)] = stripslashes($v);
47 }
48 }
49 unset($process);
50}
51
52
53
54$page = '';
55if(isset($_REQUEST['page']))
56 $page = $_REQUEST['page'];
57$step = 'start';
58if(isset($_REQUEST['step']))
59 $step = $_REQUEST['step'];
60// load server path
61function getServerPath()
62{
63 $config = array();
64 include('./config/config.php');
65 return $config['site']['serverPath'];
66}
67// save server path
68function setServerPath($newPath)
69{
70 $file = fopen("./config/config.php", "r");
71 $lines = array();
72 while (!feof($file)) {
73 $lines[] = fgets($file);
74 }
75 fclose($file);
76
77 $newConfig = array();
78 foreach ($lines as $i => $line)
79 {
80 if(substr($line, 0, strlen('$config[\'site\'][\'serverPath\']')) == '$config[\'site\'][\'serverPath\']')
81 $newConfig[] = '$config[\'site\'][\'serverPath\'] = "' . str_replace('"', '\"' , $newPath) . '";' . PHP_EOL; // do something with each line from text file here
82 else
83 $newConfig[] = $line;
84 }
85 Website::putFileContents("./config/config.php", implode('', $newConfig));
86}
87if($page == '')
88{
89 echo '<html>
90 <head>
91 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
92 <title>Installation of account maker</title>
93 </head>
94 <frameset cols="230,*">
95 <frame name="menu" src="install.php?page=menu" />
96 <frame name="step" src="install.php?page=step&step=start" />
97 <noframes><body>Frames don\'t work. Install Firefox :P</body></noframes>
98 </frameset>
99 </html>';
100}
101elseif($page == 'menu')
102{
103 echo '<h2>MENU</h2><br>
104 <b>IF NOT INSTALLED:</b><br>
105 <a href="install.php?page=step&step=start" target="step">0. Informations</a><br>
106 <a href="install.php?page=step&step=1" target="step">1. Set server path</a><br>
107 <a href="install.php?page=step&step=2" target="step">2. Check DataBase connection</a><br>
108 <a href="install.php?page=step&step=3" target="step">3. Add tables and columns to DB</a><br>
109 <a href="install.php?page=step&step=4" target="step">4. Add samples to DB</a><br>
110 <a href="install.php?page=step&step=5" target="step">5. Set Admin Account</a><br>
111 <b>Author:</b><br>
112 Gesior<br>
113 Compatible with TFS 0.3.6 and TFS 0.4 up to revision 3702</a>';
114}
115elseif($page == 'step')
116{
117 if($step >= 2 && $step <= 5)
118 {
119 //load server config $config['server']
120 if(Website::getWebsiteConfig()->getValue('useServerConfigCache'))
121 {
122 // use cache to make website load faster
123 if(Website::fileExists('./config/server.config.php'))
124 {
125 $tmp_php_config = new ConfigPHP('./config/server.config.php');
126 $config['server'] = $tmp_php_config->getConfig();
127 }
128 else
129 {
130 // if file isn't cache we should load .lua file and make .php cache
131 $tmp_lua_config = new ConfigLUA(Website::getWebsiteConfig()->getValue('serverPath') . 'config.lua');
132 $config['server'] = $tmp_lua_config->getConfig();
133 $tmp_php_config = new ConfigPHP();
134 $tmp_php_config->setConfig($tmp_lua_config->getConfig());
135 $tmp_php_config->saveToFile('./config/server.config.php');
136 }
137 }
138 else
139 {
140 $tmp_lua_config = new ConfigLUA(Website::getWebsiteConfig()->getValue('serverPath') . 'config.lua');
141 $config['server'] = $tmp_lua_config->getConfig();
142 }
143 if(Website::getServerConfig()->isSetKey('mysqlHost'))
144 {
145 define('SERVERCONFIG_SQL_TYPE', 'sqlType');
146 define('SERVERCONFIG_SQL_HOST', 'mysqlHost');
147 define('SERVERCONFIG_SQL_PORT', 'mysqlPort');
148 define('SERVERCONFIG_SQL_USER', 'mysqlUser');
149 define('SERVERCONFIG_SQL_PASS', 'mysqlPass');
150 define('SERVERCONFIG_SQL_DATABASE', 'mysqlDatabase');
151 define('SERVERCONFIG_SQLITE_FILE', 'sqlFile');
152 }
153 elseif(Website::getServerConfig()->isSetKey('sqlHost'))
154 {
155 define('SERVERCONFIG_SQL_TYPE', 'sqlType');
156 define('SERVERCONFIG_SQL_HOST', 'sqlHost');
157 define('SERVERCONFIG_SQL_PORT', 'sqlPort');
158 define('SERVERCONFIG_SQL_USER', 'sqlUser');
159 define('SERVERCONFIG_SQL_PASS', 'sqlPass');
160 define('SERVERCONFIG_SQL_DATABASE', 'sqlDatabase');
161 define('SERVERCONFIG_SQLITE_FILE', 'sqlFile');
162 }
163 else
164 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>')));
165 if(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_TYPE) == 'mysql')
166 {
167 Website::setDatabaseDriver(Database::DB_MYSQL);
168 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_HOST))
169 Website::getDBHandle()->setDatabaseHost(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_HOST));
170 else
171 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_HOST . '</b> in server config file.');
172 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PORT))
173 Website::getDBHandle()->setDatabasePort(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PORT));
174 else
175 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_PORT . '</b> in server config file.');
176 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_DATABASE))
177 Website::getDBHandle()->setDatabaseName(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_DATABASE));
178 else
179 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_DATABASE . '</b> in server config file.');
180 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_USER))
181 Website::getDBHandle()->setDatabaseUsername(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_USER));
182 else
183 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_USER . '</b> in server config file.');
184 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PASS))
185 Website::getDBHandle()->setDatabasePassword(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PASS));
186 else
187 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_PASS . '</b> in server config file.');
188 }
189 elseif(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_TYPE) == 'sqlite')
190 {
191 Website::setDatabaseDriver(Database::DB_SQLITE);
192 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQLITE_FILE))
193 Website::getDBHandle()->setDatabaseFile(Website::getServerConfig()->getValue(SERVERCONFIG_SQLITE_FILE));
194 else
195 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQLITE_FILE . '</b> in server config file.');
196 }
197 elseif(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_TYPE) == 'pgsql')
198 {
199 // does pgsql use 'port' parameter? I don't know
200 Website::setDatabaseDriver(Database::DB_PGSQL);
201 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_HOST))
202 Website::getDBHandle()->setDatabaseHost(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_HOST));
203 else
204 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_HOST . '</b> in server config file.');
205 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_DATABASE))
206 Website::getDBHandle()->setDatabaseName(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_DATABASE));
207 else
208 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_DATABASE . '</b> in server config file.');
209 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_USER))
210 Website::getDBHandle()->setDatabaseUsername(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_USER));
211 else
212 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_USER . '</b> in server config file.');
213 if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PASS))
214 Website::getDBHandle()->setDatabasePassword(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PASS));
215 else
216 new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_PASS . '</b> in server config file.');
217 }
218 else
219 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>"');
220 Website::setPasswordsEncryption(Website::getServerConfig()->getValue('encryptionType'));
221 $SQL = Website::getDBHandle();
222 }
223
224 if($step == 'start')
225 {
226 echo '<h1>STEP '.$step.'</h1>Informations<br>';
227 echo 'Welcome to Gesior Account Maker installer. <b>After 5 simple steps account maker will be ready to use!</b><br />';
228 // check access to write files
229 $writeable = array('config/config.php', 'cache', 'cache/flags', 'cache/DONT_EDIT_usercounter.txt', 'cache/DONT_EDIT_serverstatus.txt', 'custom_scripts', 'install.txt');
230 foreach($writeable as $fileToWrite)
231 {
232 if(is_writable($fileToWrite))
233 echo '<span style="color:green">CAN WRITE TO FILE: <b>' . $fileToWrite . '</b></span><br />';
234 else
235 echo '<span style="color:red">CANNOT WRITE TO FILE: <b>' . $fileToWrite . '</b> - edit file access for PHP [on linux: chmod]</span><br />';
236 }
237 }
238 elseif($step == 1)
239 {
240 if(isset($_REQUEST['server_path']))
241 {
242 echo '<h1>STEP '.$step.'</h1>Check server configuration<br>';
243 $path = $_REQUEST['server_path'];
244 $path = trim($path)."\\";
245 $path = str_replace("\\\\", "/", $path);
246 $path = str_replace("\\", "/", $path);
247 $path = str_replace("//", "/", $path);
248 setServerPath($path);
249 $tmp_lua_config = new ConfigLUA($path . 'config.lua');
250 $config['server'] = $tmp_lua_config->getConfig();
251 if(isset($config['server']['sqlType']))
252 {
253 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>';
254 }
255 else
256 {
257 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.';
258 }
259 }
260 else
261 {
262 echo 'Please write you TFS directory below. Like: <i>C:\Documents and Settings\Gesior\Desktop\TFS 0.2.9\</i><form action="install.php">
263 <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" />
264 </form>';
265 }
266 }
267 elseif($step == 2)
268 {
269 echo '<h1>STEP '.$step.'</h1>Check database connection<br>';
270 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 />';
271 $SQL->connect(); // show errors if can't connect
272 }
273 elseif($step == 3)
274 {
275 echo '<h1>STEP '.$step.'</h1>Add tables and columns to DB<br>';
276 echo 'Installer try to add new tables and columns to database.<br>';
277 $columns = array();
278 //$columns[] = array('table', 'name_of_column', 'type', 'length', 'default');
279 $columns[] = array('accounts', 'premium_points', 'INT', '11', '0');
280 $columns[] = array('accounts', 'backup_points', 'INT', '11', '0');
281 $columns[] = array('accounts', 'guild_points', 'INT', '11', '0');
282 $columns[] = array('accounts', 'key', 'VARCHAR', '20', '0');
283 $columns[] = array('accounts', 'email_new', 'VARCHAR', '255', '');
284 $columns[] = array('accounts', 'email_new_time', 'INT', '11', '0');
285 $columns[] = array('accounts', 'rlname', 'VARCHAR', '255', '');
286 $columns[] = array('accounts', 'location', 'VARCHAR', '255', '');
287 $columns[] = array('accounts', 'page_access', 'INT', '11', '0');
288 $columns[] = array('accounts', 'email_code', 'VARCHAR', '255', '');
289 $columns[] = array('accounts', 'next_email', 'INT', '11', '0');
290 $columns[] = array('accounts', 'create_date', 'INT', '11', '0');
291 $columns[] = array('accounts', 'create_ip', 'INT', '11', '0');
292 $columns[] = array('accounts', 'last_post', 'INT', '11', '0');
293 $columns[] = array('accounts', 'flag', 'VARCHAR', '80', '');
294 $columns[] = array('accounts', 'vip_time', 'INT', '15', '0');
295
296 $columns[] = array('guilds', 'description', 'TEXT', '', '');
297 $columns[] = array('guilds', 'guild_logo', 'MEDIUMBLOB', '', NULL);
298 $columns[] = array('guilds', 'create_ip', 'INT', '11', '0');
299 $columns[] = array('guilds', 'balance', 'BIGINT UNSIGNED', '', '0');
300 $columns[] = array('guilds', 'logo_gfx_name', 'varchar', '255', '');
301 $columns[] = array('killers', 'war', 'INT', '11', '0');
302
303 $columns[] = array('players', 'deleted', 'TINYINT', '1', '0');
304 $columns[] = array('players', 'description', 'VARCHAR', '255', '');
305 $columns[] = array('players', 'comment', 'TEXT', '', '');
306 $columns[] = array('players', 'create_ip', 'INT', '11', '0');
307 $columns[] = array('players', 'create_date', 'INT', '11', '0');
308 $columns[] = array('players', 'hide_char', 'INT', '11', '0');
309 $columns[] = array('players', 'signature', 'TEXT', '', '');
310
311 //Cast System
312 $columns[] = array('players', 'broadcasting', 'tinyint', '4', '0');
313 $columns[] = array('players', 'viewers', 'int', '1', '0');
314
315 $tables = array();
316 // mysql tables
317 $tables[Database::DB_MYSQL]['z_ots_comunication'] = "CREATE TABLE `z_ots_comunication` (
318 `id` int(11) NOT NULL auto_increment,
319 `name` varchar(255) NOT NULL,
320 `type` varchar(255) NOT NULL,
321 `action` varchar(255) NOT NULL,
322 `param1` varchar(255) NOT NULL,
323 `param2` varchar(255) NOT NULL,
324 `param3` varchar(255) NOT NULL,
325 `param4` varchar(255) NOT NULL,
326 `param5` varchar(255) NOT NULL,
327 `param6` varchar(255) NOT NULL,
328 `param7` varchar(255) NOT NULL,
329 `delete_it` int(2) NOT NULL default '1',
330 PRIMARY KEY (`id`)
331 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
332 $tables[Database::DB_MYSQL]['z_ots_guildcomunication'] = "CREATE TABLE `z_ots_guildcomunication` (
333 `id` int(11) NOT NULL auto_increment,
334 `name` varchar(255) NOT NULL,
335 `type` varchar(255) NOT NULL,
336 `action` varchar(255) NOT NULL,
337 `param1` varchar(255) NOT NULL,
338 `param2` varchar(255) NOT NULL,
339 `param3` varchar(255) NOT NULL,
340 `param4` varchar(255) NOT NULL,
341 `param5` varchar(255) NOT NULL,
342 `param6` varchar(255) NOT NULL,
343 `param7` varchar(255) NOT NULL,
344 `delete_it` int(2) NOT NULL default '1',
345 PRIMARY KEY (`id`)
346 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
347 $tables[Database::DB_MYSQL]['z_polls'] = "CREATE TABLE `z_polls` (
348 `id` int(11) NOT NULL AUTO_INCREMENT,
349 `question` varchar(255) NOT NULL,
350 `end` int(11) NOT NULL,
351 `start` int(11) NOT NULL,
352 `answers` int(11) NOT NULL,
353 `votes_all` int(11) NOT NULL,
354 PRIMARY KEY (`id`)
355 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
356 $tables[Database::DB_MYSQL]['accounts'] = "ALTER TABLE `accounts` ADD `vote` INT( 11 ) NOT NULL ;";
357 $tables[Database::DB_MYSQL]['z_polls_answers'] = "CREATE TABLE `z_polls_answers` (
358 `poll_id` int(11) NOT NULL,
359 `answer_id` int(11) NOT NULL,
360 `answer` varchar(255) NOT NULL,
361 `votes` int(11) NOT NULL
362 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
363 $tables[Database::DB_MYSQL]['z_network_box'] = "CREATE TABLE `z_network_box` (
364 `id` int(11) NOT NULL AUTO_INCREMENT,
365 `network_name` varchar(10) NOT NULL,
366 `network_link` varchar(50) NOT NULL,
367 PRIMARY KEY (`id`)
368 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
369 $tables[Database::DB_MYSQL]['z_shop_offer'] = "CREATE TABLE `z_shop_offer` (
370 `id` int(11) NOT NULL AUTO_INCREMENT,
371 `points` int(11) NOT NULL DEFAULT '0',
372 `itemid1` int(11) NOT NULL DEFAULT '0',
373 `count1` int(11) NOT NULL DEFAULT '0',
374 `itemid2` int(11) NOT NULL DEFAULT '0',
375 `count2` int(11) NOT NULL DEFAULT '0',
376 `offer_type` varchar(255) DEFAULT NULL,
377 `offer_description` text NOT NULL,
378 `offer_name` varchar(255) NOT NULL,
379 `pid` int(11) NOT NULL DEFAULT '0',
380 `looktype` int(3) NOT NULL DEFAULT '0',
381 PRIMARY KEY (`id`)
382 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
383 $tables[Database::DB_MYSQL]['z_shop_history_pacc'] = "CREATE TABLE `z_shop_history_pacc` (
384 `id` int(11) NOT NULL auto_increment,
385 `to_name` varchar(255) NOT NULL default '0',
386 `to_account` int(11) NOT NULL default '0',
387 `from_nick` varchar(255) NOT NULL,
388 `from_account` int(11) NOT NULL default '0',
389 `price` int(11) NOT NULL default '0',
390 `pacc_days` int(11) NOT NULL default '0',
391 `trans_state` varchar(255) NOT NULL,
392 `trans_start` int(11) NOT NULL default '0',
393 `trans_real` int(11) NOT NULL default '0',
394 PRIMARY KEY (`id`)
395 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
396 $tables[Database::DB_MYSQL]['z_shop_history_item'] = "CREATE TABLE `z_shop_history_item` (
397 `id` int(11) NOT NULL auto_increment,
398 `to_name` varchar(255) NOT NULL default '0',
399 `to_account` int(11) NOT NULL default '0',
400 `from_nick` varchar(255) NOT NULL,
401 `from_account` int(11) NOT NULL default '0',
402 `price` int(11) NOT NULL default '0',
403 `offer_id` varchar(255) NOT NULL default '',
404 `offer_desc` VARCHAR(255) NULL DEFAULT NULL,
405 `trans_state` varchar(255) NOT NULL,
406 `trans_start` int(11) NOT NULL default '0',
407 `trans_real` int(11) NOT NULL default '0',
408 PRIMARY KEY (`id`)
409 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
410 $tables[Database::DB_MYSQL]['z_shopguild_offer'] = "CREATE TABLE `z_shopguild_offer` (
411 `id` int(11) NOT NULL AUTO_INCREMENT,
412 `points` int(11) NOT NULL DEFAULT '0',
413 `itemid1` int(11) NOT NULL DEFAULT '0',
414 `count1` int(11) NOT NULL DEFAULT '0',
415 `itemid2` int(11) NOT NULL DEFAULT '0',
416 `count2` int(11) NOT NULL DEFAULT '0',
417 `offer_type` varchar(255) DEFAULT NULL,
418 `offer_description` text NOT NULL,
419 `offer_name` varchar(255) NOT NULL,
420 `pid` int(11) NOT NULL DEFAULT '0',
421 `looktype` int(3) NOT NULL DEFAULT '0',
422 PRIMARY KEY (`id`)
423 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
424 $tables[Database::DB_MYSQL]['z_shopguild_history_pacc'] = "CREATE TABLE `z_shopguild_history_pacc` (
425 `id` int(11) NOT NULL auto_increment,
426 `to_name` varchar(255) NOT NULL default '0',
427 `to_account` int(11) NOT NULL default '0',
428 `from_nick` varchar(255) NOT NULL,
429 `from_account` int(11) NOT NULL default '0',
430 `price` int(11) NOT NULL default '0',
431 `pacc_days` int(11) NOT NULL default '0',
432 `trans_state` varchar(255) NOT NULL,
433 `trans_start` int(11) NOT NULL default '0',
434 `trans_real` int(11) NOT NULL default '0',
435 PRIMARY KEY (`id`)
436 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
437 $tables[Database::DB_MYSQL]['z_shop_historyguild_item'] = "CREATE TABLE `z_shopguild_history_item` (
438 `id` int(11) NOT NULL auto_increment,
439 `to_name` varchar(255) NOT NULL default '0',
440 `to_account` int(11) NOT NULL default '0',
441 `from_nick` varchar(255) NOT NULL,
442 `from_account` int(11) NOT NULL default '0',
443 `price` int(11) NOT NULL default '0',
444 `offer_id` varchar(255) NOT NULL default '',
445 `offer_desc` VARCHAR(255) NULL DEFAULT NULL,
446 `trans_state` varchar(255) NOT NULL,
447 `trans_start` int(11) NOT NULL default '0',
448 `trans_real` int(11) NOT NULL default '0',
449 PRIMARY KEY (`id`)
450 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
451 $tables[Database::DB_MYSQL]['z_featured_article'] = "CREATE TABLE `z_featured_article` (
452 `id` int(11) NOT NULL AUTO_INCREMENT,
453 `title` varchar(50) NOT NULL,
454 `text` varchar(255) NOT NULL,
455 `date` varchar(30) NOT NULL,
456 `author` varchar(50) NOT NULL,
457 `read_more` varchar(100) NOT NULL,
458 PRIMARY KEY (`id`)
459 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
460 $tables[Database::DB_MYSQL]['z_forum'] = "CREATE TABLE `z_forum` (
461 `id` int(11) NOT NULL auto_increment,
462 `first_post` int(11) NOT NULL default '0',
463 `last_post` int(11) NOT NULL default '0',
464 `section` int(3) NOT NULL default '0',
465 `replies` int(20) NOT NULL default '0',
466 `views` int(20) NOT NULL default '0',
467 `author_aid` int(20) NOT NULL default '0',
468 `author_guid` int(20) NOT NULL default '0',
469 `post_text` text NOT NULL,
470 `post_topic` varchar(255) NOT NULL,
471 `post_smile` tinyint(1) NOT NULL default '0',
472 `post_date` int(20) NOT NULL default '0',
473 `last_edit_aid` int(20) NOT NULL default '0',
474 `edit_date` int(20) NOT NULL default '0',
475 `post_ip` varchar(15) NOT NULL default '0.0.0.0',
476 `icon_id` tinyint(4) NOT NULL DEFAULT '1',
477 `post_icon_id` tinyint(10) NOT NULL,
478 PRIMARY KEY (`id`),
479 KEY `section` (`section`)
480 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
481 $tables[Database::DB_MYSQL]['z_news_tickers'] = "CREATE TABLE `z_news_tickers` (
482 `id` INT NOT NULL AUTO_INCREMENT,
483 `date` int(11) NOT NULL DEFAULT '1',
484 `author` int(11) NOT NULL,
485 `image_id` int(3) NOT NULL DEFAULT '0',
486 `text` text NOT NULL,
487 `hide_ticker` tinyint(1) NOT NULL,
488 PRIMARY KEY (`id`)
489 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
490 $tables[Database::DB_MYSQL]['guild_wars'] = "CREATE TABLE `guild_wars` (
491 `id` INT NOT NULL AUTO_INCREMENT,
492 `guild_id` INT NOT NULL,
493 `enemy_id` INT NOT NULL,
494 `begin` BIGINT NOT NULL DEFAULT '0',
495 `end` BIGINT NOT NULL DEFAULT '0',
496 `frags` INT UNSIGNED NOT NULL DEFAULT '0',
497 `payment` BIGINT UNSIGNED NOT NULL DEFAULT '0',
498 `guild_kills` INT UNSIGNED NOT NULL DEFAULT '0',
499 `enemy_kills` INT UNSIGNED NOT NULL DEFAULT '0',
500 `status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
501 PRIMARY KEY (`id`),
502 KEY `status` (`status`),
503 KEY `guild_id` (`guild_id`),
504 KEY `enemy_id` (`enemy_id`)
505 ) ENGINE=InnoDB;";
506 $tables[Database::DB_MYSQL]['guild_wars_table_references'] = "ALTER TABLE `guild_wars`
507 ADD CONSTRAINT `guild_wars_ibfk_1` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE,
508 ADD CONSTRAINT `guild_wars_ibfk_2` FOREIGN KEY (`enemy_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE;";
509 $tables[Database::DB_MYSQL]['guild_kills'] = "CREATE TABLE `guild_kills` (
510 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
511 `guild_id` INT NOT NULL,
512 `war_id` INT NOT NULL,
513 `death_id` INT NOT NULL
514 ) ENGINE = InnoDB;";
515 $tables[Database::DB_MYSQL]['guild_kills_table_references'] = "ALTER TABLE `guild_kills`
516 ADD CONSTRAINT `guild_kills_ibfk_1` FOREIGN KEY (`war_id`) REFERENCES `guild_wars` (`id`) ON DELETE CASCADE,
517 ADD CONSTRAINT `guild_kills_ibfk_2` FOREIGN KEY (`death_id`) REFERENCES `player_deaths` (`id`) ON DELETE CASCADE,
518 ADD CONSTRAINT `guild_kills_ibfk_3` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE;";
519
520 $tables[Database::DB_MYSQL]['pagseguro_transactions'] = "CREATE TABLE `pagseguro_transactions` (
521 `transaction_code` varchar(36) NOT NULL,
522 `name` varchar(200) DEFAULT NULL,
523 `payment_method` varchar(50) NOT NULL,
524 `status` varchar(50) NOT NULL,
525 `item_count` int(11) NOT NULL,
526 `data` datetime NOT NULL,
527 UNIQUE KEY `transaction_code` (`transaction_code`,`status`),
528 KEY `name` (`name`),
529 KEY `status` (`status`)
530 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
531 // sqlite tables
532 $tables[Database::DB_SQLITE]['z_ots_comunication'] = 'CREATE TABLE "z_ots_comunication" (
533 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
534 "name" varchar(255) NOT NULL,
535 "type" varchar(255) NOT NULL,
536 "action" varchar(255) NOT NULL,
537 "param1" varchar(255) NOT NULL,
538 "param2" varchar(255) NOT NULL,
539 "param3" varchar(255) NOT NULL,
540 "param4" varchar(255) NOT NULL,
541 "param5" varchar(255) NOT NULL,
542 "param6" varchar(255) NOT NULL,
543 "param7" varchar(255) NOT NULL,
544 "delete_it" int(2) NOT NULL default 1);';
545 $tables[Database::DB_SQLITE]['z_shop_offer'] = 'CREATE TABLE "z_shop_offer" (
546 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
547 "points" int(11) NOT NULL default 0,
548 "itemid1" int(11) NOT NULL default 0,
549 "count1" int(11) NOT NULL default 0,
550 "itemid2" int(11) NOT NULL default 0,
551 "count2" int(11) NOT NULL default 0,
552 "offer_type" varchar(255) default NULL,
553 "offer_description" text NOT NULL,
554 "offer_name" varchar(255) NOT NULL);';
555 $tables[Database::DB_SQLITE]['z_shop_history_item'] = 'CREATE TABLE "z_shop_history_item" (
556 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
557 "to_name" varchar(255) NOT NULL default 0,
558 "to_account" int(11) NOT NULL default 0,
559 "from_nick" varchar(255) NOT NULL,
560 "from_account" int(11) NOT NULL default 0,
561 "price" int(11) NOT NULL default 0,
562 "offer_id" varchar(255) NOT NULL default "",
563 "offer_desc" VARCHAR(255) NULL DEFAULT NULL,
564 "trans_state" varchar(255) NOT NULL,
565 "trans_start" int(11) NOT NULL default 0,
566 "trans_real" int(11) NOT NULL default 0);';
567 $tables[Database::DB_SQLITE]['z_forum'] = 'CREATE TABLE "z_forum" (
568 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
569 "first_post" int(11) NOT NULL default 0,
570 "last_post" int(11) NOT NULL default 0,
571 "section" int(3) NOT NULL default 0,
572 "replies" int(20) NOT NULL default 0,
573 "views" int(20) NOT NULL default 0,
574 "author_aid" int(20) NOT NULL default 0,
575 "author_guid" int(20) NOT NULL default 0,
576 "post_text" text NOT NULL,
577 "post_topic" varchar(255) NOT NULL,
578 "post_smile" tinyint(1) NOT NULL default 0,
579 "post_date" int(20) NOT NULL default 0,
580 "last_edit_aid" int(20) NOT NULL default 0,
581 "edit_date" int(20) NOT NULL default 0,
582 "post_ip" varchar(15) NOT NULL default "0.0.0.0,");';
583 foreach($columns as $column)
584 {
585 if($column[4] === NULL && $SQL->query('ALTER TABLE ' . $SQL->tableName($column[0]) . ' ADD ' . $SQL->fieldName($column[1]) . ' ' . $column[2] . ' NULL DEFAULT NULL') !== false)
586 echo "<span style=\"color:green\">Column <b>" . $column[1] . "</b> added to table <b>" . $column[0] . "</b>.</span><br />";
587 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)
588 echo "<span style=\"color:green\">Column <b>" . $column[1] . "</b> added to table <b>" . $column[0] . "</b>.</span><br />";
589 else
590 echo "Could not add column <b>" . $column[1] . "</b> to table <b>" . $column[0] . "</b>. Already exist?<br />";
591 }
592 foreach($tables[$SQL->getDatabaseDriver()] as $tableName => $tableQuery)
593 {
594 if($SQL->query($tableQuery) !== false)
595 echo "<span style=\"color:green\">Table <b>" . $tableName . "</b> created.</span><br />";
596 else
597 echo "Could not create table <b>" . $tableName . "</b>. Already exist?<br />";
598 }
599 echo 'Tables and columns added to database.<br>Go to <a href="install.php?page=step&step=4">STEP 4 - Add samples</a>';
600 }
601 elseif($step == 4)
602 {
603 $check_news_ticker = $SQL->query('SELECT * FROM z_news_tickers WHERE image_id = 1 AND author = 1 AND hide_ticker = 0 LIMIT 1 OFFSET 0')->fetch();
604 if(!isset($check_news_ticker['author'])) {
605 $SQL->query('INSERT INTO z_news_tickers (date, author, image_id, text, hide_ticker) VALUES ('.time().', 1, 1, "Bem-Vindo ao Gesior 2012 Edited by Natanael Beckman!", 0)');
606 echo "Added first news ticker.<br/>";
607 } else {
608 echo "News ticker sample is already in database. New sample is not needed.<br/>";
609 }
610 echo '<h1>STEP '.$step.'</h1>Add samples to DB:<br>';
611
612 $samplePlayers = array();
613 $samplePlayers[0] = 'Rook Sample';
614 $samplePlayers[1] = 'Sorcerer Sample';
615 $samplePlayers[2] = 'Druid Sample';
616 $samplePlayers[3] = 'Paladin Sample';
617 $samplePlayers[4] = 'Knight Sample';
618 $newPlayer = new Player('Account Manager', Player::LOADTYPE_NAME);
619 if($newPlayer->isLoaded())
620 {
621 foreach($samplePlayers as $vocationID => $name)
622 {
623 $samplePlayer = new Player($name, Player::LOADTYPE_NAME);
624 if(!$samplePlayer->isLoaded())
625 {
626 $samplePlayer = new Player('Account Manager', Player::LOADTYPE_NAME);
627 $samplePlayer->setID(null); // save as new player, not edited
628 $samplePlayer->setName($name);
629 $samplePlayer->setVocation($vocationID);
630 $samplePlayer->setGroupID(1);
631 $samplePlayer->setLookType(128);
632 $samplePlayer->save();
633 echo '<span style="color:green">Added sample character: </span><span style="color:green;font-weight:bold">' . $name . '</span><br/>';
634 }
635 else
636 echo 'Sample character: <span style="font-weight:bold">' . $name . '</span> already exist in database<br/>';
637 }
638 }
639 else
640 new Error_Critic('', 'Character <i>Account Manager</i> does not exist. Cannot install sample characters!');
641 }
642 elseif($step == 5)
643 {
644 echo '<h1>STEP '.$step.'</h1>Set Admin Account<br>';
645 if(empty($_REQUEST['saveaccpassword']))
646 {
647 echo 'Admin account login is: <b>1</b><br/>Set new password to this account.<br>';
648 echo 'New password: <form action="install.php" method=POST><input type="text" name="newpass" size="35">(Don\'t give it password to anyone!)';
649 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.';
650 }
651 else
652 {
653 include_once('./system/load.compat.php');
654 $newpass = trim($_POST['newpass']);
655 if(!check_password($newpass))
656 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.';
657 else
658 {
659 //create / set pass to admin account
660 $account = new Account(1, Account::LOADTYPE_NAME);
661 if($account->isLoaded())
662 {
663 $account->setPassword($newpass); // setPassword encrypt it to ots encryption
664 $account->setPageAccess(3);
665 $account->setFlag('unknown');
666 $account->save();
667 }
668 else
669 {
670 $newAccount = new Account();
671 $newAccount->setName(1);
672 $newAccount->setPassword($newpass); // setPassword encrypt it to ots encryption
673 $newAccount->setMail(rand(0,999999) . '@gmail.com');
674 $newAccount->setPageAccess(3);
675 $newAccount->setGroupID(1);
676 $newAccount->setFlag('unknown');
677 $newAccount->setCreateIP(Visitor::getIP());
678 $newAccount->setCreateDate(time());
679 }
680 $_SESSION['account'] = 1;
681 $_SESSION['password'] = $newpass;
682 $logged = TRUE;
683 echo '<h1>Admin account login: 1<br>Admin account password: '.$newpass.'</h1><br/><h3>It\'s end of installation. Installation is blocked!</h3>';
684 if(!unlink('install.txt'))
685 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.');
686 }
687 }
688 }
689}