Merge pull request #278 from Focuslinkstech/Development

Development
This commit is contained in:
iBNu Maksum 2024-08-27 15:01:46 +07:00 committed by GitHub
commit 554479b79b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 116 additions and 20 deletions

View file

@ -138,6 +138,8 @@ CREATE TABLE `tbl_routers` (
`password` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`description` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
`coordinates` VARCHAR(50) NOT NULL DEFAULT '',
`status` ENUM('Online', 'Offline') DEFAULT 'Online',
`last_seen` DATETIME,
`coverage` VARCHAR(8) NOT NULL DEFAULT '0',
`enabled` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0 disabled'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

View file

@ -33,7 +33,7 @@ foreach ($d as $ds) {
$c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one();
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
$dvc = Package::getDevice($p);
if($_app_stage != 'demo'){
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_customer($c, $p);
@ -78,3 +78,66 @@ foreach ($d as $ds) {
echo " : ACTIVE \r\n";
}
}
if ($config['router_check']) {
$routers = ORM::for_table('tbl_routers')->find_many();
if (!$routers) {
echo "No routers found in the database.\n";
exit;
}
foreach ($routers as $router) {
[$ip, $port] = explode(':', $router->ip_address);
$isOnline = false;
try {
$timeout = 5;
if (is_callable('fsockopen') && false === stripos(ini_get('disable_functions'), 'fsockopen')) {
$fsock = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if ($fsock) {
fclose($fsock);
$isOnline = true;
} else {
throw new Exception("Unable to connect to $ip on port $port using fsockopen: $errstr ($errno)");
}
} elseif (is_callable('stream_socket_client') && false === stripos(ini_get('disable_functions'), 'stream_socket_client')) {
$connection = @stream_socket_client("$ip:$port", $errno, $errstr, $timeout);
if ($connection) {
fclose($connection);
$isOnline = true;
} else {
throw new Exception("Unable to connect to $ip on port $port using stream_socket_client: $errstr ($errno)");
}
} else {
throw new Exception("Neither fsockopen nor stream_socket_client are enabled on the server.");
}
} catch (Exception $e) {
_log($e->getMessage());
$adminEmail = $config['mail_from'];
$subject = "Router Monitoring Error Alert";
$message = "An error occurred during the monitoring of router $ip: " . (string) $e->getMessage();
Message::SendEmail($adminEmail, $subject, $message);
sendTelegram($message);
}
if ($isOnline) {
$router->last_seen = date('Y-m-d H:i:s');
$router->status = 'Online';
} else {
$router->status = 'Offline';
$adminEmail = $config['mail_from'];
$subject = "Router Offline Alert";
$message = "Dear Administrator,\nThe router with Name: {$router->name} and IP: {$router->ip_address} appears to be offline.\nThe Router was last seen online on: {$router->last_seen}\nPlease check the router's status and take appropriate action.\n\nBest regards,\nRouter Monitoring System";
Message::SendEmail($adminEmail, $subject, $message);
sendTelegram($message);
}
$router->save();
}
if ($isCli) {
echo "Cronjob finished\n";
} else {
echo "</pre>";
}
}

View file

@ -151,5 +151,9 @@
],
"2024.8.7" : [
"ALTER TABLE `tbl_customers` CHANGE `coordinates` `coordinates` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Latitude and Longitude coordinates';"
],
"2024.8.27" : [
"ALTER TABLE `tbl_routers` ADD `status` ENUM('Online', 'Offline') DEFAULT 'Online', AFTER `coordinates`;",
"ALTER TABLE `tbl_routers` ADD `last_seen` DATETIME AFTER `status`;"
]
}

View file

@ -621,6 +621,21 @@
<p class="help-block col-md-4">{Lang::T('This is to notify you when new updates is available')}
</p>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Router Check')}</label>
<div class="col-md-6">
<select name="router_check" id="router_check" class="form-control">
<option value="0" {if $_c['router_check']=='0' }selected="selected"
{/if}>{Lang::T('Disabled')}
</option>
<option value="1" {if $_c['router_check']=='1' }selected="selected"
{/if}>{Lang::T('Enabled')}
</option>
</select>
</div>
<p class="help-block col-md-4">{Lang::T('If enabled, the system will notify Admin when router goes Offline, If admin have 10 or more router and many customers, it will get overlapping, you can disabled')}
</p>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Phone OTP Required')}</label>
<div class="col-md-6">

View file

@ -40,6 +40,8 @@
<th>{Lang::T('IP Address')}</th>
<th>{Lang::T('Username')}</th>
<th>{Lang::T('Description')}</th>
<th>{Lang::T('Online Status')}</th>
<th>{Lang::T('Last Seen')}</th>
<th>{Lang::T('Status')}</th>
<th>{Lang::T('Manage')}</th>
<th>ID</th>
@ -47,27 +49,37 @@
</thead>
<tbody>
{foreach $d as $ds}
<tr {if $ds['enabled'] != 1}class="danger" title="disabled" {/if}>
<td>
<tr {if $ds['enabled'] !=1}class="danger" title="disabled" {/if}>
<td>
{if $ds['coordinates']}
<a href="https://www.google.com/maps/dir//{$ds['coordinates']}/" target="_blank"
class="btn btn-default btn-xs" title="{$ds['coordinates']}"><i
class="glyphicon glyphicon-map-marker"></i></a>
<a href="https://www.google.com/maps/dir//{$ds['coordinates']}/" target="_blank"
class="btn btn-default btn-xs" title="{$ds['coordinates']}"><i
class="glyphicon glyphicon-map-marker"></i></a>
{/if}
{$ds['name']}</td>
<td>{$ds['ip_address']}</td>
<td>{$ds['username']}</td>
<td>{$ds['description']}</td>
<td>{if $ds['enabled'] == 1}{Lang::T('Enabled')}{else}{Lang::T('Disabled')}{/if}</td>
<td>
<a href="{$_url}routers/edit/{$ds['id']}"
class="btn btn-info btn-xs">{Lang::T('Edit')}</a>
<a href="{$_url}routers/delete/{$ds['id']}" id="{$ds['id']}"
onclick="return confirm('{Lang::T('Delete')}?')"
class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-trash"></i></a>
</td>
<td>{$ds['id']}</td>
</tr>
{$ds['name']}
</td>
<td style="background-color: black; color: black;"
onmouseleave="this.style.backgroundColor = 'black';"
onmouseenter="this.style.backgroundColor = 'white';">{$ds['ip_address']}</td>
<td style="background-color: black; color: black;"
onmouseleave="this.style.backgroundColor = 'black';"
onmouseenter="this.style.backgroundColor = 'white';">{$ds['username']}</td>
<td>{$ds['description']}</td>
<td><span
class="label {if $ds['status'] == 'Online'}label-success {else}label-danger {/if}">{if
$ds['status'] == 'Online'}{Lang::T('Online')}{else}{Lang::T('Offline')}{/if}</span>
</td>
<td>{$ds['last_seen']}</td>
<td>{if $ds['enabled'] == 1}{Lang::T('Enabled')}{else}{Lang::T('Disabled')}{/if}</td>
<td>
<a href="{$_url}routers/edit/{$ds['id']}"
class="btn btn-info btn-xs">{Lang::T('Edit')}</a>
<a href="{$_url}routers/delete/{$ds['id']}" id="{$ds['id']}"
onclick="return confirm('{Lang::T('Delete')}?')"
class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-trash"></i></a>
</td>
<td>{$ds['id']}</td>
</tr>
{/foreach}
</tbody>
</table>