install.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. try {
  3. date_default_timezone_set('Europe/paris');
  4. mb_internal_encoding('UTF-8');
  5. require_once(__DIR__.'/function.php');
  6. spl_autoload_register('app_autoloader');
  7. $_ = array_map('secure_user_vars', array_merge($_POST, $_GET));
  8. require_once('class/Plugin.class.php');
  9. $entityFolder = __DIR__.'/class/';
  10. ?>
  11. <!DOCTYPE html>
  12. <html lang="fr">
  13. <head>
  14. <meta charset="utf-8">
  15. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  16. <meta name="description" content="">
  17. <meta name="author" content="">
  18. <link rel="icon" type="image/png" href="favicon.png" />
  19. <title>Installateur</title>
  20. <!-- Bootstrap core CSS -->
  21. <link href="css/bootstrap.min.css" rel="stylesheet">
  22. <!-- Font awesome -->
  23. <link rel="stylesheet" href="css/fontawesome-all.min.css">
  24. <!-- Custom styles for this template -->
  25. <link href="css/main.css" rel="stylesheet">
  26. <link href="css/theme.css" rel="stylesheet">
  27. <!-- Plugin css files -->
  28. <?php echo Plugin::callCss("css"); ?>
  29. </head>
  30. <body>
  31. <!-- Fixed navbar -->
  32. <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
  33. <a class="navbar-brand" style="background: url('img/logo/default-logo.png') no-repeat 0 center; padding-left:40px;" href="index.php"> Installateur</a>
  34. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
  35. <span class="navbar-toggler-icon"></span>
  36. </button>
  37. </nav>
  38. <!-- Begin page content -->
  39. <div class="container">
  40. <?php
  41. $entities = array();
  42. foreach(glob(__DIR__.'/connector/*.class.php') as $classFile){
  43. require_once($classFile);
  44. $className = str_replace('.class.php','',basename($classFile));
  45. $entities[$className] = $className::label.' - '.$className::description;
  46. }
  47. //check prerequisite
  48. if(file_exists(__DIR__.'/constant.php')) throw new Exception('Le script est déja installé, pour recommencer l\'installation, supprimez le fichier constant.php');
  49. if(!is_writable (__DIR__)) throw new Exception('Le dossier '.__DIR__.' doit être accessible en ecriture, merci de taper la commande linux <br/><code>sudo chown -R www-data:www-data '.__ROOT__.'</code><br/> ou de régler le dossier en écriture via votre client ftp');
  50. if(!file_exists(__DIR__.'/file')) mkdir(__DIR__.'/file',0755,true);
  51. if(!file_exists(__DIR__.'/file/avatar')) mkdir(__DIR__.'/file/avatar',0755,true);
  52. //if(!extension_loaded('gd') || !function_exists('gd_info')) throw new Exception('L\'extension php GD2 est requise, veuillez installer GD2 (sous linux : <code>sudo apt-get install php5-gd && service apache2 restart</code>)');
  53. //if(!in_array('sqlite',PDO::getAvailableDrivers())) throw new Exception('Le driver SQLITE est requis, veuillez installer sqlite3 (sous linux : <code>sudo apt-get install php5-sqlite && service apache2 restart</code>)');
  54. if(isset($_['install'])){
  55. $constantStream = file_get_contents(__DIR__.'/constant-sample.php');
  56. if(!isset($_['host'])) $_['host'] = '';
  57. if(!isset($_['login'])) $_['login'] = '';
  58. if(!isset($_['password'])) $_['password'] = '';
  59. if(!isset($_['database'])) $_['database'] = '';
  60. $cryptKey = base64_encode(time().$_['login'].mt_rand(0,1000));
  61. $constantStream = str_replace(
  62. array("{{BASE_SGBD}}","{{BASE_HOST}}","{{BASE_NAME}}","{{BASE_LOGIN}}","{{BASE_PASSWORD}}","{{ROOT_URL}}","{{CRYPT_KEY}}"),
  63. array($_['entity'],$_['host'],$_['name'],$_['login'],$_['password'],$_['root'],$cryptKey),$constantStream
  64. );
  65. file_put_contents(__DIR__.'/constant.php',$constantStream);
  66. require_once(__DIR__.'/constant.php');
  67. require_once(__ROOT__.'class'.SLASH.'Entity.class.php');
  68. //install entities
  69. Entity::install(__ROOT__.'class');
  70. global $conf;
  71. $conf = new Configuration();
  72. $conf->getAll();
  73. //create firm
  74. $firm = new Firm();
  75. $firm->label = 'Établissement';
  76. $firm->description = 'Établissement par défaut';
  77. $firm->save();
  78. //create admin rank
  79. $rank = new Rank();
  80. $rank->label = 'Administrateur';
  81. $rank->description = 'Dispose de tous les accès';
  82. $rank->save();
  83. //create default user
  84. $admin = new User();
  85. $admin->login = 'admin';
  86. $admin->password = User::password_encrypt('admin');
  87. $admin->firstname = 'Chuck';
  88. $admin->name = 'Norris';
  89. $admin->superadmin = 1;
  90. $admin->rank = $rank->id;
  91. $admin->state = User::ACTIVE;
  92. $admin->save();
  93. $_SESSION['currentUser'] = serialize($admin);
  94. $userfirmrank = new UserFirmRank();
  95. $userfirmrank->user = $admin->login;
  96. $userfirmrank->firm = $firm->id;
  97. $userfirmrank->save();
  98. $sections = array();
  99. Plugin::callHook('section',array(&$sections));
  100. foreach($sections as $section=>$description){
  101. $right = new Right();
  102. $right->rank = $rank->id;
  103. $right->section = $section;
  104. $right->read = true;
  105. $right->edit = true;
  106. $right->delete = true;
  107. $right->configure = true;
  108. $right->save();
  109. }
  110. //Activation des plugins par défaut
  111. foreach (array('fr.idleman.hackpoint','fr.idleman.wiki','fr.idleman.dashboard','fr.idleman.notification','fr.idleman.customiser') as $plugin) {
  112. Plugin::state($plugin,true);
  113. }
  114. $conf->put('core_theme','/plugin/customiser/theme/hackpoint/main.css');
  115. ?>
  116. <div class="alert alert-success alert-dismissable mt-3">
  117. <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
  118. <strong>Succès!</strong> La base est bien installée, l'utilisateur par défaut est <code>admin:admin</code>, pensez à changer le mot de passe rapidemment. <br>
  119. </div>
  120. <a class="btn btn-primary" href="index.php">Revenir à l'index</a>
  121. <?php
  122. } else {
  123. $root = 'http'.((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')|| $_SERVER['SERVER_PORT'] == 443?'s':'').'://'.$_SERVER['HTTP_HOST'].($_SERVER['SERVER_PORT']==80?'':':'.$_SERVER['SERVER_PORT']).$_SERVER['REQUEST_URI'];
  124. $root = str_replace("/install.php", "", $root );
  125. $parts = explode('?',$root);
  126. $root = array_shift($parts);
  127. ?>
  128. <div class="row mt-3">
  129. <form class="col-md-6" action="install.php" method="POST">
  130. <h3>Installation</h3>
  131. <p>Merci de bien vouloir remplir les champs ci-dessous</p>
  132. <label for="entity">Base de donnée</label>
  133. <select class="form-control" name="entity" onchange="window.location='install.php?sgbd='+$(this).val()">
  134. <option value="">-</option>
  135. <?php foreach($entities as $class=>$label): ?>
  136. <option <?php echo (isset($_['sgbd']) && $_['sgbd']==$class ? 'selected="selected"': '') ?> value="<?php echo $class ?>"><?php echo $label; ?></option>
  137. <?php endforeach; ?>
  138. </select><br/>
  139. <?php if(isset($_['sgbd']) && $_['sgbd']!=''):
  140. require_once(__DIR__.'/connector/'.$_['sgbd'].'.class.php');
  141. foreach($_['sgbd']::fields() as $field): ?>
  142. <label for="<?php echo $field['id']; ?>"><?php echo $field['label']; ?></label><br/>
  143. <?php if(!isset($field['comment'])): ?><small><?php echo $field['comment']; ?></small><br/><?php endif; ?>
  144. <input type="text" class="form-control" value="<?php echo $field['default']; ?>" name="<?php echo $field['id']; ?>" id="<?php echo $field['id']; ?>"/><br/>
  145. <?php endforeach; ?>
  146. <label for="root">Adresse web</label><br/>
  147. <input type="text" class="form-control" name="root" id="root" value="<?php echo $root; ?>"/><br/>
  148. <input type="submit" class="btn btn-primary" value="Installer" name="install"><br/><br/>
  149. <?php endif; ?>
  150. </form>
  151. </div>
  152. <?php
  153. }
  154. } catch (Exception $e) { ?>
  155. <div class="alert alert-danger">
  156. <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
  157. <strong>Oops!</strong> <?php echo $e->getMessage().' - '.$e->getFile().' L'.$e->getLine().'<hr/><pre>'.$e->getTraceAsString().'</pre>';
  158. ?>
  159. </div>
  160. <?php
  161. } ?>
  162. </div>
  163. <footer class="footer">
  164. <div class="container">
  165. <span class="text-muted">Installateur by <a href="mailto:valentin.carruesco@idleman.fr">@valentin carruesco<a></span>
  166. </div>
  167. </footer>
  168. <!-- Bootstrap core JavaScript -->
  169. <!-- Placed at the end of the document so the pages load faster -->
  170. <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  171. <script>window.jQuery || document.write('<script src="js/vendor/jquery.min.js"><\/script>')</script>
  172. <script src="js/vendor/popper.min.js"></script>
  173. <script src="js/bootstrap.min.js"></script>
  174. <script src="js/vendor/mustache.min.js"></script>
  175. <script src="js/plugins.js"></script>
  176. <script src="js/main.js"></script>
  177. <?php echo Plugin::callJs(); ?>
  178. </body>