Advertisement
foozzi

install.php

Dec 1st, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.71 KB | None | 0 0
  1. <?
  2. #### install.php ####
  3. #### v.1.0 ####
  4. #### foozzi ####
  5. #### GNUB 2011 ####
  6. #### License AGPL ####
  7. ?>
  8. <? require_once("../core/locale.php"); ?>
  9. <?php
  10. #### Если файл lock есть, выходим из установки ####
  11. if(is_file('../core/lock'))
  12.     exit($locale['i11']);
  13. ?>
  14. <?php
  15. #### Вывод ошибок ####
  16. ini_set('display_errors',1);
  17. error_reporting(E_ALL);
  18. #### Функция-инсталлятор ####
  19. function install_gnub() {
  20.     include_once('../core/config.php');
  21.     $shr = mysql_query('SHOW TABLES');
  22.     for ($tables=array(); $row3=mysql_fetch_array($shr); $tables[$row3[0]]=true); // Сотрим таблицы
  23.     if (!isset($tables[PREFIX.'categories']))  //Если таблиц еще не существует
  24.     {
  25. #### Создаем табличку admins ####
  26.   mysql_query ('CREATE TABLE '.PREFIX.'admins (
  27.   id tinyint(4) NOT NULL auto_increment,
  28.   login tinytext NOT NULL,
  29.   password tinytext NOT NULL,
  30.   status enum("admin") NOT NULL,
  31.   PRIMARY KEY  (`id`)
  32. ) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 AUTO_INCREMENT=8;') or die(mysql_error());
  33.  
  34. #### Создаем табличку config ####
  35.   mysql_query('CREATE TABLE '.PREFIX.'config (
  36.   site_name text NOT NULL,
  37.   quotes_num tinyint(4) default NULL
  38. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;') or die(mysql_error());
  39.  
  40.  
  41. #### Создаем табличку logs ####
  42.   mysql_query('CREATE TABLE '.PREFIX.'logs (
  43.   id tinyint(4) NOT NULL auto_increment,
  44.   qid tinyint(4) NOT NULL,
  45.   ip tinytext NOT NULL,
  46.   rating enum("plus","minus") default NULL,
  47.  PRIMARY KEY  (`id`)
  48. ) ENGINE=MyISAM AUTO_INCREMENT=39 DEFAULT CHARSET=utf8 AUTO_INCREMENT=39;') or die(mysql_error());
  49.  
  50.  
  51. #### Создаем табличку quotes ####
  52.   mysql_query('CREATE TABLE '.PREFIX.'quotes (
  53.   id tinyint(4) NOT NULL auto_increment,
  54.   moderator tinytext NOT NULL,
  55.   date tinytext NOT NULL,
  56.   rating tinyint(4) NOT NULL,
  57.   content text,
  58.   status enum("checked","unchecked") NOT NULL,
  59.  PRIMARY KEY  (`id`)
  60. ) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;') or die(mysql_error());
  61.  
  62. #### Заносим данные админа в таблицу admins ####
  63. $name = @$_REQUEST['name'];
  64.         if ($name == '') $name = $login;
  65.         mysql_query('INSERT INTO '.PREFIX.'admins SET
  66.            login = "'.$login.'",
  67.             status = "admin",
  68.             password = "'.md5($pass).'"')  or die(mysql_error());
  69. #### Ставим блокировку на повторную установку ####
  70. $lockt = 'lock';
  71. $lock = fopen ('../core/lock', "w");
  72. fwrite ($lock, $lockt);
  73. fclose ($lock);            
  74. require_once("../core/locale.php");
  75. echo $locale['i9']; // Вывод сообщения об удачной установке :)
  76. }
  77.  
  78. else
  79. {
  80.     echo $locale['i10']; // Вывод сообщение об не удачной установке :(
  81.     }
  82.  
  83. }  
  84. ?>
  85.  
  86. <?php
  87. #### Если кнопка "Поехали" в форме нажата, заполняем массив ####
  88. if (isset($_REQUEST['install']))
  89.     {
  90.         $config = array();
  91. #### Заполняем массив настроек тем, что пришло из формы ####      
  92.         $config['login'] = $_REQUEST['login'];
  93.         $config['pass'] = $_REQUEST['pass'];
  94.         $config['servdb'] = $_REQUEST['servdb'];
  95.         $config['userdb'] = $_REQUEST['userdb'];
  96.         $config['passwd'] = $_REQUEST['passwd'];
  97.         $config['namedb'] = $_REQUEST['namedb'];
  98.         $config['PREFIX'] = $_REQUEST['prefix'];
  99. #### Берем шаблон config.php ####
  100.         $config_tmpl = file_get_contents('config_tmpl.txt');
  101. #### обходим в цикле, заменяя части шаблона на элементы конф. массива ####
  102.         foreach ($config as $key=>$value) $config_tmpl = str_replace("<%$key%>", $value, $config_tmpl);
  103.         $cfg = fopen ('../core/config.php', "w");
  104.         fwrite ($cfg, $config_tmpl);
  105.         fclose ($cfg);
  106. #### Запуск функции установки ####
  107.         install_gnub();
  108.     }
  109. ?>
  110. <center>
  111. <form action="./install.php" method="post" >
  112. <? print_r ($locale['i1']); ?><br><input type="text" name="userdb" value="root" /><br>
  113. <? print_r ($locale['i2']); ?><br><input type="text" name="namedb" value="gnub" /><br>
  114. <? print_r ($locale['i3']); ?><br><input type="text" name="passwd" value="passwd" /><br>
  115. <? print_r ($locale['i4']); ?><br><input type="text" name="servdb" value="localhost" /><br>
  116. <? print_r ($locale['i5']); ?><br><input type="text" name="prefix" value="gnub_" /><br>
  117. <? print_r ($locale['i6']); ?><br>
  118. <? print_r ($locale['i7']); ?><br><input type="text" name="login" value="admin" /><br>
  119. <? print_r ($locale['i8']); ?><br><input type="text" name="pass" value="pass" /><br>
  120. <input type="submit" name="install" value="Поехали" /><br>
  121. </form>
  122. </center>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement