From 2843ddc4826f250a8af6203cff437929ab807a41 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 13 Apr 2012 09:47:27 +1000 Subject: view bans / unban --- inc/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/template.php') diff --git a/inc/template.php b/inc/template.php index 8d679d25..ab220454 100644 --- a/inc/template.php +++ b/inc/template.php @@ -26,7 +26,7 @@ function load_twig() { $loader->setPaths($config['dir']['template']); $twig = new Twig_Environment($loader, array( 'autoescape' => false, - 'cache' => "{$config['dir']['template']}/cache", + //'cache' => "{$config['dir']['template']}/cache", 'debug' => ($config['debug'] ? true : false), )); $twig->addExtension(new Twig_Extensions_Extension_Tinyboard()); -- cgit v1.3 From 87281687ed3ed06fd76d7bbb6c29404bb883418a Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 14 Apr 2012 22:28:21 +1000 Subject: promote/demote users, started on rebuild --- inc/mod/pages.php | 67 ++++++++++++++++++++++++++++++++++++------- inc/template.php | 2 +- mod.php | 3 ++ templates/mod/rebuild.html | 71 ++++++++++++++++++++++++++++++++++++++++++++++ templates/mod/users.html | 6 +++- 5 files changed, 136 insertions(+), 13 deletions(-) create mode 100644 templates/mod/rebuild.html (limited to 'inc/template.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 4903567a..d78ebf0d 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -143,7 +143,12 @@ function mod_page_ip($ip) { } if (isset($_POST['note'])) { - // TODO: permissions + if (hasPermission($config['mod']['create_notes'])) { + $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip"); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC); + } markup($_POST['note']); $query = prepare('INSERT INTO `ip_notes` VALUES (NULL, :ip, :mod, :time, :body)'); @@ -194,20 +199,30 @@ function mod_page_ip($ip) { $args['boards'] = $boards; - $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip"); - $query->bindValue(':ip', $ip); - $query->execute() or error(db_error($query)); - $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC); - $query = prepare("SELECT `ip_notes`.*, `username` FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip"); - $query->bindValue(':ip', $ip); - $query->execute() or error(db_error($query)); - $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC); + if (hasPermission($config['mod']['view_ban'])) { + $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip"); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC); + } + + if (hasPermission($config['mod']['view_notes'])) { + $query = prepare("SELECT `ip_notes`.*, `username` FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip"); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC); + } mod_page("IP: $ip", 'mod/view_ip.html', $args); } function mod_ban() { + global $config; + + if (!hasPermission($config['mod']['ban'])) + error($config['error']['noaccess']); + if (!isset($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'])) { mod_page("New ban", 'mod/ban_form.html', array()); return; @@ -263,6 +278,19 @@ function mod_users() { mod_page('Manage users', 'mod/users.html', $args); } +function mod_user_promote($uid, $action) { + global $config; + + if (!hasPermission($config['mod']['promoteusers'])) + error($config['error']['noaccess']); + + $query = prepare("UPDATE `mods` SET `type` = `type` " . ($action == 'promote' ? "+1 WHERE `type` < " . (int)ADMIN : "-1 WHERE `type` > " . (int)JANITOR) . " AND `id` = :id"); + $query->bindValue(':id', $uid); + $query->execute() or error(db_error($query)); + + header('Location: ?/users', true, $config['redirect_http']); +} + function mod_new_pm($username) { global $config, $mod; @@ -272,8 +300,16 @@ function mod_new_pm($username) { $query = prepare("SELECT `id` FROM `mods` WHERE `username` = :username"); $query->bindValue(':username', $username); $query->execute() or error(db_error($query)); - if (!$id = $query->fetchColumn(0)) - error($config['error']['404']); + if (!$id = $query->fetchColumn(0)) { + // Old style ?/PM: by user ID + $query = prepare("SELECT `username` FROM `mods` WHERE `id` = :username"); + $query->bindValue(':username', $username); + $query->execute() or error(db_error($query)); + if ($username = $query->fetchColumn(0)) + header('Location: ?/new_PM/' . $username, true, $config['redirect_http']); + else + error($config['error']['404']); + } if (isset($_POST['message'])) { markup($_POST['message']); @@ -291,3 +327,12 @@ function mod_new_pm($username) { mod_page("New PM for {$username}", 'mod/new_pm.html', array('username' => $username, 'id' => $id)); } +function mod_rebuild() { + global $config; + + if (!hasPermission($config['mod']['rebuild'])) + error($config['error']['noaccess']); + + mod_page("Rebuild", 'mod/rebuild.html', array('boards' => listBoards())); +} + diff --git a/inc/template.php b/inc/template.php index ab220454..8d679d25 100644 --- a/inc/template.php +++ b/inc/template.php @@ -26,7 +26,7 @@ function load_twig() { $loader->setPaths($config['dir']['template']); $twig = new Twig_Environment($loader, array( 'autoescape' => false, - //'cache' => "{$config['dir']['template']}/cache", + 'cache' => "{$config['dir']['template']}/cache", 'debug' => ($config['debug'] ? true : false), )); $twig->addExtension(new Twig_Extensions_Extension_Tinyboard()); diff --git a/mod.php b/mod.php index e7134603..f641d371 100644 --- a/mod.php +++ b/mod.php @@ -28,8 +28,11 @@ $pages = array( '!^/log/(\d+)$!' => 'log', // modlog '!^/users$!' => 'users', // manage users + '!^/users/(\d+)/(promote|demote)$!' => 'user_promote', // prmote/demote user '!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm + '!^/rebuild$!' => 'rebuild', // rebuild static files + '!^/ban$!' => 'ban', // new ban '!^/IP/([\w.:]+)$!' => 'ip', // view ip address '!^/IP/([\w.:]+)/remove_note/(\d+)$!' => 'ip_remove_note', // remove note from ip address diff --git a/templates/mod/rebuild.html b/templates/mod/rebuild.html new file mode 100644 index 00000000..763eb624 --- /dev/null +++ b/templates/mod/rebuild.html @@ -0,0 +1,71 @@ +
+
    +
  • + + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
+ +
+ +
    +
  • + + + +
  • + {% for board in boards %} +
  • + + +
  • + {% endfor %} +
+ +

+ +

+
diff --git a/templates/mod/users.html b/templates/mod/users.html index aeacc8b5..63d799d5 100644 --- a/templates/mod/users.html +++ b/templates/mod/users.html @@ -30,7 +30,11 @@ {% if mod|hasPermission(config.mod.modlog) %} - {{ user.last|ago }} + {% if user.last %} + {{ user.last|ago }} + {% else %} + never + {% endif %} {% else %} – {% endif %} -- cgit v1.3 From 41e1a2481b4d2b3217b667063d9bf5115dfec9ab Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 16 Apr 2012 17:28:57 +1000 Subject: report queue --- inc/mod/pages.php | 121 +++++++++++++++++++++++++++++++++++++++++++++ inc/template.php | 2 +- mod.php | 2 + templates/mod/report.html | 26 ++++++++++ templates/mod/reports.html | 5 ++ 5 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 templates/mod/report.html create mode 100644 templates/mod/reports.html (limited to 'inc/template.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 60f101ea..2532e2e7 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -469,3 +469,124 @@ function mod_rebuild() { mod_page("Rebuild", 'mod/rebuild.html', array('boards' => listBoards())); } +function mod_reports() { + global $config, $mod; + + if (!hasPermission($config['mod']['reports'])) + error($config['error']['noaccess']); + + $query = prepare("SELECT * FROM `reports` ORDER BY `time` DESC LIMIT :limit"); + $query->bindValue(':limit', $config['mod']['recent_reports'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + $reports = $query->fetchAll(PDO::FETCH_ASSOC); + + $report_queries = array(); + foreach ($reports as $report) { + if (!isset($report_queries[$report['board']])) + $report_queries[$report['board']] = array(); + $report_queries[$report['board']][] = $report['post']; + } + + $report_posts = array(); + foreach ($report_queries as $board => $posts) { + $report_posts[$board] = array(); + + $query = query(sprintf('SELECT * FROM `posts_%s` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error()); + while ($post = $query->fetch()) { + $report_posts[$board][$post['id']] = $post; + } + } + + $body = ''; + foreach ($reports as $report) { + if (!isset($report_posts[$report['board']][$report['post']])) { + // // Invalid report (post has since been deleted) + $query = prepare("DELETE FROM `reports` WHERE `post` = :id AND `board` = :board"); + $query->bindValue(':id', $report['post'], PDO::PARAM_INT); + $query->bindValue(':board', $report['board']); + $query->execute() or error(db_error($query)); + continue; + } + + openBoard($report['board']); + + $post = &$report_posts[$report['board']][$report['post']]; + + if (!$post['thread']) { + // Still need to fix this: + $po = new Thread( + $post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], + $post['capcode'], $post['body'], $post['time'], $post['thumb'], + $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], + $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], + $post['locked'], $post['sage'], $post['embed'], '?/', $mod, false + ); + } else { + $po = new Post( + $post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], + $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], + $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod + ); + } + + // a little messy and inefficient + $append_html = Element('mod/report.html', array('report' => $report, 'config' => $config, 'mod' => $mod)); + + // Bug fix for https://github.com/savetheinternet/Tinyboard/issues/21 + $po->body = truncate($po->body, $po->link(), $config['body_truncate'] - substr_count($append_html, '
')); + + if (mb_strlen($po->body) + mb_strlen($append_html) > $config['body_truncate_char']) { + // still too long; temporarily increase limit in the config + $__old_body_truncate_char = $config['body_truncate_char']; + $config['body_truncate_char'] = mb_strlen($po->body) + mb_strlen($append_html); + } + + $po->body .= $append_html; + + $body .= $po->build(true) . '
'; + + if(isset($__old_body_truncate_char)) + $config['body_truncate_char'] = $__old_body_truncate_char; + } + + mod_page("Report queue", 'mod/reports.html', array('reports' => $body)); +} + +function mod_report_dismiss($id, $all = false) { + global $config; + + $query = prepare("SELECT `post`, `board`, `ip` FROM `reports` WHERE `id` = :id"); + $query->bindValue(':id', $id); + $query->execute() or error(db_error($query)); + if ($report = $query->fetch(PDO::FETCH_ASSOC)) { + $ip = $report['ip']; + $board = $report['board']; + $post = $report['post']; + } else + error($config['error']['404']); + + if (!$all && !hasPermission($config['mod']['report_dismiss'], $board)) + error($config['error']['noaccess']); + + if ($all && !hasPermission($config['mod']['report_dismiss_ip'], $board)) + error($config['error']['noaccess']); + + if ($all) { + $query = prepare("DELETE FROM `reports` WHERE `ip` = :ip"); + $query->bindValue(':ip', $ip); + } else { + $query = prepare("DELETE FROM `reports` WHERE `id` = :id"); + $query->bindValue(':id', $id); + } + $query->execute() or error(db_error($query)); + + + if ($all) + modLog("Dismissed all reports by $ip"); + else + modLog("Dismissed a report for post #{$id}", $board); + + header('Location: ?/reports', true, $config['redirect_http']); +} + + diff --git a/inc/template.php b/inc/template.php index 8d679d25..5355e18c 100644 --- a/inc/template.php +++ b/inc/template.php @@ -39,7 +39,7 @@ function Element($templateFile, array $options) { if (!$twig) load_twig(); - if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod']))) { + if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) { $options['pm'] = create_pm_header(); } diff --git a/mod.php b/mod.php index 6fc216f8..78205bd3 100644 --- a/mod.php +++ b/mod.php @@ -33,6 +33,8 @@ $pages = array( '!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm '!^/rebuild$!' => 'rebuild', // rebuild static files + '!^/reports$!' => 'reports', // report queue + '!^/reports/(\d+)/dismiss(all)?$!' => 'report_dismiss', // dismiss a report '!^/ban$!' => 'ban', // new ban '!^/IP/([\w.:]+)$!' => 'ip', // view ip address diff --git a/templates/mod/report.html b/templates/mod/report.html new file mode 100644 index 00000000..c84e3c89 --- /dev/null +++ b/templates/mod/report.html @@ -0,0 +1,26 @@ +
+
+ Board: {{ config.board_abbreviation|sprintf(report.board) }} +
+ Reason: {{ report.reason }} +
+ Report date: {{ report.time|date(config.post_date) }} +
+ {% if mod|hasPermission(config.mod.show_ip, report.board) %} + Reported by: {{ report.ip }} +
+ {% endif %} + {% if mod|hasPermission(config.mod.report_dismiss, report.board) or mod|hasPermission(config.mod.report_dismiss_ip, report.board) %} +
+ {% if mod|hasPermission(config.mod.report_dismiss, report.board) %} + Dismiss + {% endif %} + {% if mod|hasPermission(config.mod.report_dismiss_ip, report.board) %} + {% if mod|hasPermission(config.mod.report_dismiss, report.board) %} + | + {% endif %} + Dismiss+ + {% endif %} + {% endif %} +
+ diff --git a/templates/mod/reports.html b/templates/mod/reports.html new file mode 100644 index 00000000..37322e35 --- /dev/null +++ b/templates/mod/reports.html @@ -0,0 +1,5 @@ +{% if reports %} + {{ reports }} +{% else %} +

(There are no reports.)

+{% endif %} -- cgit v1.3 From d3739c48c2c2deec83e6abf74ed8e03470581750 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 20 May 2012 20:20:50 +1000 Subject: Config editort --- inc/mod/pages.php | 85 ++++++++++++++++++++++++++++++++++++++++ inc/template.php | 2 +- mod.php | 2 + stylesheets/style.css | 22 +++++------ templates/mod/config-editor.html | 56 ++++++++++++++++++++++++++ templates/mod/view_ip.html | 8 ++-- 6 files changed, 158 insertions(+), 17 deletions(-) create mode 100644 templates/mod/config-editor.html (limited to 'inc/template.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 6b644867..a4e2eae1 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1539,6 +1539,91 @@ function mod_report_dismiss($id, $all = false) { header('Location: ?/reports', true, $config['redirect_http']); } + +function mod_config() { + global $config, $mod; + + if (!hasPermission($config['mod']['edit_config'])) + error($config['error']['noaccess']); + + require_once 'inc/mod/config-editor.php'; + + $conf = config_vars(); + + foreach ($conf as &$var) { + if (is_array($var['name'])) { + $c = &$config; + foreach ($var['name'] as $n) + $c = &$c[$n]; + } else { + $c = $config[$var['name']]; + } + + $var['value'] = $c; + } + unset($var); + + if (isset($_POST['save'])) { + $config_append = ''; + + foreach ($conf as $var) { + $field_name = 'cf_' . (is_array($var['name']) ? implode('/', $var['name']) : $var['name']); + + if ($var['type'] == 'boolean') + $value = isset($_POST[$field_name]); + elseif (isset($_POST[$field_name])) + $value = $_POST[$field_name]; + else + continue; // ??? + + if (!settype($value, $var['type'])) + continue; // invalid + + if ($value != $var['value']) { + // This value has been changed. + + $config_append .= '$config'; + + if (is_array($var['name'])) { + foreach ($var['name'] as $name) + $config_append .= '[' . var_export($name, true) . ']'; + } else { + $config_append .= '[' . var_export($var['name'], true) . ']'; + } + + $config_append .= ' = ' . var_export($value, true) . ";\n"; + } + } + + if(!empty($config_append)) { + $config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n"; + + if(!@file_put_contents('inc/instance-config.php', $config_append, FILE_APPEND)) { + $config_append = htmlentities($config_append); + + if($config['minify_html']) + $config_append = str_replace("\n", ' ', $config_append); + $page = array(); + $page['title'] = 'Cannot write to file!'; + $page['config'] = $config; + $page['body'] = ' +

Tinyboard could not write to inc/instance-config.php with the ammended configuration, probably due to a permissions error.

+

You may proceed with these changes manually by copying and pasting the following code to the end of inc/instance-config.php:

+ + '; + echo Element('page.html', $page); + exit; + } + } + + header('Location: ?/', true, $config['redirect_http']); + + exit; + } + + mod_page('Config editor', 'mod/config-editor.html', array('conf' => $conf)); +} + function mod_debug_antispam() { global $pdo, $config; diff --git a/inc/template.php b/inc/template.php index 5355e18c..351bde62 100644 --- a/inc/template.php +++ b/inc/template.php @@ -27,7 +27,7 @@ function load_twig() { $twig = new Twig_Environment($loader, array( 'autoescape' => false, 'cache' => "{$config['dir']['template']}/cache", - 'debug' => ($config['debug'] ? true : false), + 'debug' => $config['debug'] )); $twig->addExtension(new Twig_Extensions_Extension_Tinyboard()); $twig->addExtension(new Twig_Extensions_Extension_I18n()); diff --git a/mod.php b/mod.php index 23cacc11..5fa040ee 100644 --- a/mod.php +++ b/mod.php @@ -65,6 +65,8 @@ $pages = array( '/(\w+)/bump(un)?lock/(\d+)' => 'bumplock', // "bumplock" thread '/(\w+)/move/(\d+)' => 'move', // move thread + '/config' => 'config', // config editor + // these pages aren't listed in the dashboard without $config['debug'] '/debug/antispam' => 'debug_antispam', diff --git a/stylesheets/style.css b/stylesheets/style.css index 16da419c..1913f60a 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -388,19 +388,15 @@ div.blotter { font-weight: bold; text-align: center; } - -/* Uboachan stuff */ -div.styles-sidebar { - text-align: center; - padding-bottom: 0px; -} -div.styles-sidebar a { - margin: 0 5px; +table.mod.config-editor { + font-size: 9pt; + width: 100%; } -div.styles-sidebar a.selected { - text-decoration: none; +table.mod.config-editor td { + text-align: left; + padding: 5px; + border-bottom: 1px solid #98e; } -.category { - background: #98E; - color: black; +table.mod.config-editor input[type="text"] { + width: 98%; } diff --git a/templates/mod/config-editor.html b/templates/mod/config-editor.html new file mode 100644 index 00000000..ec7213bb --- /dev/null +++ b/templates/mod/config-editor.html @@ -0,0 +1,56 @@ +
+ + + + + + + + {% for var in conf if var.type != 'array' %} + {% if var.name|count == 1 %} + {% set name = 'cf_' ~ var.name %} + {% else %} + {% set name = 'cf_' ~ var.name|join('/') %} + {% endif %} + + + + + + + + + + + {% endfor %} +
NameValueTypeDescription
+ {% if var.name|count == 1 %} + {{ var.name }} + {% else %} + {{ var.name|join(' → ') }} + {% endif %} + + {% if var.type == 'string' %} + + {% elseif var.type == 'integer' %} + + {% elseif var.type == 'boolean' %} + + {% else %} + ? + {% endif %} + + {% if var.type == 'integer' or var.type == 'boolean' %} + Default: {{ var.default }} + {% endif %} + + {{ var.type|e }} + + {{ var.comment|join('
') }} +
+ +
    +
  • +
+
+ diff --git a/templates/mod/view_ip.html b/templates/mod/view_ip.html index e69301fd..c49880ae 100644 --- a/templates/mod/view_ip.html +++ b/templates/mod/view_ip.html @@ -1,9 +1,11 @@ {% for board_posts in posts %}
- {{ config.board_abbreviation|sprintf(board_posts.board.uri) }} - - - {{ board_posts.board.title|e }} + + {{ config.board_abbreviation|sprintf(board_posts.board.uri) }} + - + {{ board_posts.board.title|e }} + {{ board_posts.posts|join('
') }}
-- cgit v1.3