Пример #1
0
 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);
 }
Пример #2
0
 private function _getMenu($savetofile = false, $option = false)
 {
     //$twigData['boardpath'] = getCLBoardPath();
     $twigData['styles'] = explode(':', kxEnv::Get('kx:css:menustyles'));
     if ($savetofile) {
         $file = 'menu.html';
     } else {
         $file = 'menu.php';
     }
     $twigData['file'] = $file;
     $sections = array();
     $boardsExist = $this->db->select("boards")->fields("boards")->countQuery()->execute()->fetchField();
     if ($boardsExist) {
         $sections = $this->db->select("sections")->fields("sections")->orderBy("section_order")->execute()->fetchAll();
         $results = $this->db->select("boards")->fields("boards", array("board_order", "board_name", "board_desc", "board_locked", "board_trial", "board_popular"))->where("section = ?")->orderBy("board_order")->orderBy("board_name")->build();
         foreach ($sections as $key => $section) {
             $results->execute(array($section['id']));
             $boards = $results->fetchAll();
             $sections[$key]['boards'] = $boards;
         }
     }
     $twigData['boards'] = $sections;
     if ($savetofile) {
         file_put_contents(KX_ROOT . '/menu.html', kxTemplate::get('menu', $twigData));
         return true;
     } else {
         return kxTemplate::get('menu', $twigData);
     }
 }
Пример #3
0
 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);
 }
Пример #4
0
 public static function init($template_dir = null, $compiled_dir = null, $cache_dir = null)
 {
     if (self::$instance == null) {
         //echo "<p>init() called!</p>";
         if ($template_dir != null) {
             self::$template_dir = $template_dir;
         } else {
             self::$template_dir = KX_ROOT . kxEnv::get("kx:templates:dir");
         }
         $loader = new Twig_Loader_Filesystem(self::$template_dir);
         if ($cache_dir == null) {
             $cache_dir = KX_ROOT . kxEnv::get("kx:templates:cachedir");
         }
         self::$instance = new Twig_Environment($loader, array('cache' => $cache_dir, 'auto_reload' => true, 'debug' => true));
         // Load our extensions
         self::$instance->addExtension(new Twig_Extensions_Extension_I18n());
         self::$instance->addExtension(new Twig_Extensions_Extension_kxEnv());
         self::$instance->addExtension(new Twig_Extensions_Extension_DateFormat());
         self::$instance->addExtension(new Twig_Extensions_Extension_Text());
         self::$instance->addExtension(new Twig_Extensions_Extension_Round());
         self::$instance->addExtension(new Twig_Extensions_Extension_Strip());
         self::$instance->addExtension(new Twig_Extensions_Extension_Debug());
         self::$instance->addExtension(new Twig_Extensions_Extension_PHP());
         // Supply Twig with our GET/POST variables
         self::$data['_get'] = $_GET;
         self::$data['_post'] = $_POST;
         // Supply Twig with the default locale
         self::$data['locale'] = kxEnv::Get('kx:misc:locale');
         // Are we in manage? Load up the manage wrapper
         if (IN_MANAGE) {
             self::$data['current_app'] = "";
             if (KX_CURRENT_APP == "core") {
                 // Load up some variables for tabbing/menu purposes
                 if (isset(kxEnv::$request['app'])) {
                     self::$data['current_app'] = kxEnv::$request['app'];
                 }
             } else {
                 if (KX_CURRENT_APP == "board") {
                     if (kxEnv::$current_module == "posts") {
                         self::$data['current_app'] = "posts";
                     } else {
                         self::$data['current_app'] = "board";
                     }
                 }
             }
             $baseurl = kxEnv::Get('kx:paths:main:path') . '/manage.php?sid=' . (isset(kxEnv::$request['sid']) ? kxEnv::$request['sid'] : '') . '&';
             self::$data['base_url'] = $baseurl;
             // Get our manage username
             if (isset(kxEnv::$request['sid'])) {
                 $result = kxDB::getinstance()->select('staff', 'stf')->fields('stf', array('user_name'));
                 $result->innerJoin("manage_sessions", "ms", "ms.session_staff_id = stf.user_id");
                 self::assign('name', $result->condition('session_id', kxEnv::$request['sid'])->execute()->fetchField());
             }
         }
         // else {
         //	die('Not IN_MANAGE!');
         //}
     }
 }
Пример #5
0
 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);
 }
Пример #6
0
 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);
 }
Пример #7
0
 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);
 }
Пример #8
0
 /**
  * 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);
 }
Пример #9
0
 private function _filetypes()
 {
     // Retrieve filetypes from cache
     $this->twigData['filetypes'] = kxEnv::get('cache:attachments:filetypes');
     kxTemplate::output("manage/filetypes", $this->twigData);
 }
Пример #10
0
 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);
 }
Пример #11
0
 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);
 }
Пример #12
0
 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_&amp;'), "", $whereto);
                     $whereto = str_replace("module=login", "", $whereto);
                     $whereto = str_replace("do=login-validate", "", $whereto);
                     $whereto = str_replace('&amp;', '&', $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.'));
         }
     }
 }
Пример #13
0
 private function _addBan()
 {
     // TODO: Complete this
     $this->twigData['sections'] = kxFunc::fullBoardList();
     kxTemplate::output('manage/bans_add', $this->twigData);
 }
Пример #14
0
 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);
 }
Пример #15
0
 public function exec(kxEnv $environment)
 {
     kxTemplate::output("manage/boardopts", array());
 }
Пример #16
0
 private static function DisplayBannedMessage($bans, $board = '')
 {
     /* Set a cookie with the users current IP address in case they use a proxy to attempt to make another post */
     setcookie('tc_previousip', $_SERVER['REMOTE_ADDR'], time() + 604800, kxEnv::Get('kx:paths:boards:folder'));
     require_once KX_ROOT . '/lib/dwoo.php';
     kxTemplate::assign('bans', $bans);
     return $dwoo->get(KX_ROOT . kxEnv::Get('kx:templates:dir') . '/banned.tpl', $twigData);
 }
Пример #17
0
 /**
  * Regenerate each thread's corresponding html file, starting with the most recently bumped
  */
 public function regenerateThreads($id = 0)
 {
     $numimages = 0;
     $embeds = $this->db->select("embeds")->fields("embeds")->execute()->fetchAll();
     $this->twigData['embeds'] = $embeds;
     // No ID? Get every thread.
     if ($id == 0) {
         // Okay let's do this!
         $threads = $this->db->select("posts")->fields("posts")->condition("post_board", $this->board->board_id)->condition("post_parent", 0)->condition("post_deleted", 0)->orderBy("post_id", "DESC")->execute()->fetchAll();
         if (count($threads) > 0) {
             foreach ($threads as $thread) {
                 $this->regenerateThreads($thread->post_id);
             }
         }
     } else {
         for ($i = 0; $i < 3; $i++) {
             if (!$i > 0 && kxEnv::Get('kx:extras:firstlast') || $i == 1 && $replycount < 50 || $i == 2 && $replycount < 100) {
                 break;
             }
             if ($i == 0) {
                 $lastBit = "";
                 $executiontime_start_thread = microtime(true);
                 //---------------------------------------------------------------------------------------------------
                 // Okay, this may seem confusing, but we're caching this so we can use it as a prepared statement
                 // instead of executing it every time. This is only really useful if we're regenerating all threads,
                 // but the perfomance impact otherwise is minimal.
                 //----------------------------------------------------------------------------------------------------
                 if (!isset($this->board->preparedThreads)) {
                     $this->board->preparedThreads = $this->db->select("posts")->fields("posts")->where("post_board = " . $this->board->board_id . " AND (post_id = ? OR post_parent = ?) AND post_deleted = 0")->orderBy("post_id")->build();
                 }
                 // Since we prepared the statement earlier, we just need to execute it.
                 $this->board->preparedThreads->execute(array($id, $id));
                 $thread = $this->board->preparedThreads->fetchAll();
                 foreach ($thread as &$post) {
                     $post = $this->buildPost($post, false);
                     if (!empty($post->file_type)) {
                         foreach ($post->file_type as $type) {
                             if ($type == 'jpg' || $type == 'gif' || $type == 'png') {
                                 $numimages++;
                             }
                         }
                     }
                 }
                 //-----------------------------------------------------------------------
                 // When using a pointer in a foreach, the $value variable persists
                 // as the last index of an array, we can use this to our advantage here.
                 //-----------------------------------------------------------------------
                 if (kxEnv::Get('kx:extras:postspy')) {
                     $twigData['lastid'] = $post->post_id;
                 }
                 // Now we can get rid of it
                 unset($post);
                 $this->board->header = $this->pageHeader($id);
                 $this->board->postbox = $this->postBox($id);
                 //-----------
                 // Dwoo-hoo
                 //-----------
                 $this->twigData['numimages'] = $numimages;
                 $this->twigData['replythread'] = $id;
                 $this->twigData['threadid'] = $thread[0]->post_id;
                 $this->twigData['posts'] = $thread;
                 $replycount = count($thread) - 1;
                 $this->twigData['replycount'] = $replycount;
                 if (!isset($this->board->footer)) {
                     $this->board->footer = $this->footer(false, microtime(true) - $executiontime_start_thread);
                 }
             } else {
                 if ($i == 1) {
                     $lastBit = "+50";
                     $this->twigData['modifier'] = "last50";
                     // Grab the last 50 replies
                     $this->twigData['posts'] = array_slice($thread, -50, 50);
                     // Add the thread to the top of this, since it wont be included in the result
                     array_unshift($this->twigData['posts'], $thread[0]);
                 } elseif ($i == 2) {
                     $lastBit = "-100";
                     $this->twigData['modifier'] = "first100";
                     // Grab the first 100 posts
                     $this->twigData['posts'] = array_slice($thread, 0, 100);
                 }
             }
             $this->twigData['board'] = $this->board;
             //print_r($this->twigData);
             $content = kxTemplate::get('board/' . $this->boardType . '/thread', $this->twigData, true);
             kxFunc::outputToFile(KX_BOARD . '/' . $this->board->board_name . $this->archive_dir . '/res/' . $id . $lastBit . '.html', $content, $this->board->board_name);
         }
     }
 }
Пример #18
0
 private function _board()
 {
     $this->twigData['entries'] = $this->db->select("boards")->fields("boards")->orderBy("board_name")->execute()->fetchAll();
     kxTemplate::output("manage/board", $this->twigData);
 }
Пример #19
0
 public function exec(kxEnv $environment)
 {
     $twigData['entries'] = self::fillArrayWithFileNodes(new DirectoryIterator(KX_ROOT . '/application/templates/'));
     kxTemplate::output("manage/templates", $twigData);
 }