install.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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" href="#">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. <div class="collapse navbar-collapse" id="navbarCollapse">
  38. <ul class="navbar-nav mr-auto">
  39. <li class="nav-item active"><a class="nav-link" href="#">Installation <span class="sr-only">(current)</span></a></li>
  40. </ul>
  41. </div>
  42. </nav>
  43. <!-- Begin page content -->
  44. <div class="container">
  45. <?php
  46. $entities = array();
  47. foreach(glob(__DIR__.'/connector/*.class.php') as $classFile){
  48. require_once($classFile);
  49. $className = str_replace('.class.php','',basename($classFile));
  50. $entities[$className] = $className::label.' - '.$className::description;
  51. }
  52. //check prerequisite
  53. if(file_exists(__DIR__.'/constant.php')) throw new Exception('Le script est déja installé, pour recommencer l\'installation, supprimez le fichier constant.php');
  54. 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');
  55. if(!file_exists(__DIR__.'/file')) mkdir(__DIR__.'/file',0755,true);
  56. if(!file_exists(__DIR__.'/file/avatar')) mkdir(__DIR__.'/file/avatar',0755,true);
  57. //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>)');
  58. //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>)');
  59. if(isset($_['install'])){
  60. $constantStream = file_get_contents(__DIR__.'/constant-sample.php');
  61. if(!isset($_['host'])) $_['host'] = '';
  62. if(!isset($_['login'])) $_['login'] = '';
  63. if(!isset($_['password'])) $_['password'] = '';
  64. if(!isset($_['database'])) $_['database'] = '';
  65. $cryptKey = base64_encode(time().$_['login'].mt_rand(0,1000));
  66. $constantStream = str_replace(
  67. array("{{BASE_SGBD}}","{{BASE_HOST}}","{{BASE_NAME}}","{{BASE_LOGIN}}","{{BASE_PASSWORD}}","{{ROOT_URL}}","{{CRYPT_KEY}}"),
  68. array($_['entity'],$_['host'],$_['name'],$_['login'],$_['password'],$_['root'],$cryptKey),$constantStream
  69. );
  70. file_put_contents(__DIR__.'/constant.php',$constantStream);
  71. require_once(__DIR__.'/constant.php');
  72. require_once(__ROOT__.'class'.SLASH.'Entity.class.php');
  73. //install entities
  74. Entity::install(__ROOT__.'class');
  75. global $conf;
  76. $conf = new Configuration();
  77. $conf->getAll();
  78. //create firm
  79. $firm = new Firm();
  80. $firm->label = 'Établissement';
  81. $firm->description = 'Établissement par défaut';
  82. $firm->save();
  83. //create admin rank
  84. $rank = new Rank();
  85. $rank->label = 'Administrateur';
  86. $rank->description = 'Dispose de tous les accès';
  87. $rank->save();
  88. //create default user
  89. $admin = new User();
  90. $admin->login = 'admin';
  91. $admin->password = User::password_encrypt('admin');
  92. $admin->firstname = 'Chuck';
  93. $admin->name = 'Norris';
  94. $admin->superadmin = 1;
  95. $admin->rank = $rank->id;
  96. $admin->state = User::ACTIVE;
  97. $admin->save();
  98. $_SESSION['currentUser'] = serialize($admin);
  99. $userfirmrank = new UserFirmRank();
  100. $userfirmrank->user = $admin->login;
  101. $userfirmrank->firm = $firm->id;
  102. $userfirmrank->save();
  103. $sections = array();
  104. Plugin::callHook('section',array(&$sections));
  105. foreach($sections as $section=>$description){
  106. $right = new Right();
  107. $right->rank = $rank->id;
  108. $right->section = $section;
  109. $right->read = true;
  110. $right->edit = true;
  111. $right->delete = true;
  112. $right->configure = true;
  113. $right->save();
  114. }
  115. //Activation des plugins par défaut
  116. foreach (array('fr.idleman.hackpoint','fr.idleman.wiki','fr.idleman.dashboard','fr.idleman.notification') as $plugin) {
  117. Plugin::state($plugin,true);
  118. } ?>
  119. <div class="alert alert-success alert-dismissable">
  120. <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
  121. <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>
  122. </div>
  123. <a class="btn btn-primary" href="index.php">Revenir à l'index</a>
  124. <?php
  125. } else {
  126. $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'];
  127. $root = str_replace("/install.php", "", $root );
  128. $parts = explode('?',$root);
  129. $root = array_shift($parts);
  130. ?>
  131. <div class="row">
  132. <form class="col-md-3" action="install.php" method="POST">
  133. <h3>Installation</h3>
  134. <p>Merci de bien vouloir remplir les champs ci-dessous</p>
  135. <label for="entity">Base de donnée</label>
  136. <select class="form-control" name="entity" onchange="window.location='install.php?sgbd='+$(this).val()">
  137. <option value="">-</option>
  138. <?php foreach($entities as $class=>$label): ?>
  139. <option <?php echo (isset($_['sgbd']) && $_['sgbd']==$class ? 'selected="selected"': '') ?> value="<?php echo $class ?>"><?php echo $label; ?></option>
  140. <?php endforeach; ?>
  141. </select><br/>
  142. <?php if(isset($_['sgbd']) && $_['sgbd']!=''):
  143. require_once(__DIR__.'/connector/'.$_['sgbd'].'.class.php');
  144. foreach($_['sgbd']::fields() as $field): ?>
  145. <label for="<?php echo $field['id']; ?>"><?php echo $field['label']; ?></label><br/>
  146. <?php if(!isset($field['comment'])): ?><small><?php echo $field['comment']; ?></small><br/><?php endif; ?>
  147. <input type="text" class="form-control" value="<?php echo $field['default']; ?>" name="<?php echo $field['id']; ?>" id="<?php echo $field['id']; ?>"/><br/>
  148. <?php endforeach; ?>
  149. <label for="root">Adresse web</label><br/>
  150. <input type="text" class="form-control" name="root" id="root" value="<?php echo $root; ?>"/><br/>
  151. <input type="submit" class="btn btn-primary" value="Installer" name="install"><br/><br/>
  152. <?php endif; ?>
  153. </form>
  154. </div>
  155. <?php
  156. }
  157. } catch (Exception $e) { ?>
  158. <div class="alert alert-danger">
  159. <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
  160. <strong>Oops!</strong> <?php echo $e->getMessage().' - '.$e->getFile().' L'.$e->getLine().'<hr/><pre>'.$e->getTraceAsString().'</pre>';
  161. ?>
  162. </div>
  163. <?php
  164. } ?>
  165. </div>
  166. <footer class="footer">
  167. <div class="container">
  168. <span class="text-muted">Installateur by <a href="mailto:valentin.carruesco@idleman.fr">@valentin carruesco<a></span>
  169. </div>
  170. </footer>
  171. <!-- Bootstrap core JavaScript -->
  172. <!-- Placed at the end of the document so the pages load faster -->
  173. <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  174. <script>window.jQuery || document.write('<script src="js/vendor/jquery.min.js"><\/script>')</script>
  175. <script src="js/vendor/popper.min.js"></script>
  176. <script src="js/bootstrap.min.js"></script>
  177. <script src="js/vendor/mustache.min.js"></script>
  178. <script src="js/plugins.js"></script>
  179. <script src="js/main.js"></script>
  180. <?php echo Plugin::callJs(); ?>
  181. </body>