Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.

543 lines
16 KiB

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