Browse Source

Created installer.

pull/5/head
Etenil 15 years ago
parent
commit
81fd406a7e
  1. 13
      config/conf.xml
  2. 4
      index.php
  3. 278
      install.php
  4. 1
      lib/Jaxl/core/jaxl.util.php
  5. 11
      lib/XMPPConnect.php
  6. 1
      lib/widgets/Logout/Logout.php
  7. 15
      lib/widgets/Poller/poller.js
  8. 10
      user/edhelas@movim.eu/conf.xml
  9. 4
      user/edhelas@movim.eu/data.xml
  10. 10
      user/movim@movim.eu/conf.xml
  11. 4
      user/movim@movim.eu/data.xml

13
config/conf.xml

@ -1,13 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<config>
<theme>movim</theme>
<boshCookieTTL>3600</boshCookieTTL>
<boshCookiePath>/</boshCookiePath>
<boshCookieDomain>false</boshCookieDomain>
<boshCookieHTTPS>false</boshCookieHTTPS>
<boshCookieHTTPOnly>true</boshCookieHTTPOnly>
<logLevel>4</logLevel>
<accountCreation>0</accountCreation>
<install>1</install>
</config>

4
index.php

@ -37,8 +37,8 @@ require_once('init.php');
$polling = false;
$conf = new GetConf();
if($conf->getServerConfElement('install') == 1) {
// If the configuration doesn't exist, run the installer.
if(!file_exists("config/conf.xml")) {
require_once('install.php');
} else {
// Run

278
install.php

@ -1,25 +1,191 @@
<?php
function testInstall($test, $description = '', $advice = '') {
$html = '<tr><td>';
$conf = new GetConf();
$theme = $conf->getServerConfElement('theme');
if($test) {
$html.= '<img src="themes/'.$theme.'/img/accept.png"></td>
<td>'.$description.'</td>';
} else {
$html .= '<img src="themes/'.$theme.'/img/delete.png"></td>
<td>'.$description.'</td>';
$html .= '<td>'.$advice.'</td>';
define('INSTALL_VALIDATED', false);
}
$html .= '</tr>';
echo $html;
function test_dir($dir)
{
return (file_exists($dir) && is_dir($dir) && is_writable($dir));
}
?>
<!DOCTYPE html>
function test_requirements()
{
$errors = array();
$v = explode('.', phpversion());
if($v[0] < 5 || ($v[0] == 5 && $v[1] < 3)) {
$errors[] = t("PHP version mismatch. Movim requires PHP 5.3 minimum.");
}
if(!extension_loaded('curl')) {
$errors[] = sprintf(t("Movim requires the %s extension."), 'PHP Curl');
}
if(!extension_loaded('SimpleXML')) {
$errors[] = sprintf(t("Movim requires the %s extension."), 'SimpleXML');
}
if(!test_dir('./')) {
$errors[] = t("Movim's folder must be writable.");
}
/*if(!test_dir('user')) {
$errors[] = sprintf(t("The <em>%s</em> folder must exist and be writable."), 'user');
}
if(!test_dir('log')) {
$errors[] = sprintf(t("The <em>%s</em> folder must exist and be writable."), 'log');
}*/
return (count($errors) > 0)? $errors : false;
}
function make_field($name, $label, $input)
{
?>
<div class="field">
<label for="<?php echo $name;?>"><?php echo $label;?></label>
<div class="field-input">
<?php echo $input;?>
</div>
</div>
<?php
}
function make_select($name, $title, array $options, $default = null) {
$opts = "<select name=\"$name\">";
foreach($options as $name => $val) {
$selected = '';
if($default !== null && $default == $name) {
$selected = 'selected="selected" ';
}
$opts.= '<option '.$selected.'value="'.$name.'">'.$val."</option>\n";
}
$opts.= "</select>\n";
make_field($name, $title, $opts);
}
function make_checkbox($name, $title, $value)
{
$checked = "";
if($value) {
$checked = 'checked="checked" ';
}
make_field($name, $title, '<input type="checkbox" '.$checked.'name="'.$name.'" />');
}
function make_textbox($name, $title, $value)
{
make_field($name, $title, '<input type="text" name="'.$name.'" value="'.$value.'"/>');
}
function make_button($name, $label)
{
make_field($name, '&nbsp;', '<input type="submit" name="'.$name.'" value="'.$label.'" />');
}
function list_themes()
{
$dir = opendir('themes');
$themes = array();
while($theme = readdir($dir)) {
if(preg_match('/^\.+$/', $theme)
|| !is_dir('themes/'.$theme)) {
continue;
}
$themes[$theme] = $theme;
}
return $themes;
}
function show_install_form()
{
?>
<h1><?php echo t('Movim Installer'); ?></h1>
<form method="post">
<input type="hidden" name="install" value="true" />
<?php
make_select('theme', t("Theme"), list_themes());
make_textbox('boshCookieTTL', t("Bosh cookie's expiration (s)"), 3600);
make_textbox('boshCookiePath', t("Bosh cookie's path"), '/');
make_checkbox('boshCookieDomain', t("Bosh cookie's domain"), false);
make_checkbox('boshCookieHTTPS', t("Use HTTPS for Bosh"), false);
make_checkbox('boshCookieHTTPOnly', t("Use only HTTP for Bosh"), true);
make_select('verbosity', t("Log verbosity"), array('empty', 'terse', 'normal', 'talkative', 'ultimate'), 4);
make_checkbox('accountCreation', t("Allow account creation"), false);
make_button('send', 'Install');
?>
</form>
<?php
}
function make_xml($stuff)
{
static $level = 0;
$buffer = "";
// Putting the XML declaration
if($level == 0) {
$buffer = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
}
// Indentation
$indent = "";
for($i = 0; $i < $level; $i++) {
$indent.= " ";
}
// Doing the job
foreach($stuff as $tag => $value) {
if(is_array($value)) {
$buffer.= $indent.'<'.$tag.'>'.PHP_EOL;
$level++;
$buffer.= make_xml($value);
$buffer.= $indent.'</'.$tag.'>'.PHP_EOL;
} else {
$buffer.= "$indent<$tag>$value</$tag>".PHP_EOL;
}
}
$level--;
return $buffer;
}
function get_checkbox($name, $if = 'true', $else = 'false')
{
return (isset($_POST[$name])? $if : $else);
}
function perform_install()
{
// Creating the folders.
if(!test_dir('user') && !@mkdir('user')) {
printf(t("Couldn't create directory '%s'."), 'user');
return false;
}
if(!test_dir('log') && !@mkdir('log')) {
printf(t("Couldn't create directory '%s'."), 'log');
return false;
}
// Creating the configuration file.
$conf = array(
'config' => array(
'theme' => $_POST['theme'],
'boshCookieTTL' => $_POST['boshCookieTTL'],
'boshCookiePath' => $_POST['boshCookiePath'],
'boshCookieDomain' => get_checkbox('boshCookieDomain'),
'boshCookieHTTPS' => get_checkbox('boshCookieHTTPS'),
'boshCookieHTTPOnly' => get_checkbox('boshCookieHTTPOnly'),
'logLevel' => $_POST['verbosity'],
'accountCreation' => get_checkbox('accountCreation', 1, 0),
),
);
if(!@file_put_contents('config/conf.xml', make_xml($conf))) {
printf(t("Couldn't create configuration file '%s'."), 'config/conf.xml');
return false;
}
return true;
}
?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
@ -29,47 +195,41 @@ function testInstall($test, $description = '', $advice = '') {
</head>
<body>
<div id="content">
<h1><?php echo t('Compatibility Test'); ?></h1>
<center><p><?php echo t('Until these items will not be validated, MOVIM will not run properly on your server'); ?></p></center>
<table style="margin: 0 auto;">
<tr>
<th style="width: 20px;"></th>
<th style="width: 400px;"></th>
<th></th>
</tr>
<?php
$v = explode( '.', phpversion());
testInstall($v['0'] >= 5 && $v['1'] >= 3,
t('PHP version > 5.3'),
t('Activate PHP5 on your server or update it to >5.3'));
testInstall(extension_loaded('curl'),
t('CURL extension present'),
t('Install php5-libcurl package or turn on Curl extension on your host server'));
testInstall(extension_loaded('SimpleXML'),
t('SimpleXML extension present'),
t('Install php5 package'));
testInstall(is_writable('user/'),
t('User folder is writable'),
'Change folder rights');
testInstall(is_writable('log/'),
t('Log folder is writable'),
'Change folder rights');
if(!defined('INSTALL_VALIDATED') && INSTALL_VALIDATED != false) {
echo '<tr><td></td>
<td><div class="valid">'. t('You have validated all the tests, now you can switch the "install" variable to 0 in config/conf.xml') .'</div></td>
</tr>
';
}
?>
</table>
<?php
$errors = test_requirements();
if($errors) {
// Ah ah, there are some errors.
?>
<h1><?php echo t('Compatibility Test'); ?></h1>
<p class="center"><?php echo t('The following requirements were not met. Please make sure they are all satisfied in order to install Movim.'); ?></p>
<?php
foreach($errors as $error) {
?>
<p class="error"><?php echo $error;?></p>
<?php
}
} else {
// Doing the job
if(isset($_POST['install'])) {
// Installing.
if(perform_install()) {
?>
<h1><?php echo t('Movim is installed!');?></h1>
<p><?php printf(t('You can now access your shiny %sMovim instance%s'),
'<a href="index.php">',
'</a>');?></p>
<?php
} else {
show_install_form();
}
} else {
// Install form.
show_install_form();
}
}
?>
</div>
</body>

1
lib/Jaxl/core/jaxl.util.php

@ -76,6 +76,7 @@
$rs['header'] = curl_getinfo($ch);
curl_close($ch);
return $rs;
}

11
lib/XMPPConnect.php

@ -176,12 +176,17 @@ class XMPPConnect
public function pingServer()
{
define('CURL_ASYNC', false);
$this->jaxl->JAXL0206('ping');
$this->jaxl->JAXL0206('ping');
}
public function getEmptyBody($payload) {
$evt = new EventHandler();
$evt->runEvent('incomingemptybody', 'ping');
$evt = new EventHandler();
// Oooooh, am I disconnected??
if(preg_match('/condition=[\'"]item-not-found[\'"]/', $payload)) {
$evt->runEvent('serverdisconnect', null);
} else {
$evt->runEvent('incomingemptybody', 'ping');
}
}
/**

1
lib/widgets/Logout/Logout.php

@ -24,6 +24,7 @@ class Logout extends Widget
$this->addcss('logout.css');
$this->addjs('logout.js');
$this->registerEvent('postdisconnected', 'onPostDisconnect');
$this->registerEvent('serverdisconnect', 'onPostDisconnect'); // When you're kicked out
}
function onPostDisconnect($data)

15
lib/widgets/Poller/poller.js

@ -1,6 +1,3 @@
var last_poll;
var poll_flood_detect = 3;
var failed_poll_count = 0;
/**
* Attach a callback function to an event.
@ -18,8 +15,6 @@ function movimRegisterPollHandler(type, func)
*/
function movim_poll()
{
last_poll = new Date().getTime();
poller = MovimRPC_make_xmlhttp();
poller.open('GET', 'jajax.php?do=poll', true);
@ -33,16 +28,6 @@ function movim_poll()
}
if(poller.status > 0) {
var time = new Date().getTime();
if(time - last_poll < 300) {
failed_poll_count++;
if(failed_poll_count > poll_flood_detect) {
window.location = "index.php?q=disconnect";
return;
}
} else {
failed_poll_count = 0;
}
// Restarting polling.
movim_poll();
}

10
user/edhelas@movim.eu/conf.xml

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<data>
<host>movim.eu</host>
<domain>movim.eu</domain>
<port>5222</port>
<boshHost>natsu.upyum.com</boshHost>
<boshSuffix>http-bind</boshSuffix>
<boshPort>5280</boshPort>
<language>fr</language>
</data>

4
user/edhelas@movim.eu/data.xml

@ -1,4 +0,0 @@
<data>
<login>edhelas@movim.eu</login>
<pass>4f4b4d2a53a07c54d604e25a9516a7a49388abd8</pass>
</data>

10
user/movim@movim.eu/conf.xml

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<data>
<host>movim.eu</host>
<domain>movim.eu</domain>
<port>5222</port>
<boshHost>natsu.upyum.com</boshHost>
<boshSuffix>http-bind</boshSuffix>
<boshPort>80</boshPort>
<language>en</language>
</data>

4
user/movim@movim.eu/data.xml

@ -1,4 +0,0 @@
<data>
<login>movim@movim.eu</login>
<pass>2d9ad9d5a66155e70fcf4466eae06e20f9a8659c</pass>
</data>
Loading…
Cancel
Save