* * @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 WidgetLoad() { $this->_conf = Conf::getServerConf(); } 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)); } /* * Create the dirs */ function createDirs(){ if(!file_exists(BASE_PATH.'cache') && !@mkdir(BASE_PATH.'cache')) { echo t("Couldn't create directory '%s'.", 'cache'); return false; } if(!file_exists(BASE_PATH.'log') && !@mkdir(BASE_PATH.'log')) { echo t("Couldn't create directory '%s'.", 'log'); return false; } if(!file_exists(BASE_PATH.'config') && !@mkdir(BASE_PATH.'config')) { echo t("Couldn't create directory '%s'.", 'config'); return false; } } private function listThemes() { $dir = opendir(BASE_PATH.'themes'); $themes = array(); while($theme = readdir($dir)) { if(preg_match('/^\.+$/', $theme) || !is_dir(BASE_PATH.'themes/'.$theme)) { continue; } $themes[$theme] = $theme; } return $themes; } private function listLangs() { $dir = opendir(BASE_PATH.'locales'); $langs = array('en' => 'English'); $languages = get_lang_list(); while($lang = readdir($dir)) { if(!preg_match('/\.po$/', $lang)) { continue; } $lang = substr($lang, 0, strlen($lang) - 3); $langs[$lang] = $languages[$lang]; } return $langs; } function testBosh($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Fire ! $rs = array(); $rs['content'] = curl_exec($ch); $rs['errno'] = curl_errno($ch); $rs['errmsg'] = curl_error($ch); $rs['header'] = curl_getinfo($ch); if($rs['content'] != false && $rs['content'] != '') { return true; } elseif($rs['errno'] != 0 || $rs['content'] == '') { return false; } curl_close($ch); } public function ajaxAdminSubmit($form) { unset($form['']); $empty = false; if($form['repass'] == '' || !isset($form['repass'])) $form['pass'] = $this->_conf['pass']; elseif($form['pass'] == $form['repass']) { unset($form['repass']); $form['pass'] = sha1($form['pass']); } foreach($this->_conf as $key => $value) { if(isset($form[$key])) $this->_conf[$key] = $form[$key]; } Conf::saveConfFile($this->_conf); } public function ajaxRecreateDatabase() { $pd = new \modl\PostnDAO(); $pd->create(); $nd = new \modl\NodeDAO(); $nd->create(); $cd = new \modl\ContactDAO(); $cd->create(); $cad = new \modl\CapsDAO(); $cad->create(); $prd = new \modl\PresenceDAO(); $prd->create(); $rd = new \modl\RosterLinkDAO(); $rd->create(); $sd = new \modl\SessionDAO(); $sd->create(); $cd = new \modl\CacheDAO(); $cd->create(); $md = new \modl\MessageDAO(); $md->create(); $cd = new \modl\SubscriptionDAO(); $cd->create(); $pr = new \modl\PrivacyDAO(); $pr->create(); } private function prepareAdminComp() { if($this->testDir(BASE_PATH)) $this->createDirs(); $submit = $this->genCallAjax('ajaxAdminSubmit', "movim_parse_form('admin')") ."this.className='button color orange icon loading'; setTimeout(function() {location.reload(false)}, 2000);"; $this->_validatebutton = '
'.t('Submit').''; $html = '
'; $html .= '
'.t("Compatibility Check").'
'; $html .= '

'. t('Movim requires certain external components. Please install them before you can succeed:'). '


'; $html .= '
'.t('Your PHP-Version: %s
Required: 5.3.0', PHP_VERSION).'
'.t('CURL-Library').'
'.t('GD').'
'.t('SimpleXML').'
'.t('Read and write rights for the webserver in Movim\'s root directory').'
'.t('URL Rewriting support').'
'.t('URL Rewriting support').'
'; $html .= '
'; return $html; } function prepareAdminGen() { $html .= '
'.t('General Settings').'
'; $html .= '
'; /* $html .= '
'; */ $html .= '
'; $logopts = array( 0 => t('empty'), 2 => t('terse'), 4 => t('normal'), 6 => t('talkative'), 7 => t('ultimate'), ); $default_log = 4; $html .= '
'; $timezones = getTimezoneList(); $html .= '


'.date('l jS \of F Y h:i:s A').'
'; $html .= $this->_validatebutton; $html .= '
'; $html .= '
'.t("Bosh Configuration").'
'; $html .= '

'. t("Enter here the BOSH-URL in the form: http(s)://domain:port/path.").' '. t('If you enter an open BOSH-Server, you can connect to many XMPP-Servers.').' '. t('If it is closed, you have to specify the corresponding Server on the next page.').' '. t('If you are unsure about this config option visit the wiki'); '

'; if(!$this->testBosh($this->_conf['boshUrl'])) { $html .= '
'. t('Your Bosh URL is not reachable').'
'; } $html .= '
'; $html .= $this->_validatebutton; $html .= '
'; $html .= '
'.t("Whitelist - XMPP Server").'
'; $html .= '

'. t("If you want to specify a list of authorized XMPP servers on your Movim pod and forbid the connection on all the others please put their domain name here, with comma (ex: movim.eu,jabber.fr)"). '

'. '

'. t("Leave this field blank if you allow the access to all the XMPP accounts."). '

'; $html .= '
'; $html .= $this->_validatebutton; $html .= '
'; $html .= '
'.t("Information Message").'
'; $html .= '

'. t("This message will be displayed on the login page"). '

'. '

'. t("Leave this field blank if you don't want to show any message."). '

'; $html .= '
'; $html .= $this->_validatebutton; $html .= '
'; $html .= '
'.t("Administration Credential").''; if($this->_conf['user'] == 'admin' && $this->_conf['pass'] == sha1('password')) { $html .= '
'. t('Change the default username/password').'
'; } $html .= '
'; $html .= $this->_validatebutton; $html .= '

'; return $html; } function prepareAdminDB() { $html .= '
'.t("Database Settings").'
'; $md = new \modl\ModlDAO(); if(isset($md->_dao->_error)) { $html .= '
'. t("Modl wasn't able to connect to the database").'
'.$md->_dao->_error.'
'; } else { $dbrecreate = $this->genCallAjax('ajaxRecreateDatabase'); $html .= '
'.t('Recreate').'
'.t('This button will clear and recreate the Movim database.').'
'; } /*$html .= '
'; */ $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= $this->_validatebutton; $html .= '
'; $html .= '
'; return $html; } function build() { ?>
" style="margin: 1.5em;"> prepareAdminComp(); ?>
prepareAdminGen(); ?>
" style="margin: 1.5em;"> prepareAdminDB(); ?>