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>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
<script>
function unban(){
/*$.get("unban.php?&key=<?php echo $key;?>", function(data, status){
});*/
window.location.href = "unban.php?key=<?php echo $key; ?>";
window.location.href = "unban.php";
}
</script>
\ No newline at end of file
</script>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$old_addr = $_SERVER['HTTP_REFERER'];
$settings = '/etc/eterban/settings.ini';
$ini_array = parse_ini_file ("$settings");
//print_r($ini_array);
//print_r($ini_array['redis_server']);
$host_redis = $ini_array['redis_server'];
//print_r($host_redis);
$hostname = $ini_array['hostname'];
if (empty($hostname)) {
$hostname=gethostname();
//print_r ($hostname);
}
$redis = new Redis();
$redis->pconnect($host_redis,6379);
$redis->publish('unban', $ip);
$redis->publish('by', $ip . " was unblocked by $hostname");
$redis->close();
echo "Wait 5 seconds, please"
header('Content-Type: text/html; charset=utf-8');
$ip = $_SERVER['REMOTE_ADDR'] ?? '';
$settings = parse_ini_file('/etc/eterban/settings.ini');
$host_redis = is_array($settings) ? ($settings['redis_server'] ?? '') : '';
$hostname = is_array($settings) ? ($settings['hostname'] ?? '') : '';
if (!filter_var($ip, FILTER_VALIDATE_IP) || empty($host_redis)) {
http_response_code(503);
error_log('eterban: invalid client IP or Redis configuration for web unban');
exit('Unban service is temporarily unavailable.');
}
if (empty($hostname)) {
$hostname = gethostname();
}
try {
$redis = new Redis();
if (!$redis->connect($host_redis, 6379, 2.5)) {
throw new RedisException('connection failed');
}
$subscribers = $redis->publish('unban', $ip);
if ($subscribers < 1) {
throw new RedisException('no Redis subscribers');
}
$redis->publish('by', $ip . ' was unblocked by ' . $hostname);
$redis->close();
} 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>
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>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
<script>
function unban(){
/*$.get("unban.php?&key=<?php echo $key;?>", function(data, status){
});*/
window.location.href = "unban.php?key=<?php echo $key; ?>";
window.location.href = "unban.php";
}
</script>
\ No newline at end of file
</script>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$old_addr = $_SERVER['HTTP_REFERER'];
$settings = '/etc/eterban/settings.ini';
$ini_array = parse_ini_file ("$settings");
//print_r($ini_array);
//print_r($ini_array['redis_server']);
$host_redis = $ini_array['redis_server'];
//print_r($host_redis);
$hostname = $ini_array['hostname'];
if (empty($hostname)) {
$hostname=gethostname();
//print_r ($hostname);
}
$redis = new Redis();
$redis->pconnect($host_redis,6379);
$redis->publish('unban', $ip);
$redis->publish('by', $ip . " was unblocked by $hostname");
$redis->close();
echo "Wait 5 seconds, please"
header('Content-Type: text/html; charset=utf-8');
$ip = $_SERVER['REMOTE_ADDR'] ?? '';
$settings = parse_ini_file('/etc/eterban/settings.ini');
$host_redis = is_array($settings) ? ($settings['redis_server'] ?? '') : '';
$hostname = is_array($settings) ? ($settings['hostname'] ?? '') : '';
if (!filter_var($ip, FILTER_VALIDATE_IP) || empty($host_redis)) {
http_response_code(503);
error_log('eterban: invalid client IP or Redis configuration for web unban');
exit('Unban service is temporarily unavailable.');
}
if (empty($hostname)) {
$hostname = gethostname();
}
try {
$redis = new Redis();
if (!$redis->connect($host_redis, 6379, 2.5)) {
throw new RedisException('connection failed');
}
$subscribers = $redis->publish('unban', $ip);
if ($subscribers < 1) {
throw new RedisException('no Redis subscribers');
}
$redis->publish('by', $ip . ' was unblocked by ' . $hostname);
$redis->close();
} 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>
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