Browse Source

- Split and rewrite the whole administration

- Move the administration in the database
- Move the DB configuration in a ini file
- Clean some stuffs
pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
d4dc0f81d2
  1. 16
      app/controllers/AdminloginController.php
  2. 2
      app/models/postn/Postn.php
  3. 4
      app/views/admin.tpl
  4. 4
      app/views/page.tpl
  5. 432
      app/widgets/Admin/Admin.php
  6. 75
      app/widgets/Admin/_admin_db.tpl
  7. 11
      app/widgets/Admin/admin.tpl
  8. 52
      app/widgets/AdminDB/AdminDB.php
  9. 62
      app/widgets/AdminDB/admindb.tpl
  10. 12
      app/widgets/AdminDB/locales.ini
  11. 75
      app/widgets/AdminMain/AdminMain.php
  12. 0
      app/widgets/AdminMain/admin.js
  13. 172
      app/widgets/AdminMain/adminmain.tpl
  14. 23
      app/widgets/AdminMain/locales.ini
  15. 51
      app/widgets/AdminTest/AdminTest.php
  16. 36
      app/widgets/AdminTest/admintest.tpl
  17. 11
      app/widgets/AdminTest/locales.ini
  18. 19
      app/widgets/Api/Api.php
  19. 13
      app/widgets/Infos/Infos.php
  20. 24
      app/widgets/Login/Login.php
  21. 4
      app/widgets/Login/login.tpl
  22. 8
      app/widgets/System/System.php
  23. 38
      bootstrap.php
  24. 15
      config/db.example.ini
  25. 5
      system/Sessionx.php
  26. 5
      system/User.php
  27. 8
      system/controllers/BaseController.php
  28. 8
      system/i18n/i18n.php

16
app/controllers/AdminloginController.php

@ -1,20 +1,24 @@
<?php
class AdminloginController extends BaseController {
function load() {
class AdminloginController extends BaseController
{
function load()
{
$this->session_only = false;
}
function dispatch() {
function dispatch()
{
$this->page->setTitle(__('title.administration', APP_TITLE));
$this->page->menuAddLink(__('page.home'), 'main');
$this->page->menuAddLink(__('page.administration'), 'admin', true);
$conf = Conf::getServerConf();
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
if($conf['user'] == $_POST['username']
&& $conf['pass'] == sha1($_POST['password'])) {
if($config->user == $_POST['username']
&& $config->pass == sha1($_POST['password'])) {
$_SESSION['admin'] = true;
$this->name = 'admin';
}

2
app/models/postn/Postn.php

@ -1,6 +1,6 @@
<?php
namespace modl;
namespace Modl;
class Postn extends Model {
public $session;

4
app/views/admin.tpl

@ -5,7 +5,9 @@
<h1><?php echo __('page.administration'); ?></h1>
</div>
<div class="moving_block" >
<?php $this->widget('Admin');?>
<?php $this->widget('AdminMain');?>
<?php $this->widget('AdminDB');?>
<?php $this->widget('AdminTest');?>
<?php $this->widget('Statistics');?>
<?php $this->widget('Api');?>
</div>

4
app/views/page.tpl

@ -1,11 +1,13 @@
<?php /* -*- mode: html -*- */
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title><?php $this->title();?></title>
<meta name="description" content="<?php echo Conf::getServerConfElement('description'); ?>" />
<meta name="description" content="<?php echo $config->description; ?>" />
<link rel="shortcut icon" href="<?php $this->linkFile('img/favicon.ico');?>" />
<link rel="stylesheet" href="<?php echo BASE_URI; ?>app/assets/js/leaflet.css" />

432
app/widgets/Admin/Admin.php

@ -1,432 +0,0 @@
<?php
/**
* @package Widgets
*
* @file Admin.php
* This file is part of MOVIM.
*
* @brief The administration widget.
*
* @author Timothée Jaussoin <edhelas@gmail.com>
*
* @version 1.0
* @date 25 November 2011
*
* Copyright (C)2010 MOVIM project
*
* See COPYING for licensing information.
*/
class Admin extends WidgetBase {
private $_conf;
private $_validatebutton;
function load()
{
$this->addjs('admin.js');
$this->_conf = Conf::getServerConf();
if(isset($_POST)) {
$this->saveConfig($_POST);
$_POST = null;
}
}
private function saveConfig($form) {
if($form['pass'] != '' && $form['repass'] != ''
&& $form['pass'] == $form['repass']) {
unset($form['repass']);
$form['pass'] = sha1($form['pass']);
} else {
$form['pass'] = $this->_conf['pass'];
}
foreach($form as $key => $value) {
$this->_conf[$key] = $value;
}
Conf::saveConfFile($this->_conf);
}
private function isValid($what)
{
if($what)
return "message success";
else
return "message error";
}
private function testDir($dir){
return (file_exists($dir) && is_dir($dir) && is_writable($dir));
}
private function testFile($file) {
return (file_exists($file) && is_writable($file));
}
private function listThemes()
{
$dir = opendir(DOCUMENT_ROOT.'/themes');
$themes = array();
while($theme = readdir($dir)) {
if(preg_match('/^\.+$/', $theme)
|| !is_dir(DOCUMENT_ROOT.'/themes/'.$theme)) {
continue;
}
$themes[$theme] = $theme;
}
return $themes;
}
private function listLangs()
{
return loadLangArray();
}
function testBosh($url)
{
return requestURL($url, 2);
}
public function ajaxUpdateDatabase()
{
$md = \modl\Modl::getInstance();
$md->check(true);
RPC::call('movim_reload_this');
}
function prepareAdminComp()
{
$this->_validatebutton = '
<div class="clear"></div>
<input
type="submit"
class="button icon yes color green oppose"
value="'.__('button.submit').'"/>';
$html = '
<fieldset>
<legend>'.$this->__('admin.compatibility').'</legend>
<div class="clear"></div>';
$html .=
'<p>'.
$this->__('compatibility.info').
'</p><br />';
$html .= '
<div class="'.$this->isValid((version_compare(PHP_VERSION, '5.3.0') >= 0)).'">
'.$this->__('compatibility.php', PHP_VERSION).'
</div>
<div class="'.$this->isValid(extension_loaded('curl')).'">
'.$this->__('compatibility.curl').'
</div>
<div class="'.$this->isValid(extension_loaded('gd')).'">
'.$this->__('compatibility.gd').'
</div>
<div class="'.$this->isValid(extension_loaded('SimpleXml')).'">
'.$this->__('compatibility.simplexml').'
</div>
<div class="'.$this->isValid($this->testDir(DOCUMENT_ROOT)).'">
'.$this->__('compatibility.rights').'
</div>
<div class="'.$this->isValid(extension_loaded('OpenSSL')).'">
'.$this->__('compatibility.openssl').'
</div>
</fieldset>
<fieldset>
<legend>'.$this->__('compatibility.rewrite').'</legend>
<div class="clear"></div>
<div class="'.$this->isValid($_SERVER['HTTP_MOD_REWRITE']).'">
'.$this->__('compatibility.rewrite').'
</div>';
$html .= '
</fieldset>';
return $html;
}
function prepareAdminGen() {
$html .= '
<fieldset>
<legend>'.$this->__('admin.general').'</legend>
<div class="element">
<label for="movim" >'.$this->__('general.theme').'</label>
<div class="select">
<select id="theme" name="theme">';
foreach($this->listThemes() as $key => $value) {
if((string)$this->_conf['theme'] == $key)
$sel = 'selected="selected"';
else
$sel = '';
$html .= '
<option value="'.$key.'" '.$sel.'>'.$value.'</option>';
}
$html .= ' </select>
</div>
</div>';
$html .= '
<div class="element">
<label for="da">'.$this->__('general.language').'</label>
<div class="select">
<select id="defLang" name="defLang">
<option value="en">English (default)</option>';
foreach($this->listLangs() as $key => $value) {
if((string)$this->_conf['defLang'] == $key)
$sel = 'selected="selected"';
else
$sel = '';
$html .= '
<option value="'.$key.'" '.$sel.'>'.$value.'</option>';
}
$html .= ' </select>
</div>
</div>';
$env = array(
'development' => 'Development',
'production' => 'Production');
$html .= '
<div class="element">
<label for="da">'.$this->__('general.environment').'</label>
<div class="select">
<select id="environment" name="environment">';
foreach($env as $key => $value) {
if((string)$this->_conf['environment'] == $key)
$sel = 'selected="selected"';
else
$sel = '';
$html .= '
<option value="'.$key.'" '.$sel.'>'.$value.'</option>';
}
$html .= ' </select>
</div>
</div>';
$html .= '
<div class="element">
<label for="sizeLimit">'.$this->__('general.limit').'</label>
<input type="text" name="sizeLimit" id="sizeLimit" value="'.$this->_conf['sizeLimit'].'" />
</div>';
$logopts = array(
0 => t('Empty'),
1 => t('Syslog'),
2 => t('Syslog and Files')
);
$html .= '
<div class="element">
<label for="logLevel">'.$this->__('general.log_verbosity').'</label>
<div class="select">
<select id="logLevel" name="logLevel">';
foreach($logopts as $lognum => $text) {
if($this->_conf['logLevel'] == $lognum)
$sel = 'selected="selected"';
else
$sel = '';
$html .= '
<option value="'.$lognum.'" '.$sel.'>'.
$text.'
</option>';
}
$html .= ' </select>
</div>
</div>';
$timezones = getTimezoneList();
$html .= '
<div class="element">
<label for="timezone">'.$this->__('general.timezone').'</label>
<div class="select">
<select id="timezone" name="timezone">';
foreach($timezones as $key => $value) {
if($this->_conf['timezone'] == $key) {
$sel = 'selected="selected"';
} else
$sel = '';
$html .= '
<option value="'.$key.'" '.$sel.'>'.
$key.' ('.number_format($value, 2).')
</option>';
}
$html .= ' </select>
</div>
<br /><br />
<span class="dTimezone">'.date('l jS \of F Y h:i:s A').'</span>
</div>';
$html .= $this->_validatebutton;
$html .= '
</fieldset>';
$html .= '
<fieldset>
<legend>'.$this->__('bosh.title').'</legend>
<div class="clear"></div>';
$html .= '<p>'.
$this->__('bosh.info1').' '.
$this->__('bosh.info2').' '.
$this->__('bosh.info3').' '.
$this->__('bosh.info4', '<a href="http://wiki.movim.eu/install">', '</a>');
'</p>';
if(!$this->testBosh($this->_conf['boshUrl'])) {
$html .= '
<div class="message error">'.
$this->__('bosh.not_recheable').'
</div>';
}
$html .= '
<div class="element">
<label for="boshUrl">'.$this->__('bosh.label').'</label>
<input type="text" id="boshUrl" name="boshUrl" value="'.$this->_conf['boshUrl'].'"/>
</div>';
$html .= $this->_validatebutton;
$html .= '
</fieldset>';
$html .= '
<fieldset>
<legend>'.$this->__('whitelist.title').'</legend>
<div class="clear"></div>';
$html .=
'<p>'.$this->__('whitelist.info1').'</p>'.
'<p>'.$this->__('whitelist.info2').'</p>';
$html .= '
<div class="element large">
<label for="xmppWhiteList">'.$this->__('whitelist.label').'</label>
<input type="text" name="xmppWhiteList" id="xmppWhiteList" value="'.$this->_conf['xmppWhiteList'].'" />
</div>';
$html .= $this->_validatebutton;
$html .= '
</fieldset>';
$html .= '
<fieldset>
<legend>'.$this->__('information.title').'</legend>
<div class="clear"></div>';
if($this->_conf['description'] == '')
$description = __('global.description');
else
$description = $this->_conf['description'];
$html .= '
<div class="element large">
<label for="description">'.$this->__('information.description').'</label>
<textarea type="text" name="description" id="description" />'.$description.'</textarea>
</div>
<div class="clear"></div>';
$html .= '<p>'.
$this->__('information.info1').
'</p>'.
'<p>'.
$this->__('information.info2').
'</p>';
$html .= '
<div class="element large">
<label for="info">'.$this->__('information.label').'</label>
<textarea type="text" name="info" id="info" />'.$this->_conf['info'].'</textarea>
</div>';
$html .= $this->_validatebutton;
$html .= '
</fieldset>';
$html .= '
<fieldset>
<legend>'.$this->__('credentials.title').'</legend>';
if($this->_conf['user'] == 'admin' || $this->_conf['pass'] == sha1('password')) {
$html .= '
<div class="message error">'.
$this->__('credentials.info').'
</div>';
}
$html .= '
<div class="element" >
<label for="username">'.$this->__('credentials.username').'</label>
<input type="text" id="user" name="user" value="'.$this->_conf['user'].'"/>
</div>
<div class="clear"></div>
<div class="element">
<label for="pass">'.$this->__('credentials.password').'</label>
<input type="password" id="pass" name="pass" value=""/>
</div>
<div class="element">
<label for="repass">'.$this->__('credentials.re_password').'</label>
<input type="password" id="repass" name="repass" value=""/>
</div> ';
$html .= $this->_validatebutton;
$html .= '
</fieldset><br />';
return $html;
}
function prepareAdminDB() {
$dbview = $this->tpl();
$md = \modl\Modl::getInstance();
$infos = $md->check();
$errors = '';
$dbview->assign('infos', $infos);
$dbview->assign('db_update', $this->genCallAjax('ajaxUpdateDatabase')
."this.className='button color orange icon loading'; setTimeout(function() {location.reload(false)}, 1000);");
try {
$md->connect();
} catch(Exception $e) {
$errors = $e->getMessage();
}
$dbview->assign('connected', $md->_connected);
$dbview->assign('validatebutton', $this->_validatebutton);
$dbview->assign('conf', $this->_conf);
$dbview->assign('supported_db', $md->getSupportedDatabases());
$dbview->assign('errors', $errors);
$html = $dbview->draw('_admin_db', true);
return $html;
}
}

75
app/widgets/Admin/_admin_db.tpl

@ -1,75 +0,0 @@
<fieldset>
<legend>{$c->__('')}</legend>
<div class="clear"></div>
{if="!$connected"}
<div class="message error">
{$c->__('db.connect_error')}
</div>
<div class="message error">
{$errors}
</div>
{else}
<div class="message success">
{$c->__('db.connect_success')}
</div>
{if="null !== $infos"}
<p>{$c->__('db.update')}</p>
<div class="message warning">
{loop="$infos"}
<p>{$value}</p>
{/loop}
<a class="button color green icon refresh"
onclick="{$db_update}"
style="float: right;">{$c->__('button.update')}</a>
<div class="clear"></div>
</div>
{else}
<div class="message success">
{$c->__('db.up_to_date')}
</div>
{/if}
{/if}
<div class="clear"></div>
<div class="element">
<label for="logLevel">{$c->__('db.type')}</label>
<div class="select">
<select id="dbType" name="dbType">
{loop="$supported_db"}
<option value="{$key}"
{if="$key == $conf.dbType"}
selected="selected"
{/if}>
{$value}
</option>
{/loop}
</select>
</div>
</div>
<div class="element">
<label for="dbUsername">{$c->__('db.username')}</label>
<input type="text" name="dbUsername" id="dbUsername" value="{$conf.dbUsername}" />
</div>
<div class="element">
<label for="dbPassword">{$c->__('db.password')}</label>
<input type="password" name="dbPassword" id="dbPassword" value="{$conf.dbPassword}" />
</div>
<div class="element">
<label for="dbHost">{$c->__('db.host')}</label>
<input type="text" name="dbHost" id="dbHost" value="{$conf.dbHost}" />
</div>
<div class="element">
<label for="dbPort">{$c->__('db.port')}</label>
<input type="text" name="dbPort" id="dbPort" value="{$conf.dbPort}" />
<div class="message info">
PostgreSQL - 5432 | MySQL - 3306
</div>
</div>
<div class="element">
<label for="dbName">{$c->__('db.name')}</label>
<input type="text" name="dbName" id="dbName" value="{$conf.dbName}" />
</div>
{$validatebutton}
</fieldset>

11
app/widgets/Admin/admin.tpl

@ -1,11 +0,0 @@
<form name="admin" id="adminform" action="#" method="post">
<div id="admincomp" class="tabelem padded" title="{$c->__('admin.compatibility')}">
{$c->prepareAdminComp()}
</div>
<div id="admingen" class="tabelem padded" title="{$c->__('admin.general')}">
{$c->prepareAdminGen()}
</div>
<div id="admindb" class="tabelem padded" title="{$c->__('db.legend')}">
{$c->prepareAdminDB()}
</div>
</form>

52
app/widgets/AdminDB/AdminDB.php

@ -0,0 +1,52 @@
<?php
/**
* @package Widgets
*
* @file AdminDB.php
* This file is part of Movim.
*
* @brief The DB Administration widget
*
* @author Jaussoin Timothée <edhelas@movim.eu>
* Copyright (C)2014 Movim project
*
* See COPYING for licensing information.
*/
class AdminDB extends WidgetBase
{
function load() {
}
function display()
{
$md = \modl\Modl::getInstance();
$infos = $md->check();
$errors = '';
$this->view->assign('infos', $infos);
$this->view->assign('db_update', $this->genCallAjax('ajaxUpdateDatabase')
."this.className='button color orange icon loading'; setTimeout(function() {location.reload(false)}, 1000);");
try {
$md->connect();
} catch(Exception $e) {
$errors = $e->getMessage();
}
if(file_exists(DOCUMENT_ROOT.'/config/db.ini')) {
$conf = parse_ini_file(DOCUMENT_ROOT.'/config/db.ini');
}
$supported = $md->getSupportedDatabases();
$this->view->assign('connected', $md->_connected);
$this->view->assign('validatebutton', $this->_validatebutton);
$this->view->assign('conf', $conf);
$this->view->assign('dbtype', $supported[$conf['type']]);
$this->view->assign('errors', $errors);
}
}

62
app/widgets/AdminDB/admindb.tpl

@ -0,0 +1,62 @@
<div id="admindb" class="tabelem padded" title="{$c->__('db.legend')}">
<fieldset>
<legend>{$c->__('')}</legend>
<div class="clear"></div>
{if="!$connected"}
<div class="message error">
{$c->__('db.connect_error')}
</div>
<div class="message error">
{$errors}
</div>
{else}
<div class="message success">
{$c->__('db.connect_success')}
</div>
{if="null !== $infos"}
<p>{$c->__('db.update')}</p>
<div class="message warning">
{loop="$infos"}
<p>{$value}</p>
{/loop}
<a class="button color green icon refresh"
onclick="{$db_update}"
style="float: right;">{$c->__('button.update')}</a>
<div class="clear"></div>
</div>
{else}
<div class="message success">
{$c->__('db.up_to_date')}
</div>
{/if}
{/if}
<div class="clear"></div>
<div class="element">
<label for="logLevel">{$c->__('db.type')}</label>
<span>{$dbtype}</span>
</div>
<div class="element">
<label for="dbUsername">{$c->__('db.username')}</label>
<span>{$conf.username}</span>
</div>
<div class="element">
<label for="dbPassword">{$c->__('db.password')}</label>
<span>Password</span>
</div>
<div class="element">
<label for="dbHost">{$c->__('db.host')}</label>
<span>{$conf.host}</span>
</div>
<div class="element">
<label for="dbPort">{$c->__('db.port')}</label>
<span>{$conf.port}</span>
</div>
<div class="element">
<label for="dbName">{$c->__('db.name')}</label>
<span>{$conf.database}</span>
</div>
</fieldset>
</div>

12
app/widgets/AdminDB/locales.ini

@ -0,0 +1,12 @@
[db]
db.legend = 'Database Settings'
db.connect_error = "Modl wasn't able to connect to the database"
db.connect_success = 'Movim is connected to the database'
db.update = 'The database need to be updated'
db.up_to_date = 'Movim database is up to date'
db.type = 'Database Type'
db.username = 'Username'
db.password = 'Password'
db.host = 'Host'
db.port = 'Port'
db.name = 'Database Name'

75
app/widgets/AdminMain/AdminMain.php

@ -0,0 +1,75 @@
<?php
/**
* @package Widgets
*
* @file AdminMain.php
* This file is part of Movim.
*
* @brief The main configuration on Movim
*
* @author Jaussoin Timothée <edhelas@movim.eu>
* Copyright (C)2014 Movim project
*
* See COPYING for licensing information.
*/
class AdminMain extends WidgetBase
{
function load() {
$this->addjs('admin.js');
$form = $_POST;
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
if(isset($form)) {
if($form['pass'] != '' && $form['repass'] != ''
&& $form['pass'] == $form['repass']) {
unset($form['repass']);
$form['pass'] = sha1($form['pass']);
} else {
$form['pass'] = $config->pass;
}
foreach($form as $key => $value) {
$config->$key = $value;
}
$cd->set($config);
}
}
public function testBosh($url)
{
return requestURL($url, 2);
}
public function date()
{
return date('l jS \of F Y h:i:s A');
}
function display()
{
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$this->view->assign('conf', $cd->get());
$this->view->assign('logs',
array(
0 => t('Empty'),
1 => t('Syslog'),
2 => t('Syslog and Files'))
);
$this->view->assign('envs',
array(
'development' => 'Development',
'production' => 'Production')
);
$this->view->assign('timezones', getTimezoneList());
$this->view->assign('langs', loadLangArray());
}
}

0
app/widgets/Admin/admin.js → app/widgets/AdminMain/admin.js

172
app/widgets/AdminMain/adminmain.tpl

@ -0,0 +1,172 @@
<form name="admin" id="adminform" action="#" method="post">
<div id="admingen" class="tabelem padded" title="{$c->__('admin.general')}">
<fieldset>
<legend>{$c->__('admin.general')}</legend>
<div class="element">
<label for="da">{$c->__('general.language')}</label>
<div class="select">
<select id="locale" name="locale">
<option value="en">English (default)</option>';
{loop="$langs"}
<option value="{$key}"
{if="$conf->locale == $key"}
selected="selected"
{/if}>
{$value}
</option>
{/loop}
</select>
</div>
</div>
<div class="element">
<label for="da">{$c->__('general.environment')}</label>
<div class="select">
<select id="environment" name="environment">';
{loop="$envs"}
<option value="{$key}"
{if="$conf->environment == $key"}
selected="selected"
{/if}>
{$value}
</option>
{/loop}
</select>
</div>
</div>
<div class="element">
<label for="sizelimit">{$c->__('general.limit')}</label>
<input type="text" name="sizelimit" id="sizelimit" value="{$conf->sizelimit}" />
</div>
<div class="element">
<label for="loglevel">{$c->__('general.log_verbosity')}</label>
<div class="select">
<select id="loglevel" name="loglevel">
{loop="$logs"}
<option value="{$key}"
{if="$conf->loglevel == $key"}
selected="selected"
{/if}>
{$value}
</option>
{/loop}
</select>
</div>
</div>
<div class="element">
<label for="timezone">{$c->__('general.timezone')}</label>
<div class="select">
<select id="timezone" name="timezone">
{loop="$timezones"}
<option value="{$key}"
{if="$conf->timezone == $key"}
selected="selected"
{/if}>
{$key} ({$value|number_format:2})
</option>
{/loop}
</select>
</div>
<br /><br />
<span class="dTimezone">{$c->date()}</span>
</div>
</fieldset>
<fieldset>
<legend>{$c->__('bosh.title')}</legend>
<div class="clear"></div>
<p>
{$c->__('bosh.info1')}<br />
{$c->__('bosh.info2')}<br />
{$c->__('bosh.info3')}<br />
{$c->__('bosh.info4', '<a href="http://wiki.movim.eu/install">', '</a>')}
</p>
{if="!$c->testBosh($conf->boshurl)"}
<div class="message error">
{$c->__('bosh.not_recheable')}
</div>
{/if}
<div class="element">
<label for="boshurl">{$c->__('bosh.label')}</label>
<input type="text" id="boshurl" name="boshurl" value="{$conf->boshurl}"/>
</div>
</fieldset>
<fieldset>
<legend>{$c->__('whitelist.title')}</legend>
<div class="clear"></div>
<p>{$c->__('whitelist.info1')}</p>
<p>{$c->__('whitelist.info2')}</p>
<div class="element large">
<label for="xmppwhiteiist">{$c->__('whitelist.label')}</label>
<input type="text" name="xmppwhitelist" id="xmppwhitelist" value="{$conf->xmppwhitelist}" />
</div>
</fieldset>
<fieldset>
<legend>{$c->__('information.title')}</legend>
<div class="clear"></div>
<div class="element large">
<label for="description">{$c->__('information.description')}</label>
<textarea type="text" name="description" id="description" />{$conf->description}</textarea>
</div>
<div class="clear"></div>
<p>{$c->__('information.info1')}</p>
<p>{$c->__('information.info2')}</p>
<div class="element large">
<label for="info">{$c->__('information.label')}</label>
<textarea type="text" name="info" id="info" />{$conf->info}</textarea>
</div>
</fieldset>
<fieldset>
<legend>{$c->__('credentials.title')}</legend>
{if="$conf->user == 'admin' || $conf->pass == sha1('password')"}
<div class="message error">
{$c->__('credentials.info')}
</div>
{/if}
<div class="element" >
<label for="username">{$c->__('credentials.username')}</label>
<input type="text" id="user" name="user" value="{$conf->user}"/>
</div>
<div class="clear"></div>
<div class="element">
<label for="pass">{$c->__('credentials.password')}</label>
<input type="password" id="pass" name="pass" value=""/>
</div>
<div class="element">
<label for="repass">{$c->__('credentials.re_password')}</label>
<input type="password" id="repass" name="repass" value=""/>
</div>
</fieldset>
<input
type="submit"
class="button icon yes color green oppose"
value="{$c->__('button.submit')}"/>
<div class="clear"></div>
</div>
</form>

23
app/widgets/Admin/locales.ini → app/widgets/AdminMain/locales.ini

@ -1,4 +1,3 @@
admin.compatibility = 'Compatibility Check'
admin.general = 'General Settings'
[general]
@ -38,25 +37,3 @@ information.info1 = 'This message will be displayed on the login page'
information.info2 = "Leave this field blank if you don't want to show any message."
information.label = 'Information Message'
[compatibility]
compatibility.info = 'Movim requires certain external components. Please install them before you can succeed:'
compatibility.php = 'Your PHP-Version: %s <br>Required: 5.3.0'
compatibility.curl = 'CURL-Library'
compatibility.gd = 'GD'
compatibility.simplexml = 'SimpleXML'
compatibility.rights = "Read and write rights for the webserver in Movim's root directory"
compatibility.openssl = 'OpenSSL'
compatibility.rewrite = 'URL Rewriting support'
[db]
db.legend = 'Database Settings'
db.connect_error = "Modl wasn't able to connect to the database"
db.connect_success = 'Movim is connected to the database'
db.update = 'The database need to be updated'
db.up_to_date = 'Movim database is up to date'
db.type = 'Database Type'
db.username = 'Username'
db.password = 'Password'
db.host = 'Host'
db.port = 'Port'
db.name = 'Database Name'

51
app/widgets/AdminTest/AdminTest.php

@ -0,0 +1,51 @@
<?php
/**
* @package Widgets
*
* @file AdminTest.php
* This file is part of Movim.
*
* @brief The Admin Pest part
*
* @author Jaussoin Timothée <edhelas@movim.eu>
* Copyright (C)2014 Movim project
*
* See COPYING for licensing information.
*/
class AdminTest extends WidgetBase
{
function load() {
}
public function valid($what)
{
if($what)
return "message success";
else
return "message error";
}
public function version()
{
return (version_compare(PHP_VERSION, '5.3.0') >= 0);
}
public function testDir($dir)
{
return (file_exists($dir) && is_dir($dir) && is_writable($dir));
}
public function testFile($file)
{
return (file_exists($file) && is_writable($file));
}
function display()
{
}
}

36
app/widgets/AdminTest/admintest.tpl

@ -0,0 +1,36 @@
<div id="admincomp" class="tabelem padded" title="{$c->__('admin.compatibility')}">
<fieldset>
<legend>{$c->__('admin.compatibility')}</legend>
<div class="clear"></div>
<p>
{$c->__('compatibility.info')}
</p><br />
<div class="{$c->valid($c->version())}">
{$c->__('compatibility.php', PHP_VERSION)}
</div>
<div class="{$c->valid(extension_loaded('curl'))}">
{$c->__('compatibility.curl')}
</div>
<div class="{$c->valid(extension_loaded('gd'))}">
{$c->__('compatibility.gd')}
</div>
<div class="{$c->valid(extension_loaded('SimpleXml'))}">
{$c->__('compatibility.simplexml')}
</div>
<div class="{$c->valid($c->testDir(DOCUMENT_ROOT))}">
{$c->__('compatibility.rights')}
</div>
<div class="{$c->valid(extension_loaded('OpenSSL'))}">
{$c->__('compatibility.openssl')}
</div>
</fieldset>
<fieldset>
<legend>{$c->__('compatibility.rewrite')}</legend>
<div class="clear"></div>
<div class="{$c->valid($_SERVER['HTTP_MOD_REWRITE'])}">
{$c->__('compatibility.rewrite')}
</div>
</fieldset>
</div>

11
app/widgets/AdminTest/locales.ini

@ -0,0 +1,11 @@
admin.compatibility = 'Compatibility Check'
[compatibility]
compatibility.info = 'Movim requires certain external components. Please install them before you can succeed:'
compatibility.php = 'Your PHP-Version: %s <br>Required: 5.3.0'
compatibility.curl = 'CURL-Library'
compatibility.gd = 'GD'
compatibility.simplexml = 'SimpleXML'
compatibility.rights = "Read and write rights for the webserver in Movim's root directory"
compatibility.openssl = 'OpenSSL'
compatibility.rewrite = 'URL Rewriting support'

19
app/widgets/Api/Api.php

@ -34,16 +34,17 @@ class Api extends WidgetBase {
$json = requestURL(MOVIM_API.'status', 1, array('uri' => BASE_URI));
$json = json_decode($json);
$conf = Conf::getServerConf();
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
if(isset($json)) {
$this->view->assign('json', $json);
if($json->status == 200) {
$this->view->assign('unregister', $this->genCallAjax('ajaxUnregister'));
$this->view->assign('unregister_status', $conf['unregister']);
$this->view->assign('unregister_status', $config->unregister);
} else {
$conf['unregister'] = false;
Conf::saveConfFile($conf);
$config->unregister = false;
$cd->set($config);
$this->view->assign('register', $this->genCallAjax('ajaxRegister'));
}
} else {
@ -74,12 +75,12 @@ class Api extends WidgetBase {
function ajaxUnregister()
{
$conf = Conf::getServerConf();
$conf['unregister'] = !$conf['unregister'];
Conf::saveConfFile($conf);
sleep(2);
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$config->unregister = !$config->unregister;
$cd->set($config);
RPC::call('movim_reload_this');
RPC::commit();
}

13
app/widgets/Infos/Infos.php

@ -31,7 +31,8 @@ class Infos extends WidgetBase
$pop = $pop-2;
// We get the global configuration
$conf = Conf::getServerConf();
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$sd = new \Modl\SessionxDAO();
@ -43,11 +44,11 @@ class Infos extends WidgetBase
$infos = array(
'url' => BASE_URI,
'language' => $conf['defLang'],
'whitelist' => $conf['xmppWhiteList'],
'timezone' => $conf['timezone'],
'description' => $conf['description'],
'unregister' => $conf['unregister'],
'language' => $config->locale,
'whitelist' => $config->xmppwhitelist,
'timezone' => $config->timezone,
'description' => $config->description,
'unregister' => $config->unregister,
'php_version' => phpversion(),
'rewrite' => $rewrite,
'version' => APP_VERSION,

24
app/widgets/Login/Login.php

@ -17,8 +17,8 @@
* See COPYING for licensing information.
*/
class Login extends WidgetBase {
class Login extends WidgetBase
{
function load()
{
$this->addcss('login.css');
@ -30,8 +30,12 @@ class Login extends WidgetBase {
function display()
{
$submit = $this->genCallAjax('ajaxLogin', "movim_parse_form('login')");
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$this->view->assign('submit', $submit);
$this->view->assign('conf', Conf::getServerConf($submit));
$this->view->assign('info', $config->info);
$this->view->assign('submit_event',
'document.getElementById(\'submitb\').click();
'.$submit.'
@ -68,9 +72,10 @@ class Login extends WidgetBase {
$this->view->assign('facebook',
$this->__('account.facebook',
'<a href="#" onclick="fillExample(\'your.id@chat.facebook.com \', \'\');">', '</a>'));
$conf = Conf::getServerConf();
$whitelist = $conf['xmppWhiteList'];
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$whitelist = $config->xmppwhitelist;
if(isset($whitelist) && $whitelist!=''){
$this->view->assign('whitelist', $whitelist);
@ -206,7 +211,8 @@ class Login extends WidgetBase {
function ajaxLogin($element)
{
// We get the Server Configuration
$serverconfig = Conf::getServerConf();
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$warning = false;
@ -227,12 +233,12 @@ class Login extends WidgetBase {
// Check whitelisted server
if(
$serverconfig['xmppWhiteList'] != '' &&!
$config->xmppwhitelist != '' &&!
in_array(
end(
explode('@', $element['login'])
),
explode(',',$serverconfig['xmppWhiteList'])
explode(',',$config->xmppwhitelist)
)
)
$warning = 'serverunauthorized';

4
app/widgets/Login/login.tpl

@ -4,9 +4,9 @@
{$c->__('error.too_old')}
</div>
{else}
{if="isset($conf.info) && $conf.info != ''"}
{if="isset($info) && $info != ''"}
<div class="message warning">
{$conf.info}
{$info}
</div>
{/if}
<form

8
app/widgets/System/System.php

@ -31,10 +31,12 @@ class System extends WidgetBase {
$this->view->assign('fail_safe', '');
// And we load some public values of the system configuration
$conf = Conf::getServerConf();
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$public_conf = array(
'bosh_url' => $conf['boshUrl'],
'timezone' => $conf['timezone']
'bosh_url' => $config->boshurl,
'timezone' => $config->timezone
);
$this->view->assign('server_conf', json_encode($public_conf));
}

38
bootstrap.php

@ -9,7 +9,7 @@ use Monolog\Handler\SyslogHandler;
/**
* Error Handler...
*/
function systemErrorHandler ( $errno , $errstr , $errfile , $errline , $errcontext=null )
function systemErrorHandler($errno, $errstr, $errfile, $errline, $errcontext = null)
{
$log = new Logger('movim');
$log->pushHandler(new SyslogHandler('movim'));
@ -42,10 +42,10 @@ class Bootstrap {
$this->loadDispatcher();
$this->loadHelpers();
$this->setTimezone();
$loadmodlsuccess = $this->loadModl();
$this->setTimezone();
if($loadmodlsuccess) {
$this->startingSession();
} else {
@ -115,7 +115,7 @@ class Bootstrap {
define('HELPERS_PATH', DOCUMENT_ROOT . '/app/helpers/');
define('WIDGETS_PATH', DOCUMENT_ROOT . '/app/widgets/');
define('MOVIM_API', 'https://api.movim.eu/');
define('MOVIM_API', 'http://localhost/api/public/');
if (!defined('DOCTYPE')) {
define('DOCTYPE','text/html');
@ -202,11 +202,15 @@ class Bootstrap {
}
private function setLogs() {
/*$cd = new \Modl\ConfigDAO();
$config = $cd->get();
try {
define('ENVIRONMENT', Conf::getServerConfElement('environment'));
define('ENVIRONMENT', $config->environment);
} catch (Exception $e) {
define('ENVIRONMENT','development');//default environment is production
}
}*/
define('ENVIRONMENT','development');//default environment is production
/**
* LOG_MANAGEMENT: define where logs are saved, prefer error_log, or log_folder if you use mutual server.
* 'error_log' : save in file defined on your file server
@ -219,7 +223,7 @@ class Bootstrap {
ini_set('log_errors', 1);
ini_set('display_errors', 0);
ini_set('error_reporting', E_ALL );
} else {
ini_set('log_errors', 1);
ini_set('display_errors', 0);
@ -230,14 +234,15 @@ class Bootstrap {
}
set_error_handler('systemErrorHandler', E_ALL);
define('LOG_LEVEL', (int)Conf::getServerConfElement('logLevel'));
define('LOG_LEVEL', 1);
}
private function setTimezone() {
// We set the default timezone to the server timezone
$conf = Conf::getServerConf();
if(isset($conf['timezone']))
date_default_timezone_set($conf['timezone']);
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
date_default_timezone_set($config->timezone);
}
private function loadModl() {
@ -245,6 +250,7 @@ class Bootstrap {
$db = Modl\Modl::getInstance();
$db->setModelsPath(APP_PATH.'models');
Modl\Utils::loadModel('Config');
Modl\Utils::loadModel('Presence');
Modl\Utils::loadModel('Contact');
Modl\Utils::loadModel('Privacy');
@ -258,8 +264,14 @@ class Bootstrap {
Modl\Utils::loadModel('Message');
Modl\Utils::loadModel('Sessionx');
Modl\Utils::loadModel('Conference');
if(file_exists(DOCUMENT_ROOT.'/config/db.ini')) {
$conf = parse_ini_file(DOCUMENT_ROOT.'/config/db.ini');
} else {
echo 'Cannot find config/db.ini file';
}
$db->setConnectionArray(Conf::getServerConf());
$db->setConnectionArray($conf);
$db->connect();
return true;

15
config/db.example.ini

@ -0,0 +1,15 @@
; This is the database configuration of Movim
; You need to copy an rename this file to 'db.ini' and complete the values
[db]
; The type can be 'pgsql' or 'mysql'
type = 'mysql'
; The database username
username = 'username'
; The password
password = 'password'
; Where can we find the database ?
host = 'localhost'
; The port number, 3306 for MySQL and 5432 for PostGreSQL
port = 3306
; The database name
database = 'movim'

5
system/Sessionx.php

@ -95,9 +95,10 @@ class Sessionx {
}
public function init($user, $pass, $host, $domain) {
$serverconfig = Conf::getServerConf();
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$this->_url = $serverconfig['boshUrl'];
$this->_url = $config->boshurl;
$this->_port = 5222;
$this->_host = $host;
$this->_domain = $domain;

5
system/User.php

@ -40,7 +40,10 @@ class User {
if($session->config)
$this->config = $session->config;
$this->sizelimit = (int)Conf::getServerConfElement('sizeLimit');
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$this->sizelimit = (int)$config->sizelimit;
$this->userdir = DOCUMENT_ROOT.'/users/'.$this->username.'/';
$this->useruri = BASE_URI.'users/'.$this->username.'/';

8
system/controllers/BaseController.php

@ -23,20 +23,24 @@ class BaseController {
*/
function loadLanguage() {
$user = new User();
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
if($user->isLogged()) {
$lang = $user->getConfig('language');
if(isset($lang)) {
loadLanguage($lang);
} else {
// Load default language.
loadLanguage(Conf::getServerConfElement('defLang'));
loadLanguage($config->locale);
}
}
else if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
loadLanguageAuto();
}
else {
loadLanguage(Conf::getServerConfElement('defLang'));
loadLanguage($config->locale);
}
}

8
system/i18n/i18n.php

@ -70,7 +70,7 @@ function __() {
global $translationshash;
$args = func_get_args();
if(array_key_exists($args[0], $translationshash)) {
if(is_array($translationshash) && array_key_exists($args[0], $translationshash)) {
$args[0] = $translationshash[$args[0]];
return call_user_func_array('t', $args);
} else {
@ -158,8 +158,12 @@ function loadLanguageAuto()
while((list($key, $value) = each($langs)) && $langNotFound == true) {
$exploded = explode('-', $key);
$key = reset($exploded);
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
if($key == 'en') {
loadLanguage(Conf::getServerConfElement('defLang'));
loadLanguage($config->locale);
$langNotFound = false;
} elseif(file_exists(LOCALES_PATH . $key . '.po')) {
loadLanguage($key);

Loading…
Cancel
Save