Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

553 satır
17 KiB

  1. <?php
  2. use Friendica\App;
  3. use Friendica\Core\System;
  4. require_once "include/Photo.php";
  5. $install_wizard_pass = 1;
  6. function install_init(App $a) {
  7. // $baseurl/install/testrwrite to test if rewite in .htaccess is working
  8. if ($a->argc == 2 && $a->argv[1] == "testrewrite") {
  9. echo "ok";
  10. killme();
  11. }
  12. // We overwrite current theme css, because during install we could not have a working mod_rewrite
  13. // so we could not have a css at all. Here we set a static css file for the install procedure pages
  14. $a->config['system']['theme'] = "../install";
  15. $a->theme['stylesheet'] = System::baseUrl()."/view/install/style.css";
  16. global $install_wizard_pass;
  17. if (x($_POST, 'pass')) {
  18. $install_wizard_pass = intval($_POST['pass']);
  19. }
  20. }
  21. function install_post(App $a) {
  22. global $install_wizard_pass;
  23. switch($install_wizard_pass) {
  24. case 1:
  25. case 2:
  26. return;
  27. break; // just in case return don't return :)
  28. case 3:
  29. $urlpath = $a->get_path();
  30. $dbhost = notags(trim($_POST['dbhost']));
  31. $dbuser = notags(trim($_POST['dbuser']));
  32. $dbpass = notags(trim($_POST['dbpass']));
  33. $dbdata = notags(trim($_POST['dbdata']));
  34. $phpath = notags(trim($_POST['phpath']));
  35. require_once("include/dba.php");
  36. if (!dba::connect($dbhost, $dbuser, $dbpass, $dbdata, true)) {
  37. $a->data['db_conn_failed'] = true;
  38. }
  39. return;
  40. break;
  41. case 4:
  42. $urlpath = $a->get_path();
  43. $dbhost = notags(trim($_POST['dbhost']));
  44. $dbuser = notags(trim($_POST['dbuser']));
  45. $dbpass = notags(trim($_POST['dbpass']));
  46. $dbdata = notags(trim($_POST['dbdata']));
  47. $phpath = notags(trim($_POST['phpath']));
  48. $timezone = notags(trim($_POST['timezone']));
  49. $language = notags(trim($_POST['language']));
  50. $adminmail = notags(trim($_POST['adminmail']));
  51. $rino = 2;
  52. // connect to db
  53. dba::connect($dbhost, $dbuser, $dbpass, $dbdata, true);
  54. $tpl = get_markup_template('htconfig.tpl');
  55. $txt = replace_macros($tpl,array(
  56. '$dbhost' => $dbhost,
  57. '$dbuser' => $dbuser,
  58. '$dbpass' => $dbpass,
  59. '$dbdata' => $dbdata,
  60. '$timezone' => $timezone,
  61. '$language' => $language,
  62. '$urlpath' => $urlpath,
  63. '$phpath' => $phpath,
  64. '$adminmail' => $adminmail,
  65. '$rino' => $rino
  66. ));
  67. $result = file_put_contents('.htconfig.php', $txt);
  68. if (! $result) {
  69. $a->data['txt'] = $txt;
  70. }
  71. $errors = load_database();
  72. if ($errors) {
  73. $a->data['db_failed'] = $errors;
  74. } else {
  75. $a->data['db_installed'] = true;
  76. }
  77. return;
  78. break;
  79. }
  80. }
  81. function install_content(App $a) {
  82. global $install_wizard_pass;
  83. $o = '';
  84. $wizard_status = "";
  85. $install_title = t('Friendica Communications Server - Setup');
  86. if (x($a->data, 'db_conn_failed')) {
  87. $install_wizard_pass = 2;
  88. $wizard_status = t('Could not connect to database.');
  89. }
  90. if (x($a->data, 'db_create_failed')) {
  91. $install_wizard_pass = 2;
  92. $wizard_status = t('Could not create table.');
  93. }
  94. $db_return_text = "";
  95. if (x($a->data, 'db_installed')) {
  96. $txt = '<p style="font-size: 130%;">';
  97. $txt .= t('Your Friendica site database has been installed.') . EOL;
  98. $db_return_text .= $txt;
  99. }
  100. if (x($a->data, 'db_failed')) {
  101. $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
  102. $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>";
  103. $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL;
  104. $db_return_text .= $txt;
  105. }
  106. if (dba::$connected) {
  107. $r = q("SELECT COUNT(*) as `total` FROM `user`");
  108. if (dbm::is_result($r) && $r[0]['total']) {
  109. $tpl = get_markup_template('install.tpl');
  110. return replace_macros($tpl, array(
  111. '$title' => $install_title,
  112. '$pass' => '',
  113. '$status' => t('Database already in use.'),
  114. '$text' => '',
  115. ));
  116. }
  117. }
  118. if (x($a->data, 'txt') && strlen($a->data['txt'])) {
  119. $db_return_text .= manual_config($a);
  120. }
  121. if ($db_return_text != "") {
  122. $tpl = get_markup_template('install.tpl');
  123. return replace_macros($tpl, array(
  124. '$title' => $install_title,
  125. '$pass' => "",
  126. '$text' => $db_return_text . what_next(),
  127. ));
  128. }
  129. switch ($install_wizard_pass) {
  130. case 1: { // System check
  131. $checks = array();
  132. check_funcs($checks);
  133. check_imagik($checks);
  134. check_htconfig($checks);
  135. check_smarty3($checks);
  136. check_keys($checks);
  137. if (x($_POST, 'phpath')) {
  138. $phpath = notags(trim($_POST['phpath']));
  139. }
  140. check_php($phpath, $checks);
  141. check_htaccess($checks);
  142. /// @TODO Maybe move this out?
  143. function check_passed($v, $c) {
  144. if ($c['required']) {
  145. $v = $v && $c['status'];
  146. }
  147. return $v;
  148. }
  149. $checkspassed = array_reduce($checks, "check_passed", true);
  150. $tpl = get_markup_template('install_checks.tpl');
  151. $o .= replace_macros($tpl, array(
  152. '$title' => $install_title,
  153. '$pass' => t('System check'),
  154. '$checks' => $checks,
  155. '$passed' => $checkspassed,
  156. '$see_install' => t('Please see the file "INSTALL.txt".'),
  157. '$next' => t('Next'),
  158. '$reload' => t('Check again'),
  159. '$phpath' => $phpath,
  160. '$baseurl' => System::baseUrl(),
  161. ));
  162. return $o;
  163. }; break;
  164. case 2: { // Database config
  165. $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
  166. $dbuser = notags(trim($_POST['dbuser']));
  167. $dbpass = notags(trim($_POST['dbpass']));
  168. $dbdata = notags(trim($_POST['dbdata']));
  169. $phpath = notags(trim($_POST['phpath']));
  170. $tpl = get_markup_template('install_db.tpl');
  171. $o .= replace_macros($tpl, array(
  172. '$title' => $install_title,
  173. '$pass' => t('Database connection'),
  174. '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
  175. '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
  176. '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
  177. '$status' => $wizard_status,
  178. '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
  179. '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
  180. '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, t("For security reasons the password must not be empty"), 'required'),
  181. '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
  182. '$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.'), 'required', 'autofocus', 'email'),
  183. '$lbl_10' => t('Please select a default timezone for your website'),
  184. '$baseurl' => System::baseUrl(),
  185. '$phpath' => $phpath,
  186. '$submit' => t('Submit'),
  187. ));
  188. return $o;
  189. }; break;
  190. case 3: { // Site settings
  191. require_once('include/datetime.php');
  192. $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
  193. $dbuser = notags(trim($_POST['dbuser']));
  194. $dbpass = notags(trim($_POST['dbpass']));
  195. $dbdata = notags(trim($_POST['dbdata']));
  196. $phpath = notags(trim($_POST['phpath']));
  197. $adminmail = notags(trim($_POST['adminmail']));
  198. $timezone = ((x($_POST, 'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
  199. /* Installed langs */
  200. $lang_choices = get_available_languages();
  201. $tpl = get_markup_template('install_settings.tpl');
  202. $o .= replace_macros($tpl, array(
  203. '$title' => $install_title,
  204. '$pass' => t('Site settings'),
  205. '$status' => $wizard_status,
  206. '$dbhost' => $dbhost,
  207. '$dbuser' => $dbuser,
  208. '$dbpass' => $dbpass,
  209. '$dbdata' => $dbdata,
  210. '$phpath' => $phpath,
  211. '$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.'), 'required', 'autofocus', 'email'),
  212. '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
  213. '$language' => array('language', t('System Language:'), 'en', t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices),
  214. '$baseurl' => System::baseUrl(),
  215. '$submit' => t('Submit'),
  216. ));
  217. return $o;
  218. }; break;
  219. }
  220. }
  221. /**
  222. * checks : array passed to template
  223. * title : string
  224. * status : boolean
  225. * required : boolean
  226. * help : string optional
  227. */
  228. function check_add(&$checks, $title, $status, $required, $help) {
  229. $checks[] = array(
  230. 'title' => $title,
  231. 'status' => $status,
  232. 'required' => $required,
  233. 'help' => $help,
  234. );
  235. }
  236. function check_php(&$phpath, &$checks) {
  237. $passed = $passed2 = $passed3 = false;
  238. if (strlen($phpath)) {
  239. $passed = file_exists($phpath);
  240. } else {
  241. $phpath = trim(shell_exec('which php'));
  242. $passed = strlen($phpath);
  243. }
  244. $help = "";
  245. if (!$passed) {
  246. $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
  247. $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run the background processing. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-poller'>'Setup the poller'</a>") . EOL;
  248. $help .= EOL . EOL;
  249. $tpl = get_markup_template('field_input.tpl');
  250. $help .= replace_macros($tpl, array(
  251. '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
  252. ));
  253. $phpath = "";
  254. }
  255. check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
  256. if ($passed) {
  257. $cmd = "$phpath -v";
  258. $result = trim(shell_exec($cmd));
  259. $passed2 = ( strpos($result, "(cli)") !== false);
  260. list($result) = explode("\n", $result);
  261. $help = "";
  262. if (!$passed2) {
  263. $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
  264. $help .= t('Found PHP version: ')."<tt>$result</tt>";
  265. }
  266. check_add($checks, t('PHP cli binary'), $passed2, true, $help);
  267. }
  268. if ($passed2) {
  269. $str = autoname(8);
  270. $cmd = "$phpath testargs.php $str";
  271. $result = trim(shell_exec($cmd));
  272. $passed3 = $result == $str;
  273. $help = "";
  274. if (!$passed3) {
  275. $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
  276. $help .= t('This is required for message delivery to work.');
  277. }
  278. check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
  279. }
  280. }
  281. function check_keys(&$checks) {
  282. $help = '';
  283. $res = false;
  284. if (function_exists('openssl_pkey_new')) {
  285. $res = openssl_pkey_new(array(
  286. 'digest_alg' => 'sha1',
  287. 'private_key_bits' => 4096,
  288. 'encrypt_key' => false
  289. ));
  290. }
  291. // Get private key
  292. if (! $res) {
  293. $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
  294. $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
  295. }
  296. check_add($checks, t('Generate encryption keys'), $res, true, $help);
  297. }
  298. function check_funcs(&$checks) {
  299. $ck_funcs = array();
  300. check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
  301. check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
  302. check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
  303. check_add($ck_funcs, t('PDO or MySQLi PHP module'), true, true, "");
  304. check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
  305. check_add($ck_funcs, t('XML PHP module'), true, true, "");
  306. check_add($ck_funcs, t('iconv module'), true, true, "");
  307. if (function_exists('apache_get_modules')) {
  308. if (! in_array('mod_rewrite',apache_get_modules())) {
  309. check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
  310. } else {
  311. check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
  312. }
  313. }
  314. if (! function_exists('curl_init')) {
  315. $ck_funcs[0]['status'] = false;
  316. $ck_funcs[0]['help'] = t('Error: libCURL PHP module required but not installed.');
  317. }
  318. if (! function_exists('imagecreatefromjpeg')) {
  319. $ck_funcs[1]['status'] = false;
  320. $ck_funcs[1]['help'] = t('Error: GD graphics PHP module with JPEG support required but not installed.');
  321. }
  322. if (! function_exists('openssl_public_encrypt')) {
  323. $ck_funcs[2]['status'] = false;
  324. $ck_funcs[2]['help'] = t('Error: openssl PHP module required but not installed.');
  325. }
  326. if (! function_exists('mysqli_connect') && !class_exists('pdo')) {
  327. $ck_funcs[3]['status'] = false;
  328. $ck_funcs[3]['help'] = t('Error: PDO or MySQLi PHP module required but not installed.');
  329. }
  330. if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', PDO::getAvailableDrivers())) {
  331. $ck_funcs[3]['status'] = false;
  332. $ck_funcs[3]['help'] = t('Error: The MySQL driver for PDO is not installed.');
  333. }
  334. if (! function_exists('mb_strlen')) {
  335. $ck_funcs[4]['status'] = false;
  336. $ck_funcs[4]['help'] = t('Error: mb_string PHP module required but not installed.');
  337. }
  338. if (! function_exists('iconv_strlen')) {
  339. $ck_funcs[7]['status'] = false;
  340. $ck_funcs[7]['help'] = t('Error: iconv PHP module required but not installed.');
  341. }
  342. $checks = array_merge($checks, $ck_funcs);
  343. // check for XML DOM Documents being able to be generated
  344. try {
  345. $xml = new DOMDocument();
  346. } catch (Exception $e) {
  347. $ck_funcs[6]['status'] = false;
  348. $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.');
  349. }
  350. }
  351. function check_htconfig(&$checks) {
  352. $status = true;
  353. $help = "";
  354. if ((file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
  355. (!file_exists('.htconfig.php') && !is_writable('.'))) {
  356. $status = false;
  357. $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;
  358. $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;
  359. $help .= t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Friendica top folder.').EOL;
  360. $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
  361. }
  362. check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
  363. }
  364. function check_smarty3(&$checks) {
  365. $status = true;
  366. $help = "";
  367. if (!is_writable('view/smarty3')) {
  368. $status = false;
  369. $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
  370. $help .= t('In order to store these compiled templates, the web server needs to have write access to the directory view/smarty3/ under the Friendica top level folder.').EOL;
  371. $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
  372. $help .= t('Note: as a security measure, you should give the web server write access to view/smarty3/ only--not the template files (.tpl) that it contains.').EOL;
  373. }
  374. check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
  375. }
  376. function check_htaccess(&$checks) {
  377. $status = true;
  378. $help = "";
  379. if (function_exists('curl_init')) {
  380. $test = fetch_url(System::baseUrl()."/install/testrewrite");
  381. if ($test != "ok") {
  382. $test = fetch_url(normalise_link(System::baseUrl()."/install/testrewrite"));
  383. }
  384. if ($test != "ok") {
  385. $status = false;
  386. $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
  387. }
  388. check_add($checks, t('Url rewrite is working'), $status, true, $help);
  389. } else {
  390. // cannot check modrewrite if libcurl is not installed
  391. /// @TODO Maybe issue warning here?
  392. }
  393. }
  394. function check_imagik(&$checks) {
  395. $imagick = false;
  396. $gif = false;
  397. if (class_exists('Imagick')) {
  398. $imagick = true;
  399. $supported = Photo::supportedTypes();
  400. if (array_key_exists('image/gif', $supported)) {
  401. $gif = true;
  402. }
  403. }
  404. if ($imagick == false) {
  405. check_add($checks, t('ImageMagick PHP extension is not installed'), $imagick, false, "");
  406. } else {
  407. check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
  408. if ($imagick) {
  409. check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
  410. }
  411. }
  412. }
  413. function manual_config(App $a) {
  414. $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8');
  415. $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.');
  416. $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
  417. return $o;
  418. }
  419. function load_database_rem($v, $i) {
  420. $l = trim($i);
  421. if (strlen($l)>1 && ($l[0] == "-" || ($l[0] == "/" && $l[1] == "*"))) {
  422. return $v;
  423. } else {
  424. return $v."\n".$i;
  425. }
  426. }
  427. function load_database() {
  428. require_once("include/dbstructure.php");
  429. $errors = update_structure(false, true);
  430. return $errors;
  431. }
  432. function what_next() {
  433. $baseurl = System::baseUrl();
  434. return
  435. t('<h1>What next</h1>')
  436. ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
  437. .t('Please see the file "INSTALL.txt".')
  438. ."</p><p>"
  439. .t("Go to your new Friendica node <a href='$baseurl/register'>registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.")
  440. ."</p>";
  441. }