From 00183e3d0ef9e785f0fed2f87d17b724db16fcc7 Mon Sep 17 00:00:00 2001 From: Siby P Varkey Date: Tue, 10 Jul 2018 16:16:17 +0530 Subject: [PATCH] New updated version with feature addition & bug fixes Additional options in Profile creation. Provision to enable 'Remove accounts' on expiry, grace period, price option etc. Multiple user creation - More password type choices added. Provision to correct IP/Host settings in the config.php file, if the present settings are wrong or not connecting to the host. --- ajax_add_profile.php | 67 ++++++++++++++++++++++++--------- ajax_addusers.php | 39 ++++++++++++++++++-- ajax_edit_profile.php | 73 ++++++++++++++++++++++++++---------- ajax_get_profiles.php | 22 +++++++++-- config.php | 2 +- header.php | 37 +++++++++++++++++-- home.php | 27 +++++++++++--- login.php | 8 ++-- modal_delete_guest.php | 22 +++++------ modal_get_profiles.php | 84 ++++++++++++++++++++++++++++++------------ modal_get_user.php | 2 +- settings.php | 10 ++--- 12 files changed, 295 insertions(+), 98 deletions(-) diff --git a/ajax_add_profile.php b/ajax_add_profile.php index 55f6db7..60f3c13 100644 --- a/ajax_add_profile.php +++ b/ajax_add_profile.php @@ -4,23 +4,53 @@ use PEAR2\Net\RouterOS; require_once 'PEAR2/Autoload.php'; require_once 'config.php'; if ( !isset($_SESSION) ) session_start(); -$util = new RouterOS\Util($client = new RouterOS\Client("$host", "$user", "$pass")); - -$profile_name=strtolower($_GET['profile_name']); -$session_timeout=$_GET['session_timeout']; -$shared_users=$_GET['shared_users']; -$mac_cookie_timeout=$_GET['mac_cookie_timeout']; -$keepalive_timeout=$_GET['keepalive_timeout']; -$rx_rate_limit=$_GET['rx_rate_limit']; -$tx_rate_limit=$_GET['tx_rate_limit']; - -$rate_limit = $rx_rate_limit.'/'.$tx_rate_limit; -if (empty($session_timeout)) $session_timeout = '3d 00:00:00'; -if (empty($mac_cookie_timeout)) $mac_cookie_timeout = '3d 00:00:00'; -if (empty($keepalive_timeout)) $keepalive_timeout = '00:02:00'; - if ($_SESSION['user_level'] == 1) { - + $util = new RouterOS\Util($client = new RouterOS\Client("$host", "$user", "$pass")); + + $profile_name=strtolower($_GET['profile_name']); + $session_timeout=$_GET['session_timeout']; + $shared_users=$_GET['shared_users']; + $mac_cookie_timeout=$_GET['mac_cookie_timeout']; + $keepalive_timeout=$_GET['keepalive_timeout']; + $rx_rate_limit=$_GET['rx_rate_limit']; + $tx_rate_limit=$_GET['tx_rate_limit']; + + $validity = $_GET['validity']; + $grace_period = $_GET['grace_period']; + $on_expiry = $_GET['on_expiry']; + $price = $_GET['price']; + $lock_user = $_GET['lock_user']; + + $rate_limit = $rx_rate_limit.'/'.$tx_rate_limit; + if (empty($session_timeout)) $session_timeout = '3d 00:00:00'; + if (empty($mac_cookie_timeout)) $mac_cookie_timeout = '3d 00:00:00'; + if (empty($keepalive_timeout)) $keepalive_timeout = '00:02:00'; + if ($price == "") {$price = "0";} + if($lock_user == Enable){$mac_bind = ';[:local mac $"mac-address"; /ip hotspot user set mac-address=$mac [find where name=$user]]';} else {$mac_bind = "";} + + $login_script = ""; + + switch ($on_expiry) { + case "rem": + $login_script = ':put (",rem,'.$price.','.$validity.','.$grace_period.',,'.$lock_user.',");{:local date [/system clock get date ];:local time [/system clock get time ];:local uptime ('.$validity.');[/system scheduler add disabled=no interval=$uptime name=$user on-event="[/ip hotspot active remove [find where user=$user]];[/ip hotspot user set limit-uptime=1s [find where name=$user]];[/sys sch re [find where name=$user]];[/sys script run [find where name=$user]];[/sys script re [find where name=$user]]" start-date=$date start-time=$time];[/system script add name=$user source=":local date [/system clock get date ];:local time [/system clock get time ];:local uptime ('.$grace_period.');[/system scheduler add disabled=no interval=\$uptime name=$user on-event= \"[/ip hotspot user remove [find where name=$user]];[/ip hotspot active remove [find where user=$user]];[/sys sch re [find where name=$user]]\"]"]'; + break; + case "ntf": + $login_script = ':put (",ntf,'.$price.','.$validity.',,,'.$lock_user.',"); {:local date [/system clock get date ];:local time [/system clock get time ];:local uptime ('.$validity.');[/system scheduler add disabled=no interval=$uptime name=$user on-event= "[/ip hotspot user set limit-uptime=1s [find where name=$user]];[/ip hotspot active remove [find where user=$user]];[/sys sch re [find where name=$user]]" start-date=$date start-time=$time]'; + break; + case "remc": + $login_script = ':put (",remc,'.$price.','.$validity.','.$grace_period.',,'.$lock_user.',"); {:local price ('.$price.');:local date [/system clock get date ];:local time [/system clock get time ];:local uptime ('.$validity.');[/system scheduler add disabled=no interval=$uptime name=$user on-event="[/ip hotspot active remove [find where user=$user]];[/ip hotspot user set limit-uptime=1s [find where name=$user]];[/sys sch re [find where name=$user]];[/sys script run [find where name=$user]];[/sys script re [find where name=$user]]" start-date=$date start-time=$time];[/system script add name=$user source=":local date [/system clock get date ];:local time [/system clock get time ];:local uptime ('.$grace_period.');[/system scheduler add disabled=no interval=\$uptime name=$user on-event= \"[/ip hotspot user remove [find where name=$user]];[/ip hotspot active remove [find where user=$user]];[/sys sch re [find where name=$user]]\"]"];:local bln [:pick $date 0 3]; :local thn [:pick $date 7 11];[:local mac $"mac-address"; /system script add name="$date-|-$time-|-$user-|-$price-|-$address-|-$mac-|-'.$validity.'" owner="$bln$thn" source=$date comment=Zetozone]'; + break; + case "ntfc": + $login_script = ':put (",ntfc,'.$price.','.$validity.',,,'.$lock_user.',"); {:local price ('.$price.');:local date [/system clock get date ];:local time [/system clock get time ];:local uptime ('.$validity.');[/system scheduler add disabled=no interval=$uptime name=$user on-event= "[/ip hotspot user set limit-uptime=1s [find where name=$user]];[/ip hotspot active remove [find where user=$user]];[/sys sch re [find where name=$user]]" start-date=$date start-time=$time];:local bln [:pick $date 0 3]; :local thn [:pick $date 7 11];[:local mac $"mac-address"; /system script add name="$date-|-$time-|-$user-|-$price-|-$address-|-$mac-|-'.$validity.'" owner="$bln$thn" source=$date comment=Zetozone]'; + break; + case "0": + if ($price != "" ){ + $login_script = ':put (",,'.$price.',,,noexp,'.$lock_user.',")'; + } + break; + } + $login_script .= $mac_bind; + if (!empty($profile_name)) { $util->setMenu('/ip hotspot user profile'); @@ -32,7 +62,10 @@ if ($_SESSION['user_level'] == 1) { 'session-timeout' => "$session_timeout", 'shared-users' => "$shared_users", 'mac-cookie-timeout' => "$mac_cookie_timeout", - 'keepalive-timeout' => "$keepalive_timeout" + 'keepalive-timeout' => "$keepalive_timeout", + 'status-autorefresh' => "1m", + 'transparent-proxy' => "yes", + 'on-login' => "$login_script", ) ); /* diff --git a/ajax_addusers.php b/ajax_addusers.php index 5c262fa..2c51e77 100644 --- a/ajax_addusers.php +++ b/ajax_addusers.php @@ -14,9 +14,36 @@ if (isset($_GET['limit_uptime'])) $limit_uptime = $_GET['limit_uptime']; if (isset($_GET['limit_bytes'])) $limit_bytes = $_GET['limit_bytes']; if (isset($_GET['profile'])) $profile = $_GET['profile']; if (isset($_GET['same_pass'])) $same_pass = $_GET['same_pass']; +if (isset($_GET['pass_type'])) $pass_type = $_GET['pass_type']; if ( !isset($_SESSION) ) session_start(); +switch ($pass_type) { + case "s": + $passAlphabet = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; + break; + case "c": + $passAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; + break; + case "n": + $passAlphabet = "123456789123456789123456789123456789123456789123456789"; + break; + case "sc": + $passAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + break; + case "sn": + $passAlphabet = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz123456789123456789123456789"; + break; + case "cn": + $passAlphabet = "123456789123456789123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789123456789123456789"; + break; + case "scn": + $passAlphabet = "abcdefghijklmnopqrstuvwxyz123456789123456789123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; + break; +} + +$passAlphabetLimit = strlen($passAlphabet)-1; + if($_SESSION['user_level'] >= 1 and $_SESSION['user_level'] <= 3) { include('dbconfig.php'); $stmt = $DB_con->prepare("SELECT booking_id from hotspot_vouchers ORDER BY booking_id DESC LIMIT 1"); @@ -35,22 +62,28 @@ if($_SESSION['user_level'] >= 1 and $_SESSION['user_level'] <= 3) { $k = 1; for($i=0; $i < $no_of_users; $i++){ - $passAlphabet = 'abcdefghikmnpqrstuvxyz23456789'; - $passAlphabetLimit = strlen($passAlphabet)-1; + //$passAlphabet = 'abcdefghikmnpqrstuvxyz23456789'; + //$passAlphabetLimit = strlen($passAlphabet)-1; $pass = ''; $uid = ''; + //Password generation for ($j = 0; $j < $passLength; ++$j) { $pass .= $passAlphabet[mt_rand(0, $passAlphabetLimit)]; } + $pass = str_shuffle($pass); + //Username generation for ($j = 0; $j < $passLength; ++$j) { $uid .= $passAlphabet[mt_rand(0, $passAlphabetLimit)]; } + //Adding prefix to username $user_name = $user_prefix.$uid; + + //username & password same or different if ($same_pass == 2) { $pass_word = $pass; } else { $pass_word = $user_name; } + $util->setMenu('/ip hotspot user'); $iv = count($util); - if (intval($limit_bytes) != 0) { $limit_bytes_total = (intval($limit_bytes) * 1024 * 1024 * 1024 ); $util->add( diff --git a/ajax_edit_profile.php b/ajax_edit_profile.php index 453c6ca..89097e5 100644 --- a/ajax_edit_profile.php +++ b/ajax_edit_profile.php @@ -1,27 +1,58 @@ setArgument('shared-users', $shared_users); $setRequest->setArgument('mac-cookie-timeout', $mac_cookie_timeout); $setRequest->setArgument('keepalive-timeout', $keepalive_timeout); - + + $setRequest->setArgument('status-autorefresh', "1m"); + $setRequest->setArgument('transparent-proxy', "yes"); + $setRequest->setArgument('on-login', "$login_script"); + $client->sendSync($setRequest); /* if(strtolower($session_timeout) == 'none') { diff --git a/ajax_get_profiles.php b/ajax_get_profiles.php index 8076ca5..288d5c8 100644 --- a/ajax_get_profiles.php +++ b/ajax_get_profiles.php @@ -11,7 +11,7 @@ if ($_SESSION['user_level'] == 1) { $profile_name=$_GET['profile_name']; $printRequest = new RouterOS\Request('/ip hotspot user profile print'); - $printRequest->setArgument('.proplist', '.id,name,address-pool,rate-limit,session-timeout,shared-users,mac-cookie-timeout,keepalive-timeout'); + $printRequest->setArgument('.proplist', '.id,name,address-pool,rate-limit,session-timeout,shared-users,mac-cookie-timeout,keepalive-timeout,on-login'); $printRequest->setQuery(RouterOS\Query::where('name', $profile_name)); foreach ($client->sendSync($printRequest)->getAllOfType(RouterOS\Response::TYPE_DATA) as $item) { @@ -21,13 +21,29 @@ if ($_SESSION['user_level'] == 1) { $tshared_users = $item->getProperty("shared-users"); $trate_limit = $item->getProperty("rate-limit"); $tsession_timeout = $item->getProperty("session-timeout"); - $tshared_users = $item->getProperty("shared-users"); + $ton_login = $item->getProperty("on-login"); $tmac_cookie_timeout = $item->getProperty("mac-cookie-timeout"); $tkeepalive_timeout = $item->getProperty("keepalive-timeout"); + + $exploded = explode(",",$ton_login); + + $ton_expiry = $exploded[1]; + $tprice = $exploded[2]; + $tvalidity = $exploded[3]; + $tgrace_period = $exploded[4]; + $tlock_user = $exploded[6]; + + if($ton_expiry == "rem"){ $tton_expiry = "Remove"; } + elseif ($ton_expiry == "ntf"){ $tton_expiry = "Notice"; } + elseif ($ton_expiry == "remc") { $tton_expiry = "Remove & Record"; } + elseif ($ton_expiry == "ntfc") { $tton_expiry = "Notice & Record"; } + else $tton_expiry = "0"; + $arr = array('name' => $tname, 'address_pool' => $taddress_pool, 'rate_limit' => $trate_limit, 'session_timeout' => $tsession_timeout, 'shared_users' => $tshared_users, 'mac_cookie_timeout' => $tmac_cookie_timeout, - 'keepalive_timeout' => $tkeepalive_timeout ); + 'keepalive_timeout' => $tkeepalive_timeout, 'on_expiry' => $ton_expiry, 'price' => $tprice, 'validity' => $tvalidity, + 'grace_period' => $tgrace_period, 'lock_user' => $tlock_user ); echo json_encode($arr); } diff --git a/config.php b/config.php index 278d47a..d06756f 100644 --- a/config.php +++ b/config.php @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/header.php b/header.php index 371c648..54a60a0 100644 --- a/header.php +++ b/header.php @@ -106,6 +106,7 @@ function ajaxMultiple(){ var limit_bytes = document.getElementById('limit_bytes').value; var profile = document.getElementById('profile').value; var same_pass = document.getElementById('same_pass').value; + var Pass_type = document.getElementById('pass_type').value; // btns = [{text:"No",action:"cmodalClose",style:"cmodal-cancel"}, {text:"Yes",action:"test.php",style:"cmodal-ok"}]; @@ -149,7 +150,9 @@ function ajaxMultiple(){ } var queryString = "?no_of_users=" + no_of_users ; - queryString += "&pass_length=" + pass_length + "&user_prefix=" + user_prefix + "&limit_uptime=" + limit_uptime + "&profile=" + profile + "&same_pass=" + same_pass + "&limit_bytes=" + limit_bytes; + queryString += "&pass_length=" + pass_length + "&user_prefix=" + user_prefix ; + queryString += "&limit_uptime=" + limit_uptime + "&profile=" + profile + "&same_pass=" + same_pass; + queryString += "&limit_bytes=" + limit_bytes + "&pass_type=" + Pass_type; ajaxRequest.open("GET", "ajax_addusers.php" + queryString, true); ajaxRequest.send(null); } @@ -675,7 +678,7 @@ $('#getProfileModal').on('show.bs.modal', function (event) { dataType: "json", success: function(data) { - //console.log (data); + //console.log(data); var Name = data.name; var Address_pool = data.address_pool; var Rate_limit = data.rate_limit; @@ -689,6 +692,12 @@ $('#getProfileModal').on('show.bs.modal', function (event) { var Mac_cookie_timeout = data.mac_cookie_timeout; var Keepalive_timeout = data.keepalive_timeout; + var Validity = data.validity; + var Grace_period = data.grace_period; + var On_expiry = data.on_expiry; + var Price = data.price; + var Lock_user = data.lock_user; + modal.find('.modal-body #profile_name').val(Name) modal.find('.modal-body #address_pool').val(Address_pool) modal.find('.modal-body #rx_rate_limit').val(Rx_rate_limit) @@ -697,10 +706,14 @@ $('#getProfileModal').on('show.bs.modal', function (event) { modal.find('.modal-body #shared_users').val(Shared_users) modal.find('.modal-body #mac_cookie_timeout').val(Mac_cookie_timeout) modal.find('.modal-body #keepalive_timeout').val(Keepalive_timeout) - + + modal.find('.modal-body #validity').val(Validity) + modal.find('.modal-body #grace_period').val(Grace_period) + modal.find('.modal-body #on_expiry').val(On_expiry) + modal.find('.modal-body #price').val(Price) + modal.find('.modal-body #lock_user').val(Lock_user) } }) - }) } ) @@ -721,6 +734,12 @@ function addprofile(oForm) { var Mac_cookie_timeout = oForm.elements["mac_cookie_timeout"].value; var Keepalive_timeout = oForm.elements["keepalive_timeout"].value; + var Validity = oForm.elements["validity"].value; + var Grace_period = oForm.elements["grace_period"].value; + var On_expiry = oForm.elements["on_expiry"].value; + var Price = oForm.elements["price"].value; + var Lock_user = oForm.elements["lock_user"].value; + var ajaxRequest; // The variable that makes Ajax possible! try{ @@ -765,6 +784,8 @@ function addprofile(oForm) { queryString += "&session_timeout=" + Session_timeout; queryString += "&shared_users=" + Shared_users + "&mac_cookie_timeout=" + Mac_cookie_timeout + "&keepalive_timeout=" + Keepalive_timeout; queryString += "&rx_rate_limit=" + Rx_rate_limit + "&tx_rate_limit=" + Tx_rate_limit; + queryString += "&validity=" + Validity + "&grace_period=" + Grace_period; + queryString += "&on_expiry=" + On_expiry + "&price=" + Price + "&lock_user=" + Lock_user; ajaxRequest.open("GET", "ajax_add_profile.php" + queryString, true); ajaxRequest.send(null); @@ -838,6 +859,12 @@ function editprofile(oForm) { var Mac_cookie_timeout = oForm.elements["mac_cookie_timeout"].value; var Keepalive_timeout = oForm.elements["keepalive_timeout"].value; + var Validity = oForm.elements["validity"].value; + var Grace_period = oForm.elements["grace_period"].value; + var On_expiry = oForm.elements["on_expiry"].value; + var Price = oForm.elements["price"].value; + var Lock_user = oForm.elements["lock_user"].value; + var ajaxRequest; // The variable that makes Ajax possible! try{ @@ -882,6 +909,8 @@ function editprofile(oForm) { queryString += "&session_timeout=" + Session_timeout; queryString += "&shared_users=" + Shared_users + "&mac_cookie_timeout=" + Mac_cookie_timeout + "&keepalive_timeout=" + Keepalive_timeout; queryString += "&rx_rate_limit=" + Rx_rate_limit + "&tx_rate_limit=" + Tx_rate_limit; + queryString += "&validity=" + Validity + "&grace_period=" + Grace_period; + queryString += "&on_expiry=" + On_expiry + "&price=" + Price + "&lock_user=" + Lock_user; ajaxRequest.open("GET", "ajax_edit_profile.php" + queryString, true); ajaxRequest.send(null); diff --git a/home.php b/home.php index 1ea2909..04d1a7b 100644 --- a/home.php +++ b/home.php @@ -229,13 +229,13 @@
- +
- +
@@ -248,7 +248,7 @@
-
+
-
+
+
+ +
+ +
+
@@ -566,7 +580,7 @@ setArgument('.proplist', '.id,server,name,profile,limit-uptime,limit-bytes-total,uptime,bytes-in,bytes-out'); $printRequest->setQuery(RouterOS\Query::where('.id', '*0', RouterOS\Query::OP_EQ) ->not()); @@ -865,6 +879,7 @@ \ No newline at end of file diff --git a/login.php b/login.php index 1ac6c30..98e32d8 100644 --- a/login.php +++ b/login.php @@ -17,15 +17,15 @@ ini_set('display_errors', 1); ?>
- +
- +
- +
- +
diff --git a/modal_delete_guest.php b/modal_delete_guest.php index b81f2cb..bfee7f6 100644 --- a/modal_delete_guest.php +++ b/modal_delete_guest.php @@ -5,39 +5,39 @@ @@ -45,7 +45,7 @@
- +
diff --git a/modal_get_profiles.php b/modal_get_profiles.php index d97ed12..a46f3d1 100644 --- a/modal_get_profiles.php +++ b/modal_get_profiles.php @@ -5,24 +5,56 @@