* * @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 = ' '; return $html; } function build() { ?>