Exemplo n.º 1
0
 public function __construct()
 {
     parent::__construct("Report Queue", el('h2', "Reports"), Config::getCfg('permissions')['delete']);
     $reports = Model::get()->getReports();
     $html = "<table class='reportTable'><tr><th colspan='3'>Report Queue</th></tr><tr><th style='width:3em;'>Times</th><th>Post</th><th style='width:20em;'>Options</th></tr>";
     foreach ($reports as $report) {
         $hash = bin2hex($report['md5']);
         $html .= "<tr id='report{$report['no']}'>";
         $html .= "<td>" . $report['count'] . "</td>";
         $html .= "<td><a href='{$report['threadid']}#p{$report['no']}' data-board='{$report['board']}' data-thread='{$report['threadid']}' data-post='{$report['no']}' class='quotelink noEmbed'>&gt;&gt;{$report['no']}</a></td>";
         $html .= "<td><a class='button' href='javascript:deletePost({$report['no']},\"{$report['board']}\");' >Delete&nbsp;Post</a>&nbsp;";
         $html .= "<a class='button' href='javascript:banImage(\"{$hash}\");' id='ban{$hash}'>Ban&nbsp;Image</a>&nbsp;";
         $html .= "<a class='button' href='javascript:deleteReport({$report['no']},\"{$report['board']}\");'>Delete&nbsp;Report</a>&nbsp;";
         $html .= "<a class='button' href='javascript:banReporter({$report['no']},\"{$report['board']}\");'>Ban&nbsp;Reporter</a></td>";
         $html .= "</tr>";
     }
     $html .= "</table>";
     if (Site::getUser()->getPrivilege() >= Config::getCfg('permissions')['owner']) {
         $html .= "<br><table class='reportTable'><tr><th colspan='3'>Last Few Deleted Posts</th></tr><tr><th style='width:3em;'>Board</th><th>Post</th><th style='width:7em;'>Options</th></tr>";
         foreach (Model::get()->getBoards() as $board) {
             $lastFew = OldModel::getLastNDeletedPosts($board->getName(), 5);
             foreach ($lastFew as $report) {
                 $html .= "<tr id='report{$report['no']}'>";
                 $html .= "<td>" . $board->getName() . "</td>";
                 $html .= "<td>&gt;&gt;{$report['no']} ({$report['name']}{$report['trip']})</td>";
                 $html .= "<td><a class='button' href='javascript:restorePost({$report['no']},\"{$board->getName()}\");' >Restore&nbsp;Post</a></td>";
                 $html .= "</tr>";
             }
         }
         $html .= "</table>";
     }
     $this->appendToBody($html);
 }
Exemplo n.º 2
0
 function __construct()
 {
     parent::__construct(Config::getCfg('site')['pagetitle'], "", 0);
     $boards = Model::get()->getBoards();
     $archiveBoards = array_filter($boards, function ($b) {
         return $b->isArchive();
     });
     $plainBoards = array_filter($boards, function ($b) {
         return !$b->isArchive();
     });
     $html = "<div class='boardlist_big'><h1>Archived Boards</h1><hr style='width:64px;'>";
     foreach ($archiveBoards as $b) {
         $html .= Site::parseHtmlFragment("indexArchiveBoard.html", ["%ago%", "%crawltime%", "%shortname%", "%longname%", "%posts%", "%threads%", "%firstcrawl%"], [ago(time() - $b->getLastCrawl()), $b->getLastCrawl(), $b->getName(), $b->getLongName(), $b->getNoPosts(), $b->getNoThreads(), date("j F Y", $b->getFirstCrawl())]);
     }
     $html .= "</div>";
     $html .= "<script type='text/javascript' src='/script/boardUpdate.js'></script>";
     if (count($plainBoards) > 0) {
         $html .= "<div class='boardlist_big'><h1>Boards</h1><hr style='width:64px;'>";
         foreach ($plainBoards as $b) {
             $html .= Site::parseHtmlFragment("indexBoard.html", ["%ago%", "%crawltime%", "%shortname%", "%longname%", "%posts%", "%threads%", "%firstcrawl%"], [ago(time() - $b->getLastCrawl()), $b->getLastCrawl(), $b->getName(), $b->getLongName(), $b->getNoPosts(), $b->getNoThreads(), date("j F Y", $b->getFirstCrawl())]);
         }
         $html .= "</div>";
     }
     $this->setBody($html);
 }
Exemplo n.º 3
0
 static function setStyle() : string
 {
     $styles = Config::getCfg("styles");
     if (in_array(post('style'), array_keys($styles))) {
         Site::getUser()->setTheme(post('style'));
     }
     return '';
 }
Exemplo n.º 4
0
 function setTheme($theme)
 {
     if (in_array($theme, array_keys(Config::getCfg('styles')))) {
         if ($this->uid != 0) {
             OldModel::updateUserTheme($this->uid, $theme);
         }
         $this->theme = $theme;
     }
 }
Exemplo n.º 5
0
 public function __construct()
 {
     parent::__construct("Apply for Access", "", 0);
     $db = Config::getMysqliConnectionRW();
     $err = '';
     if (isset($_POST['username'])) {
         if (post('captcha') == $_SESSION['captcha']) {
             $username = $db->real_escape_string(post('username'));
             $password = md5(post('password'));
             $email = $db->real_escape_string(post('email'));
             $reason = $db->real_escape_string(post('why'));
             $ip = Site::ip();
             $db->query("INSERT INTO `request` (`ip`,`username`,`password`,`email`,`reason`,`time`) VALUES ('{$ip}','{$username}',UNHEX('{$password}'),'{$email}','{$reason}',UNIX_TIMESTAMP())");
             header('Location: /');
             exit;
         } else {
             $err = 'Invalid captcha.';
         }
     }
     $q = $db->query("SELECT * FROM `request` WHERE `ip`='" . Site::ip() . "'");
     if ($q->num_rows === 0) {
         $_SESSION['captcha'] = rand(100000, 999999);
         if ($err != '') {
             $this->appendToBody("<p class='center'>{$err}</p>");
         }
         $this->appendToBody(Site::parseHtmlFragment('reqForm.html', ['__captcha__'], ['<img src="/captcha" alt="captcha">']));
     } else {
         $r = $q->fetch_assoc();
         if ($r['accepted'] == 0) {
             $this->appendToBody("<h2>Hold Your Horses</h2><p class='center'>You have successfully applied. Check this page or your email for your status.</p>");
         } else {
             if ($r['accepted'] == -1) {
                 $this->appendToBody("<h2>Oh noes ;_;</h2><p class='center'>Sorry, your application has been reviewed and denied. Now that you have seen this message, you may submit a new application.</p>");
                 $db->query("DELETE FROM `request` WHERE `ip`='" . Site::ip() . "'");
             } else {
                 if ($r['accepted'] == 1) {
                     $this->appendToBody("<h2>Congratulations</h2><p class='center'>Your application was reviewed and accepted.<br>You may now log in with the username and password that you chose.</p>");
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 function renderHeader()
 {
     parent::renderHeader();
     if (!$this->clearHeader) {
         $this->header .= Site::parseHtmlFragment('pagebody.html', ['<!-- boardlist -->', '<!-- name -->', '<!-- subtitle -->'], [Board::getBoardList(), Config::getCfg('site')['name'], Config::getCfg('site')['subtitle']]);
         if ($_SERVER['SCRIPT_NAME'] != "/index.php") {
             if ($this->board == null) {
                 $this->header .= div('[' . a('HOME', '/index.php') . ']', 'centertext');
             } else {
                 $this->header .= "<div style='position:relative; top: -20px;' id='topLinks'>[<a href='/index.php'>Home</a>]";
                 if ($_SERVER['SCRIPT_NAME'] != "/board.php") {
                     $this->header .= " [" . a('Return', "/{$this->board->getName()}/") . "]";
                 }
                 if ($_SERVER['SCRIPT_NAME'] != "/catalog.php" && !$this->board->isSwfBoard()) {
                     $this->header .= " [" . a('Catalog', "/{$this->board->getName()}/catalog") . "]";
                 }
                 $this->header .= "</div><br>";
             }
         }
     }
     return $this->header;
 }
Exemplo n.º 7
0
 function getImgUrl()
 {
     if (!$this->hasImage()) {
         return "";
     }
     $imgcfg = $this->ext == '.swf' ? Config::getCfg("servers")["swf"] : Config::getCfg("servers")["images"];
     if ($imgcfg['https']) {
         $url = 'https://' . $imgcfg['httpshostname'] . ($imgcfg['httpsport'] != 443 ? ":" . $imgcfg['httpsport'] : "");
     } else {
         $url = 'http://' . $imgcfg['hostname'] . ($imgcfg['port'] != 80 ? ":" . $imgcfg['port'] : "");
     }
     $md5Hex = bin2hex($this->md5bin);
     return $url . str_replace(['%hex%', '%ext%', '%1%', '%2%'], [$md5Hex, $this->ext, $md5Hex[0], $md5Hex[1]], $imgcfg['format']);
 }
Exemplo n.º 8
0
             }
         }
     } else {
         log_error("No threads could be downloaded.");
     }
     /*
      * Update "Last updated" server var
      */
     o("Updating last update time: " . date("Y-m-d H:i:s"));
     $pdo->query("UPDATE `boards` SET `last_crawl`='" . $highestTime . "' WHERE `shortname`='{$board}'");
     $lastTime = $highestTime;
 } catch (Throwable $e) {
     log_exception($e);
     o("Restarting script...");
     $pdo = null;
     Config::closePDOConnectionRW();
     sleep(5);
     if (PHP_OS != "WINNT") {
         // spawn a new process
         if (!pcntl_fork()) {
             pcntl_exec(PHP_BINARY, $argv);
         }
         die;
     } else {
         $args = implode(' ', $argv);
         exec("psexec -d -accepteula C:\\php\\php.exe {$args}");
         die;
     }
 }
 if (time() - $startTime < EXEC_TIME) {
     wait:
Exemplo n.º 9
0
 static function getSiteHostname()
 {
     return Config::getCfg("servers")["site"]["hostname"];
 }
Exemplo n.º 10
0
 public static function updateUserTheme($uid, $theme)
 {
     try {
         $db = Config::getMysqliConnectionRW();
         $q = $db->prepare("UPDATE `users` SET `theme`=? WHERE `uid`=?");
         $q->bind_param("si", $theme, $uid);
         $q->execute();
     } catch (Exception $ex) {
     }
 }
Exemplo n.º 11
0
 public function changePassword(int $uid, string $old, string $new) : bool
 {
     $dbl = Config::getMysqliConnectionRW();
     $user = $dbl->query("SELECT * FROM `users` WHERE `uid`={$uid}")->fetch_assoc();
     if ($user['password_hash'] == md5($old, true)) {
         $new = md5($new);
         $dbl->query("UPDATE `users` SET `password_hash`=UNHEX('{$new}') WHERE `uid`={$uid}");
         if (!$dbl->errno) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 12
0
 public static function sitectl(array $path) : array
 {
     Site::requirePrivilege(Config::getCfg('permissions')['owner']);
     switch (strtolower($path[3])) {
         case 'enterbackupmode':
             Site::enterBackupMode();
             break;
         case 'exitbackupmode':
             Site::exitBackupMode();
             break;
     }
     return ['result' => 'success'];
 }
Exemplo n.º 13
0
 public static function styles(array $path) : array
 {
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 60));
     header('Cache-Control: max-age=3600, public, must-revalidate');
     header_remove("Pragma");
     return Config::getCfg("styles");
 }
Exemplo n.º 14
0
 protected function renderHeader()
 {
     $styles = "";
     foreach (Config::getCfg('styles')[$this->user->getTheme()] as $css) {
         $styles .= "<link rel='stylesheet' type='text/css' href='{$css}' data-name='theme'>";
     }
     $ga = Config::getCfg('site')['ga_id'] ?? '';
     if ($ga != '') {
         $analytics = Site::parseHtmlFragment("ga.html", ['__ID__'], [$ga]);
     } else {
         $analytics = "";
     }
     $this->header = Site::parseHtmlFragment('pagehead.html', ['<!-- styles -->', '<!-- pageTitle -->', '<!-- additionalHeaders -->', '<!-- navbar -->', '<!-- ga -->'], [$styles, $this->title, $this->addToHead, $this->renderNavBar(), $analytics]);
     return $this->header;
 }
Exemplo n.º 15
0
 /**
  * Routes to the proper view given a path relative to the site root.
  * @param string $path
  * @throws Exception
  * @throws NotFoundException if the path can't be routed
  */
 public static function route(string $path)
 {
     $exploded = explode('/', $path);
     $base = strtolower($exploded[1]);
     switch ($base) {
         case "do":
             // Action pages begin with do
             Action::run($exploded);
             break;
         case "api":
             // API endpoints begin with api
             $page = PublicApi::run($exploded);
             break;
         case "admin":
             $page = AdminApi::run($exploded);
             break;
         case "_":
             // Fuuka API support
             $page = FuukaApiAdaptor::run($exploded);
             break;
         default:
             $pages = Config::getCfg('pages');
             $boards = Model::get()->getBoards(true);
             if (array_key_exists($base, $boards)) {
                 $board = $boards[$base];
                 if (isset($exploded[2])) {
                     switch ($exploded[2]) {
                         case "catalog":
                             $page = new Catalog($board);
                             break;
                         case "thread":
                         case "res":
                             $num = $exploded[3] ?? "";
                             if (is_numeric($num)) {
                                 $page = new ThreadView(Model::get()->getThread($board, $num));
                             } else {
                                 throw new Exception("Invalid thread id provided");
                             }
                             break;
                         case "post":
                             $post = Model::get()->getPost($board, $exploded[3] ?? 0);
                             try {
                                 $thread = Model::get()->getThread($board, $post->threadid);
                                 header("Location: /{$board->getName()}/thread/{$post->getThreadId()}#{$post->getNo()}");
                                 exit;
                             } catch (NotFoundException $ex) {
                                 $page = new OrphanPost($post);
                             }
                             break;
                         case "search":
                             $page = new Search($board, $exploded);
                             break;
                         case "":
                             $page = new BoardIndexPage($boards[$base], 1);
                             break;
                         default:
                             if (is_numeric($exploded[2])) {
                                 $page = new BoardIndexPage($boards[$base], $exploded[2]);
                             } else {
                                 throw new Exception("Unknown board page requested");
                             }
                             break;
                     }
                 } else {
                     if (!array_key_exists($base, $pages)) {
                         header("Location: {$path}/");
                         exit;
                     } else {
                         $class = '\\View\\Pages\\' . $pages[$base];
                         $page = new $class();
                     }
                 }
             } else {
                 if (array_key_exists($base, $pages)) {
                     $class = '\\View\\Pages\\' . $pages[$base];
                     $page = new $class();
                 }
             }
             break;
     }
     if (isset($page)) {
         echo $page->display();
     } else {
         throw new NotFoundException('Unrecognized URL: ' . $path);
     }
 }