2 require_once "include/Photo.php";
4 $install_wizard_pass=1;
7 function install_init(&$a){
9 // $baseurl/install/testrwrite to test if rewite in .htaccess is working
10 if ($a->argc==2 && $a->argv[1]=="testrewrite") {
14 global $install_wizard_pass;
16 $install_wizard_pass = intval($_POST['pass']);
20 function install_post(&$a) {
21 global $install_wizard_pass, $db;
23 switch($install_wizard_pass) {
27 break; // just in case return don't return :)
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']));
36 require_once("include/dba.php");
38 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
39 /*if(get_db_errno()) {
41 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
43 if(! get_db_errno()) {
44 $r = q("CREATE DATABASE '%s'",
49 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
51 $a->data['db_create_failed']=true;
54 $a->data['db_conn_failed']=true;
59 $a->data['db_conn_failed']=true;
65 $urlpath = $a->get_path();
66 $dbhost = notags(trim($_POST['dbhost']));
67 $dbuser = notags(trim($_POST['dbuser']));
68 $dbpass = notags(trim($_POST['dbpass']));
69 $dbdata = notags(trim($_POST['dbdata']));
70 $phpath = notags(trim($_POST['phpath']));
71 $timezone = notags(trim($_POST['timezone']));
72 $adminmail = notags(trim($_POST['adminmail']));
75 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
77 $tpl = get_markup_template('htconfig.tpl');
78 $txt = replace_macros($tpl,array(
83 '$timezone' => $timezone,
84 '$urlpath' => $urlpath,
86 '$adminmail' => $adminmail
90 $result = file_put_contents('.htconfig.php', $txt);
92 $a->data['txt'] = $txt;
95 $errors = load_database($db);
99 $a->data['db_failed'] = $errors;
101 $a->data['db_installed'] = true;
108 function get_db_errno() {
109 if(class_exists('mysqli'))
110 return mysqli_connect_errno();
112 return mysql_errno();
115 function install_content(&$a) {
117 global $install_wizard_pass, $db;
120 $install_title = t('Friendica Communications Server - Setup');
124 if(x($a->data,'db_conn_failed')) {
125 $install_wizard_pass = 2;
126 $wizard_status = t('Could not connect to database.');
128 if(x($a->data,'db_create_failed')) {
129 $install_wizard_pass = 2;
130 $wizard_status = t('Could not create table.');
134 if(x($a->data,'db_installed')) {
135 $txt = '<p style="font-size: 130%;">';
136 $txt .= t('Your Friendica site database has been installed.') . EOL;
137 $db_return_text .= $txt;
140 if(x($a->data,'db_failed')) {
141 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
142 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>" ;
143 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL ;
144 $db_return_text .= $txt;
147 if($db && $db->connected) {
148 $r = q("SELECT COUNT(*) as `total` FROM `user`");
149 if($r && count($r) && $r[0]['total']) {
150 $tpl = get_markup_template('install.tpl');
151 return replace_macros($tpl, array(
152 '$title' => $install_title,
154 '$status' => t('Database already in use.'),
160 if(x($a->data,'txt') && strlen($a->data['txt'])) {
161 $db_return_text .= manual_config($a);
164 if ($db_return_text!="") {
165 $tpl = get_markup_template('install.tpl');
166 return replace_macros($tpl, array(
167 '$title' => $install_title,
169 '$text' => $db_return_text . what_next(),
173 switch ($install_wizard_pass){
174 case 1: { // System check
179 check_funcs($checks);
181 check_imagik($checks);
183 check_htconfig($checks);
185 check_smarty3($checks);
189 if(x($_POST,'phpath'))
190 $phpath = notags(trim($_POST['phpath']));
192 check_php($phpath, $checks);
194 check_htaccess($checks);
196 function check_passed($v, $c){
198 $v = $v && $c['status'];
201 $checkspassed = array_reduce($checks, "check_passed", true);
205 $tpl = get_markup_template('install_checks.tpl');
206 $o .= replace_macros($tpl, array(
207 '$title' => $install_title,
208 '$pass' => t('System check'),
209 '$checks' => $checks,
210 '$passed' => $checkspassed,
211 '$see_install' => t('Please see the file "INSTALL.txt".'),
212 '$next' => t('Next'),
213 '$reload' => t('Check again'),
214 '$phpath' => $phpath,
215 '$baseurl' => $a->get_baseurl(),
220 case 2: { // Database config
222 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
223 $dbuser = notags(trim($_POST['dbuser']));
224 $dbpass = notags(trim($_POST['dbpass']));
225 $dbdata = notags(trim($_POST['dbdata']));
226 $phpath = notags(trim($_POST['phpath']));
229 $tpl = get_markup_template('install_db.tpl');
230 $o .= replace_macros($tpl, array(
231 '$title' => $install_title,
232 '$pass' => t('Database connection'),
233 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
234 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
235 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
237 '$status' => $wizard_status,
239 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
240 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
241 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, '', 'required'),
242 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
243 '$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'),
247 '$lbl_10' => t('Please select a default timezone for your website'),
249 '$baseurl' => $a->get_baseurl(),
251 '$phpath' => $phpath,
253 '$submit' => t('Submit'),
258 case 3: { // Site settings
259 require_once('include/datetime.php');
260 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
261 $dbuser = notags(trim($_POST['dbuser']));
262 $dbpass = notags(trim($_POST['dbpass']));
263 $dbdata = notags(trim($_POST['dbdata']));
264 $phpath = notags(trim($_POST['phpath']));
266 $adminmail = notags(trim($_POST['adminmail']));
267 $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
269 $tpl = get_markup_template('install_settings.tpl');
270 $o .= replace_macros($tpl, array(
271 '$title' => $install_title,
272 '$pass' => t('Site settings'),
274 '$status' => $wizard_status,
276 '$dbhost' => $dbhost,
277 '$dbuser' => $dbuser,
278 '$dbpass' => $dbpass,
279 '$dbdata' => $dbdata,
280 '$phpath' => $phpath,
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.'), 'required', 'autofocus', 'email'),
285 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
287 '$baseurl' => $a->get_baseurl(),
291 '$submit' => t('Submit'),
301 * checks : array passed to template
305 * help : string optional
307 function check_add(&$checks, $title, $status, $required, $help){
311 'required' => $required,
316 function check_php(&$phpath, &$checks) {
317 $passed = $passed2 = $passed3 = false;
318 if (strlen($phpath)){
319 $passed = file_exists($phpath);
321 $phpath = trim(shell_exec('which php'));
322 $passed = strlen($phpath);
326 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
327 $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='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-poller'>'Setup the poller'</a>") . EOL ;
329 $tpl = get_markup_template('field_input.tpl');
330 $help .= replace_macros($tpl, array(
331 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
336 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
340 $result = trim(shell_exec($cmd));
341 $passed2 = ( strpos($result, "(cli)") !== false );
342 list($result) = explode("\n", $result);
345 $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
346 $help .= t('Found PHP version: ')."<tt>$result</tt>";
348 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
354 $cmd = "$phpath testargs.php $str";
355 $result = trim(shell_exec($cmd));
356 $passed3 = $result == $str;
359 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
360 $help .= t('This is required for message delivery to work.');
362 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
368 function check_keys(&$checks) {
374 if(function_exists('openssl_pkey_new'))
375 $res=openssl_pkey_new(array(
376 'digest_alg' => 'sha1',
377 'private_key_bits' => 4096,
378 'encrypt_key' => false ));
383 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
384 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
386 check_add($checks, t('Generate encryption keys'), $res, true, $help);
391 function check_funcs(&$checks) {
393 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
394 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
395 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
396 check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
397 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
398 check_add($ck_funcs, t('mcrypt PHP module'), true, true, "");
401 if(function_exists('apache_get_modules')){
402 if (! in_array('mod_rewrite',apache_get_modules())) {
403 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
405 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
409 if(! function_exists('curl_init')){
410 $ck_funcs[0]['status']= false;
411 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
413 if(! function_exists('imagecreatefromjpeg')){
414 $ck_funcs[1]['status']= false;
415 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
417 if(! function_exists('openssl_public_encrypt')) {
418 $ck_funcs[2]['status']= false;
419 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
421 if(! function_exists('mysqli_connect')){
422 $ck_funcs[3]['status']= false;
423 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
425 if(! function_exists('mb_strlen')){
426 $ck_funcs[4]['status']= false;
427 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
429 if(! function_exists('mcrypt_create_iv')){
430 $ck_funcs[5]['status']= false;
431 $ck_funcs[5]['help']= t('Error: mcrypt PHP module required but not installed.');
434 $checks = array_merge($checks, $ck_funcs);
436 // check for 'mcrypt_create_iv()', needed for RINO2
437 if ($ck_funcs[5]['status']) {
438 if (function_exists('mcrypt_create_iv')) {
440 $__help = "If you are using php_cli, please make sure that mcrypt module is enabled in its config file";
443 $__help = t('Function mcrypt_create_iv() is not defined. This is needed to enable RINO2 encryption layer.');
445 check_add($checks, t('mcrypt_create_iv() function'), $__status, false, $__help);
449 /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
450 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
454 function check_htconfig(&$checks) {
457 if( (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
458 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
461 $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;
462 $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;
463 $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;
464 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
467 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
471 function check_smarty3(&$checks) {
474 if( !is_writable('view/smarty3') ) {
477 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
478 $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;
479 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
480 $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;
483 check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
487 function check_htaccess(&$checks) {
491 if (function_exists('curl_init')){
492 $test = fetch_url($a->get_baseurl()."/install/testrewrite");
495 $test = fetch_url(normalise_link($a->get_baseurl()."/install/testrewrite"));
499 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
501 check_add($checks, t('Url rewrite is working'), $status, true, $help);
503 // cannot check modrewrite if libcurl is not installed
507 function check_imagik(&$checks) {
511 if (class_exists('Imagick')) {
513 $supported = Photo::supportedTypes();
514 if (array_key_exists('image/gif', $supported)) {
518 check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
520 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
526 function manual_config(&$a) {
527 $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8');
528 $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.');
529 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
533 function load_database_rem($v, $i){
535 if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
543 function load_database($db) {
545 require_once("include/dbstructure.php");
546 $errors = update_structure(false, true);
548 /* $str = file_get_contents('database.sql');
549 $arr = explode(';',$str);
551 foreach($arr as $a) {
552 if(strlen(trim($a))) {
553 $r = @$db->q(trim($a));
555 $errors .= t('Errors encountered creating database tables.') . $a . EOL;
563 function what_next() {
565 $baseurl = $a->get_baseurl();
567 t('<h1>What next</h1>')
568 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
569 .t('Please see the file "INSTALL.txt".')
571 .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.")