install.php 8.5 KB

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