Upload files to "system"
Signed-off-by: nestict <icttechnest@gmail.com>
This commit is contained in:
parent
3d46b68bd6
commit
dbe54cb3d0
2773
system/orm.php
Normal file
2773
system/orm.php
Normal file
File diff suppressed because it is too large
Load Diff
163
system/router_status_check.php
Normal file
163
system/router_status_check.php
Normal file
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
// Include necessary files
|
||||
include "../init.php";
|
||||
|
||||
$isCli = php_sapi_name() === 'cli';
|
||||
if (!$isCli) {
|
||||
echo "<pre>";
|
||||
}
|
||||
|
||||
echo "PHP Time\t" . date('Y-m-d H:i:s') . "\n";
|
||||
$res = ORM::raw_execute('SELECT NOW() AS WAKTU;');
|
||||
$statement = ORM::get_last_statement();
|
||||
$rows = array();
|
||||
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
|
||||
echo "MYSQL Time\t" . $row['WAKTU'] . "\n";
|
||||
}
|
||||
$_c = $config;
|
||||
|
||||
function icmp_ping($ip_address, $timeout = 15, $count = 20) { // Updated timeout and count
|
||||
$ip_parts = explode(':', $ip_address);
|
||||
$ip = $ip_parts[0];
|
||||
|
||||
$escaped_ip = escapeshellarg($ip);
|
||||
|
||||
exec("ping -c $count -W $timeout $escaped_ip 2>&1", $output, $return_var);
|
||||
|
||||
// Log ping command output and return status for debugging
|
||||
error_log("Ping command output: " . implode("\n", $output));
|
||||
error_log("Ping command return status: $return_var");
|
||||
|
||||
if ($return_var === 0) {
|
||||
// Parse ping output to check for packet loss and average round-trip time
|
||||
$statistics = implode("\n", $output);
|
||||
if (preg_match('/(\d+)% packet loss/', $statistics, $matches)) {
|
||||
$packet_loss = intval($matches[1]);
|
||||
if ($packet_loss === 0) {
|
||||
return true; // Successful ping with no packet loss
|
||||
} elseif ($packet_loss < 100) {
|
||||
// Packet loss is detected but not 100%, consider as minor issue
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false; // Default to false if ping failed or packet loss detected
|
||||
}
|
||||
|
||||
function get_appconfig_value($setting) {
|
||||
// Retrieve configuration value from database table
|
||||
$config = ORM::for_table('tbl_appconfig')->where('setting', $setting)->find_one();
|
||||
return $config ? $config->value : null;
|
||||
}
|
||||
|
||||
function send_sms($phone_number, $message) {
|
||||
// Send SMS using configured URL template
|
||||
$sms_url_template = get_appconfig_value('sms_url');
|
||||
if (!$sms_url_template) {
|
||||
echo "SMS URL not configured\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$url = str_replace(['[text]', '[number]'], [urlencode($message), urlencode($phone_number)], $sms_url_template);
|
||||
|
||||
// Initiate CURL request to send SMS
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
echo 'Curl error: ' . curl_error($ch) . "\n";
|
||||
} else {
|
||||
echo "SMS sent to $phone_number with response: $response and HTTP code: $http_code\n";
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
function send_whatsapp($phone_number, $message) {
|
||||
// Send WhatsApp message using configured URL template
|
||||
$wa_url_template = get_appconfig_value('wa_url');
|
||||
if (!$wa_url_template) {
|
||||
echo "WhatsApp URL not configured\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$url = str_replace(['[text]', '[number]'], [urlencode($message), urlencode($phone_number)], $wa_url_template);
|
||||
|
||||
// Initiate CURL request to send WhatsApp message
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
echo 'Curl error: ' . curl_error($ch) . "\n";
|
||||
} else {
|
||||
echo "WhatsApp message sent to $phone_number with response: $response and HTTP code: $http_code\n";
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
function check_and_update_router_status($router) {
|
||||
// Check current router status via ICMP ping
|
||||
$current_status = $router->status;
|
||||
$new_status = icmp_ping($router['ip_address'], 15, 20) ? 'Online' : 'Offline'; // Adjusted timeout and count
|
||||
|
||||
$current_time = date('Y-m-d H:i:s');
|
||||
|
||||
if ($current_status !== $new_status) {
|
||||
// Status has changed, notify all users and update status
|
||||
$users = ORM::for_table('tbl_users')->find_many();
|
||||
|
||||
if ($new_status === 'Offline') {
|
||||
// Router is offline, send notifications
|
||||
foreach ($users as $user) {
|
||||
$message = "Router {$router['name']} is Offline at $current_time. Error.";
|
||||
send_sms($user['phone'], $message);
|
||||
send_whatsapp($user['phone'], $message);
|
||||
}
|
||||
$router->offline_since = $current_time; // Record offline time
|
||||
} else {
|
||||
// Router is back online, calculate downtime and notify users
|
||||
$offline_since = new DateTime($router->offline_since);
|
||||
$now = new DateTime($current_time);
|
||||
$interval = $offline_since->diff($now);
|
||||
$downtime = $interval->format('%h h, %i m, and %s s');
|
||||
|
||||
foreach ($users as $user) {
|
||||
$message = "Router {$router['name']} is now Online at $current_time. Fixed. Downtime: $downtime.";
|
||||
send_sms($user['phone'], $message);
|
||||
send_whatsapp($user['phone'], $message);
|
||||
}
|
||||
$router->offline_since = null; // Clear offline_since after coming online
|
||||
}
|
||||
}
|
||||
|
||||
// Update router status and last check time
|
||||
$router->status = $new_status;
|
||||
$router->last_check = $current_time;
|
||||
$router->save();
|
||||
}
|
||||
|
||||
// Get all active routers from database
|
||||
$routers = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
|
||||
|
||||
// Check status for each router
|
||||
foreach ($routers as $router) {
|
||||
check_and_update_router_status($router);
|
||||
}
|
||||
|
||||
echo "Router status check completed at " . date('Y-m-d H:i:s') . "\n";
|
||||
?>
|
106
system/updates.json
Normal file
106
system/updates.json
Normal file
@ -0,0 +1,106 @@
|
||||
{
|
||||
"2023.8.9": [
|
||||
"ALTER TABLE `tbl_customers` ADD `balance` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT 'For Money Deposit' AFTER `email`;",
|
||||
"CREATE TABLE `tbl_customers_meta` (`id` int(11) NOT NULL, `customer_id` int(11) NOT NULL,`meta_key` varchar(64) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '', `meta_value` longtext COLLATE utf8mb4_general_ci) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
||||
"ALTER TABLE `tbl_customers_meta` ADD PRIMARY KEY (`id`);",
|
||||
"ALTER TABLE `tbl_customers_meta` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;"
|
||||
],
|
||||
"2023.8.14": [
|
||||
"ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '' COMMENT 'For PPPOE Login' AFTER `password`;",
|
||||
"ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
|
||||
"ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
|
||||
"ALTER TABLE `tbl_customers` ADD `auto_renewal` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Auto renewall using balance' AFTER `balance`;"
|
||||
],
|
||||
"2023.8.23": [
|
||||
"ALTER TABLE `tbl_customers` CHANGE `pppoe_password` `pppoe_password` VARCHAR(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login';"
|
||||
],
|
||||
"2023.8.28": [
|
||||
"ALTER TABLE `tbl_user_recharges` ADD `recharged_time` time NOT NULL DEFAULT '00:00:00' AFTER `recharged_on`;",
|
||||
"ALTER TABLE `tbl_transactions` ADD `recharged_time` time NOT NULL DEFAULT '00:00:00' AFTER `recharged_on`;"
|
||||
],
|
||||
"2023.9.5": [
|
||||
"DROP TABLE `tbl_language`;",
|
||||
"ALTER TABLE `tbl_plans` ADD `pool_expired` varchar(40) NOT NULL DEFAULT '' AFTER `pool`;"
|
||||
],
|
||||
"2023.9.27": [
|
||||
"ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance','Radius') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
|
||||
"ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance','Radius') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;"
|
||||
],
|
||||
"2023.9.28": [
|
||||
"ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
|
||||
"ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;"
|
||||
],
|
||||
"2023.10.1": [
|
||||
"ALTER TABLE `tbl_plans` ADD `is_radius` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '1 is radius' AFTER `routers`; "
|
||||
],
|
||||
"2023.10.24": [
|
||||
"ALTER TABLE `nas` ADD `routers` VARCHAR(32) NOT NULL DEFAULT '' AFTER `description`;"
|
||||
],
|
||||
"2023.12.15": [
|
||||
"ALTER TABLE `tbl_customers` ADD `service_type` ENUM('Hotspot','PPPoE','Others') DEFAULT 'Others' COMMENT 'For selecting user type' AFTER `balance`;"
|
||||
],
|
||||
"2024.1.11": [
|
||||
"ALTER TABLE `tbl_plans` ADD `allow_purchase` ENUM('yes','no') DEFAULT 'yes' COMMENT 'allow to show package in buy package page' AFTER `enabled`;"
|
||||
],
|
||||
"2024.2.7": [
|
||||
"ALTER TABLE `tbl_voucher` ADD `generated_by` INT NOT NULL DEFAULT '0' COMMENT 'id admin' AFTER `status`;",
|
||||
"ALTER TABLE `tbl_users` ADD `root` INT NOT NULL DEFAULT '0' COMMENT 'for sub account' AFTER `id`;"
|
||||
],
|
||||
"2024.2.12": [
|
||||
"ALTER TABLE `tbl_users` CHANGE `user_type` `user_type` ENUM('SuperAdmin','Admin','Report','Agent','Sales') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;"
|
||||
],
|
||||
"2024.2.15": [
|
||||
"ALTER TABLE `tbl_users` CHANGE `password` `password` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
|
||||
"ALTER TABLE `tbl_users` ADD `phone` VARCHAR(32) NOT NULL DEFAULT '' AFTER `password`, ADD `email` VARCHAR(128) NOT NULL DEFAULT '' AFTER `phone`, ADD `city` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kota' AFTER `email`, ADD `subdistrict` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kecamatan' AFTER `city`, ADD `ward` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kelurahan' AFTER `subdistrict`;"
|
||||
],
|
||||
"2024.2.16": [
|
||||
"ALTER TABLE `tbl_customers` ADD `created_by` INT NOT NULL DEFAULT '0' AFTER `auto_renewal`;"
|
||||
],
|
||||
"2024.2.19": [
|
||||
"CREATE TABLE `tbl_customers_fields` (`id` INT PRIMARY KEY AUTO_INCREMENT, `customer_id` INT NOT NULL, `field_name` VARCHAR(255) NOT NULL, `field_value` VARCHAR(255) NOT NULL, FOREIGN KEY (customer_id) REFERENCES tbl_customers(id));"
|
||||
],
|
||||
"2024.2.20" : [
|
||||
"ALTER TABLE `tbl_plans` ADD `list_expired` VARCHAR(32) NOT NULL DEFAULT '' COMMENT 'address list' AFTER `pool_expired`;",
|
||||
"ALTER TABLE `tbl_bandwidth` ADD `burst` VARCHAR(128) NOT NULL DEFAULT '' AFTER `rate_up_unit`;"
|
||||
],
|
||||
"2024.2.20.1" : [
|
||||
"DROP TABLE IF EXISTS `tbl_customers_meta`;"
|
||||
],
|
||||
"2024.2.23" : [
|
||||
"ALTER TABLE `tbl_transactions` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `type`;",
|
||||
"ALTER TABLE `tbl_user_recharges` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `type`;"
|
||||
],
|
||||
"2024.3.3" : [
|
||||
"ALTER TABLE `tbl_plans` CHANGE `validity_unit` `validity_unit` ENUM('Mins','Hrs','Days','Months','Period') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;"
|
||||
],
|
||||
"2024.3.12" : [
|
||||
"ALTER TABLE `tbl_plans` CHANGE `allow_purchase` `prepaid` ENUM('yes','no') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'yes' COMMENT 'is prepaid';"
|
||||
],
|
||||
"2024.3.14" : [
|
||||
"ALTER TABLE `tbl_transactions` ADD `note` VARCHAR(256) NOT NULL DEFAULT '' COMMENT 'for note' AFTER `type`;"
|
||||
],
|
||||
"2024.3.19" : [
|
||||
"ALTER TABLE `tbl_customers` ADD `coordinates` VARCHAR(50) NOT NULL DEFAULT '' COMMENT 'Latitude and Longitude coordinates' AFTER `email`;"
|
||||
],
|
||||
"2024.3.19.1" : [
|
||||
"ALTER TABLE `tbl_customers` ADD `account_type` ENUM('Business', 'Personal') DEFAULT 'Personal' COMMENT 'For selecting account type' AFTER `coordinates`;"
|
||||
],
|
||||
"2024.3.19.2" : [
|
||||
"ALTER TABLE `tbl_plans` ADD `plan_type` ENUM('Business', 'Personal') DEFAULT 'Personal' COMMENT 'For selecting account type' ;"
|
||||
],
|
||||
"2023.3.20": [
|
||||
"ALTER TABLE `tbl_customers` CHANGE `pppoe_password` `pppoe_password` VARCHAR(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login';"
|
||||
],
|
||||
"2024.4.5" : [
|
||||
"ALTER TABLE `tbl_payment_gateway` ADD `trx_invoice` VARCHAR(25) NOT NULL DEFAULT '' COMMENT 'from tbl_transactions' AFTER `paid_date`;"
|
||||
],
|
||||
"2024.5.17" : [
|
||||
"ALTER TABLE `tbl_customers` ADD `status` ENUM('Active','Banned','Disabled') NOT NULL DEFAULT 'Active' AFTER `auto_renewal`;"
|
||||
],
|
||||
"2024.5.18" : [
|
||||
"ALTER TABLE `tbl_customers` CHANGE `status` `status` ENUM('Active','Banned','Disabled','Inactive','Limited','Suspended') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'Active';"
|
||||
],
|
||||
"2024.5.20" : [
|
||||
"ALTER TABLE `tbl_customers` ADD `city` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `address`, ADD `district` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `city`, ADD `state` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `district`, ADD `zip` VARCHAR(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `state`;"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user