/** * Class constructor * * Load the database instance and determine some informations about the page viewed * * This contructor has to be called in each child class before any actions * * @access protected */ protected function __construct() { if (!extension_loaded('json')) { $mail = new Mail(WS_EMAIL, 'Json not loaded', 'Lynxpress needs json extension to be loaded'); $mail->send(); throw new Exception('Json not loaded'); } $this->_db =& Database::load(); $this->pid(); $this->page(); }
/** * Retrieve default page setting * * @access private */ private function get_setting() { try { $to_read['table'] = 'setting'; $to_read['columns'] = array('SETTING_ID'); $to_read['condition_columns'][':t'] = 'setting_type'; $to_read['condition_select_types'][':t'] = '='; $to_read['condition_values'][':t'] = 'default_page'; $to_read['value_types'][':t'] = 'str'; $this->_setting = $this->_db->read($to_read); $this->_setting = new Setting($this->_setting[0]['SETTING_ID']); $this->_setting->_data = json_decode($this->_setting->_data, true); } catch (Exception $e) { $mail = new Mail(WS_EMAIL, 'Couldn\'t retrieve default page setting', $e->getMessage()); $mail->send(); } }
/** * Create a new user * * @access private */ private function create() { if ($this->check_post_data()) { try { $to_read['table'] = 'user'; $to_read['columns'] = array('USER_ID'); $to_read['condition_columns'][':u'] = 'user_username'; $to_read['condition_select_types'][':u'] = 'LIKE'; $to_read['condition_values'][':u'] = $this->_new_user->_username; $to_read['value_types'][':u'] = 'str'; $user = $this->_db->read($to_read); if (!empty($user)) { throw new Exception('Username already used!'); } $this->_new_user->create(); Session::monitor_activity('added a new member: ' . $this->_new_user->_username); if ($this->_new_user->_result_action === true && VPost::send_pwd(false)) { $to = $this->_new_user->_email; $subject = 'Your password for ' . WS_NAME; $message = 'This is your password: '******'Location: index.php?ns=users&ctl=manage'); } elseif ($this->_new_user->_result_action === true) { header('Location: index.php?ns=users&ctl=manage'); } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } }
* Lynxpress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Lynxpress. If not, see http://www.gnu.org/licenses/. */ namespace Site; use Library\Variable\Server as VServer; use Library\Mail\Mail; use Exception; try { define('PATH', ''); define('INC', 'includes/'); define('ADMIN', 'admin/'); require_once 'config.php'; require_once INC . 'class.loader.inc.php'; Loader::load(); new Session(); $title = '404 Page Not Found'; $menu = array('Sorry but the Lynx didn\'t show up'); require_once Html::header(); Html::_404(); require_once Html::footer(); $mail = new Mail(WS_EMAIL, '"404 not found reached', str_replace('",', "\",\n", json_encode(VServer::all()))); $mail->send(); } catch (Exception $e) { die('<h1>' . $e->getMessage() . '</h1>'); }
/** * Update lynxpress * * @access private */ private function update() { if (VPost::update()) { try { if (Helper::check_update() === false) { throw new Exception('No update available!'); } //make a backup of the database first, with an email sent to webmaster with the whole dump $bk = new Backup(); $bk->save('backup/dump-' . date('Y-m-d-H:i:s') . '.sql'); $html = new File(); $html->_content = '<!--The Lynx is not here!-->'; $html->save('backup/index.html'); $mail = new Mail(WS_EMAIL, 'Databse dump made before update at ' . date('Y-m-d H:i:s'), $bk->_sql); $mail->send(); //end backup //retrieve json manifest from the server $manifest = new Curl('http://update.lynxpress.org/manifest.json'); $manifest = json_decode($manifest->_content, true); //retrieve zip with all files inside $curl_zip = new Curl('http://versions.lynxpress.org/Lynxpress-' . $manifest['version'] . '.zip'); if ($curl_zip->_content == '<!--The Lynx is not here!-->') { throw new Exception('Can\'t retrieve lynxpress archive'); } $zip = new File(); $zip->_content = $curl_zip->_content; $zip->save('tmp/update.zip'); unset($zip); unset($curl_zip); File::unzip('tmp/update.zip', 'tmp/update/'); File::delete('tmp/update.zip'); //check if all files are readable foreach ($manifest['src'] as $src) { File::read('tmp/update/Lynxpress-' . $manifest['version'] . '/' . $src); } //replace all files registered in the manifest foreach ($manifest['src'] as $key => $src) { File::read('tmp/update/Lynxpress-' . $manifest['version'] . '/' . $src)->save($manifest['dest'][$key]); File::delete('tmp/update/Lynxpress-' . $manifest['version'] . '/' . $src); } //execute special queries foreach ($manifest['queries'] as $query) { $this->_db->query(str_replace('{{prefix}}', DB_PREFIX, $query)); } //remove files foreach ($manifest['remove'] as $file) { File::delete($file, false); } $config = File::read(PATH . 'config.php'); $config->_content = str_replace('(\'WS_VERSION\', \'' . WS_VERSION . '\')', '(\'WS_VERSION\', \'' . $manifest['version'] . '\')', $config->_content); $config->save(); unset($config); $config = File::read(PATH . 'config.sample.php'); $config->_content = str_replace('(\'WS_VERSION\', \'' . WS_VERSION . '\')', '(\'WS_VERSION\', \'' . $manifest['version'] . '\')', $config->_content); $config->save(); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::ws_update($result); } }
/** * Send mail to webmaster * * @access private */ private function send() { if (VPost::submit(false)) { if (!VPost::c_email() || !VPost::c_object() || !VPost::c_content()) { $this->_result = false; } elseif (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\\._-]+)+\$/", VPost::c_email())) { $this->_result = 'false email'; } else { $mail = new Mail(VPost::recaiver(), VPost::c_object(), VPost::c_content(), VPost::c_email()); $mail->send(); $this->_result = true; } } }