Hubzilla core code
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.
 
 
 
 
 
 

737 lines
25 KiB

  1. <?php
  2. namespace Zotlabs\Module;
  3. /**
  4. * @file mod/setup.php
  5. *
  6. * Controller for the initial setup/installation.
  7. *
  8. * @todo This setup module could need some love and improvements.
  9. */
  10. /**
  11. * @brief Initialisation for the setup module.
  12. *
  13. */
  14. class Setup extends \Zotlabs\Web\Controller {
  15. private static $install_wizard_pass = 1;
  16. function init() {
  17. // Ensure that if somebody hasn't read the install documentation and doesn't have all
  18. // the required modules or has a totally borked shared hosting provider and they can't
  19. // figure out what the hell is going on - that we at least spit out an error message which
  20. // we can inquire about when they write to tell us that our software doesn't work.
  21. // The worst thing we can do at this point is throw a white screen of death and rely on
  22. // them knowing about servers and php modules and logfiles enough so that we can guess
  23. // at the source of the problem. As ugly as it may be, we need to throw a technically worded
  24. // PHP error message in their face. Once installation is complete application errors will
  25. // throw a white screen because these error messages divulge information which can
  26. // potentially be useful to hackers.
  27. error_reporting(E_ERROR | E_WARNING | E_PARSE );
  28. ini_set('log_errors', '0');
  29. ini_set('display_errors', '1');
  30. // $baseurl/setup/testrwrite to test if rewite in .htaccess is working
  31. if (argc() == 2 && argv(1) == "testrewrite") {
  32. echo 'ok';
  33. killme();
  34. }
  35. if (x($_POST, 'pass'))
  36. $this->install_wizard_pass = intval($_POST['pass']);
  37. else
  38. $this->install_wizard_pass = 1;
  39. }
  40. /**
  41. * @brief Handle the actions of the different setup steps.
  42. *
  43. */
  44. function post() {
  45. switch($this->install_wizard_pass) {
  46. case 1:
  47. case 2:
  48. return;
  49. // implied break;
  50. case 3:
  51. $urlpath = \App::get_path();
  52. $dbhost = trim($_POST['dbhost']);
  53. $dbport = intval(trim($_POST['dbport']));
  54. $dbuser = trim($_POST['dbuser']);
  55. $dbpass = trim($_POST['dbpass']);
  56. $dbdata = trim($_POST['dbdata']);
  57. $dbtype = intval(trim($_POST['dbtype']));
  58. $phpath = trim($_POST['phpath']);
  59. $adminmail = trim($_POST['adminmail']);
  60. $siteurl = trim($_POST['siteurl']);
  61. $advanced = ((intval($_POST['advanced'])) ? 1 : 0);
  62. // $siteurl should not have a trailing slash
  63. $siteurl = rtrim($siteurl,'/');
  64. require_once('include/dba/dba_driver.php');
  65. $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
  66. if(! \DBA::$dba->connected) {
  67. echo 'Database Connect failed: ' . DBA::$dba->error;
  68. killme();
  69. }
  70. return;
  71. // implied break;
  72. case 4:
  73. $urlpath = \App::get_path();
  74. $dbhost = notags(trim($_POST['dbhost']));
  75. $dbport = intval(notags(trim($_POST['dbport'])));
  76. $dbuser = notags(trim($_POST['dbuser']));
  77. $dbpass = notags(trim($_POST['dbpass']));
  78. $dbdata = notags(trim($_POST['dbdata']));
  79. $dbtype = intval(notags(trim($_POST['dbtype'])));
  80. $phpath = notags(trim($_POST['phpath']));
  81. $timezone = notags(trim($_POST['timezone']));
  82. $adminmail = notags(trim($_POST['adminmail']));
  83. $siteurl = notags(trim($_POST['siteurl']));
  84. $advanced = ((intval($_POST['advanced'])) ? 1 : 0);
  85. if($siteurl != z_root()) {
  86. $test = z_fetch_url($siteurl."/setup/testrewrite");
  87. if((! $test['success']) || ($test['body'] != 'ok')) {
  88. \App::$data['url_fail'] = true;
  89. \App::$data['url_error'] = $test['error'];
  90. return;
  91. }
  92. }
  93. if(! \DBA::$dba->connected) {
  94. // connect to db
  95. $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
  96. }
  97. if(! \DBA::$dba->connected) {
  98. echo 'CRITICAL: DB not connected.';
  99. killme();
  100. }
  101. $tpl = get_intltext_template('htconfig.tpl');
  102. $txt = replace_macros($tpl,array(
  103. '$dbhost' => $dbhost,
  104. '$dbport' => $dbport,
  105. '$dbuser' => $dbuser,
  106. '$dbpass' => $dbpass,
  107. '$dbdata' => $dbdata,
  108. '$dbtype' => $dbtype,
  109. '$uno' => 1 - $advanced,
  110. '$timezone' => $timezone,
  111. '$siteurl' => $siteurl,
  112. '$site_id' => random_string(),
  113. '$phpath' => $phpath,
  114. '$adminmail' => $adminmail
  115. ));
  116. $result = file_put_contents('.htconfig.php', $txt);
  117. if(! $result) {
  118. \App::$data['txt'] = $txt;
  119. }
  120. $errors = $this->load_database($db);
  121. if($errors)
  122. \App::$data['db_failed'] = $errors;
  123. else
  124. \App::$data['db_installed'] = true;
  125. return;
  126. // implied break;
  127. default:
  128. break;
  129. }
  130. }
  131. function get_db_errno() {
  132. if(class_exists('mysqli'))
  133. return mysqli_connect_errno();
  134. else
  135. return mysql_errno();
  136. }
  137. /**
  138. * @brief Get output for the setup page.
  139. *
  140. * Depending on the state we are currently in it returns different content.
  141. *
  142. * @return string parsed HTML output
  143. */
  144. function get() {
  145. $o = '';
  146. $wizard_status = '';
  147. $install_title = t('$Projectname Server - Setup');
  148. if(x(\App::$data, 'db_conn_failed')) {
  149. $this->install_wizard_pass = 2;
  150. $wizard_status = t('Could not connect to database.');
  151. }
  152. if(x(\App::$data, 'url_fail')) {
  153. $this->install_wizard_pass = 3;
  154. $wizard_status = t('Could not connect to specified site URL. Possible SSL certificate or DNS issue.');
  155. if(\App::$data['url_error'])
  156. $wizard_status .= ' ' . \App::$data['url_error'];
  157. }
  158. if(x(\App::$data, 'db_create_failed')) {
  159. $this->install_wizard_pass = 2;
  160. $wizard_status = t('Could not create table.');
  161. }
  162. $db_return_text = '';
  163. if(x(\App::$data, 'db_installed')) {
  164. $txt = '<p style="font-size: 130%;">';
  165. $txt .= t('Your site database has been installed.') . EOL;
  166. $db_return_text .= $txt;
  167. }
  168. if(x(\App::$data, 'db_failed')) {
  169. $txt = t('You may need to import the file "install/schema_xxx.sql" manually using a database client.') . EOL;
  170. $txt .= t('Please see the file "install/INSTALL.txt".') . EOL ."<hr>" ;
  171. $txt .= "<pre>".\App::$data['db_failed'] . "</pre>". EOL ;
  172. $db_return_text .= $txt;
  173. }
  174. if(\DBA::$dba && \DBA::$dba->connected) {
  175. $r = q("SELECT COUNT(*) as `total` FROM `account`");
  176. if($r && count($r) && $r[0]['total']) {
  177. $tpl = get_markup_template('install.tpl');
  178. return replace_macros($tpl, array(
  179. '$title' => $install_title,
  180. '$pass' => '',
  181. '$status' => t('Permission denied.'),
  182. '$text' => '',
  183. ));
  184. }
  185. }
  186. if(x(\App::$data, 'txt') && strlen(\App::$data['txt'])) {
  187. $db_return_text .= $this->manual_config($a);
  188. }
  189. if ($db_return_text != "") {
  190. $tpl = get_markup_template('install.tpl');
  191. return replace_macros($tpl, array(
  192. '$title' => $install_title,
  193. '$pass' => '',
  194. '$text' => $db_return_text . $this->what_next(),
  195. ));
  196. }
  197. switch ($this->install_wizard_pass){
  198. case 1: { // System check
  199. $checks = array();
  200. $this->check_funcs($checks);
  201. $this->check_htconfig($checks);
  202. $this->check_store($checks);
  203. $this->check_smarty3($checks);
  204. $this->check_keys($checks);
  205. if (x($_POST, 'phpath'))
  206. $phpath = notags(trim($_POST['phpath']));
  207. $this->check_php($phpath, $checks);
  208. $this->check_phpconfig($checks);
  209. $this->check_htaccess($checks);
  210. $checkspassed = array_reduce($checks, "self::check_passed", true);
  211. $tpl = get_markup_template('install_checks.tpl');
  212. $o .= replace_macros($tpl, array(
  213. '$title' => $install_title,
  214. '$pass' => t('System check'),
  215. '$checks' => $checks,
  216. '$passed' => $checkspassed,
  217. '$see_install' => t('Please see the file "install/INSTALL.txt".'),
  218. '$next' => t('Next'),
  219. '$reload' => t('Check again'),
  220. '$phpath' => $phpath,
  221. '$baseurl' => z_root(),
  222. ));
  223. return $o;
  224. }; break;
  225. case 2: { // Database config
  226. $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : '127.0.0.1');
  227. $dbuser = notags(trim($_POST['dbuser']));
  228. $dbport = intval(notags(trim($_POST['dbport'])));
  229. $dbpass = notags(trim($_POST['dbpass']));
  230. $dbdata = notags(trim($_POST['dbdata']));
  231. $dbtype = intval(notags(trim($_POST['dbtype'])));
  232. $phpath = notags(trim($_POST['phpath']));
  233. $adminmail = notags(trim($_POST['adminmail']));
  234. $siteurl = notags(trim($_POST['siteurl']));
  235. $tpl = get_markup_template('install_db.tpl');
  236. $o .= replace_macros($tpl, array(
  237. '$title' => $install_title,
  238. '$pass' => t('Database connection'),
  239. '$info_01' => t('In order to install $Projectname we need to know how to connect to your database.'),
  240. '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
  241. '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
  242. '$status' => $wizard_status,
  243. '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, t('Default is 127.0.0.1')),
  244. '$dbport' => array('dbport', t('Database Port'), $dbport, t('Communication port number - use 0 for default')),
  245. '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, ''),
  246. '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, ''),
  247. '$dbdata' => array('dbdata', t('Database Name'), $dbdata, ''),
  248. '$dbtype' => array('dbtype', t('Database Type'), $dbtype, '', array( 0=>'MySQL', 1=>'PostgreSQL' )),
  249. '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.')),
  250. '$siteurl' => array('siteurl', t('Website URL'), z_root(), t('Please use SSL (https) URL if available.')),
  251. '$lbl_10' => t('Please select a default timezone for your website'),
  252. '$baseurl' => z_root(),
  253. '$phpath' => $phpath,
  254. '$submit' => t('Submit'),
  255. ));
  256. return $o;
  257. }; break;
  258. case 3: { // Site settings
  259. require_once('include/datetime.php');
  260. $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : '127.0.0.1');
  261. $dbport = intval(notags(trim($_POST['dbuser'])));
  262. $dbuser = notags(trim($_POST['dbuser']));
  263. $dbpass = notags(trim($_POST['dbpass']));
  264. $dbdata = notags(trim($_POST['dbdata']));
  265. $dbtype = intval(notags(trim($_POST['dbtype'])));
  266. $phpath = notags(trim($_POST['phpath']));
  267. $adminmail = notags(trim($_POST['adminmail']));
  268. $siteurl = notags(trim($_POST['siteurl']));
  269. $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
  270. $tpl = get_markup_template('install_settings.tpl');
  271. $o .= replace_macros($tpl, array(
  272. '$title' => $install_title,
  273. '$pass' => t('Site settings'),
  274. '$status' => $wizard_status,
  275. '$dbhost' => $dbhost,
  276. '$dbport' => $dbport,
  277. '$dbuser' => $dbuser,
  278. '$dbpass' => $dbpass,
  279. '$dbdata' => $dbdata,
  280. '$phpath' => $phpath,
  281. '$dbtype' => $dbtype,
  282. '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.')),
  283. '$siteurl' => array('siteurl', t('Website URL'), z_root(), t('Please use SSL (https) URL if available.')),
  284. '$advanced' => array('advanced', t('Enable $Projectname <strong>advanced</strong> features?'), 1, t('Some advanced features, while useful - may be best suited for technically proficient audiences')),
  285. '$timezone' => array('timezone', t('Please select a default timezone for your website'), $timezone, '', get_timezones()),
  286. '$baseurl' => z_root(),
  287. '$submit' => t('Submit'),
  288. ));
  289. return $o;
  290. }; break;
  291. }
  292. }
  293. /**
  294. * @brief Add a check result to the array for output.
  295. *
  296. * @param[in,out] array &$checks array passed to template
  297. * @param string $title a title for the check
  298. * @param boolean $status
  299. * @param boolean $required
  300. * @param[optional] string $help optional help string
  301. */
  302. function check_add(&$checks, $title, $status, $required, $help = '') {
  303. $checks[] = array(
  304. 'title' => $title,
  305. 'status' => $status,
  306. 'required' => $required,
  307. 'help' => $help
  308. );
  309. }
  310. /**
  311. * @brief Checks the PHP environment.
  312. *
  313. * @param[in,out] string &$phpath
  314. * @param[out] array &$checks
  315. */
  316. function check_php(&$phpath, &$checks) {
  317. $help = '';
  318. if(version_compare(PHP_VERSION, '5.4') < 0) {
  319. $help .= t('PHP version 5.4 or greater is required.');
  320. $this->check_add($checks, t('PHP version'), false, false, $help);
  321. }
  322. if (strlen($phpath)) {
  323. $passed = file_exists($phpath);
  324. } else {
  325. if(is_windows())
  326. $phpath = trim(shell_exec('where php'));
  327. else
  328. $phpath = trim(shell_exec('which php'));
  329. $passed = strlen($phpath);
  330. }
  331. if(!$passed) {
  332. $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
  333. $help .= t('If you don\'t have a command line version of PHP installed on server, you will not be able to run background polling via cron.') . EOL;
  334. $help .= EOL . EOL ;
  335. $tpl = get_markup_template('field_input.tpl');
  336. $help .= replace_macros($tpl, array(
  337. '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
  338. ));
  339. $phpath = '';
  340. }
  341. $this->check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
  342. if($passed) {
  343. $str = autoname(8);
  344. $cmd = "$phpath install/testargs.php $str";
  345. $result = trim(shell_exec($cmd));
  346. $passed2 = $result == $str;
  347. $help = '';
  348. if(!$passed2) {
  349. $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
  350. $help .= t('This is required for message delivery to work.');
  351. }
  352. $this->check_add($checks, t('PHP register_argc_argv'), $passed, true, $help);
  353. }
  354. }
  355. /**
  356. * @brief Some PHP configuration checks.
  357. *
  358. * @todo Change how we display such informational text. Add more description
  359. * how to change them.
  360. *
  361. * @param[out] array &$checks
  362. */
  363. function check_phpconfig(&$checks) {
  364. require_once 'include/environment.php';
  365. $help = '';
  366. $result = getPhpiniUploadLimits();
  367. $help = sprintf(t('Your max allowed total upload size is set to %s. Maximum size of one file to upload is set to %s. You are allowed to upload up to %d files at once.'),
  368. userReadableSize($result['post_max_size']),
  369. userReadableSize($result['max_upload_filesize']),
  370. $result['max_file_uploads']
  371. );
  372. $help .= '<br>' . t('You can adjust these settings in the servers php.ini.');
  373. $this->check_add($checks, t('PHP upload limits'), true, false, $help);
  374. }
  375. /**
  376. * @brief Check if the openssl implementation can generate keys.
  377. *
  378. * @param[out] array $checks
  379. */
  380. function check_keys(&$checks) {
  381. $help = '';
  382. $res = false;
  383. if (function_exists('openssl_pkey_new')) {
  384. $res = openssl_pkey_new(array(
  385. 'digest_alg' => 'sha1',
  386. 'private_key_bits' => 4096,
  387. 'encrypt_key' => false)
  388. );
  389. }
  390. // Get private key
  391. if (! $res) {
  392. $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
  393. $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
  394. }
  395. $this->check_add($checks, t('Generate encryption keys'), $res, true, $help);
  396. }
  397. /**
  398. * @brief Check for some PHP functions and modules.
  399. *
  400. * @param[in,out] array &$checks
  401. */
  402. function check_funcs(&$checks) {
  403. $ck_funcs = array();
  404. // add check metadata, the real check is done bit later and return values set
  405. $this->check_add($ck_funcs, t('libCurl PHP module'), true, true);
  406. $this->check_add($ck_funcs, t('GD graphics PHP module'), true, true);
  407. $this->check_add($ck_funcs, t('OpenSSL PHP module'), true, true);
  408. $this->check_add($ck_funcs, t('mysqli or postgres PHP module'), true, true);
  409. $this->check_add($ck_funcs, t('mb_string PHP module'), true, true);
  410. $this->check_add($ck_funcs, t('mcrypt PHP module'), true, true);
  411. $this->check_add($ck_funcs, t('xml PHP module'), true, true);
  412. if(function_exists('apache_get_modules')){
  413. if (! in_array('mod_rewrite', apache_get_modules())) {
  414. $this->check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
  415. } else {
  416. $this->check_add($ck_funcs, t('Apache mod_rewrite module'), true, true);
  417. }
  418. }
  419. if((! function_exists('proc_open')) || strstr(ini_get('disable_functions'),'proc_open')) {
  420. $this->check_add($ck_funcs, t('proc_open'), false, true, t('Error: proc_open is required but is either not installed or has been disabled in php.ini'));
  421. }
  422. else {
  423. $this->check_add($ck_funcs, t('proc_open'), true, true);
  424. }
  425. if(! function_exists('curl_init')) {
  426. $ck_funcs[0]['status'] = false;
  427. $ck_funcs[0]['help'] = t('Error: libCURL PHP module required but not installed.');
  428. }
  429. if(! function_exists('imagecreatefromjpeg')) {
  430. $ck_funcs[1]['status'] = false;
  431. $ck_funcs[1]['help'] = t('Error: GD graphics PHP module with JPEG support required but not installed.');
  432. }
  433. if(! function_exists('openssl_public_encrypt')) {
  434. $ck_funcs[2]['status'] = false;
  435. $ck_funcs[2]['help'] = t('Error: openssl PHP module required but not installed.');
  436. }
  437. if(! function_exists('mysqli_connect') && !function_exists('pg_connect')) {
  438. $ck_funcs[3]['status'] = false;
  439. $ck_funcs[3]['help'] = t('Error: mysqli or postgres PHP module required but neither are installed.');
  440. }
  441. if(! function_exists('mb_strlen')) {
  442. $ck_funcs[4]['status'] = false;
  443. $ck_funcs[4]['help'] = t('Error: mb_string PHP module required but not installed.');
  444. }
  445. if(! function_exists('mcrypt_encrypt')) {
  446. $ck_funcs[5]['status'] = false;
  447. $ck_funcs[5]['help'] = t('Error: mcrypt PHP module required but not installed.');
  448. }
  449. if(! extension_loaded('xml')) {
  450. $ck_funcs[6]['status'] = false;
  451. $ck_funcs[6]['help'] = t('Error: xml PHP module required for DAV but not installed.');
  452. }
  453. $checks = array_merge($checks, $ck_funcs);
  454. }
  455. /**
  456. * @brief Check for .htconfig requirements.
  457. *
  458. * @param[out] array &$checks
  459. */
  460. function check_htconfig(&$checks) {
  461. $status = true;
  462. $help = '';
  463. if( (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
  464. (!file_exists('.htconfig.php') && !is_writable('.')) ) {
  465. $status = false;
  466. $help = t('The web installer needs to be able to create a file called ".htconfig.php" in the top folder of your web server and it is unable to do so.') .EOL;
  467. $help .= t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.').EOL;
  468. $help .= t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Red top folder.').EOL;
  469. $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "install/INSTALL.txt" for instructions.').EOL;
  470. }
  471. $this->check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
  472. }
  473. /**
  474. * @brief Checks for our templating engine Smarty3 requirements.
  475. *
  476. * @param[out] array &$checks
  477. */
  478. function check_smarty3(&$checks) {
  479. $status = true;
  480. $help = '';
  481. if(! is_writable(TEMPLATE_BUILD_PATH) ) {
  482. $status = false;
  483. $help = t('Red uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
  484. $help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the top level web folder.'), TEMPLATE_BUILD_PATH) . EOL;
  485. $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
  486. $help .= sprintf( t('Note: as a security measure, you should give the web server write access to %s only--not the template files (.tpl) that it contains.'), TEMPLATE_BUILD_PATH) . EOL;
  487. }
  488. $this->check_add($checks, sprintf( t('%s is writable'), TEMPLATE_BUILD_PATH), $status, true, $help);
  489. }
  490. /**
  491. * @brief Check for store directory.
  492. *
  493. * @param[out] array &$checks
  494. */
  495. function check_store(&$checks) {
  496. $status = true;
  497. $help = '';
  498. @os_mkdir(TEMPLATE_BUILD_PATH, STORAGE_DEFAULT_PERMISSIONS, true);
  499. if(! is_writable('store')) {
  500. $status = false;
  501. $help = t('Red uses the store directory to save uploaded files. The web server needs to have write access to the store directory under the Red top level folder') . EOL;
  502. $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
  503. }
  504. $this->check_add($checks, t('store is writable'), $status, true, $help);
  505. }
  506. /**
  507. * @brief Check URL rewrite und SSL certificate.
  508. *
  509. * @param[out] array &$checks
  510. */
  511. function check_htaccess(&$checks) {
  512. $a = get_app();
  513. $status = true;
  514. $help = '';
  515. $ssl_error = false;
  516. $url = z_root() . '/setup/testrewrite';
  517. if (function_exists('curl_init')){
  518. $test = z_fetch_url($url);
  519. if(! $test['success']) {
  520. if(strstr($url,'https://')) {
  521. $test = z_fetch_url($url,false,0,array('novalidate' => true));
  522. if($test['success']) {
  523. $ssl_error = true;
  524. }
  525. }
  526. else {
  527. $test = z_fetch_url(str_replace('http://','https://',$url),false,0,array('novalidate' => true));
  528. if($test['success']) {
  529. $ssl_error = true;
  530. }
  531. }
  532. if($ssl_error) {
  533. $help = t('SSL certificate cannot be validated. Fix certificate or disable https access to this site.') . EOL;
  534. $help .= t('If you have https access to your website or allow connections to TCP port 443 (the https: port), you MUST use a browser-valid certificate. You MUST NOT use self-signed certificates!') . EOL;
  535. $help .= t('This restriction is incorporated because public posts from you may for example contain references to images on your own hub.') . EOL;
  536. $help .= t('If your certificate is not recognized, members of other sites (who may themselves have valid certificates) will get a warning message on their own site complaining about security issues.') . EOL;
  537. $help .= t('This can cause usability issues elsewhere (not just on your own site) so we must insist on this requirement.') .EOL;
  538. $help .= t('Providers are available that issue free certificates which are browser-valid.'). EOL;
  539. $this->check_add($checks, t('SSL certificate validation'), false, true, $help);
  540. }
  541. }
  542. if ((! $test['success']) || ($test['body'] != "ok")) {
  543. $status = false;
  544. $help = t('Url rewrite in .htaccess is not working. Check your server configuration.'.'Test: '.var_export($test,true));
  545. }
  546. $this->check_add($checks, t('Url rewrite is working'), $status, true, $help);
  547. } else {
  548. // cannot check modrewrite if libcurl is not installed
  549. }
  550. }
  551. function manual_config(&$a) {
  552. $data = htmlspecialchars(\App::$data['txt'], ENT_COMPAT, 'UTF-8');
  553. $o = t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.');
  554. $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
  555. return $o;
  556. }
  557. function load_database_rem($v, $i){
  558. $l = trim($i);
  559. if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
  560. return $v;
  561. } else {
  562. return $v."\n".$i;
  563. }
  564. }
  565. function load_database($db) {
  566. $str = file_get_contents(\DBA::$dba->get_install_script());
  567. $arr = explode(';',$str);
  568. $errors = false;
  569. foreach($arr as $a) {
  570. if(strlen(trim($a))) {
  571. $r = dbq(trim($a));
  572. if(! $r) {
  573. $errors .= t('Errors encountered creating database tables.') . $a . EOL;
  574. }
  575. }
  576. }
  577. return $errors;
  578. }
  579. function what_next() {
  580. $a = get_app();
  581. // install the standard theme
  582. set_config('system', 'allowed_themes', 'redbasic');
  583. // Set a lenient list of ciphers if using openssl. Other ssl engines
  584. // (e.g. NSS used in RedHat) require different syntax, so hopefully
  585. // the default curl cipher list will work for most sites. If not,
  586. // this can set via config. Many distros are now disabling RC4,
  587. // but many Red sites still use it and are unable to change it.
  588. // We do not use SSL for encryption, only to protect session cookies.
  589. // z_fetch_url() is also used to import shared links and other content
  590. // so in theory most any cipher could show up and we should do our best
  591. // to make the content available rather than tell folks that there's a
  592. // weird SSL error which they can't do anything about.
  593. $x = curl_version();
  594. if(stristr($x['ssl_version'],'openssl'))
  595. set_config('system','curl_ssl_ciphers','ALL:!eNULL');
  596. // Create a system channel
  597. require_once ('include/channel.php');
  598. create_sys_channel();
  599. $baseurl = z_root();
  600. return
  601. t('<h1>What next</h1>')
  602. ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
  603. .t('Please see the file "install/INSTALL.txt".')
  604. ."</p><p>"
  605. .t("Go to your new hub <a href='$baseurl/register'>registration page</a> and register as new member. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.")
  606. ."</p>";
  607. }
  608. static private function check_passed($v, $c) {
  609. if ($c['required'])
  610. $v = $v && $c['status'];
  611. return $v;
  612. }
  613. }