public function exec(kxEnv $environment) { $dbsize = 0; switch ($this->db->driver()) { case 'mysql': $twigData['dbtype'] = 'MySQL'; $results = $this->db->query("SHOW TABLE STATUS"); foreach ($results as $line) { $dbsize += $line->data_length + $line->index_length; } break; case 'pgsql': $twigData['dbtype'] = 'PostgreSQL'; $results = $this->db->query("SELECT pg_database_size('" . substr(kxEnv::get("kx:db:dsn"), strpos(kxEnv::get("kx:db:dsn"), "dbname=") + 7, strlen(kxEnv::get("kx:db:dsn"))) . "')"); foreach ($results as $line) { $dbsize += $line->pg_database_size; } break; case 'sqlite': $twigData['dbtype'] = 'SQLite'; $dbsize = filesize(substr(kxEnv::get("kx:db:dsn"), strpos(kxEnv::get("kx:db:dsn"), "sqlite:") + 7, strlen(kxEnv::get("kx:db:dsn")))); break; default: $twigData['dbtype'] = $this->db->driver(); } $twigData['dbsize'] = kxFunc::convertBytes($dbsize); $twigData['dbversion'] = substr($this->db->version(), 0, strrpos($this->db->version(), '-') !== FALSE ? strrpos($this->db->version(), '-') : strlen($this->db->version())); $twigData['stats']['numboards'] = $this->db->select("boards")->countQuery()->execute()->fetchField(); $twigData['stats']['totalposts'] = $this->db->select("posts")->countQuery()->execute()->fetchField(); $twigData['stats']['edahaversion'] = kxEnv::get("cache:version"); kxTemplate::output("manage/index", $twigData); }
public function exec(kxEnv $environment) { $types = array("posts", "uniques", "files"); if (!isset($this->request['time'])) { $this->request['time'] = 24; } $boards = $this->db->select("boards")->fields("boards")->execute()->fetchAll(); foreach ($types as $type) { switch ($type) { case "posts": // Total posts $result = $this->db->select("posts"); break; case "uniques": // Total uniques $result = $this->db->select("posts")->fields("posts", array("post_ip_md5"))->distinct(); break; case "files": // Total Files $result = $this->db->select("post_files"); $result->join("posts", NULL, "file_post = post_id"); break; } $result = $result->where("post_deleted = ?")->where("post_board = ?")->where("post_timestamp >= ?"); $results[$type] = $result->countQuery()->build(); } foreach ($boards as $board) { foreach ($results as $k => $result) { $result->execute(array(0, $board->board_id, !empty($this->request['time']) ? time() - $this->request['time'] * 60 * 60 : 0)); $twigData['stats'][$board->board_name][$k] = $result->fetchField(); } } kxTemplate::output("manage/stats", $twigData); }
private function _show() { if ($this->request['action'] == 'edit' && !empty($this->request['embed_id'])) { $this->twigData['edit_embed'] = $this->db->select("embeds")->fields("embeds")->condition("embed_id", $this->request['embed_id'])->execute()->fetch(); } $this->twigData['embeds'] = $this->db->select("embeds")->fields("embeds")->orderBy("embed_id")->execute()->fetchAll(); kxTemplate::output("manage/embeds", $this->twigData); }
private function _board() { // DATABASE DRIVERS, DATABASE DRIVERS NEVER CHANGE // EXCEPT WHEN SAZ F***S WITH THEM $array_o_boards = $this->db->select("boards")->fields('boards', array('board_name', 'board_desc'))->orderBy("board_name")->execute()->fetchAll(); $this->twigData['entries'] = array(); foreach ($array_o_boards as $board) { $this->twigData['entries'][$board->board_name] = $board->board_desc; } //print_r($this->twigData['entries']); kxTemplate::output("manage/board", $this->twigData); }
public function exec(kxEnv $environment) { if (isset($this->request['p'])) { switch ($this->request['p']) { case 'faq': $type = 1; break; case 'rules': $type = 2; break; } } else { $this->request['p'] = ''; $type = 0; } $this->twigData['styles'] = explode(':', kxEnv::Get('kx:css:menustyles')); $entries = $this->db->select("front")->fields("front")->condition("entry_type", $type); if ($this->request['p'] != '') { $entries->orderBy("entry_order", "ASC"); } else { $entries->orderBy("entry_time", "DESC"); if (!isset($this->request['view'])) { $entries->range(0, 1); } } $this->twigData['entries'] = $entries->execute()->fetchAll(); $sections = $this->db->select("sections")->fields("sections")->orderBy("section_order")->execute()->fetchAll(); $boards = $this->db->select("boards")->fields("boards", array('board_name', 'board_desc'))->where("board_section = ?")->orderBy("board_order")->build(); // Add boards to an array within their section foreach ($sections as $section) { $boards->execute(array($section->id)); $section->boards = $boards->fetchAll(); } $this->twigData['sections'] = $sections; // Get recent images $images = $this->db->select("post_files"); $images->innerJoin("posts", "", "post_id = file_post AND post_board = file_board"); $images = $images->fields("post_files", array("file_name", "file_type", "file_board", "file_thumb_width", "file_thumb_height"))->fields("posts", array("post_id", "post_parent"))->condition("file_name", "", "!=")->orderBy("post_timestamp", "DESC")->range(0, 3)->execute()->fetchAll(); $i = 0; if (count($images) > 0) { $results = $this->db->select('boards')->fields('boards', array('board_name'))->where('board_id = ?')->range(0, 1)->build(); while ($i < count($images)) { $results->execute(array($images[$i]->board_id)); $board = $results->fetchAll(); $images[$i]->boardname = $board[0]->board_name; $i++; } } $this->twigData['images'] = $images; kxTemplate::output("index", $this->twigData); }
public function exec(kxEnv $environment) { kxTemplate::output("manage/boardopts", array()); }
private function _show() { $options = $this->db->select("configuration")->fields("configuration")->orderBy("config_id")->execute()->fetchAll(); $twig_data['options'] = $options; kxTemplate::output("manage/site_config", $twig_data); }
public function loginValidate() { // Remove old login attempts $this->db->delete("loginattempts")->condition("attempt_time", time() - 1200, "<")->execute(); // Are we locked out still? $results = $this->db->select("loginattempts")->fields("loginattempts", array("attempt_ip"))->condition("attempt_ip", $_SERVER['REMOTE_ADDR'])->execute()->fetchAll(); if (count($results) > 5) { kxFunc::showError(_gettext('System lockout'), _gettext('Sorry, because of your numerous failed logins, you have been locked out from logging in for 20 minutes. Please wait and then try again.')); } else { // Find users with the username supplied to us $results = $this->db->select("staff")->fields("staff", array("user_id", "user_name", "user_password", "user_salt"))->condition("user_name", $this->request['username'])->execute()->fetchAll(); if (count($results) > 0) { if (md5($this->request['password'] . $results[0]->user_salt) == $results[0]->user_password) { // Let's make our session $session_id = md5(uniqid(microtime())); $this->request['sid'] = $session_id; // Delete any sessions that already exist for this user $this->db->delete("manage_sessions")->condition("session_staff_id", $results[0]->user_id)->execute(); // Insert our new values $this->db->insert("manage_sessions")->fields(array('session_id' => $session_id, 'session_ip' => $_SERVER['REMOTE_ADDR'], 'session_staff_id' => $results[0]->user_id, 'session_location' => "index", 'session_log_in_time' => time(), 'session_last_action' => time(), 'session_url' => ""))->execute(); // Set the cookies so ajax functions will load $this->SetModerationCookies(); //$this->environment->get('kx:classes:core:logging:id')->manageLog(_gettext('Logged in'), 1); // Let's figure out where we need to go $whereto = ""; // Unfiltered on purpose if ($_POST['qstring']) { $whereto = stripslashes($_POST['qstring']); $whereto = str_replace(kxEnv::Get('kx:paths:script:path'), "", $whereto); $whereto = str_ireplace("?manage.php", "", $whereto); $whereto = ltrim($whereto, '?'); $whereto = preg_replace("/sid=(\\w){32}/", "", $whereto); $whereto = str_replace(array('old_&', 'old_&'), "", $whereto); $whereto = str_replace("module=login", "", $whereto); $whereto = str_replace("do=login-validate", "", $whereto); $whereto = str_replace('&', '&', $whereto); $whereto = preg_replace("/&{1,}/", "&", $whereto); } $url = kxEnv::Get('kx:paths:script:path') . kxEnv::Get('kx:paths:script:folder') . '/manage.php?sid=' . $session_id . '&' . $whereto; if (!empty($_COOKIE['use_frames'])) { $twigData['url'] = $url; kxTemplate::output("manage/frames", $twigData); } else { kxFunc::doRedirect($url, true); } exit; } else { $this->db->insert("loginattempts")->fields(array('attempt_name' => $this->request['username'], 'attempt_ip' => $_SERVER['REMOTE_ADDR'], 'attempt_time' => time()))->execute(); $this->showForm(_gettext('Incorrect username/password.')); } } else { $this->db->insert("loginattempts")->fields(array('attempt_name' => $this->request['username'], 'attempt_ip' => $_SERVER['REMOTE_ADDR'], 'attempt_time' => time()))->execute(); $this->showForm(_gettext('Incorrect username/password.')); } } }
private function _addBan() { // TODO: Complete this $this->twigData['sections'] = kxFunc::fullBoardList(); kxTemplate::output('manage/bans_add', $this->twigData); }
private function _rules() { $this->twigData['entries'] = $this->db->select("front")->fields("front")->condition("entry_type", 2)->orderBy("entry_order", "ASC")->execute()->fetchAll(); kxTemplate::output("manage/rules", $this->twigData); }
private function _board() { $this->twigData['entries'] = $this->db->select("boards")->fields("boards")->orderBy("board_name")->execute()->fetchAll(); kxTemplate::output("manage/board", $this->twigData); }
/** * Allows adding, editing, and deleting of staff members */ private function _show() { $twigData = array(); if ($_GET['act'] == 'add' && $_POST) { // Adds a new staff member kxForm::addRule('username', 'required')->addRule('pwd1', 'required')->addRule('pwd1', 'value', true, $this->request['pwd2'])->addRule('type', 'numeric')->check(); $results = $this->db->select("staff")->fields("staff")->condition("user_name", $this->request['username'])->countQuery()->execute()->fetchField(); if ($results == 0) { $salt = substr(md5(time() . kxEnv::Get('kx:misc:randomseed')), -rand(3, 6)); //$this->_createSalt(); TODO: Decide hashing algorithm, replace current $this->db->insert("staff")->fields(array('user_name' => $this->request['username'], 'user_password' => md5($this->request['pwd1'] . $salt), 'user_salt' => $salt, 'user_type' => intval($this->request['type']), 'user_add_time' => time()))->execute(); $twigData['notice_type'] = 'success'; $twigData['notice'] = _gettext('User added successfully'); } else { // User with that username already exists $twigData['notice_type'] = 'error'; $twigData['notice'] = _gettext('A user with that username already exists'); } } elseif ($_GET['act'] == 'edit') { // Edits a user's information kxForm::addRule('id', 'numeric')->check(); $user = $this->db->select("staff")->fields("staff", array("user_id", "user_name", "user_salt", "user_type"))->condition("user_id", $this->request['id'])->execute()->fetch(); if ($_POST) { kxForm::addRule('pwd1', 'value', true, $this->request['pwd2'])->addRule('type', 'numeric')->check(); $values = array('user_type' => $this->request['type']); if (!empty($this->request['pwd1'])) { $values['user_password'] = md5($this->request['pwd1'] . $user['user_salt']); } $this->db->update("staff")->fields($values)->condition("user_id", $this->request['id'])->execute(); $twigData['notice_type'] = 'success'; $twigData['notice'] = _gettext('User info updated!'); } $twigData['user'] = $user; } elseif ($_GET['act'] == 'del') { // Deletes a user kxForm::addRule('id', 'numeric')->check(); $user_exists = $this->db->select("staff")->condition("user_id", $this->request['id'])->countQuery()->execute()->fetchField(); if ($user_exists) { $this->db->delete("staff")->condition("user_id", $this->request['id'])->execute(); $twigData['notice_type'] = 'success'; $twigData['notice'] = _gettext('User successfully deleted!'); } else { $twigData['notice_type'] = 'error'; $twigData['notice'] = _gettext('A user with that ID does not exist'); } } $staff = $this->db->select("staff")->fields("staff")->orderBy("user_type")->orderBy("user_add_time")->execute()->fetchAll(); $twigData['staffmembers'] = $staff; kxTemplate::output("manage/staff_show", $twigData); }
public static function showError($errormsg, $extended = '') { $twigData['styles'] = explode(':', kxEnv::Get('kx:styles:menustyles')); $twigData['errormsg'] = $errormsg; if ($extended != '') { $twigData['errormsgext'] = '<br /><div style="text-align: center;font-size: 1.25em;">' . $extended . '</div>'; } kxTemplate::output('error', $twigData); die; }
public function showFilters() { $this->twigData['filters'] = $this->db->select("filter")->fields("filter")->execute()->fetchAll(); $this->twigData['sections'] = kxFunc::fullBoardList(); kxTemplate::output('manage/filter', $this->twigData); }
private function _filetypes() { // Retrieve filetypes from cache $this->twigData['filetypes'] = kxEnv::get('cache:attachments:filetypes'); kxTemplate::output("manage/filetypes", $this->twigData); }
public function exec(kxEnv $environment) { $twigData['entries'] = self::fillArrayWithFileNodes(new DirectoryIterator(KX_ROOT . '/application/templates/')); kxTemplate::output("manage/templates", $twigData); }