3 $install_wizard_pass=1;
6 function install_init(&$a){
7 global $install_wizard_pass;
9 $install_wizard_pass = intval($_POST['pass']);
13 function install_post(&$a) {
14 global $install_wizard_pass, $db;
16 switch($install_wizard_pass) {
20 break; // just in case return don't return :)
22 $urlpath = $a->get_path();
23 $dbhost = notags(trim($_POST['dbhost']));
24 $dbuser = notags(trim($_POST['dbuser']));
25 $dbpass = notags(trim($_POST['dbpass']));
26 $dbdata = notags(trim($_POST['dbdata']));
27 $phpath = notags(trim($_POST['phpath']));
29 require_once("dba.php");
31 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
32 /*if(get_db_errno()) {
34 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
36 if(! get_db_errno()) {
37 $r = q("CREATE DATABASE '%s'",
42 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
44 $a->data['db_create_failed']=true;
47 $a->data['db_conn_failed']=true;
52 $a->data['db_conn_failed']=true;
58 $urlpath = $a->get_path();
59 $dbhost = notags(trim($_POST['dbhost']));
60 $dbuser = notags(trim($_POST['dbuser']));
61 $dbpass = notags(trim($_POST['dbpass']));
62 $dbdata = notags(trim($_POST['dbdata']));
63 $phpath = notags(trim($_POST['phpath']));
64 $timezone = notags(trim($_POST['timezone']));
65 $adminmail = notags(trim($_POST['adminmail']));
68 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
70 $tpl = get_intltext_template('htconfig.tpl');
71 $txt = replace_macros($tpl,array(
76 '$timezone' => $timezone,
77 '$urlpath' => $urlpath,
79 '$adminmail' => $adminmail
82 $result = file_put_contents('.htconfig.php', $txt);
84 $a->data['txt'] = $txt;
87 $errors = load_database($db);
90 $a->data['db_failed'] = $errors;
92 $a->data['db_installed'] = true;
99 function get_db_errno() {
100 if(class_exists('mysqli'))
101 return mysqli_connect_errno();
103 return mysql_errno();
106 function install_content(&$a) {
108 global $install_wizard_pass, $db;
111 $install_title = t('Friendica Social Communications Server - Setup');
113 if(x($a->data,'txt') && strlen($a->data['txt'])) {
114 $tpl = get_markup_template('install.tpl');
115 return replace_macros($tpl, array(
116 '$title' => $install_title,
117 '$pass' => t('Database connection'),
118 '$text' => manual_config($a),
122 if(x($a->data,'db_conn_failed')) {
123 $install_wizard_pass = 2;
124 $wizard_status = t('Could not connect to database.');
126 if(x($a->data,'db_create_failed')) {
127 $install_wizard_pass = 2;
128 $wizard_status = t('Could not create table.');
131 if(x($a->data,'db_installed')) {
132 $txt = '<p style="font-size: 130%;">';
133 $txt .= t('Your Friendica site database has been installed.') . EOL;
134 $txt .= t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL ;
135 $txt .= t('Please see the file "INSTALL.txt".') . EOL ;
137 $txt .= '<a href="' . $a->get_baseurl() . '/register' . '">' . t('Proceed to registration') . '</a>' ;
140 $tpl = get_markup_template('install.tpl');
141 return replace_macros($tpl, array(
142 '$title' => $install_title,
143 '$pass' => t('Proceed with Installation'),
149 if(x($a->data,'db_failed')) {
150 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
151 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>" ;
152 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL ;
154 $tpl = get_markup_template('install.tpl');
155 return replace_macros($tpl, array(
156 '$title' => $install_title,
157 '$pass' => t('Database connection'),
158 '$status' => t('Database import failed.'),
164 if($db && $db->connected) {
165 $r = q("SELECT COUNT(*) as `total` FROM `user`");
166 if($r && count($r) && $r[0]['total']) {
167 $tpl = get_markup_template('install.tpl');
168 return replace_macros($tpl, array(
169 '$title' => $install_title,
171 '$status' => t('Permission denied.'),
177 switch ($install_wizard_pass){
178 case 1: { // System check
183 check_funcs($checks);
185 check_htconfig($checks);
189 if(x($_POST,'phpath'))
190 $phpath = notags(trim($_POST['phpath']));
192 check_php($phpath, $checks);
195 function check_passed($v, $c){
197 $v = $v && $c['status'];
200 $checkspassed = array_reduce($checks, "check_passed", true);
203 $tpl = get_markup_template('install_checks.tpl');
204 $o .= replace_macros($tpl, array(
205 '$title' => $install_title,
206 '$pass' => t('System check'),
207 '$checks' => $checks,
208 '$passed' => $checkspassed,
209 '$see_install' => t('Please see the file "INSTALL.txt".'),
210 '$next' => t('Next'),
211 '$reload' => t('Check again'),
212 '$phpath' => $phpath,
213 '$baseurl' => $a->get_baseurl(),
218 case 2: { // Database config
220 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
221 $dbuser = notags(trim($_POST['dbuser']));
222 $dbpass = notags(trim($_POST['dbpass']));
223 $dbdata = notags(trim($_POST['dbdata']));
224 $phpath = notags(trim($_POST['phpath']));
227 $tpl = get_markup_template('install_db.tpl');
228 $o .= replace_macros($tpl, array(
229 '$title' => $install_title,
230 '$pass' => t('Database connection'),
231 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
232 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
233 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
235 '$status' => $wizard_status,
237 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, ''),
238 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, ''),
239 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, ''),
240 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, ''),
241 '$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.')),
245 '$lbl_10' => t('Please select a default timezone for your website'),
247 '$baseurl' => $a->get_baseurl(),
249 '$phpath' => $phpath,
251 '$submit' => t('Submit'),
256 case 3: { // Site settings
257 require_once('datetime.php');
258 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
259 $dbuser = notags(trim($_POST['dbuser']));
260 $dbpass = notags(trim($_POST['dbpass']));
261 $dbdata = notags(trim($_POST['dbdata']));
262 $phpath = notags(trim($_POST['phpath']));
264 $adminmail = notags(trim($_POST['adminmail']));
265 $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
267 $tpl = get_markup_template('install_settings.tpl');
268 $o .= replace_macros($tpl, array(
269 '$title' => $install_title,
270 '$pass' => t('Site settings'),
272 '$status' => $wizard_status,
274 '$dbhost' => $dbhost,
275 '$dbuser' => $dbuser,
276 '$dbpass' => $dbpass,
277 '$dbdata' => $dbdata,
278 '$phpath' => $phpath,
280 '$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 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
285 '$baseurl' => $a->get_baseurl(),
289 '$submit' => t('Submit'),
299 * checks : array passed to template
303 * help : string optional
305 function check_add(&$checks, $title, $status, $required, $help){
309 'required' => $required,
314 function check_php(&$phpath, &$checks) {
315 if (strlen($phpath)){
316 $passed = file_exists($phpath);
318 $phpath = trim(shell_exec('which php'));
319 $passed = strlen($phpath);
323 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
324 $tpl = get_markup_template('field_input.tpl');
325 $help .= replace_macros($tpl, array(
326 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable')),
331 check_add($checks, t('Command line PHP'), $passed, true, $help);
335 $cmd = "$phpath testargs.php $str";
336 $result = trim(shell_exec($cmd));
337 $passed2 = $result == $str;
340 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
341 $help .= t('This is required for message delivery to work.');
343 check_add($checks, t('PHP "register_argc_argv"'), $passed, true, $help);
349 function check_keys(&$checks) {
355 if(function_exists('openssl_pkey_new'))
356 $res=openssl_pkey_new(array(
357 'digest_alg' => 'sha1',
358 'private_key_bits' => 4096,
359 'encrypt_key' => false ));
364 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
365 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
367 check_add($checks, t('Generate encryption keys'), $res, true, $help);
372 function check_funcs(&$checks) {
374 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
375 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
376 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
377 check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
378 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
381 if(function_exists('apache_get_modules')){
382 if (! in_array('mod_rewrite',apache_get_modules())) {
383 check_add($ck_funcs, t('Apace mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
385 check_add($ck_funcs, t('Apace mod_rewrite module'), true, true, "");
388 if(! function_exists('curl_init')){
389 $ck_funcs[0]['status']= false;
390 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
392 if(! function_exists('imagecreatefromjpeg')){
393 $ck_funcs[1]['status']= false;
394 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
396 if(! function_exists('openssl_public_encrypt')) {
397 $ck_funcs[2]['status']= false;
398 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
400 if(! function_exists('mysqli_connect')){
401 $ck_funcs[3]['status']= false;
402 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
404 if(! function_exists('mb_strlen')){
405 $ck_funcs[4]['status']= false;
406 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
409 $checks = array_merge($checks, $ck_funcs);
411 /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
412 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
416 function check_htconfig(&$checks) {
419 if( (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
420 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
423 $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;
424 $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;
425 $help .= t('Please check with your site documentation or support people to see if this situation can be corrected.').EOL;
426 $help .= t('If not, you may be required to perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
429 check_add($checks, t('.htconfig.php is writable'), $status, true, $help);
434 function manual_config(&$a) {
435 $data = htmlentities($a->data['txt']);
436 $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.');
437 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
441 function load_database_rem($v, $i){
443 if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
451 function load_database($db) {
453 $str = file_get_contents('database.sql');
454 $str = array_reduce(explode("\n", $str),"load_database_rem","");
455 $arr = explode(';',$str);
457 foreach($arr as $a) {
458 if(strlen(trim($a))) {
459 $r = @$db->q(trim($a));
461 $errors .= t('Errors encountered creating database tables.') . $a . EOL;