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") {
15 // We overwrite current theme css, because during install we could not have a working mod_rewrite
16 // so we could not have a css at all. Here we set a static css file for the install procedure pages
17 $a->config['system']['theme'] = "../install";
18 $a->theme['stylesheet'] = $a->get_baseurl()."/view/install/style.css";
22 global $install_wizard_pass;
24 $install_wizard_pass = intval($_POST['pass']);
28 function install_post(&$a) {
29 global $install_wizard_pass, $db;
31 switch($install_wizard_pass) {
35 break; // just in case return don't return :)
37 $urlpath = $a->get_path();
38 $dbhost = notags(trim($_POST['dbhost']));
39 $dbuser = notags(trim($_POST['dbuser']));
40 $dbpass = notags(trim($_POST['dbpass']));
41 $dbdata = notags(trim($_POST['dbdata']));
42 $phpath = notags(trim($_POST['phpath']));
44 require_once("include/dba.php");
46 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
47 /*if(get_db_errno()) {
49 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
51 if(! get_db_errno()) {
52 $r = q("CREATE DATABASE '%s'",
57 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
59 $a->data['db_create_failed']=true;
62 $a->data['db_conn_failed']=true;
67 $a->data['db_conn_failed']=true;
73 $urlpath = $a->get_path();
74 $dbhost = notags(trim($_POST['dbhost']));
75 $dbuser = notags(trim($_POST['dbuser']));
76 $dbpass = notags(trim($_POST['dbpass']));
77 $dbdata = notags(trim($_POST['dbdata']));
78 $phpath = notags(trim($_POST['phpath']));
79 $timezone = notags(trim($_POST['timezone']));
80 $language = notags(trim($_POST['language']));
81 $adminmail = notags(trim($_POST['adminmail']));
84 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
86 $tpl = get_markup_template('htconfig.tpl');
87 $txt = replace_macros($tpl,array(
92 '$timezone' => $timezone,
93 '$language' => $language,
94 '$urlpath' => $urlpath,
96 '$adminmail' => $adminmail
100 $result = file_put_contents('.htconfig.php', $txt);
102 $a->data['txt'] = $txt;
105 $errors = load_database($db);
109 $a->data['db_failed'] = $errors;
111 $a->data['db_installed'] = true;
118 function get_db_errno() {
119 if(class_exists('mysqli'))
120 return mysqli_connect_errno();
122 return mysql_errno();
125 function install_content(&$a) {
127 global $install_wizard_pass, $db;
130 $install_title = t('Friendica Communications Server - Setup');
134 if(x($a->data,'db_conn_failed')) {
135 $install_wizard_pass = 2;
136 $wizard_status = t('Could not connect to database.');
138 if(x($a->data,'db_create_failed')) {
139 $install_wizard_pass = 2;
140 $wizard_status = t('Could not create table.');
144 if(x($a->data,'db_installed')) {
145 $txt = '<p style="font-size: 130%;">';
146 $txt .= t('Your Friendica site database has been installed.') . EOL;
147 $db_return_text .= $txt;
150 if(x($a->data,'db_failed')) {
151 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
152 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>" ;
153 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL ;
154 $db_return_text .= $txt;
157 if($db && $db->connected) {
158 $r = q("SELECT COUNT(*) as `total` FROM `user`");
159 if($r && count($r) && $r[0]['total']) {
160 $tpl = get_markup_template('install.tpl');
161 return replace_macros($tpl, array(
162 '$title' => $install_title,
164 '$status' => t('Database already in use.'),
170 if(x($a->data,'txt') && strlen($a->data['txt'])) {
171 $db_return_text .= manual_config($a);
174 if ($db_return_text!="") {
175 $tpl = get_markup_template('install.tpl');
176 return replace_macros($tpl, array(
177 '$title' => $install_title,
179 '$text' => $db_return_text . what_next(),
183 switch ($install_wizard_pass){
184 case 1: { // System check
189 check_funcs($checks);
191 check_imagik($checks);
193 check_htconfig($checks);
195 check_smarty3($checks);
199 if(x($_POST,'phpath'))
200 $phpath = notags(trim($_POST['phpath']));
202 check_php($phpath, $checks);
204 check_htaccess($checks);
206 function check_passed($v, $c){
208 $v = $v && $c['status'];
211 $checkspassed = array_reduce($checks, "check_passed", true);
215 $tpl = get_markup_template('install_checks.tpl');
216 $o .= replace_macros($tpl, array(
217 '$title' => $install_title,
218 '$pass' => t('System check'),
219 '$checks' => $checks,
220 '$passed' => $checkspassed,
221 '$see_install' => t('Please see the file "INSTALL.txt".'),
222 '$next' => t('Next'),
223 '$reload' => t('Check again'),
224 '$phpath' => $phpath,
225 '$baseurl' => $a->get_baseurl(),
230 case 2: { // Database config
232 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
233 $dbuser = notags(trim($_POST['dbuser']));
234 $dbpass = notags(trim($_POST['dbpass']));
235 $dbdata = notags(trim($_POST['dbdata']));
236 $phpath = notags(trim($_POST['phpath']));
239 $tpl = get_markup_template('install_db.tpl');
240 $o .= replace_macros($tpl, array(
241 '$title' => $install_title,
242 '$pass' => t('Database connection'),
243 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
244 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
245 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
247 '$status' => $wizard_status,
249 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
250 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
251 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, '', 'required'),
252 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
253 '$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'),
257 '$lbl_10' => t('Please select a default timezone for your website'),
259 '$baseurl' => $a->get_baseurl(),
261 '$phpath' => $phpath,
263 '$submit' => t('Submit'),
268 case 3: { // Site settings
269 require_once('include/datetime.php');
270 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
271 $dbuser = notags(trim($_POST['dbuser']));
272 $dbpass = notags(trim($_POST['dbpass']));
273 $dbdata = notags(trim($_POST['dbdata']));
274 $phpath = notags(trim($_POST['phpath']));
276 $adminmail = notags(trim($_POST['adminmail']));
277 $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
278 /* Installed langs */
279 $lang_choices = get_avaiable_languages();
281 $tpl = get_markup_template('install_settings.tpl');
282 $o .= replace_macros($tpl, array(
283 '$title' => $install_title,
284 '$pass' => t('Site settings'),
286 '$status' => $wizard_status,
288 '$dbhost' => $dbhost,
289 '$dbuser' => $dbuser,
290 '$dbpass' => $dbpass,
291 '$dbdata' => $dbdata,
292 '$phpath' => $phpath,
294 '$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'),
297 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
298 '$language' => array('language', t('System Language:'), 'en', t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices),
299 '$baseurl' => $a->get_baseurl(),
303 '$submit' => t('Submit'),
313 * checks : array passed to template
317 * help : string optional
319 function check_add(&$checks, $title, $status, $required, $help){
323 'required' => $required,
328 function check_php(&$phpath, &$checks) {
329 $passed = $passed2 = $passed3 = false;
330 if (strlen($phpath)){
331 $passed = file_exists($phpath);
333 $phpath = trim(shell_exec('which php'));
334 $passed = strlen($phpath);
338 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
339 $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 ;
341 $tpl = get_markup_template('field_input.tpl');
342 $help .= replace_macros($tpl, array(
343 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
348 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
352 $result = trim(shell_exec($cmd));
353 $passed2 = ( strpos($result, "(cli)") !== false );
354 list($result) = explode("\n", $result);
357 $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
358 $help .= t('Found PHP version: ')."<tt>$result</tt>";
360 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
366 $cmd = "$phpath testargs.php $str";
367 $result = trim(shell_exec($cmd));
368 $passed3 = $result == $str;
371 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
372 $help .= t('This is required for message delivery to work.');
374 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
380 function check_keys(&$checks) {
386 if(function_exists('openssl_pkey_new'))
387 $res=openssl_pkey_new(array(
388 'digest_alg' => 'sha1',
389 'private_key_bits' => 4096,
390 'encrypt_key' => false ));
395 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
396 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
398 check_add($checks, t('Generate encryption keys'), $res, true, $help);
403 function check_funcs(&$checks) {
405 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
406 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
407 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
408 check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
409 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
410 check_add($ck_funcs, t('mcrypt PHP module'), true, true, "");
413 if(function_exists('apache_get_modules')){
414 if (! in_array('mod_rewrite',apache_get_modules())) {
415 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
417 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
421 if(! function_exists('curl_init')){
422 $ck_funcs[0]['status']= false;
423 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
425 if(! function_exists('imagecreatefromjpeg')){
426 $ck_funcs[1]['status']= false;
427 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
429 if(! function_exists('openssl_public_encrypt')) {
430 $ck_funcs[2]['status']= false;
431 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
433 if(! function_exists('mysqli_connect')){
434 $ck_funcs[3]['status']= false;
435 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
437 if(! function_exists('mb_strlen')){
438 $ck_funcs[4]['status']= false;
439 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
441 if(! function_exists('mcrypt_create_iv')){
442 $ck_funcs[5]['status']= false;
443 $ck_funcs[5]['help']= t('Error: mcrypt PHP module required but not installed.');
446 $checks = array_merge($checks, $ck_funcs);
448 // check for 'mcrypt_create_iv()', needed for RINO2
449 if ($ck_funcs[5]['status']) {
450 if (function_exists('mcrypt_create_iv')) {
452 $__help = "If you are using php_cli, please make sure that mcrypt module is enabled in its config file";
455 $__help = t('Function mcrypt_create_iv() is not defined. This is needed to enable RINO2 encryption layer.');
457 check_add($checks, t('mcrypt_create_iv() function'), $__status, false, $__help);
461 /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
462 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
466 function check_htconfig(&$checks) {
469 if( (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
470 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
473 $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;
474 $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;
475 $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;
476 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
479 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
483 function check_smarty3(&$checks) {
486 if( !is_writable('view/smarty3') ) {
489 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
490 $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;
491 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
492 $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;
495 check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
499 function check_htaccess(&$checks) {
503 if (function_exists('curl_init')){
504 $test = fetch_url($a->get_baseurl()."/install/testrewrite");
507 $test = fetch_url(normalise_link($a->get_baseurl()."/install/testrewrite"));
511 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
513 check_add($checks, t('Url rewrite is working'), $status, true, $help);
515 // cannot check modrewrite if libcurl is not installed
519 function check_imagik(&$checks) {
523 if (class_exists('Imagick')) {
525 $supported = Photo::supportedTypes();
526 if (array_key_exists('image/gif', $supported)) {
530 check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
532 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
538 function manual_config(&$a) {
539 $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8');
540 $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.');
541 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
545 function load_database_rem($v, $i){
547 if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
555 function load_database($db) {
557 require_once("include/dbstructure.php");
558 $errors = update_structure(false, true);
560 /* $str = file_get_contents('database.sql');
561 $arr = explode(';',$str);
563 foreach($arr as $a) {
564 if(strlen(trim($a))) {
565 $r = @$db->q(trim($a));
567 $errors .= t('Errors encountered creating database tables.') . $a . EOL;
575 function what_next() {
577 $baseurl = $a->get_baseurl();
579 t('<h1>What next</h1>')
580 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
581 .t('Please see the file "INSTALL.txt".')
583 .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.")