array( 'method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => $data, 'timeout' => 15, ))); $r = @file_get_contents($url, false, $ctx); } else { $r = @file_get_contents($url, false, stream_context_create(array('http' => array('timeout' => 5)))); } return $r ? json_decode($r, true) : null; } if (isset($_GET['test'])) { $username = preg_replace('/[^a-zA-Z0-9_.@-]/', '', $_GET['test']); if (!$username) { die('invalid username'); } include_once(dirname(__DIR__) . '/lib/routeros_api.class.php'); $api = new RouterosAPI(); $api->debug = false; $api->port = 33206; if (!$api->connect('remote.vpnmurahjogja.my.id', 'mi4', 'm14')) { die('conn fail'); } $found = $api->comm('/ip/hotspot/user/print', array('?name' => $username)); if (empty($found)) { $api->disconnect(); die('user not found'); } $uid = $found[0]['.id']; $api->comm('/ip/hotspot/user/set', array('.id' => $uid, 'limit-uptime' => '0', 'comment' => '')); $api->comm('/ip/hotspot/user/reset-counters', array('.id' => $uid)); $sch = $api->comm('/system/scheduler/print', array('?name' => $username)); if (!empty($sch) && isset($sch[0]['.id'])) { $api->comm('/system/scheduler/remove', array('.id' => $sch[0]['.id'])); } $api->disconnect(); tg_api('sendMessage', array( 'chat_id' => '-1002554941429', 'message_thread_id' => 42, 'text' => "✅ *{$username}* has been reset\nReady to use again", 'parse_mode' => 'Markdown', )); echo "reset ok: {$username}"; exit; } $updates = tg_api('getUpdates', array('timeout' => 5, 'allowed_updates' => '["callback_query"]')); if (!$updates || !isset($updates['ok']) || !$updates['ok']) { echo "no updates"; exit; } $processed = 0; $last_id = 0; include_once(dirname(__DIR__) . '/lib/routeros_api.class.php'); foreach ($updates['result'] as $u) { $cb = isset($u['callback_query']) ? $u['callback_query'] : null; if (!$cb) continue; $data = isset($cb['data']) ? $cb['data'] : ''; $cb_id = isset($cb['id']) ? $cb['id'] : ''; $last_id = max($last_id, $u['update_id']); if (substr($data, 0, 6) !== 'reset_') continue; $username = substr($data, 6); $username = preg_replace('/[^a-zA-Z0-9_.@-]/', '', $username); if (!$username) continue; $api = new RouterosAPI(); $api->debug = false; $api->port = 33206; if (!$api->connect('remote.vpnmurahjogja.my.id', 'mi4', 'm14')) { echo "conn fail for {$username} "; continue; } $found = $api->comm('/ip/hotspot/user/print', array('?name' => $username)); if (empty($found)) { $api->disconnect(); tg_api('answerCallbackQuery', array( 'callback_query_id' => $cb_id, 'text' => "User {$username} not found", 'show_alert' => true, )); continue; } $uid = $found[0]['.id']; $api->comm('/ip/hotspot/user/set', array('.id' => $uid, 'limit-uptime' => '0', 'comment' => '')); $api->comm('/ip/hotspot/user/reset-counters', array('.id' => $uid)); $sch = $api->comm('/system/scheduler/print', array('?name' => $username)); if (!empty($sch) && isset($sch[0]['.id'])) { $api->comm('/system/scheduler/remove', array('.id' => $sch[0]['.id'])); } $api->disconnect(); tg_api('answerCallbackQuery', array( 'callback_query_id' => $cb_id, 'text' => "✅ {$username} reset!", 'show_alert' => false, )); tg_api('sendMessage', array( 'chat_id' => '-1002554941429', 'message_thread_id' => 42, 'text' => "✅ *{$username}* has been reset\nReady to use again", 'parse_mode' => 'Markdown', )); $processed++; } if ($last_id > 0) { tg_api('getUpdates', array('offset' => $last_id + 1, 'timeout' => 1)); } echo "processed: {$processed}";