~kili4n/+junk/installer

« back to all changes in this revision

Viewing changes to install/index.php

  • Committer: kilian.holzinger at gmail
  • Date: 2012-08-02 09:29:56 UTC
  • Revision ID: kilian.holzinger@gmail.com-20120802092956-xwwu2beqtabz3x3x
Starting with a new installer

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
error_reporting(E_ALL);
6
6
ini_set('display_errors', '1');
7
7
 
 
8
$tmpfile = "../config/conf.xml.temp";
 
9
$conffile = "../config/conf.xml";
 
10
 
8
11
function get_mysql_port() {
9
12
    $port = ini_get('mysql.default_port');
10
13
    if($port == "")
37
40
        return count($err);
38
41
}
39
42
 
40
 
function test_dir($dir)
41
 
{
42
 
  return (file_exists($dir) && is_dir($dir) && is_writable($dir));
43
 
}
 
43
 
44
44
 
45
45
function list_themes()
46
46
{
77
77
  return $langs;
78
78
}
79
79
 
80
 
function test_requirements()
81
 
{
82
 
  $errors = array();
83
 
 
84
 
  if(!(version_compare(PHP_VERSION, '5.3.0') >= 0)) {
85
 
    $errors[] = t("PHP version mismatch. Movim requires PHP 5.3 minimum.")." ".t("Actual version : "). PHP_VERSION .
86
 
                '<div class="guidance">'.t("Update your PHP version or contact your server administrator").'</div>';
87
 
  }
88
 
  if(!extension_loaded('curl')) {
89
 
    $errors[] = t("Movim requires the %s extension.", 'PHP Curl') .
90
 
                '<div class="guidance">'.t("Install %s and %s packages", 'php5-curl', 'curl').'</div>';
91
 
  }
92
 
  if(!extension_loaded('gd')) {
93
 
    $errors[] = t("Movim requires the %s extension.", 'PHP GD') .
94
 
                '<div class="guidance">'.t("Install the %s package", 'php5-gd').'</div>';
95
 
  }
96
 
  if(!extension_loaded('SimpleXML')) {
97
 
    $errors[] = t("Movim requires the %s extension.", 'SimpleXML') .
98
 
                '<div class="guidance">'.t("Install the %s package", 'php5-cli').'</div>';
99
 
  }
100
 
  if(!test_dir('../')) {
101
 
    $errors[] = t("Movim's folder must be writable.") .
102
 
                '<div class="guidance">'.t("Enable read and write rights on Movim's root folder").'</div>';
103
 
  }
104
 
  /*if(!test_dir('user')) {
105
 
    $errors[] = t("The <em>%s</em> folder must exist and be writable.", 'user');
106
 
  }
107
 
  if(!test_dir('log')) {
108
 
    $errors[] = t("The <em>%s</em> folder must exist and be writable.", 'log');
109
 
  }*/
110
 
 
111
 
  // Must have sqlite or mysql (so far...)
112
 
  if(!extension_loaded('mysql') && !class_exists('SQLite3')) {
113
 
      $exts = array('MySQL', 'SQLite');
114
 
      $exts_txt = implode(t("or"), $exts);
115
 
      $errors[] = t("Movim requires the %s extension.", $exts_txt);
116
 
  }
117
 
 
118
 
  global $databases;
119
 
  if(extension_loaded('mysql'))
120
 
      $databases['mysql'] = 'MySQL';
121
 
  if(class_exists('SQLite3'))
122
 
      $databases['sqlite'] = 'SQLite';
123
 
 
124
 
  return (count($errors) > 0)? $errors : false;
125
 
}
126
 
 
127
80
function get_checkbox($name, $if = 'true', $else = 'false')
128
81
{
129
82
  return (isset($_POST[$name])? $if : $else);
190
143
    }
191
144
}
192
145
 
 
146
function test_dir($dir){
 
147
        return (file_exists($dir) && is_dir($dir) && is_writable($dir));
 
148
}
 
149
/*
 
150
 * Create the dirs 
 
151
 */
 
152
 
 
153
function create_dirs(){
 
154
 
 
155
  if(!test_dir('../cache') && !@mkdir('../cache')) {
 
156
    echo t("Couldn't create directory '%s'.", 'cache');
 
157
    return false;
 
158
  }
 
159
  if(!test_dir('../log') && !@mkdir('../log')) {
 
160
    echo t("Couldn't create directory '%s'.", 'log');
 
161
    return false;
 
162
  }
 
163
  if(!test_dir('../config') && !@mkdir('../config')) {
 
164
    echo t("Couldn't create directory '%s'.", 'config');
 
165
    return false;
 
166
  }
 
167
}
 
168
 
 
169
//Returns the content of the post, of the xml, or a placeholder string
 
170
function get_entry($post){
 
171
        global $xml;
 
172
        if(isset($_POST[$post])){
 
173
                return $_POST[$post];
 
174
        }elseif(isset($xml->$post)){
 
175
                return $xml->$post;
 
176
        }else{
 
177
                return "n/a";
 
178
        }
 
179
}
 
180
 
 
181
//Checks if movim already knows the user choice, or it returns a preset for the given form data
 
182
function get_preset_value($post, $preset){
 
183
        if(get_entry($post) == "n/a" || get_entry($post) == ""){
 
184
                return $preset;
 
185
        }else{
 
186
                return get_entry($post);
 
187
        }
 
188
}
 
189
 
 
190
function make_config(){
 
191
        global $xml;
 
192
        $conf = array(
 
193
        'config' => array(
 
194
          'theme'              => get_entry('theme'),
 
195
          'defLang'            => get_entry('defLang'),
 
196
//        'boshCookieTTL'      => $_POST['boshCookieTTL'],
 
197
//        'boshCookiePath'     => $_POST['boshCookiePath'],
 
198
//        'boshCookieDomain'   => get_checkbox('boshCookieDomain'),
 
199
//        'boshCookieHTTPS'    => get_checkbox('boshCookieHTTPS'),
 
200
//        'boshCookieHTTPOnly' => get_checkbox('boshCookieHTTPOnly'),
 
201
          'logLevel'           => get_entry('logLevel'),
 
202
          //you should be able to do something with new pods, so:
 
203
          'accountCreation'    => True,
 
204
//        'host'               => $_POST['host'],
 
205
//        'domain'             => $_POST['domain'],
 
206
//        'defBoshHost'        => $_POST['defBoshHost'],
 
207
//        'defBoshSuffix'      => $_POST['defBoshSuffix'],
 
208
//        'defBoshPort'        => $_POST['defBoshPort'],
 
209
//        'storageDriver'      => $_POST['datajar'],
 
210
//        'storageConnection'  => $_POST['database'],
 
211
//        'proxyEnabled'       => get_checkbox('proxyEnabled'),
 
212
//        'proxyURL'           => $_POST['proxyURL'], 
 
213
//        'proxyPort'          => $_POST['proxyPort'],
 
214
          'maxUsers'           => get_entry('maxUsers'),
 
215
          ),
 
216
        );
 
217
        if(!@file_put_contents('../config/conf.xml.temp', make_xml($conf))) {
 
218
        echo t("Couldn't create configuration file '%s'.", 'config/conf.xml.temp');
 
219
        return false;
 
220
        }
 
221
        
 
222
        return true;
 
223
}
 
224
 
 
225
 
193
226
function make_xml($stuff)
194
227
{
195
228
  static $level = 0;
222
255
  return $buffer;
223
256
}
224
257
 
225
 
function perform_install()
226
 
{
227
 
  // Creating the folders.
228
 
  if(!test_dir('../cache') && !@mkdir('../cache')) {
229
 
    echo t("Couldn't create directory '%s'.", 'cache');
230
 
    return false;
231
 
  }
232
 
  if(!test_dir('../log') && !@mkdir('../log')) {
233
 
    echo t("Couldn't create directory '%s'.", 'log');
234
 
    return false;
235
 
  }
236
 
  if(!test_dir('../config') && !@mkdir('../config')) {
237
 
    echo t("Couldn't create directory '%s'.", 'config');
238
 
    return false;
239
 
  }
240
 
 
241
 
  // Creating the configuration file.
242
 
  $conf = array(
243
 
    'config' => array(
244
 
      'theme'              => $_POST['theme'],
245
 
      'defLang'            => $_POST['language'],
246
 
      'boshCookieTTL'      => $_POST['boshCookieTTL'],
247
 
      'boshCookiePath'     => $_POST['boshCookiePath'],
248
 
      'boshCookieDomain'   => get_checkbox('boshCookieDomain'),
249
 
      'boshCookieHTTPS'    => get_checkbox('boshCookieHTTPS'),
250
 
      'boshCookieHTTPOnly' => get_checkbox('boshCookieHTTPOnly'),
251
 
      'logLevel'           => $_POST['verbosity'],
252
 
      'accountCreation'    => get_checkbox('accountCreation', 1, 0),
253
 
      'host'               => $_POST['host'],
254
 
      'domain'             => $_POST['domain'],
255
 
      'defBoshHost'        => $_POST['defBoshHost'],
256
 
      'defBoshSuffix'      => $_POST['defBoshSuffix'],
257
 
      'defBoshPort'        => $_POST['defBoshPort'],
258
 
      'storageDriver'      => $_POST['datajar'],
259
 
      'storageConnection'  => $_POST['database'],
260
 
      'proxyEnabled'       => get_checkbox('proxyEnabled'),
261
 
      'proxyURL'           => $_POST['proxyURL'],
262
 
      'proxyPort'          => $_POST['proxyPort'],
263
 
      'maxUsers'           => $_POST['maxUsers'],
264
 
      ),
265
 
    );
266
 
  if(!@file_put_contents('../config/conf.xml', make_xml($conf))) {
267
 
    echo t("Couldn't create configuration file '%s'.", 'config/conf.xml');
268
 
    return false;
269
 
  }
270
 
 
271
 
  return true;
272
 
}
273
 
 
274
 
$step = 'part1.php';
275
 
 
276
 
if(isset($_POST['install'])) {
277
 
    // We test the Bosh configuration
278
 
    if(!test_bosh($_POST['defBoshHost'], $_POST['defBoshPort'], $_POST['defBoshSuffix'], $_POST['host'])) {
279
 
        goto loadpage;
280
 
    }
281
 
 
282
 
        // We create the configuration file
283
 
    perform_install();
284
 
 
285
 
    // We try to connect to the database
286
 
    try {
287
 
        include('../init.php');
288
 
    } catch (Exception $e) {
289
 
                set_error('bdd', t("Database connection failed with error '%s'", $e->getMessage()));
290
 
        goto loadpage;
291
 
    }
292
 
 
293
 
    // We create correctly the tables
294
 
    global $sdb;
295
 
    $contact = new Contact();
296
 
    $sdb->create($contact);
297
 
 
298
 
    $conf = new ConfVar();
299
 
    $sdb->create($conf);
300
 
 
301
 
    $message = new Message();
302
 
    $sdb->create($message);
303
 
 
304
 
    $presence = new Presence();
305
 
    $sdb->create($presence);
306
 
 
307
 
    $post = new Post();
308
 
    $sdb->create($post);
309
 
 
310
 
    $caps = new Caps();
311
 
    $sdb->create($caps);
312
 
 
313
 
    $attachment = new Attachment();
314
 
    $sdb->create($attachment);
315
 
 
316
 
        $step = 'part2.php';
317
 
}
318
 
 
319
 
loadpage:
320
 
require($step);
 
258
 
 
259
 
 
260
function generate_Tooltip($text, $background=True){
 
261
        $html = 'onmouseover=" elmnt = document.getElementById(\'leftside\'); elmnt.innerHTML=\''.$text.'\'; ';
 
262
        if($background){
 
263
                $html .= 'this.style.background = \'#F8F8F8\';" onmouseout="this.style.background=\'white\';"';
 
264
        }else{
 
265
                $html .= '"';
 
266
        }
 
267
        return $html;
 
268
}
 
269
 
 
270
 
 
271
 
 
272
$steps = array(
 
273
        t("Compatibility Check"),
 
274
        t("General Settings"),
 
275
        t("Database Settings"),
 
276
        t("Bosh Configuration"),
 
277
        t("XMPP Server"),
 
278
        t("Done")
 
279
        );
 
280
 
 
281
 
 
282
 
 
283
#################
 
284
#Handle the forms
 
285
###############
 
286
if(isset($_POST['back'])){
 
287
        $_POST['step'] -= 2;
 
288
}
 
289
//When the tests do not fail, we just create some directories and succeed to the next step
 
290
if(isset($_POST['step'])) {
 
291
        switch($_POST['step']){
 
292
                
 
293
                //The checks passed:
 
294
                case 0:{
 
295
                        //We load the array.
 
296
                        $xml = simplexml_load_file($tmpfile);
 
297
                        create_dirs();
 
298
                        $step = 1;
 
299
                        break;
 
300
                        
 
301
                //Store the basic settings
 
302
                }case 1:{
 
303
                        //We load the array.
 
304
                        $xml = simplexml_load_file($tmpfile);
 
305
                        make_config();
 
306
                        $step = 2;
 
307
                        break;
 
308
                        
 
309
                //Store the DB settings
 
310
                #TODO: Verify the SQL Settings
 
311
                }case 2: {
 
312
                        //We load the array.
 
313
                        $xml = simplexml_load_file($tmpfile);
 
314
                        $step = 3;
 
315
                        break;
 
316
                        
 
317
                //The BOSH settings
 
318
                #TODO: Check if bosh settings are right and whether open Bosh (e.g. connect to random xmpp); when bosh closed warn the user
 
319
                }case 3: {
 
320
                        $step = 4;
 
321
                        break;
 
322
                        
 
323
                #TODO: Display all Settings again
 
324
                }case 4: {
 
325
                        break;
 
326
                        
 
327
                #TOTO: Write Database; Rename conf.xml.part
 
328
                }case 5: {
 
329
                        break;
 
330
                //If the user goes back to the checks:
 
331
                }case -1: {
 
332
                        $step = 0;
 
333
                        break;
 
334
                        
 
335
                }default: die("Something went wrong");
 
336
        }
 
337
}else{
 
338
        $step = 0;
 
339
}
 
340
 
 
341
 
 
342
require('template.php');
321
343
 
322
344
?>