4 function install_post(&$a) {
8 $dbhost = notags(trim($_POST['dbhost']));
9 $dbuser = notags(trim($_POST['dbuser']));
10 $dbpass = notags(trim($_POST['dbpass']));
11 $dbdata = notags(trim($_POST['dbdata']));
12 $timezone = notags(trim($_POST['timezone']));
13 $phpath = notags(trim($_POST['phpath']));
15 require_once("dba.php");
17 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true);
19 if(mysqli_connect_errno()) {
20 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
21 if(! mysql_connect_errno()) {
22 $r = q("CREATE DATABASE '%s'",
26 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true);
28 if(mysqli_connect_errno()) {
29 notice( t('Could not create/connect to database.') . EOL);
34 notice( t('Connected to database.') . EOL);
36 $tpl = load_view_file('view/htconfig.tpl');
37 $txt = replace_macros($tpl,array(
42 '$timezone' => $timezone,
45 $result = file_put_contents('.htconfig.php', $txt);
50 $errors = load_database($db);
52 // Our sessions normally are stored in the database. But as we have only managed
53 // to get it bootstrapped milliseconds ago, we have to apply a bit of trickery so
54 // that you'll see the following important notice (which is stored in the session).
56 session_write_close();
58 require_once('session.php');
60 session_regenerate_id();
62 $_SESSION['sysmsg'] = '';
64 notice( t('Database import succeeded.') . EOL
65 . t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL
66 . t('Please see the file INSTALL.') . EOL );
67 goaway($a->get_baseurl() . '/register' );
70 $db = null; // start fresh
71 notice( t('Database import failed.') . EOL
72 . t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL
73 . t('Please see the file INSTALL.') . EOL );
78 function install_content(&$a) {
82 notice( t('Welcome to Friendika.') . EOL);
87 $o .= check_htconfig();
91 if(strlen($a->data)) {
92 $o .= manual_config($a);
96 $o .= check_php($phpath);
101 require_once('datetime.php');
103 $tpl = load_view_file('view/install_db.tpl');
104 $o .= replace_macros($tpl, array(
105 '$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
106 '$submit' => t('Submit'),
107 '$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
108 '$dbuser' => notags(trim($_POST['dbuser'])),
109 '$dbpass' => notags(trim($_POST['dbpass'])),
110 '$dbdata' => notags(trim($_POST['dbdata'])),
117 function check_php(&$phpath) {
119 $phpath = trim(shell_exec('which php'));
120 if(! strlen($phpath)) {
121 $o .= t('Could not find a command line version of PHP in the web server PATH.') . EOL;
122 $o .= t('This is required. Please adjust the configuration file .htconfig.php accordingly.') . EOL;
124 if(strlen($phpath)) {
126 $cmd = "$phpath testargs.php $str";
127 $result = trim(shell_exec($cmd));
128 if($result != $str) {
129 $o .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.') . EOL;
130 $o .= t('This is required for message delivery to work.') . EOL;
137 function check_keys() {
143 if(function_exists('openssl_pkey_new'))
144 $res=openssl_pkey_new(array(
145 'digest_alg' => 'sha1',
146 'private_key_bits' => 4096,
147 'encrypt_key' => false ));
152 $o .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys') . EOL;
159 function check_funcs() {
160 if((function_exists('apache_get_modules')) && (! in_array('mod_rewrite',apache_get_modules())))
161 notice( t('Error: Apache webserver mod-rewrite module is required but not installed.') . EOL);
162 if(! function_exists('curl_init'))
163 notice( t('Error: libCURL PHP module required but not installed.') . EOL);
164 if(! function_exists('imagecreatefromjpeg'))
165 notice( t('Error: GD graphics PHP module with JPEG support required but not installed.') . EOL);
166 if(! function_exists('openssl_public_encrypt'))
167 notice( t('Error: openssl PHP module required but not installed.') . EOL);
168 if(! function_exists('mysqli_connect'))
169 notice( t('Error: mysqli PHP module required but not installed.') . EOL);
170 if((x($_SESSION,'sysmsg')) && strlen($_SESSION['sysmsg']))
171 notice( t('Please see the file "INSTALL".') . EOL);
175 function check_htconfig() {
177 if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
178 || (! is_writable('.'))) {
180 $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.');
181 $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.');
182 $o .= t('Please check with your site documentation or support people to see if this situation can be corrected.');
183 $o .= t('If not, you may be required to perform a manual installation. Please see the file "INSTALL" for instructions.');
190 function manual_config(&$a) {
191 $data = htmlentities($a->data);
192 $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.');
193 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
198 function load_database($db) {
200 $str = file_get_contents('database.sql');
201 $arr = explode(';',$str);
203 foreach($arr as $a) {
204 if(strlen(trim($a))) {
205 $r = @$db->q(trim($a));
207 notice( t('Errors encountered creating database tables.') . $a . EOL);