init: workspace opencode sync

This commit is contained in:
2026-08-15 00:28:08 +07:00
commit 2451170708
122 changed files with 10549 additions and 0 deletions
+127
View File
@@ -0,0 +1,127 @@
<?php
error_reporting(0);
$secret = 'msr-2026-reset';
if (!isset($_GET['key']) || $_GET['key'] !== $secret) { http_response_code(403); die('auth failed'); }
$bot = '5115036608:AAGeyXVq5eNvdAkaCQHU9NfH16uAAiSKiuk';
function tg_api($method, $params = array()) {
global $bot;
$url = "https://api.telegram.org/bot{$bot}/{$method}";
if (!empty($params)) {
$data = http_build_query($params);
$ctx = stream_context_create(array('http' => 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}";