4 function install_post(&$a) {
8 $urlpath = $a->get_path();
9 $dbhost = notags(trim($_POST['dbhost']));
10 $dbuser = notags(trim($_POST['dbuser']));
11 $dbpass = notags(trim($_POST['dbpass']));
12 $dbdata = notags(trim($_POST['dbdata']));
13 $timezone = notags(trim($_POST['timezone']));
14 $phpath = notags(trim($_POST['phpath']));
16 require_once("dba.php");
18 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
20 if(mysqli_connect_errno()) {
22 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
23 if(! mysqli_connect_errno()) {
24 $r = q("CREATE DATABASE '%s'",
29 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
32 if(mysqli_connect_errno()) {
33 notice( t('Could not create/connect to database.') . EOL);
38 notice( t('Connected to database.') . EOL);
40 $tpl = load_view_file('view/htconfig.tpl');
41 $txt = replace_macros($tpl,array(
46 '$timezone' => $timezone,
47 '$urlpath' => $urlpath,
50 $result = file_put_contents('.htconfig.php', $txt);
55 $errors = load_database($db);
58 $a->data['db_failed'] = true;
60 $a->data['db_installed'] = true;
66 function install_content(&$a) {
71 if(x($a->data,'db_installed')) {
72 $o .= '<h2>' . t('Proceed with Installation') . '</h2>';
73 $o .= '<p style="font-size: 130%;">';
74 $o .= t('Your Friendika site database has been installed.') . EOL;
75 $o .= t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL ;
76 $o .= t('Please see the file "INSTALL.txt".') . EOL ;
78 $o .= '<a href="' . $a->get_baseurl() . '/register' . '">' . t('Proceed to registration') . '</a>' ;
83 if(x($a->data,'db_failed')) {
84 $o .= t('Database import failed.') . EOL;
85 $o .= t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
86 $o .= t('Please see the file "INSTALL.txt".') . EOL ;
90 if($db && $db->connected) {
91 $r = q("SELECT COUNT(*) as `total` FROM `user`");
92 if($r && count($r) && $r[0]['total']) {
93 notice( t('Permission denied.') . EOL);
98 notice( t('Welcome to Friendika.') . EOL);
103 $o .= check_htconfig();
107 if(strlen($a->data)) {
108 $o .= manual_config($a);
112 $o .= check_php($phpath);
117 require_once('datetime.php');
119 $tpl = load_view_file('view/install_db.tpl');
120 $o .= replace_macros($tpl, array(
121 '$baseurl' => $a->get_baseurl(),
122 '$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
123 '$submit' => t('Submit'),
124 '$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
125 '$dbuser' => notags(trim($_POST['dbuser'])),
126 '$dbpass' => notags(trim($_POST['dbpass'])),
127 '$dbdata' => notags(trim($_POST['dbdata'])),
134 function check_php(&$phpath) {
136 $phpath = trim(shell_exec('which php'));
137 if(! strlen($phpath)) {
138 $o .= t('Could not find a command line version of PHP in the web server PATH.') . EOL;
139 $o .= t('This is required. Please adjust the configuration file .htconfig.php accordingly.') . EOL;
141 if(strlen($phpath)) {
143 $cmd = "$phpath testargs.php $str";
144 $result = trim(shell_exec($cmd));
145 if($result != $str) {
146 $o .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.') . EOL;
147 $o .= t('This is required for message delivery to work.') . EOL;
154 function check_keys() {
160 if(function_exists('openssl_pkey_new'))
161 $res=openssl_pkey_new(array(
162 'digest_alg' => 'sha1',
163 'private_key_bits' => 4096,
164 'encrypt_key' => false ));
169 $o .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys') . EOL;
170 $o .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".') . EOL;
177 function check_funcs() {
178 if((function_exists('apache_get_modules')) && (! in_array('mod_rewrite',apache_get_modules())))
179 notice( t('Error: Apache webserver mod-rewrite module is required but not installed.') . EOL);
180 if(! function_exists('curl_init'))
181 notice( t('Error: libCURL PHP module required but not installed.') . EOL);
182 if(! function_exists('imagecreatefromjpeg'))
183 notice( t('Error: GD graphics PHP module with JPEG support required but not installed.') . EOL);
184 if(! function_exists('openssl_public_encrypt'))
185 notice( t('Error: openssl PHP module required but not installed.') . EOL);
186 if(! function_exists('mysqli_connect'))
187 notice( t('Error: mysqli PHP module required but not installed.') . EOL);
188 if((x($_SESSION,'sysmsg')) && strlen($_SESSION['sysmsg']))
189 notice( t('Please see the file "INSTALL.txt".') . EOL);
193 function check_htconfig() {
195 if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
196 || (! is_writable('.'))) {
198 $o = 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.');
199 $o .= 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.');
200 $o .= t('Please check with your site documentation or support people to see if this situation can be corrected.');
201 $o .= t('If not, you may be required to perform a manual installation. Please see the file "INSTALL.txt" for instructions.');
208 function manual_config(&$a) {
209 $data = htmlentities($a->data);
210 $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.');
211 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
216 function load_database($db) {
218 $str = file_get_contents('database.sql');
219 $arr = explode(';',$str);
221 foreach($arr as $a) {
222 if(strlen(trim($a))) {
223 $r = @$db->q(trim($a));
225 notice( t('Errors encountered creating database tables.') . $a . EOL);