install.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. /*
  3. @nom: install
  4. @auteur: Idleman (idleman@idleman.fr)
  5. @description: Page d'installation du script (a supprimer après installation)
  6. */
  7. require_once('Functions.class.php');
  8. require_once('i18n.php');
  9. global $i18n;
  10. $install_terminee=false;
  11. if (isset($_GET['lang']))
  12. $currentLanguage = i18n_init($_GET['lang']);
  13. else
  14. $currentLanguage = i18n_init(Functions::getBrowserLanguages());
  15. $languageList = $i18n->languages;
  16. if (file_exists('constant.php')) {
  17. die(_t('ALREADY_INSTALLED'));
  18. }
  19. // Cookie de la session
  20. $cookiedir = '';
  21. if(dirname($_SERVER['SCRIPT_NAME'])!='/') $cookiedir=dirname($_SERVER["SCRIPT_NAME"]).'/';
  22. session_set_cookie_params(0, $cookiedir);
  23. session_start();
  24. // Protection des variables
  25. $_ = array_merge($_GET, $_POST);
  26. $whiteList = array(
  27. /* La liste blanche recense les variables ne devant pas être passées via
  28. la sécurisation, mais simplement échappées pour Php. */
  29. 'mysqlHost', 'mysqlLogin', 'mysqlMdp', 'mysqlBase', 'mysqlPrefix',
  30. );
  31. foreach($_ as $key=>&$val){
  32. $val = in_array($key, $whiteList)
  33. ? str_replace("'", "\'", $val)
  34. : Functions::secure($val);
  35. }
  36. // Valeurs par défaut, remplacées si une autre valeur est saisie.
  37. foreach (array('login','mysqlBase','mysqlHost','mysqlLogin','mysqlMdp','mysqlPrefix','password','root') as $var) {
  38. /* Initalise les variables avec le contenu des champs
  39. * pour rappeler les valeurs déjà saisies. */
  40. if (!empty($_[$var]))
  41. $$var = $_[$var];
  42. else
  43. $$var = '';
  44. }
  45. if (empty($root)) {
  46. // Ne peut être vide, alors on met la valeur par défaut
  47. $root = str_replace(
  48. basename(__FILE__),
  49. '',
  50. 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']
  51. );
  52. }
  53. if (!isset($_['mysqlPrefix'])) {
  54. // Le formulaire n'étant pas soumis, on met cette valeur par défaut.
  55. $mysqlPrefix = 'leed_';
  56. }
  57. $lib_errors = _t('ERROR');
  58. $lib_success = _t('SUCCESS');
  59. if(isset($_['installButton'])){
  60. if (empty($_['password']) || empty($_['login'])) {
  61. $test[$lib_errors][] = _t('INSTALL_ERROR_USERPWD');
  62. }
  63. if (!Functions::testDb(
  64. $_['mysqlHost'], $_['mysqlLogin'], $_['mysqlMdp'], $_['mysqlBase']
  65. )) {
  66. $test[$lib_errors][] = _t('INSTALL_ERROR_CONNEXION');
  67. } else {
  68. $test[$lib_success][] = _t('INSTALL_INFO_CONNEXION');
  69. }
  70. }
  71. if(!is_writable('./')){
  72. $test[$lib_errors][]=_t('INSTALL_ERROR_RIGHT', array(str_replace(basename(__FILE__),'',__FILE__)));
  73. }else{
  74. $test[$lib_success][]=_t('INSTALL_INFO_RIGHT');
  75. }
  76. if (!@function_exists('mysql_connect')){
  77. $test[$lib_errors][] = _t('INSTALL_ERROR_MYSQLCONNECT');
  78. }else{
  79. $test[$lib_success][] = _t('INSTALL_INFO_MYSQLCONNECT');
  80. }
  81. if (!@function_exists('file_get_contents')){
  82. $test[$lib_errors][] = _t('INSTALL_ERROR_FILEGET');
  83. }else{
  84. $test[$lib_success][] = _t('INSTALL_INFO_FILEGET');
  85. }
  86. if (!@function_exists('file_put_contents')){
  87. $test[$lib_errors][] = _t('INSTALL_ERROR_FILEPUT');
  88. }else{
  89. $test[$lib_success][] = _t('INSTALL_INFO_FILEPUT');
  90. }
  91. if (@version_compare(PHP_VERSION, '5.1.0') <= 0){
  92. $test[$lib_errors][] = _t('INSTALL_ERROR_PHPV', array(PHP_VERSION));
  93. }else{
  94. $test[$lib_success][] = _t('INSTALL_INFO_PHPV', array(PHP_VERSION));
  95. }
  96. if(ini_get('safe_mode') && ini_get('max_execution_time')!=0){
  97. $test[$lib_errors][] = _t('INSTALL_ERROR_SAFEMODE');
  98. }else{
  99. $test[$lib_success][] = _t('INSTALL_INFO_SAFEMODE');
  100. }
  101. if (isset($_['installButton']) && empty($test[$lib_errors])) { // Pas d'erreur, l'installation peut se faire.
  102. $constant = "<?php
  103. define('VERSION_NUMBER','1.6');
  104. define('VERSION_NAME','Dev');
  105. //Host de Mysql, le plus souvent localhost ou 127.0.0.1
  106. define('MYSQL_HOST','{$mysqlHost}');
  107. //Identifiant MySQL
  108. define('MYSQL_LOGIN','{$mysqlLogin}');
  109. //mot de passe MySQL
  110. define('MYSQL_MDP','{$mysqlMdp}');
  111. //Nom de la base MySQL ou se trouvera leed
  112. define('MYSQL_BDD','{$mysqlBase}');
  113. //Prefix des noms des tables leed pour les bases de données uniques
  114. define('MYSQL_PREFIX','{$mysqlPrefix}');
  115. //Nombre de pages affichées dans la barre de pagination
  116. define('PAGINATION_SCALE',5);
  117. //Nombre de flux mis à jour lors de la synchronisation graduée
  118. define('SYNC_GRAD_COUNT',10);
  119. //Langue utilisée
  120. define('LANGUAGE','".$_POST['install_changeLngLeed']."');
  121. ?>";
  122. file_put_contents('constant.php', $constant);
  123. if (!is_readable('constant.php'))
  124. die('"constant.php" not found!');
  125. require_once('constant.php');
  126. require_once('MysqlEntity.class.php');
  127. class_exists('Update') or require_once('Update.class.php');
  128. Update::ExecutePatch(true);
  129. require_once('Feed.class.php');
  130. require_once('Event.class.php');
  131. require_once('User.class.php');
  132. require_once('Folder.class.php');
  133. require_once('Configuration.class.php');
  134. $cryptographicSalt = User::generateSalt();
  135. $synchronisationCode = substr(sha1(rand(0,30).time().rand(0,30)),0,10);
  136. $root = (substr($_['root'], strlen($_['root'])-1)=='/'?$_['root']:$_['root'].'/');
  137. // DOSSIERS À CONSERVER TELS QUELS, SI DÉJÀ EXISTANTS
  138. $feedManager = new Feed(); $feedManager->create();
  139. $eventManager = new Event(); $eventManager->create();
  140. // COMPTE ADMINISTRATEUR, RÀZ SI NÉCESSAIRE
  141. $userManager = new User();
  142. if ($userManager->tableExists()) {
  143. // Suppose qu'il n'y a qu'un seul utilisateur
  144. $userManager->truncate();
  145. }
  146. $userManager->create();
  147. $admin = new User();
  148. $admin->setLogin($_['login']);
  149. $admin->setPassword($_['password'],$cryptographicSalt);
  150. $admin->save();
  151. $_SESSION['currentUser'] = serialize($admin);
  152. // DOSSIERS DE FLUX, RECRÉE LE DOSSIER GÉNÉRAL SI NÉCESSAIRE
  153. $folderManager = new Folder();
  154. $folderManager->create();
  155. if ($folderManager->rowCount()==0) {
  156. //Création du dossier général
  157. $folder = new Folder();
  158. $folder->setName(_t('GENERAL_FOLDER'));
  159. $folder->setParent(-1);
  160. $folder->setIsopen(1);
  161. $folder->save();
  162. }
  163. // REMET À ZÉRO LA CONFIGURATION
  164. $configurationManager = new Configuration();
  165. if ($configurationManager->tableExists()) {
  166. $configurationManager->truncate();
  167. }
  168. $configurationManager->create();
  169. $configurationManager->add('articleDisplayAnonymous','0');
  170. $configurationManager->add('articleDisplayAuthor','1');
  171. $configurationManager->add('articleDisplayDate','1');
  172. $configurationManager->add('articleDisplayFolderSort','1');
  173. $configurationManager->add('articleDisplayHomeSort','1');
  174. $configurationManager->add('articleDisplayLink','1');
  175. $configurationManager->add('articleDisplayMode','summary');
  176. $configurationManager->add('articlePerPages','5');
  177. $configurationManager->add('cryptographicSalt', $cryptographicSalt);
  178. $configurationManager->add('displayOnlyUnreadFeedFolder','false');
  179. $configurationManager->add('feedMaxEvents','50');
  180. $configurationManager->add('theme','marigolds');
  181. $configurationManager->add('optionFeedIsVerbose',1);
  182. $configurationManager->add('synchronisationCode',$synchronisationCode);
  183. $configurationManager->add('synchronisationEnableCache','0');
  184. $configurationManager->add('synchronisationForceFeed','0');
  185. $configurationManager->add('synchronisationType','auto');
  186. $configurationManager->add('root',$root);
  187. $install_terminee=true;
  188. } /* Ci-dessous, on y va si :
  189. - la page est simplement affichée, sans avoir été validée
  190. - le formulaire est soumis, mais l'installation ne peut se faire
  191. */
  192. ?>
  193. <!doctype html>
  194. <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
  195. <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
  196. <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
  197. <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
  198. <head>
  199. <meta charset="utf-8">
  200. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  201. <title><?php echo _t('INSTALL_TITLE') ?></title>
  202. <meta name="viewport" content="width=device-width">
  203. <link rel="stylesheet" href="templates/marigolds/css/style.css">
  204. <style>
  205. code {
  206. color:#000;
  207. font-size: 1em;
  208. }
  209. .install h1 {
  210. margin-bottom: 1.3em;
  211. }
  212. .install h2 {
  213. margin-bottom: 0.1em;
  214. font-size: 1.5em;
  215. }
  216. .install ul {
  217. margin: 0;
  218. padding: 0;
  219. }
  220. .install li {
  221. list-style: none outside none;
  222. }
  223. .install span {
  224. display: inline-block;
  225. width: 8em;
  226. padding-right: 1em;
  227. }
  228. button#installButton {
  229. margin-top: 1em;
  230. font-size: 2em;
  231. }
  232. .message {
  233. color: #ffffff;
  234. margin-bottom: 2em;
  235. }
  236. .message li {
  237. border:1px solid #212121
  238. }
  239. .messageError {
  240. background-color: #F16529;
  241. }
  242. .messageSuccess {
  243. background-color: #008000;
  244. }
  245. </style>
  246. </head>
  247. <body>
  248. <div class="global-wrapper">
  249. <div id="header-container">
  250. <header class="wrapper clearfix">
  251. <h1 class="logo" id="title"><a href="./index.php">L<i>eed</i></a></h1>
  252. <nav>
  253. </nav>
  254. </header>
  255. </div>
  256. <?php
  257. if ($install_terminee){
  258. echo '<div id="main-container">
  259. <div id="main" class="wrapper clearfix">
  260. <div id="menuBar"></div>
  261. <h1>'._t('INSTALL_TITLE_END').'</h1>
  262. <span>'._t('INSTALL_END').'</span>
  263. <hr>
  264. <button id="installButton" name="installButton" onclick="document.location.href=\'settings.php#preferenceBloc\'">'._t('INSTALL_BTN_END').'</button>
  265. ';
  266. // écriture des balises de fin et ne pas faire la suite
  267. echo '</div>
  268. <div id="footer-container">
  269. <footer class="wrapper">
  270. <p>Leed "Light Feed" by <a target="_blank" href="http://blog.idleman.fr">Idleman</a></p>
  271. </footer>
  272. </div>
  273. </body>
  274. </html>';
  275. exit();
  276. }
  277. ?>
  278. <div id="main-container">
  279. <div id="main" class="wrapper clearfix">
  280. <div id="menuBar">
  281. <aside>
  282. <h3 class="left"><?php echo _t('INSTALL_PRE_REQUIS') ?></h3>
  283. <ul class="clear" style="margin:0">
  284. <?php
  285. foreach($test as $type=>$messages){
  286. $class = 'message ';
  287. $class .= $lib_errors==$type ? 'messageError':'messageSuccess';
  288. echo "<li class='$class'>$type&nbsp;:\n<ul>";
  289. foreach ($messages as $message){
  290. echo "<li>$message</li>\n";
  291. }
  292. echo "</ul></li>";
  293. }
  294. ?>
  295. </ul>
  296. </aside>
  297. </div>
  298. <form action="install.php" method="POST" class="install">
  299. <h1><?php echo _t('INSTALL_TITLE') ?></h1>
  300. <h2><?php echo _t('INSTALL_TAB_GENERAL') ?></h2>
  301. <ul>
  302. <li>
  303. <span><?php echo _t('INSTALL_LANGUAGE') ?></span>
  304. <select name="install_changeLngLeed" onchange="window.location.href='install.php?lang='+this[this.selectedIndex].value">
  305. <?php
  306. foreach($languageList as $lang){
  307. $sel = $lang==$currentLanguage?'selected=selected':'';
  308. echo "<option $sel value='$lang'>$lang</option>";
  309. }
  310. ?>
  311. </select>
  312. </li>
  313. <li>
  314. <span><?php echo _t('PROJECT_ROOT') ?></span>
  315. <input type="text" name="root" value="<?php echo $root; ?>">
  316. </li>
  317. </ul>
  318. <h2><?php echo _t('INSTALL_TAB_BDD') ?></h2>
  319. <ul>
  320. <li>
  321. <span><?php echo _t('INSTALL_HOST') ?></span>
  322. <input type="text" name="mysqlHost" value="<?php echo $mysqlHost; ?>" placeholder="<?php echo _t('INSTALL_COMMENT_HOST') ?>">
  323. </li>
  324. <li>
  325. <span><?php echo _t('LOGIN') ?></span>
  326. <input type="text" name="mysqlLogin" value="<?php echo $mysqlLogin; ?>">
  327. </li>
  328. <li>
  329. <span><?php echo _t('PASSWORD') ?></span>
  330. <input type="text" autocomplete="off" name="mysqlMdp" value="<?php echo $mysqlMdp; ?>" placeholder="<?php echo _t('INSTALL_DISPLAY_CLEAR') ?>">
  331. </li>
  332. <li>
  333. <span><?php echo _t('INSTALL_BDD') ?></span>
  334. <input type="text" name="mysqlBase" value="<?php echo $mysqlBase; ?>" placeholder="<?php echo _t('INSTALL_COMMENT_BDD') ?>">
  335. </li>
  336. <li>
  337. <span><?php echo _t('INSTALL_PREFIX_TABLE') ?></span>
  338. <input type="text" name="mysqlPrefix" value="<?php echo $mysqlPrefix; ?>">
  339. </li>
  340. </ul>
  341. <h2><?php echo _t('INSTALL_TAB_ADMIN') ?></h2>
  342. <ul>
  343. <li>
  344. <span><?php echo _t('LOGIN') ?></span>
  345. <input type="text" name="login" value="<?php echo $login; ?>" placeholder="<?php echo _t('LOGIN') ?>">
  346. </li>
  347. <li>
  348. <span><?php echo _t('PASSWORD') ?></span>
  349. <input type="text" autocomplete="off" name="password" value="<?php echo $password; ?>" placeholder="<?php echo _t('INSTALL_DISPLAY_CLEAR') ?>">
  350. </li>
  351. </ul>
  352. <button id="installButton" name="installButton"><?php echo _t('INSTALL_BTN') ?></button>
  353. </form>
  354. </div>
  355. <div id="footer-container">
  356. <footer class="wrapper">
  357. <p>Leed "Light Feed" by <a target="_blank" href="http://blog.idleman.fr">Idleman</a></p>
  358. </footer>
  359. </div>
  360. </body>
  361. </html>