You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
8.1 KiB

  1. <?php
  2. require_once('../system/Lang/i18n.php');
  3. require_once('../system/Lang/languages.php');
  4. function get_mysql_port() {
  5. $port = ini_get('mysql.default_port');
  6. if($port == "")
  7. $port = ini_get('mysqli.default_port');
  8. if($port == "")
  9. $port = 3306;
  10. return $port;
  11. }
  12. $err = array();
  13. function set_error($error_name, $error_message)
  14. {
  15. global $err;
  16. $err[$error_name] = $error_message;
  17. }
  18. function err($error_name)
  19. {
  20. global $err;
  21. if(isset($err[$error_name])) {
  22. return $err[$error_name];
  23. } else {
  24. return false;
  25. }
  26. }
  27. function has_errors()
  28. {
  29. global $err;
  30. return count($err);
  31. }
  32. function test_dir($dir)
  33. {
  34. return (file_exists($dir) && is_dir($dir) && is_writable($dir));
  35. }
  36. function list_themes()
  37. {
  38. $dir = opendir('../themes');
  39. $themes = array();
  40. while($theme = readdir($dir)) {
  41. if(preg_match('/^\.+$/', $theme)
  42. || !is_dir('../themes/'.$theme)) {
  43. continue;
  44. }
  45. $themes[$theme] = $theme;
  46. }
  47. return $themes;
  48. }
  49. function list_lang()
  50. {
  51. $dir = opendir('../i18n');
  52. $langs = array('en' => 'English');
  53. $languages = get_lang_list();
  54. while($lang = readdir($dir)) {
  55. if(!preg_match('/\.po$/', $lang)) {
  56. continue;
  57. }
  58. $lang = substr($lang, 0, strlen($lang) - 3);
  59. $langs[$lang] = $languages[$lang];
  60. }
  61. return $langs;
  62. }
  63. function test_requirements()
  64. {
  65. $errors = array();
  66. if(!(version_compare(PHP_VERSION, '5.3.0') >= 0)) {
  67. $errors[] = t("PHP version mismatch. Movim requires PHP 5.3 minimum.")." ".t("Actual version : "). PHP_VERSION .
  68. '<div class="guidance">'.t("Update your PHP version or contact your server administrator").'</div>';
  69. }
  70. if(!extension_loaded('curl')) {
  71. $errors[] = t("Movim requires the %s extension.", 'PHP Curl') .
  72. '<div class="guidance">'.t("Install %s and %s packages", 'php5-curl', 'curl').'</div>';
  73. }
  74. if(!extension_loaded('gd')) {
  75. $errors[] = t("Movim requires the %s extension.", 'PHP GD') .
  76. '<div class="guidance">'.t("Install the %s package", 'php5-gd').'</div>';
  77. }
  78. if(!extension_loaded('SimpleXML')) {
  79. $errors[] = t("Movim requires the %s extension.", 'SimpleXML') .
  80. '<div class="guidance">'.t("Install the %s package", 'php5-cli').'</div>';
  81. }
  82. if(!test_dir('../')) {
  83. $errors[] = t("Movim's folder must be writable.") .
  84. '<div class="guidance">'.t("Enable read and write rights on Movim's root folder").'</div>';
  85. }
  86. /*if(!test_dir('user')) {
  87. $errors[] = t("The <em>%s</em> folder must exist and be writable.", 'user');
  88. }
  89. if(!test_dir('log')) {
  90. $errors[] = t("The <em>%s</em> folder must exist and be writable.", 'log');
  91. }*/
  92. // Must have sqlite or mysql (so far...)
  93. if(!extension_loaded('mysql') && !class_exists('SQLite3')) {
  94. $exts = array('MySQL', 'SQLite');
  95. $exts_txt = implode(t("or"), $exts);
  96. $errors[] = t("Movim requires the %s extension.", $exts_txt);
  97. }
  98. global $databases;
  99. if(extension_loaded('mysql'))
  100. $databases['mysql'] = 'MySQL';
  101. if(class_exists('SQLite3'))
  102. $databases['sqlite'] = 'SQLite';
  103. return (count($errors) > 0)? $errors : false;
  104. }
  105. function get_checkbox($name, $if = 'true', $else = 'false')
  106. {
  107. return (isset($_POST[$name])? $if : $else);
  108. }
  109. function test_bosh($boshhost, $port, $suffix, $host)
  110. {
  111. $url = (get_checkbox('boshCookieHTTPS') == "true")? 'https://' : 'http://';
  112. $url .= $boshhost.":".$port.'/'.$suffix;
  113. $headers = array('Accept-Encoding: gzip, deflate', 'Content-Type: text/xml; charset=utf-8');
  114. $data = "
  115. <body content='text/xml; charset=utf-8'
  116. hold='1'
  117. rid='1573741820'
  118. to='".$host."'
  119. secure='true'
  120. wait='60'
  121. xml:lang='en'
  122. xmpp:version='1.0'
  123. xmlns='http://jabber.org/protocol/httpbind'
  124. xmlns:xmpp='urn:xmpp:xbosh'/>";
  125. $ch = curl_init($url);
  126. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  127. curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
  128. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  129. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  130. curl_setopt($ch, CURLOPT_VERBOSE, false);
  131. curl_setopt($ch, CURLOPT_POST, 1);
  132. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  133. $rs = array();
  134. $rs['content'] = curl_exec($ch);
  135. $rs['errno'] = curl_errno($ch);
  136. $rs['errmsg'] = curl_error($ch);
  137. $rs['header'] = curl_getinfo($ch);
  138. if($rs['errno']) {
  139. set_error('bosh', t("Bosh connection failed with error `%s'", $rs['errmsg']));
  140. return false;
  141. }
  142. curl_close($ch);
  143. $arr = simplexml_load_string($rs["content"]);
  144. if(is_object($arr))
  145. $att = $arr->attributes();
  146. if($att['type'] == 'terminate') {
  147. set_error('bosh', t("XMPP connection through Bosh failed with error `%s'", $att['condition']));
  148. }
  149. else if(isset($att['sid'])) {
  150. return true;
  151. }
  152. else {
  153. return false;
  154. }
  155. }
  156. function make_xml($stuff)
  157. {
  158. static $level = 0;
  159. $buffer = "";
  160. // Putting the XML declaration
  161. if($level == 0) {
  162. $buffer = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
  163. }
  164. // Indentation
  165. $indent = "";
  166. for($i = 0; $i < $level; $i++) {
  167. $indent.= " ";
  168. }
  169. // Doing the job
  170. foreach($stuff as $tag => $value) {
  171. if(is_array($value)) {
  172. $buffer.= $indent.'<'.$tag.'>'.PHP_EOL;
  173. $level++;
  174. $buffer.= make_xml($value);
  175. $buffer.= $indent.'</'.$tag.'>'.PHP_EOL;
  176. } else {
  177. $buffer.= "$indent<$tag>$value</$tag>".PHP_EOL;
  178. }
  179. }
  180. $level--;
  181. return $buffer;
  182. }
  183. function perform_install()
  184. {
  185. // Creating the folders.
  186. if(!test_dir('../user') && !@mkdir('../user')) {
  187. echo t("Couldn't create directory '%s'.", 'user');
  188. return false;
  189. }
  190. if(!test_dir('../log') && !@mkdir('../log')) {
  191. echo t("Couldn't create directory '%s'.", 'log');
  192. return false;
  193. }
  194. if(!test_dir('../config') && !@mkdir('../config')) {
  195. echo t("Couldn't create directory '%s'.", 'config');
  196. return false;
  197. }
  198. // Creating the configuration file.
  199. $conf = array(
  200. 'config' => array(
  201. 'theme' => $_POST['theme'],
  202. 'defLang' => $_POST['language'],
  203. 'boshCookieTTL' => $_POST['boshCookieTTL'],
  204. 'boshCookiePath' => $_POST['boshCookiePath'],
  205. 'boshCookieDomain' => get_checkbox('boshCookieDomain'),
  206. 'boshCookieHTTPS' => get_checkbox('boshCookieHTTPS'),
  207. 'boshCookieHTTPOnly' => get_checkbox('boshCookieHTTPOnly'),
  208. 'logLevel' => $_POST['verbosity'],
  209. 'accountCreation' => get_checkbox('accountCreation', 1, 0),
  210. 'host' => $_POST['host'],
  211. 'domain' => $_POST['domain'],
  212. 'defBoshHost' => $_POST['defBoshHost'],
  213. 'defBoshSuffix' => $_POST['defBoshSuffix'],
  214. 'defBoshPort' => $_POST['defBoshPort'],
  215. 'storageDriver' => $_POST['storage'],
  216. 'storageConnection' => $_POST['database'],
  217. 'proxyEnabled' => get_checkbox('proxyEnabled'),
  218. 'proxyURL' => $_POST['proxyURL'],
  219. 'proxyPort' => $_POST['proxyPort'],
  220. ),
  221. );
  222. if(!@file_put_contents('../config/conf.xml', make_xml($conf))) {
  223. echo t("Couldn't create configuration file '%s'.", 'config/conf.xml');
  224. return false;
  225. }
  226. return true;
  227. }
  228. $step = 'part1.php';
  229. if(isset($_POST['install'])) {
  230. // We test the Bosh configuration
  231. if(!test_bosh($_POST['defBoshHost'], $_POST['defBoshPort'], $_POST['defBoshSuffix'], $_POST['host'])) {
  232. goto loadpage;
  233. }
  234. // We create the configuration file
  235. perform_install();
  236. // We try to connect to the database
  237. try {
  238. include('../init.php');
  239. } catch (Exception $e) {
  240. set_error('bdd', t("Database connection failed with error `%s'", $e->getMessage()));
  241. goto loadpage;
  242. }
  243. // We create correctly the tables
  244. global $sdb;
  245. $contact = new Contact();
  246. $sdb->create($contact);
  247. $conf = new ConfVar();
  248. $sdb->create($conf);
  249. $message = new Message();
  250. $sdb->create($message);
  251. $presence = new Presence();
  252. $sdb->create($presence);
  253. $attachment = new Attachment();
  254. $sdb->create($attachment);
  255. $step = 'part2.php';
  256. }
  257. loadpage:
  258. require($step);
  259. ?>