1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-12 01:50:48 +01:00

add telegrams

This commit is contained in:
h00j 2021-03-12 21:51:42 +01:00
parent 8decd4f73f
commit 4ef7feabf2
9 changed files with 210 additions and 18 deletions

View File

@ -1554,6 +1554,12 @@
$config['mod']['create_notes'] = $config['mod']['view_notes'];
// Remote notes
$config['mod']['remove_notes'] = ADMIN;
// View telegrams
$config['mod']['view_telegrams'] = JANITOR;
// Create telegrams
$config['mod']['create_telegrams'] = $config['mod']['view_telegrams'];
// Remote telegrams
$config['mod']['remove_telegrams'] = ADMIN;
// Create a new board
$config['mod']['newboard'] = ADMIN;
// Manage existing boards (change title, etc)

View File

@ -2286,6 +2286,9 @@ msgstr "usuń"
#: ../../../../templates/cache/b1/4c/16a427b0d49ecf353c259d9fb606841783484eca9d790e766fdf0e3e9754.php:208
msgid "New note"
msgstr "Nowa notka"
msgid "New telegram"
msgstr "Nowa depesza"
#. line 94
#. line 7
@ -3510,3 +3513,6 @@ msgstr "Pokazuj bany tylko z boardów, które moderuję"
#: ../../../../templates/cache/ba/55/2553cc018aecf7d29a62331aec4bedc71b646817c7e4c4e7d1a885263676.php:55
msgid "Show only active bans"
msgstr "Pokazuj tylko aktywne bany"
msgid "Important message from Moderation"
msgstr "Ważna wiadomość od Moderacji"

View File

@ -793,6 +793,27 @@ function mod_ip_remove_note($cloaked_ip, $id) {
header('Location: ?/IP/' . $cloaked_ip . '#notes', true, $config['redirect_http']);
}
function mod_ip_remove_telegram($cloaked_ip, $id) {
$ip = uncloak_ip($cloaked_ip);
global $config, $mod;
if (!hasPermission($config['mod']['remove_telegrams']))
error($config['error']['noaccess']);
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
error("Invalid IP address.");
$query = prepare('DELETE FROM ``telegrams`` WHERE `ip` = :ip AND `id` = :id');
$query->bindValue(':ip', $ip);
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
modLog("Removed a telegram for <a href=\"?/IP/{$cloaked_ip}\">{$cloaked_ip}</a>");
header('Location: ?/IP/' . $cloaked_ip . '#telegrams', true, $config['redirect_http']);
}
function mod_page_ip($cip) {
$ip = uncloak_ip($cip);
global $config, $mod;
@ -828,7 +849,26 @@ function mod_page_ip($cip) {
header('Location: ?/IP/' . $cip . '#notes', true, $config['redirect_http']);
return;
}
if (isset($_POST['telegram'])) {
if (!hasPermission($config['mod']['create_telegrams']))
error($config['error']['noaccess']);
$_POST['telegram'] = escape_markup_modifiers($_POST['telegram']);
markup($_POST['telegram']);
$query = prepare('INSERT INTO ``telegrams`` VALUES (NULL, :mod_id, :ip, :message, 0, :created_at)');
$query->bindValue(':ip', $ip);
$query->bindValue(':mod_id', $mod['id']);
$query->bindValue(':created_at', time());
$query->bindValue(':message', $_POST['telegram']);
$query->execute() or error(db_error($query));
modLog("Added a telegram for <a href=\"?/IP/{$cip}\">{$cip}</a>");
header('Location: ?/IP/' . $cip . '#telegrams', true, $config['redirect_http']);
return;
}
$args = array();
$args['ip'] = $ip;
$args['posts'] = array();
@ -872,7 +912,14 @@ function mod_page_ip($cip) {
$query->execute() or error(db_error($query));
$args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
}
if (hasPermission($config['mod']['view_telegrams'])) {
$query = prepare("SELECT ``telegrams``.*, `username` FROM ``telegrams`` LEFT JOIN ``mods`` ON `mod_id` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `created_at` DESC");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
$args['telegrams'] = $query->fetchAll(PDO::FETCH_ASSOC);
}
if (hasPermission($config['mod']['modlog_ip'])) {
$query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 50");
$query->bindValue(':search', '%' . $cip . '%');

View File

@ -346,6 +346,21 @@ CREATE TABLE IF NOT EXISTS `captchas` (
PRIMARY KEY (`cookie`,`extra`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `telegrams`
--
CREATE TABLE IF NOT EXISTS `telegrams` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`mod_id` int(11) unsigned NOT NULL,
`ip` varchar(39) CHARACTER SET ascii NOT NULL,
`message` text NOT NULL,
`seen` tinyint(1) NOT NULL DEFAULT FALSE,
`created_at` INT(11),
PRIMARY KEY(`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

View File

@ -1,4 +1,4 @@
<?php
6<?php
/*
* Copyright (c) 2010-2014 Tinyboard Development Group
@ -59,7 +59,8 @@ $pages = array(
'/IP/([\w.:]+)' => 'secure_POST ip', // view ip address
'/IP/([\w.:]+)/remove_note/(\d+)' => 'secure ip_remove_note', // remove note from ip address
'/IP/([\w.:-]+)/remove_telegram/(\d+)' => 'secure ip_remove_telegram', // remove telegram from ip address
'/ban' => 'secure_POST ban', // new ban
'/bans' => 'secure_POST bans', // ban list
'/bans.json' => 'secure bans_json', // ban list JSON

View File

@ -402,17 +402,19 @@ if (isset($_POST['delete'])) {
if (!$resp['success']) {
error($config['error']['captcha']);
}
// Same, but now with our custom captcha provider
if (($config['captcha']['enabled']) || (($post['op']) && ($config['new_thread_capt'])) ) {
$resp = file_get_contents($config['captcha']['provider_check'] . "?" . http_build_query([
'mode' => 'check',
'text' => $_POST['captcha_text'],
'extra' => $config['captcha']['extra'],
'cookie' => $_POST['captcha_cookie']
]));
if ($resp !== '1') {
error($config['error']['captcha'] .
'<script>if (actually_load_captcha !== undefined) actually_load_captcha("'.$config['captcha']['provider_get'].'", "'.$config['captcha']['extra'].'");</script>');
// Same, but now with our custom captcha provider
if (($config['captcha']['enabled']) || (($post['op']) && ($config['new_thread_capt'])) ) {
$resp = file_get_contents($config['captcha']['provider_check'] . "?" . http_build_query([
'mode' => 'check',
'text' => $_POST['captcha_text'],
'extra' => $config['captcha']['extra'],
'cookie' => $_POST['captcha_cookie']
]));
if ($resp !== '1') {
error($config['error']['captcha'] .
'<script>if (actually_load_captcha !== undefined) actually_load_captcha("'.$config['captcha']['provider_get'].'", "'.$config['captcha']['extra'].'");</script>');
}
}
}
}
}
@ -1201,6 +1203,15 @@ if (isset($_POST['delete'])) {
if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"');
// Any telegrams to show?
$query = prepare('SELECT * FROM ``telegrams`` WHERE ``ip`` = :ip AND ``seen`` = 0');
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->execute() or error(db_error($query));
$telegrams = $query->fetchAll(PDO::FETCH_ASSOC);
if (count($telegrams) > 0)
goto skip_redirect;
if (!isset($_POST['json_response'])) {
header('Location: ' . $redirect, true, $config['redirect_http']);
} else {
@ -1211,7 +1222,9 @@ if (isset($_POST['delete'])) {
'id' => $id
));
}
skip_redirect:
if ($config['try_smarter'] && $post['op'])
$build_pages = range(1, $config['max_pages']);
@ -1222,6 +1235,20 @@ if (isset($_POST['delete'])) {
buildIndex();
if (count($telegrams) > 0) {
$ids = implode(', ', array_map(function($x) { return (int)$x['id']; }, $telegrams));
query("UPDATE ``telegrams`` SET ``seen`` = 1 WHERE ``id`` IN({$ids})") or error(db_error());
die(Element('page.html', array(
'title' => _('Important message from Moderation'),
'config' => $config,
'body' => Element('important.html', array(
'config' => $config,
'redirect' => $redirect,
'telegrams' => $telegrams,
))
)));
}
// We are already done, let's continue our heavy-lifting work in the background (if we run off FastCGI)
if (function_exists('fastcgi_finish_request'))
@fastcgi_finish_request();
@ -1230,7 +1257,7 @@ if (isset($_POST['delete'])) {
rebuildThemes('post-thread', $board['uri']);
else
rebuildThemes('post', $board['uri']);
} elseif (isset($_POST['appeal'])) {
if (!isset($_POST['ban_id']))
error($config['error']['bot']);
@ -1279,4 +1306,4 @@ if (isset($_POST['delete'])) {
// They opened post.php in their browser manually.
error($config['error']['nopost']);
}
}
}

12
templates/important.html Normal file
View File

@ -0,0 +1,12 @@
<div class="ban">
{% for telegram in telegrams %}
<div style="padding: 10px;">
<cite>{{ telegram.created_at|date(config.post_date) }}</cite>
<p>{{ telegram.message }}</p>
</div>
<hr>
{% endfor %}
<div style="padding:20px;text-align:center;">
<a href="{{ redirect }}">{%trans 'Return' %}</a>
</div>
</div>

View File

@ -81,6 +81,84 @@
</fieldset>
{% endif %}
{% if mod|hasPermission(config.mod.view_telegrams) %}
<fieldset id="telegrams">
<legend>
{% set telegrams_on_record = 'telegram' ~ (telegrams|count != 1 ? 's' : '') ~ ' on record' %}
<legend>{{ telegrams|count }} {% trans telegrams_on_record %}</legend>
</legend>
{% if telegrams|count > 0 %}
<table class="modlog">
<tr>
<th>{% trans 'Staff' %}</th>
<th>{% trans 'Message' %}</th>
<th>{% trans 'Date' %}</th>
<th class="minimal">{% trans 'Seen' %}</th>
{% if mod|hasPermission(config.mod.remove_telegrams) %}
<th>{% trans 'Actions' %}</th>
{% endif %}
</tr>
{% for telegram in telegrams %}
<tr>
<td class="minimal">
{% if telegram.username %}
<a href="?/new_PM/{{ telegram.username|e }}">{{ telegram.username|e }}</a>
{% else %}
<em>{% trans 'deleted?' %}</em>
{% endif %}
</td>
<td>
{{ telegram.message }}
</td>
<td class="minimal">
{{ telegram.time|date(config.post_date) }}
</td>
<td>
{% if telegram.seen %}
{% trans 'Yes' %}
{% else %}
{% trans 'No' %}
{% endif %}
</td>
{% if mod|hasPermission(config.mod.remove_telegrams) %}
<td class="minimal">
<a href="?/IP/{{ ip|cloak_ip|url_encode(true) }}/remove_telegram/{{ telegram.id }}">
<small>[{% trans 'remove' %}]</small>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</table>
{% endif %}
{% if mod|hasPermission(config.mod.create_telegrams) %}
<form action="" method="post" style="margin:0">
<input type="hidden" name="token" value="{{ security_token }}">
<table>
<tr>
<th>{% trans 'Staff' %}</th>
<td>{{ mod.username|e }}</td>
</tr>
<tr>
<th>
<label for="telegram">{% trans 'Message' %}</label>
</th>
<td>
<textarea id="telegram" name="telegram" rows="5" cols="30"></textarea>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="{% trans 'New telegram' %}"></td>
</tr>
</table>
</form>
{% endif %}
</fieldset>
{% endif %}
{% if bans|count > 0 and mod|hasPermission(config.mod.view_ban) %}
<fieldset id="bans">
{% set bans_on_record = 'ban' ~ (bans|count != 1 ? 's' : '') ~ ' on record' %}