Commit 4cfb9f45 authored by Vitaly Lipatov's avatar Vitaly Lipatov

web: report undelivered unban requests

parent a9efc009
//Где сменить IP-адреса серверов
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "You are banned!, Your IP: $ip <br>";
$settings = '/etc/eterban/settings.ini';
$ini_array = parse_ini_file ("$settings");
$host_redis = $ini_array['redis_server'];
$redis = new Redis;
$redis->pconnect ($host_redis,6379);
$key = $redis->get($ip);
?>
<button onclick="unban()">Unban</button> <button onclick="unban()">Unban</button>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
<script> <script>
function unban(){ function unban(){
/*$.get("unban.php?&key=<?php echo $key;?>", function(data, status){ window.location.href = "unban.php";
});*/
window.location.href = "unban.php?key=<?php echo $key; ?>";
} }
</script> </script>
<?php <?php
$ip = $_SERVER['REMOTE_ADDR']; header('Content-Type: text/html; charset=utf-8');
$old_addr = $_SERVER['HTTP_REFERER'];
$settings = '/etc/eterban/settings.ini'; $ip = $_SERVER['REMOTE_ADDR'] ?? '';
$ini_array = parse_ini_file ("$settings"); $settings = parse_ini_file('/etc/eterban/settings.ini');
//print_r($ini_array); $host_redis = is_array($settings) ? ($settings['redis_server'] ?? '') : '';
//print_r($ini_array['redis_server']); $hostname = is_array($settings) ? ($settings['hostname'] ?? '') : '';
$host_redis = $ini_array['redis_server'];
//print_r($host_redis); if (!filter_var($ip, FILTER_VALIDATE_IP) || empty($host_redis)) {
$hostname = $ini_array['hostname']; http_response_code(503);
if (empty($hostname)) { error_log('eterban: invalid client IP or Redis configuration for web unban');
$hostname=gethostname(); exit('Unban service is temporarily unavailable.');
//print_r ($hostname); }
}
if (empty($hostname)) {
$hostname = gethostname();
}
try {
$redis = new Redis(); $redis = new Redis();
$redis->pconnect($host_redis,6379); if (!$redis->connect($host_redis, 6379, 2.5)) {
$redis->publish('unban', $ip); throw new RedisException('connection failed');
$redis->publish('by', $ip . " was unblocked by $hostname"); }
$subscribers = $redis->publish('unban', $ip);
if ($subscribers < 1) {
throw new RedisException('no Redis subscribers');
}
$redis->publish('by', $ip . ' was unblocked by ' . $hostname);
$redis->close(); $redis->close();
echo "Wait 5 seconds, please" } catch (RedisException $error) {
http_response_code(503);
error_log('eterban: web unban request was not delivered: ' . $error->getMessage());
exit('Unban service is temporarily unavailable. Please contact an administrator.');
}
echo 'Unban request accepted. Wait 5 seconds, please.';
?> ?>
<script> <script>
function update() function update()
......
//Где сменить IP-адреса серверов
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "You are banned!, Your IP: $ip <br>";
$settings = '/etc/eterban/settings.ini';
$ini_array = parse_ini_file ("$settings");
$host_redis = $ini_array['redis_server'];
$redis = new Redis;
$redis->pconnect ($host_redis,6379);
$key = $redis->get($ip);
?>
<button onclick="unban()">Unban</button> <button onclick="unban()">Unban</button>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
<script> <script>
function unban(){ function unban(){
/*$.get("unban.php?&key=<?php echo $key;?>", function(data, status){ window.location.href = "unban.php";
});*/
window.location.href = "unban.php?key=<?php echo $key; ?>";
} }
</script> </script>
<?php <?php
$ip = $_SERVER['REMOTE_ADDR']; header('Content-Type: text/html; charset=utf-8');
$old_addr = $_SERVER['HTTP_REFERER'];
$settings = '/etc/eterban/settings.ini'; $ip = $_SERVER['REMOTE_ADDR'] ?? '';
$ini_array = parse_ini_file ("$settings"); $settings = parse_ini_file('/etc/eterban/settings.ini');
//print_r($ini_array); $host_redis = is_array($settings) ? ($settings['redis_server'] ?? '') : '';
//print_r($ini_array['redis_server']); $hostname = is_array($settings) ? ($settings['hostname'] ?? '') : '';
$host_redis = $ini_array['redis_server'];
//print_r($host_redis); if (!filter_var($ip, FILTER_VALIDATE_IP) || empty($host_redis)) {
$hostname = $ini_array['hostname']; http_response_code(503);
if (empty($hostname)) { error_log('eterban: invalid client IP or Redis configuration for web unban');
$hostname=gethostname(); exit('Unban service is temporarily unavailable.');
//print_r ($hostname); }
}
if (empty($hostname)) {
$hostname = gethostname();
}
try {
$redis = new Redis(); $redis = new Redis();
$redis->pconnect($host_redis,6379); if (!$redis->connect($host_redis, 6379, 2.5)) {
$redis->publish('unban', $ip); throw new RedisException('connection failed');
$redis->publish('by', $ip . " was unblocked by $hostname"); }
$subscribers = $redis->publish('unban', $ip);
if ($subscribers < 1) {
throw new RedisException('no Redis subscribers');
}
$redis->publish('by', $ip . ' was unblocked by ' . $hostname);
$redis->close(); $redis->close();
echo "Wait 5 seconds, please" } catch (RedisException $error) {
http_response_code(503);
error_log('eterban: web unban request was not delivered: ' . $error->getMessage());
exit('Unban service is temporarily unavailable. Please contact an administrator.');
}
echo 'Unban request accepted. Wait 5 seconds, please.';
?> ?>
<script> <script>
function update() function update()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment