radius_client

This commit is contained in:
Ibnu Maksum 2023-10-12 14:33:37 +07:00
parent e19423471f
commit 48583c869b
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
3 changed files with 68 additions and 8 deletions

View File

@ -1,5 +1,8 @@
<?php <?php
/**
* Radius Class
* based https://gist.github.com/nasirhafeez/6669b24aab0bda545f60f9da5ed14f25
*/
class Radius class Radius
{ {
@ -132,26 +135,57 @@ class Radius
/** /**
* When add a plan to Customer, use this * When add a plan to Customer, use this
*/ */
public static function customerAddPlan($customer, $plan, $expired = null, $quota = null) public static function customerAddPlan($customer, $plan, $expired = null)
{ {
if (Radius::customerUpsert($customer, $plan)) { if (Radius::customerUpsert($customer, $plan)) {
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne(); $p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
if ($p) { if ($p) {
// if exists // if exists
$p->groupname = "plan_" . $plan['id']; $p->groupname = "plan_" . $plan['id'];
return $p->save(); $p->save();
} else { } else {
$p = Radius::getTableUserPackage()->create(); $p = Radius::getTableUserPackage()->create();
$p->username = $customer['username']; $p->username = $customer['username'];
$p->groupname = "plan_" . $plan['id']; $p->groupname = "plan_" . $plan['id'];
$p->priority = 1; $p->priority = 1;
return $p->save(); $p->save();
} }
//expired if ($plan['type'] == 'HOTSPOT' && $plan['typebp'] == "Limited") {
if ($plan['type'] == 'HOTSPOT') { if ($plan['limit_type'] == "Time_Limit") {
if ($plan['time_unit'] == 'Hrs')
$timelimit = $plan['time_limit'] * 60 * 60;
else
$timelimit = $plan['time_limit'] * 60;
Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit);
} else if ($plan['limit_type'] == "Data_Limit") {
if ($plan['data_unit'] == 'GB')
$datalimit = $plan['data_limit'] . "000000000";
else
$datalimit = $plan['data_limit'] . "000000";
Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
} else if ($plan['limit_type'] == "Both_Limit") {
if ($plan['time_unit'] == 'Hrs')
$timelimit = $plan['time_limit'] * 60 * 60;
else
$timelimit = $plan['time_limit'] . ":00";
if ($plan['data_unit'] == 'GB')
$datalimit = $plan['data_limit'] . "000000000";
else
$datalimit = $plan['data_limit'] . "000000";
Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit);
}
}else{
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Max-Volume')->delete();
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Expire-After')->delete();
} }
Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired))); // expired user
if($expired!=null){
Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
}else{
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'expiration')->delete();
}
return true;
} }
return false; return false;
} }

View File

@ -23,6 +23,14 @@ switch ($action) {
$logo = 'system/uploads/logo.default.png'; $logo = 'system/uploads/logo.default.png';
} }
$ui->assign('logo', $logo); $ui->assign('logo', $logo);
if(empty($_c['radius_client'])){
try{
$_c['radius_client'] = shell_exec('which radclient');
$ui->assign('_c', $_c);
}catch(Exception $e){
//ignore
}
}
run_hook('view_app_settings'); #HOOK run_hook('view_app_settings'); #HOOK
$ui->display('app-settings.tpl'); $ui->display('app-settings.tpl');
break; break;
@ -234,6 +242,7 @@ switch ($action) {
$http_proxy = _post('http_proxy'); $http_proxy = _post('http_proxy');
$http_proxyauth = _post('http_proxyauth'); $http_proxyauth = _post('http_proxyauth');
$radius_enable = _post('radius_enable'); $radius_enable = _post('radius_enable');
$radius_client = _post('radius_client');
run_hook('save_settings'); #HOOK run_hook('save_settings'); #HOOK
@ -448,6 +457,17 @@ switch ($action) {
$d->save(); $d->save();
} }
$d = ORM::for_table('tbl_appconfig')->where('setting', 'radius_client')->find_one();
if ($d) {
$d->value = $radius_client;
$d->save();
} else {
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'radius_client';
$d->value = $radius_client;
$d->save();
}
$note = _post('note'); $note = _post('note');
$d = ORM::for_table('tbl_appconfig')->where('setting', 'note')->find_one(); $d = ORM::for_table('tbl_appconfig')->where('setting', 'note')->find_one();
$d->value = $note; $d->value = $note;

View File

@ -82,6 +82,12 @@
</div> </div>
<p class="help-block col-md-4 text-red">Radius Not Yet Ready</p> <p class="help-block col-md-4 text-red">Radius Not Yet Ready</p>
</div> </div>
<div class="form-group">
<label class="col-md-2 control-label text-muted">Radius Client</label>
<div class="col-md-6">
<input type="text" class="form-control" name="radius_client" value="{$_c['radius_client']}">
</div>
</div>
</div> </div>
<div class="panel-heading"> <div class="panel-heading">
<div class="btn-group pull-right"> <div class="btn-group pull-right">