diff --git a/configure_hotspot.php b/configure_hotspot.php
new file mode 100755
index 0000000..55bd3c4
--- /dev/null
+++ b/configure_hotspot.php
@@ -0,0 +1,209 @@
+ 251) {
+ $final_num_users = 251;
+ } else if ($num_users < 10) {
+ $final_num_users = 10;
+ } else {
+ $final_num_users = $num_users;
+ }
+ return $final_num_users;
+}*/
+
+function checkOctet($octet) {
+ $final_octet = 0;
+ if ($octet > 255) {
+ $final_octet = 255;
+ } else if ($octet < 0) {
+ $final_octet = 0;
+ } else {
+ $final_octet = $octet;
+ }
+ return $final_octet;
+}
+
+function multiexplode ($delimiters, $string) {
+ $ready = str_replace($delimiters, $delimiters[0], $string);
+ $launch = explode($delimiters[0], $ready);
+ return $launch;
+}
+
+function genPool($oct1, $oct2, $oct3, $oct4, $mask) {
+ $oct = 3;
+ $du = 24;
+ $dl = 16;
+ $first_host = "";
+ $last_host = "";
+
+ $pool = "";
+ #find the octet we are working in
+ if ($mask >= 16 and $mask <= 24) {
+ $oct = 3;
+ $du = 24;
+ $dl = 16;
+ } else if ($mask >= 24 and $mask < 32) {
+ $oct = 4;
+ $du = 32;
+ $dl = 24;
+ }
+ #get the subnet increment
+ $inc = 2 ** ($du - $mask);
+
+ #get the number of hosts
+ $hosts = (2 ** (32 - $mask)) - 2;
+
+ #validate network address and get the pool range
+ if ($oct == 3 and ($oct3 % $inc == 0)) {
+ $serv = "$oct1.$oct2.$oct3.1";
+ $first_host = "$oct1.$oct2.$oct3.2";
+ $last_host = "$oct1.$oct2." . ($oct3 + ($inc - 1)) . ".254";
+ } else if ($oct == 4 and ($oct4 % $inc == 0)) {
+ $serv = "$oct1.$oct2.$oct3." . ($oct4 + 1);
+ $first_host = "$oct1.$oct2.$oct3." . ($oct4 + 2);
+ $last_host = "$oct1.$oct2.$oct3." . (($oct4 + $inc) - 2);
+ }
+# else {
+# echo "bad network\n";
+# exit;
+# }
+
+ #output results
+ return array("pool" => "$first_host-$last_host", "server" => $serv);
+}
+
+function setup($router_addr, $username, $password) {
+ $API = new RouterosAPI();
+ $API->debug = true;
+ $poolName = randomString() . randomString() . randomString();
+ $dhcpName = randomString() . randomString() . randomString();
+ $profName = randomString() . randomString() . randomString();
+
+ $net = $_POST["hs_net"];
+ $octs = multiexplode(array(".", "/"), $net);
+ $mask = $octs[4];
+
+ $pool_array = genPool($octs[0], $octs[1], $octs[2], $octs[3], $mask);
+ $serv = $pool_array["server"];
+ $pool = $pool_array["pool"];
+
+ if ($API->connect($router_addr, $username, $password)) {
+
+ $API->write("/interface/wireless/set", false);
+ $API->write("=.id=*6", false);
+ $API->write("=ssid=" . $_POST["hs_ssid"], false);
+ $API->write("=mode=ap-bridge", false);
+ $API->write("=wireless-protocol=802.11", false);
+ $API->write("=disabled=no");
+ $READ = $API->read(false);
+/*
+ $API->write("/interface/bridge/add", false);
+ $API->write("=name=bridge-hotspot", false);
+ $API->write("=arp=enabled", false);
+ $API->write("protocol-mode=stp", false);
+ $API->write("=disabled=no");
+ $READ = $API->read(false);
+
+ $API->write("/interface/bridge/port/add", false);
+ $API->write("=interface=wlan1", false);
+ $API->write("=bridge=bridge-hotspot");
+ $READ = $API->read(false);
+*/
+ $API->write("/ip/address/add", false);
+ $API->write("=address=$serv/$mask", false);
+ $API->write("=interface=wlan1");
+ $READ = $API->read(false);
+
+ $API->write("/ip/pool/add", false);
+ $API->write("=name=" . $poolName, false);
+ $API->write("=ranges=$pool");
+ $READ = $API->read(false);
+
+ $API->write("/ip/dhcp-server/add", false);
+ $API->write("=name=" . $dhcpName, false);
+ $API->write("=interface=wlan1", false);
+ $API->write("=address-pool=" . $poolName, false);
+ $API->write("=lease-time=3d", false);
+ $API->write("=disabled=no");
+ $READ = $API->read(false);
+
+ $API->write("/ip/dhcp-server/network/add", false);
+ $API->write("=address=$net", false);
+ $API->write("=gateway=$serv");
+ $READ = $API->read(false);
+
+ $API->write("/routing/ospf/network/add", false);
+ $API->write("=network=$net", false);
+ $API->write("=area=backbone");
+ $READ = $API->read(false);
+
+ $API->write("/ip/hotspot/profile/add", false);
+ $API->write("=name=" . $profName, false);
+ $API->write("=dns-name=" . $_POST["hs_dns"], false);
+ $API->write("=hotspot-address=$serv", false);
+ $API->write("=use-radius=yes", false);
+ $API->write("=radius-accounting=yes", false);
+ $API->write("=login-by=http-pap");
+ $READ = $API->read(false);
+
+ $API->write("/ip/hotspot/add", false);
+ $API->write("=profile=" . $profName, false);
+ $API->write("=name=" . $_POST["hs_ssid"], false);
+ $API->write("=address-pool=" . $poolName, false);
+ $API->write("=interface=wlan1", false);
+ $API->write("=addresses-per-mac=1", false);
+ $API->write("=disabled=no");
+ $READ = $API->read(false);
+
+// $API->write("/ip/firewall/nat/set", false);
+// $API->write("=.id=*1", false);
+// $API->write("=src-address=$net");
+// $READ = $API->read(false);
+
+ $conn = new mysqli("localhost", "mgt", "admin_mgt", "manager_db");
+ if ($conn->connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+ $sql = "select * from radlogin where id = 1";
+ $result = $conn->query($sql);
+ $row = $result->fetch_assoc();
+
+ $API->write("/radius/add", false);
+ $API->write("=address=" . $row["radaddress"], false);
+ $API->write("=secret=" . $row["radsecret"], false);
+ $API->write("=service=hotspot", false);
+ $API->write("=disabled=no");
+ $READ = $API->read(false);
+
+ $API->write("/radius/incoming/set", false);
+ $API->write("=accept=yes");
+ $READ = $API->read(false);
+
+ $conn->close();
+ }
+}
+
+function randomString() {
+ $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $randString = '';
+ for ($i = 0; $i < 10; $i++) {
+ $randString = $characters[rand(0, strlen($characters))];
+ }
+ return $randString;
+}
+
+function checkOctet_bool($octet) {
+ $octet_ok = TRUE;
+ if ($octet > 255 or $octet < 0) {
+ $octet_ok = FALSE;
+ } else {
+ $octet = TRUE;
+ }
+ return $octet_ok;
+}
+
+?>
+
diff --git a/disabler.php b/disabler.php
new file mode 100755
index 0000000..9a992f3
--- /dev/null
+++ b/disabler.php
@@ -0,0 +1,8 @@
+
+
+
diff --git a/general_settings.php b/general_settings.php
new file mode 100755
index 0000000..05b9c1a
--- /dev/null
+++ b/general_settings.php
@@ -0,0 +1,241 @@
+
+
+
+
+
+
+
+
+
+connect_error) {
+ die("Connection failed: " . $conn_1->connect_error);
+ }
+
+ $sql_1 = "update login set username=\"$new_username\",".
+ " password=\"$new_password\" where id = 1";
+ $sql_2 = "select * from login where id = 1";
+ $sql_3 = "update radlogin set radaddress=\"$new_radaddr\",".
+ " radsecret=\"$new_radsecret\" where id = 1";
+
+ #get the old credentials
+ $result = $conn_1->query($sql_2);
+ $row = $result->fetch_assoc();
+ $db_username = $row["username"];
+ $db_password = $row["password"];
+
+ #validate the user with the credentials
+ if ($old_username === $db_username and $old_password === $db_password) {
+ if ($conn_1->query($sql_1) === FALSE) {
+ die("Query \"$sql_1\" failed!");
+ } else {
+ #change the credentials of the routers
+ $conn_2 = new mysqli($servername, "radius", "radpass", "radius");
+ if ($conn_2->connect_error) {
+ die("Connection failed: " . $conn_2->connect_error);
+ }
+ $sql_4 = "select nasname from nas";
+ $result_2 = $conn_2->query($sql_4);
+ if ($result_2->num_rows > 0) {
+ $API = new RouterosAPI();
+ $API->debug = true; # hope this doesn't mess stuff up
+ while ($row = $result_2->fetch_assoc()) {
+ if ($API->connect($row["nasname"], $old_username, $old_password)) {
+ $API->write("/user/set", false);
+ $API->write("=.id=*1", false);
+ $API->write("=name=$new_username", false);
+ $API->write("=password=$new_password");
+ $READ = $API->read(false);
+ }
+ }
+ $msg_1 = "
+
+ Credentials saved
+
";
+ } else {
+ $msg_1 = "
+
+ Credentials saved
+
+ but no routers added
+
";
+ }
+ $conn_2->close();
+ }
+ if ($conn_1->query($sql_3) === FALSE) {
+ die("Query \"$sql_3\" failed!");
+ } else {
+ $msg_2 = "
+ RADIUS settings saved
";
+ }
+ }
+
+ $conn_1->close();
+
+}
+?>
+
+
+GENERAL SETTINGS
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/hotspots.php b/hotspots.php
new file mode 100755
index 0000000..bd3a967
--- /dev/null
+++ b/hotspots.php
@@ -0,0 +1,210 @@
+
+
+
+
+
+
+
+
+
+= 22 and $octs[4] <= 29
+ and checkOctet_bool($octs[0]) and checkOctet_bool($octs[1])
+ and checkOctet_bool($octs[2]) and checkOctet_bool($octs[3])) {
+ $servername = "localhost";
+ $username = "radius";
+ $password = "radpass";
+ $dbname = "radius";
+
+ $conn_1 = new mysqli($servername, $username, $password, $dbname);
+ $conn_2 = new mysqli($servername, "mgt", "admin_mgt", "manager_db");
+ if ($conn_1->connect_error or $conn_2->connection_error) {
+ die("Connection failed: " . $conn_1->connect_error . " "
+ .$conn_2->connection_error);
+ }
+
+ $sql_1 = "select nasname from nas";
+ $result = $conn_1->query($sql_1);
+
+ $sql_2 = "select * from login where id = 1";
+ $login = ($conn_2->query($sql_2))->fetch_assoc();
+
+ if ($result->num_rows > 0) {
+ while($row = $result->fetch_assoc()) {
+ setup($row["nasname"], $login["username"], $login["password"]);
+ }
+ }
+ $conn_1->close();
+ $conn_2->close();
+ } else {
+ //$msg = "
+ // Invalid subnet mask or network
";
+ }
+}
+?>
+
+
+
+
HOTSPOTS
+
+
+
+
+
+
+HOTSPOT CREATED WITH THE FOLLOWING SETTINGS";
+ echo "";
+
+ echo "";
+ echo "HOTSPOT NAME | ";
+ echo "HOTSPOT ADDRESS | ";
+ echo "
";
+
+ echo "";
+ echo "" . $_POST["hs_ssid"] . " | ";
+ echo "" . $_POST["hs_net"] . " | ";
+ echo "
";
+
+ echo "
";
+
+ echo '
+
+
+
+
+
diff --git a/imgback.jpg b/imgback.jpg
new file mode 100755
index 0000000..b47813b
Binary files /dev/null and b/imgback.jpg differ
diff --git a/index.php b/index.php
new file mode 100755
index 0000000..a26b742
--- /dev/null
+++ b/index.php
@@ -0,0 +1,10 @@
+
+require 'voucher.php';
+Congratulation! You have logged into password protected page. Click here to Logout.
diff --git a/login.php b/login.php
new file mode 100755
index 0000000..ae96489
--- /dev/null
+++ b/login.php
@@ -0,0 +1,145 @@
+
+
+
+
+
+ '123456','username1' => 'password1','username2' => 'password2');
+ $username = "mgt";
+ $password = "admin_mgt";
+ $server = "localhost";
+ $db = "manager_db";
+
+ $conn = new mysqli($server, $username, $password, $db);
+
+ if ($conn->connect_error) {
+ die("Connection failed: " . $conn->conncet_error);
+ }
+
+ $sql_1 = "select * from login where id = 1";
+ $result = $conn->query($sql_1);
+ $row = $result->fetch_assoc();
+ $db_username = $row["username"];
+ $db_password = $row["password"];
+
+ /* Check and assign submitted Username and Password to new variable */
+ $Username = isset($_POST['Username']) ? $_POST['Username'] : '';
+ $Password = isset($_POST['Password']) ? $_POST['Password'] : '';
+
+ /* Check Username and Password existence in defined array */
+ if ($Username === $db_username & $Password === $db_password){
+ /* Success: Set session variables and redirect to Protected page */
+
+ $_SESSION['UserData']['Username']=$db_password;
+
+ header("location:routers.php");
+
+ exit;
+ } else {
+ /*Unsuccessful attempt: Set error message */
+ $msg="Invalid Login Details";
+ }
+ }
+?>
+
+
+
+WELCOME TO NETFACE
+Your configurations partner
+
+
+
+
diff --git a/logout.php b/logout.php
new file mode 100755
index 0000000..a94e6b6
--- /dev/null
+++ b/logout.php
@@ -0,0 +1,5 @@
+
\ No newline at end of file
diff --git a/make_vouchers.php b/make_vouchers.php
new file mode 100755
index 0000000..3a0cc7e
--- /dev/null
+++ b/make_vouchers.php
@@ -0,0 +1,97 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+
+ #make vouchers
+ for ($x = 0; $x < $num_vouchers; $x++) {
+ $randu = substr(md5(microtime()), rand(0, 26), 5);
+ $voucher_login = $voucher_prefix . "--" . $randu;
+ $randpw = substr(md5(microtime()), rand(0, 26), 5);
+ $voucher_pw = $randpw;
+
+ $sql_1 = "insert into radcheck (username, attribute, op, value) values " .
+ "(\"$voucher_login\", \"MD5-Password\", \":=\"," .
+ " MD5(\"$voucher_pw\"))";
+ if ($conn->query($sql_1) == FALSE) {
+ echo "Error :" . $sql_1 . "\n" . $conn->error . "\n";
+ }
+
+ $vouchers_str = $vouchers_str .
+ "Username: " . $voucher_login . "\nPassword: "
+ . $voucher_pw . "\n\n";
+
+ $sql_2 = "insert into radusergroup (username, groupname, priority)" .
+ " values (\"$voucher_login\", \"$group_name\", \"1\")";
+ if ($conn->query($sql_2) == FALSE) {
+ echo "Error :" . $sql_2 . "\n" . $conn->error . "\n";
+ }
+
+ }
+
+ $sql_groupcheck = "select attribute from radgroupcheck " .
+ "where groupname = \"$group_name\"";
+ $sql_groupreply = "select attribute from radgroupreply " .
+ "where groupname = \"$group_name\"";
+ $result_1 = $conn->query($sql_groupcheck);
+ $result_2 = $conn->query($sql_groupreply);
+
+ if ($result_1->num_rows == 0 && $result_2->num_rows == 0) {
+ #create group attributes
+
+ #in radgroupcheck
+ $sql_3 = "insert into radgroupcheck (groupname, attribute, op, value)" .
+ " values (\"$group_name\", \"Max-All-Session\"," .
+ " \":=\", \"$time_limit\")";
+ if ($conn->query($sql_3) == FALSE) {
+ echo "Error :" . $sql_3 . "\n" . $conn->error . "\n";
+ }
+
+ #in radgroupreply
+ $sql_4 = "insert into radgroupreply (groupname, attribute, op, value)" .
+ " values (\"$group_name\", \"Session-Timeout\"," .
+ " \":=\", \"$time_limit\"), " .
+ "(\"$group_name\", \"Framed-Compression\"," .
+ " \":=\", \"Van-Jacobsen-TCP-IP\"), " .
+ "(\"$group_name\", \"Framed-Protocol\"," .
+ " \":=\", \"PPP\"), " .
+ "(\"$group_name\", \"Framed-MTU\"," .
+ " \":=\", \"1500\"), " .
+ "(\"$group_name\", \"Service-Type\"," .
+ " \":=\", \"Login-User\")";
+ if ($conn->query($sql_4) == FALSE) {
+ echo "Error :" . $sql_4 . "\n" . $conn->error . "\n";
+ }
+ }
+
+ $conn->close();
+
+ #write file
+ echo "$vouchers_str";
+}
+
+?>
diff --git a/menu.php b/menu.php
new file mode 100755
index 0000000..44018bc
--- /dev/null
+++ b/menu.php
@@ -0,0 +1,17 @@
+
+
+
+
+ ';
+?>
+
+
diff --git a/remove_router.php b/remove_router.php
new file mode 100755
index 0000000..32b6be1
--- /dev/null
+++ b/remove_router.php
@@ -0,0 +1,28 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+
+ $sql_1 = "delete from nas where nasname = \"$addr\"";
+ if ($conn->query($sql_1) == FALSE) {
+ echo "Error: " . $sql_1 . "\h" . $conn->error . "\n";
+ } else {
+ header("Location: routers.php");
+ //echo "Router removed!";
+ }
+
+ $conn->close();
+}
+?>
+
+
diff --git a/routeros_api.class.php b/routeros_api.class.php
new file mode 100755
index 0000000..f1e5153
--- /dev/null
+++ b/routeros_api.class.php
@@ -0,0 +1,425 @@
+debug) {
+ echo $text . "\n";
+ }
+ }
+
+
+ /**
+ *
+ *
+ * @param string $length
+ *
+ * @return void
+ */
+ public function encodeLength($length)
+ {
+ if ($length < 0x80) {
+ $length = chr($length);
+ } elseif ($length < 0x4000) {
+ $length |= 0x8000;
+ $length = chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
+ } elseif ($length < 0x200000) {
+ $length |= 0xC00000;
+ $length = chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
+ } elseif ($length < 0x10000000) {
+ $length |= 0xE0000000;
+ $length = chr(($length >> 24) & 0xFF) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
+ } elseif ($length >= 0x10000000) {
+ $length = chr(0xF0) . chr(($length >> 24) & 0xFF) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
+ }
+
+ return $length;
+ }
+
+
+ /**
+ * Login to RouterOS
+ *
+ * @param string $ip Hostname (IP or domain) of the RouterOS server
+ * @param string $login The RouterOS username
+ * @param string $password The RouterOS password
+ *
+ * @return boolean If we are connected or not
+ */
+ public function connect($ip, $login, $password)
+ {
+ for ($ATTEMPT = 1; $ATTEMPT <= $this->attempts; $ATTEMPT++) {
+ $this->connected = false;
+ $PROTOCOL = ($this->ssl ? 'ssl://' : '' );
+ $context = stream_context_create(array('ssl' => array('ciphers' => 'ADH:ALL', 'verify_peer' => false, 'verify_peer_name' => false)));
+ $this->debug('Connection attempt #' . $ATTEMPT . ' to ' . $PROTOCOL . $ip . ':' . $this->port . '...');
+ $this->socket = @stream_socket_client($PROTOCOL . $ip.':'. $this->port, $this->error_no, $this->error_str, $this->timeout, STREAM_CLIENT_CONNECT,$context);
+ if ($this->socket) {
+ socket_set_timeout($this->socket, $this->timeout);
+ $this->write('/login');
+ $RESPONSE = $this->read(false);
+ if (isset($RESPONSE[0]) && $RESPONSE[0] == '!done') {
+ $MATCHES = array();
+ if (preg_match_all('/[^=]+/i', $RESPONSE[1], $MATCHES)) {
+ if ($MATCHES[0][0] == 'ret' && strlen($MATCHES[0][1]) == 32) {
+ $this->write('/login', false);
+ $this->write('=name=' . $login, false);
+ $this->write('=response=00' . md5(chr(0) . $password . pack('H*', $MATCHES[0][1])));
+ $RESPONSE = $this->read(false);
+ if (isset($RESPONSE[0]) && $RESPONSE[0] == '!done') {
+ $this->connected = true;
+ break;
+ }
+ }
+ }
+ }
+ fclose($this->socket);
+ }
+ sleep($this->delay);
+ }
+
+ if ($this->connected) {
+ $this->debug('Connected...');
+ } else {
+ $this->debug('Error...');
+ }
+ return $this->connected;
+ }
+
+
+ /**
+ * Disconnect from RouterOS
+ *
+ * @return void
+ */
+ public function disconnect()
+ {
+ // let's make sure this socket is still valid. it may have been closed by something else
+ if( is_resource($this->socket) ) {
+ fclose($this->socket);
+ }
+ $this->connected = false;
+ $this->debug('Disconnected...');
+ }
+
+
+ /**
+ * Parse response from Router OS
+ *
+ * @param array $response Response data
+ *
+ * @return array Array with parsed data
+ */
+ public function parseResponse($response)
+ {
+ if (is_array($response)) {
+ $PARSED = array();
+ $CURRENT = null;
+ $singlevalue = null;
+ foreach ($response as $x) {
+ if (in_array($x, array('!fatal','!re','!trap'))) {
+ if ($x == '!re') {
+ $CURRENT =& $PARSED[];
+ } else {
+ $CURRENT =& $PARSED[$x][];
+ }
+ } elseif ($x != '!done') {
+ $MATCHES = array();
+ if (preg_match_all('/[^=]+/i', $x, $MATCHES)) {
+ if ($MATCHES[0][0] == 'ret') {
+ $singlevalue = $MATCHES[0][1];
+ }
+ $CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
+ }
+ }
+ }
+
+ if (empty($PARSED) && !is_null($singlevalue)) {
+ $PARSED = $singlevalue;
+ }
+
+ return $PARSED;
+ } else {
+ return array();
+ }
+ }
+
+
+ /**
+ * Parse response from Router OS
+ *
+ * @param array $response Response data
+ *
+ * @return array Array with parsed data
+ */
+ public function parseResponse4Smarty($response)
+ {
+ if (is_array($response)) {
+ $PARSED = array();
+ $CURRENT = null;
+ $singlevalue = null;
+ foreach ($response as $x) {
+ if (in_array($x, array('!fatal','!re','!trap'))) {
+ if ($x == '!re') {
+ $CURRENT =& $PARSED[];
+ } else {
+ $CURRENT =& $PARSED[$x][];
+ }
+ } elseif ($x != '!done') {
+ $MATCHES = array();
+ if (preg_match_all('/[^=]+/i', $x, $MATCHES)) {
+ if ($MATCHES[0][0] == 'ret') {
+ $singlevalue = $MATCHES[0][1];
+ }
+ $CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
+ }
+ }
+ }
+ foreach ($PARSED as $key => $value) {
+ $PARSED[$key] = $this->arrayChangeKeyName($value);
+ }
+ return $PARSED;
+ if (empty($PARSED) && !is_null($singlevalue)) {
+ $PARSED = $singlevalue;
+ }
+ } else {
+ return array();
+ }
+ }
+
+
+ /**
+ * Change "-" and "/" from array key to "_"
+ *
+ * @param array $array Input array
+ *
+ * @return array Array with changed key names
+ */
+ public function arrayChangeKeyName(&$array)
+ {
+ if (is_array($array)) {
+ foreach ($array as $k => $v) {
+ $tmp = str_replace("-", "_", $k);
+ $tmp = str_replace("/", "_", $tmp);
+ if ($tmp) {
+ $array_new[$tmp] = $v;
+ } else {
+ $array_new[$k] = $v;
+ }
+ }
+ return $array_new;
+ } else {
+ return $array;
+ }
+ }
+
+
+ /**
+ * Read data from Router OS
+ *
+ * @param boolean $parse Parse the data? default: true
+ *
+ * @return array Array with parsed or unparsed data
+ */
+ public function read($parse = true)
+ {
+ $RESPONSE = array();
+ $receiveddone = false;
+ while (true) {
+ // Read the first byte of input which gives us some or all of the length
+ // of the remaining reply.
+ $BYTE = ord(fread($this->socket, 1));
+ $LENGTH = 0;
+ // If the first bit is set then we need to remove the first four bits, shift left 8
+ // and then read another byte in.
+ // We repeat this for the second and third bits.
+ // If the fourth bit is set, we need to remove anything left in the first byte
+ // and then read in yet another byte.
+ if ($BYTE & 128) {
+ if (($BYTE & 192) == 128) {
+ $LENGTH = (($BYTE & 63) << 8) + ord(fread($this->socket, 1));
+ } else {
+ if (($BYTE & 224) == 192) {
+ $LENGTH = (($BYTE & 31) << 8) + ord(fread($this->socket, 1));
+ $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
+ } else {
+ if (($BYTE & 240) == 224) {
+ $LENGTH = (($BYTE & 15) << 8) + ord(fread($this->socket, 1));
+ $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
+ $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
+ } else {
+ $LENGTH = ord(fread($this->socket, 1));
+ $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
+ $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
+ $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
+ }
+ }
+ }
+ } else {
+ $LENGTH = $BYTE;
+ }
+
+ $_ = "";
+
+ // If we have got more characters to read, read them in.
+ if ($LENGTH > 0) {
+ $_ = "";
+ $retlen = 0;
+ while ($retlen < $LENGTH) {
+ $toread = $LENGTH - $retlen;
+ $_ .= fread($this->socket, $toread);
+ $retlen = strlen($_);
+ }
+ $RESPONSE[] = $_;
+ $this->debug('>>> [' . $retlen . '/' . $LENGTH . '] bytes read.');
+ }
+
+ // If we get a !done, make a note of it.
+ if ($_ == "!done") {
+ $receiveddone = true;
+ }
+
+ $STATUS = socket_get_status($this->socket);
+ if ($LENGTH > 0) {
+ $this->debug('>>> [' . $LENGTH . ', ' . $STATUS['unread_bytes'] . ']' . $_);
+ }
+
+ if ((!$this->connected && !$STATUS['unread_bytes']) || ($this->connected && !$STATUS['unread_bytes'] && $receiveddone)) {
+ break;
+ }
+ }
+
+ if ($parse) {
+ $RESPONSE = $this->parseResponse($RESPONSE);
+ }
+
+ return $RESPONSE;
+ }
+
+
+ /**
+ * Write (send) data to Router OS
+ *
+ * @param string $command A string with the command to send
+ * @param mixed $param2 If we set an integer, the command will send this data as a "tag"
+ * If we set it to boolean true, the funcion will send the comand and finish
+ * If we set it to boolean false, the funcion will send the comand and wait for next command
+ * Default: true
+ *
+ * @return boolean Return false if no command especified
+ */
+ public function write($command, $param2 = true)
+ {
+ if ($command) {
+ $data = explode("\n", $command);
+ foreach ($data as $com) {
+ $com = trim($com);
+ fwrite($this->socket, $this->encodeLength(strlen($com)) . $com);
+ $this->debug('<<< [' . strlen($com) . '] ' . $com);
+ }
+
+ if (gettype($param2) == 'integer') {
+ fwrite($this->socket, $this->encodeLength(strlen('.tag=' . $param2)) . '.tag=' . $param2 . chr(0));
+ $this->debug('<<< [' . strlen('.tag=' . $param2) . '] .tag=' . $param2);
+ } elseif (gettype($param2) == 'boolean') {
+ fwrite($this->socket, ($param2 ? chr(0) : ''));
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ /**
+ * Write (send) data to Router OS
+ *
+ * @param string $com A string with the command to send
+ * @param array $arr An array with arguments or queries
+ *
+ * @return array Array with parsed
+ */
+ public function comm($com, $arr = array())
+ {
+ $count = count($arr);
+ $this->write($com, !$arr);
+ $i = 0;
+ if ($this->isIterable($arr)) {
+ foreach ($arr as $k => $v) {
+ switch ($k[0]) {
+ case "?":
+ $el = "$k=$v";
+ break;
+ case "~":
+ $el = "$k~$v";
+ break;
+ default:
+ $el = "=$k=$v";
+ break;
+ }
+
+ $last = ($i++ == $count - 1);
+ $this->write($el, $last);
+ }
+ }
+
+ return $this->read();
+ }
+
+ /**
+ * Standard destructor
+ *
+ * @return void
+ */
+ public function __destruct()
+ {
+ $this->disconnect();
+ }
+}
diff --git a/routers.php b/routers.php
new file mode 100755
index 0000000..085be09
--- /dev/null
+++ b/routers.php
@@ -0,0 +1,251 @@
+
+
+
+
+
+
+
+
+
+
+
+connect_error or $conn_2->connect_error) {
+ die("Connection failed: " . $conn_1->connect_error . " "
+ . $conn_2->connect_error);
+ }
+
+ $sql_1 = "select radsecret from radlogin where id = 1";
+ $result = $conn_1->query($sql_1);
+ $row = $result->fetch_assoc();
+ $secret = $row["radsecret"];
+ $sql_2 = "insert into nas (nasname, secret, shortname) values " .
+ "(\"$addr\", \"$secret\", \"$name\")";
+
+ if ($conn_2->query($sql_2) == FALSE) {
+ $msg = "
Error adding router
";
+ } else {
+ $msg = "Router added
";
+ }
+
+ $conn_1->close();
+ $conn_2->close();
+}
+?>
+
+
+
+ROUTERS
+
+
+
+
+
+
+
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+ $sql_2 = "select * from login where id = 1";
+ $result = $conn_1->query($sql_2);
+ $row = $result->fetch_assoc();
+ $login_result = ftp_login($conn_id, $row["username"], $row["password"]);
+ if (ftp_put($conn_id, $trg_file_path,
+ "/var/www/html/init/" . $login_file, FTP_ASCII)) {
+ echo "
+ Successfully uploaded your login page to router
";
+ } else {
+ echo "
+ There was a problem while uploading your login page to router
+
";
+ }
+ $conn_1->close();
+ ftp_close($conn_id);
+}
+
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $addr = $_POST["router_addr"];
+ if(isset($msg)) {echo $msg;}
+ uploadMikLoginPage($addr, "login.html");
+}
+ $servername = "localhost";
+ $username = "radius";
+ $password = "radpass";
+ $dbname = "radius";
+
+
+ $conn = new mysqli($servername, $username, $password, $dbname);
+
+ if ($conn->connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+
+ $sql_2 = "select nasname, shortname from nas";
+ $result = $conn->query($sql_2);
+
+ echo "ROUTERS ADDED
";
+
+ echo "";
+
+ echo "";
+ echo "ROUTER NAME | ";
+ echo "ROUTER ADDRESS | ";
+ echo "
";
+
+ if ($result->num_rows > 0) {
+ while($row = $result->fetch_assoc()) {
+ echo "";
+ echo "" . $row["shortname"] . " | ";
+ echo "" . $row["nasname"] . " | ";
+ echo "
";
+ }
+ } else {
+ echo "";
+ echo " --- | ";
+ echo " --- | ";
+ echo "
";
+ }
+
+ echo "
";
+
+ $conn->close();
+
+?>
+
+
+
+
diff --git a/script.js b/script.js
new file mode 100755
index 0000000..4eb0c60
--- /dev/null
+++ b/script.js
@@ -0,0 +1,2 @@
+document.getElementById("form").innerHTML = "";
+document.getElementById("script").innerHTML = "";
diff --git a/setup_one_hotspot.php b/setup_one_hotspot.php
new file mode 100755
index 0000000..d83f4b1
--- /dev/null
+++ b/setup_one_hotspot.php
@@ -0,0 +1,112 @@
+;
+
+
+
+
+
+
+
+
+
+= 22 and $octs[4] <= 29
+ and checkOctet_bool($octs[0]) and checkOctet_bool($octs[1])
+ and checkOctet_bool($octs[2]) and checkOctet_bool($octs[3])) {
+ $conn = new mysqli("localhost", "mgt", "admin_mgt", "manager_db");
+ if ($conn->connection_error) {
+ die("Connection failed: " . $conn->connection_error);
+ }
+ $result = $conn->query("select * from login where id = 1");
+ $row = $result->fetch_assoc();
+ setup($_POST["router_addr"], $row["username"], $row["password"]);
+ $conn->close();
+ } else {
+ $msg = "
+ Invalid subnet mask or network
";
+ }
+}
+?>
+
+
+
+
+
+
+HOTSPOT CREATED WITH THE FOLLOWING SETTINGS";
+ echo "";
+
+ echo "";
+ echo "HOTSPOT NAME | ";
+ echo "HOTSPOT ADDRESS | ";
+ echo "
";
+
+ echo "";
+ echo "" . $_POST["hs_ssid"] . " | ";
+ echo "" . $_POST["hs_net"]. " | ";
+ echo "
";
+
+ echo "
";
+
+ echo '
+
+
+
+
+
diff --git a/tutorial.php b/tutorial.php
new file mode 100755
index 0000000..bcc4db9
--- /dev/null
+++ b/tutorial.php
@@ -0,0 +1,119 @@
+
+
+
+
+
+
+
+
+
+
+TUTORIAL
+HOW TO SETUP A HOTSPOT
+
+STEP 1: ADD A MIKROTIK ROUTER TO THIS WEB INTERFACE
+ Click "Routers" on the menu above. Go to the "ADD ROUTER" section.
+
Type in the IP address of the router you want to add,
+ for example 10.10.1.1.
+ Next, type in the Name of that router.
+ This could be anything you want, for example "Conference Hall Hotspot".
+ Lastly, type in the RADIUS secret. This is a secret password which
+ your router uses for authentication from the RADIUS server. Without it,
+ your router will not be able to provide internet to your users.
+ We recommend setting a secure password.
+ Click ADD when done.
+ You will see your added router at the bottom of that page.
+
+
+
+
+
diff --git a/upload_Logo.php b/upload_Logo.php
new file mode 100755
index 0000000..784d054
--- /dev/null
+++ b/upload_Logo.php
@@ -0,0 +1,85 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+ $sql = "select * from login where id = 1";
+ $result = $conn->query($sql);
+ $row = $result->fetch_assoc();
+ $login_result = ftp_login($conn_id, $row["username"], $row["password"]);
+ if (ftp_put($conn_id, $trg_file_path,
+ "/var/www/html/logo/" . $logo_file, FTP_BINARY)) {
+ echo "Successfully uploaded your logo to router " . $router_addr . "\n\n";
+ } else {
+ echo "There was a problem uploading your logo to router " . $router_addr .
+ "\n\n";
+ }
+ $conn->close();
+ ftp_close($conn_id);
+}
+
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $target_dir = "logo/";
+ $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
+ $uploadOk = 1;
+ $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
+ // Check if image file is a actual image or fake image
+ if(isset($_POST["submit"])) {
+ $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
+ if($check !== false) {
+ echo "File is an image - " . $check["mime"] . ".";
+ $uploadOk = 1;
+ } else {
+ echo "File is not an image.";
+ $uploadOk = 0;
+ }
+ }
+ // Check if file already exists
+ if (file_exists($target_file)) {
+ echo "Sorry, the logo already exists.";
+ $uploadOk = 0;
+ }
+ // Check file size
+ $KiB = 1024;
+ if ($_FILES["fileToUpload"]["size"] > (500 * $KiB)) {
+ echo "Sorry, your file is too large.";
+ $uploadOk = 0;
+ }
+ // Allow only PNG file format
+ if($imageFileType != "png") {
+ echo "Sorry, only PNG files are allowed.";
+ $uploadOk = 0;
+ }
+ // Check if $uploadOk is set to 0 by an error
+ if ($uploadOk == 0) {
+ echo "Sorry, your logo was not uploaded.";
+ // if everything is ok, try to upload file
+ } else {
+ if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
+ $target_file)) {
+ rename($target_file, $target_dir . "company_logo.png");
+ $conn = new mysqli("localhost", "radius", "radpass", "radius");
+ if ($conn->connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+ $sql_1 = "select nasname from nas";
+ $result = $conn->query($sql_1);
+ if ($result->num_rows > 0) {
+ while($row = $result->fetch_assoc()) {
+ uploadMikLogo($row["nasname"], "company_logo.png");
+ }
+ }
+ echo "Successfully uploaded your logo to Web UI.\n\n";
+ $conn->close();
+ header("Location: general_settings.php");
+ } else {
+ echo "There was an problem while uploading your logo to Web UI.\n\n";
+ }
+ }
+
+}
+?>
+
diff --git a/upload_logo.php b/upload_logo.php
new file mode 100755
index 0000000..8ac9799
--- /dev/null
+++ b/upload_logo.php
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+
+
+
+
+UPLOAD CUSTOM LOGO
+
+
+ (500 * $KiB)) {
+ echo "Sorry, your file is too large.";
+ $uploadOk = 0;
+ }
+ // Allow only PNG file format
+ if($imageFileType != "png") {
+ echo "Sorry, only PNG files are allowed.";
+ $uploadOk = 0;
+ }
+ // Check if $uploadOk is set to 0 by an error
+ if ($uploadOk == 0) {
+ echo "Sorry, your logo was not uploaded.";
+ // if everything is ok, try to upload file
+ } else {
+ if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
+ $target_file)) {
+ rename($target_file, $target_dir . "company_logo.png");
+ $conn = new mysqli("localhost", "radius", "radpass", "radius");
+ if ($conn->connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+ $sql_1 = "select nasname from nas";
+ $result = $conn->query($sql_1);
+ if ($result->num_rows > 0) {
+ while($row = $result->fetch_assoc()) {
+ uploadMikLogo($row["nasname"], "company_logo.png");
+ }
+ }
+ echo "Successfully uploaded your logo to Web UI.";
+ $conn->close();
+ } else {
+ echo "There was an problem while uploading your logo to Web UI.";
+ }
+ }
+
+}
+?>
+
+
diff --git a/vouchers.php b/vouchers.php
new file mode 100755
index 0000000..346c67b
--- /dev/null
+++ b/vouchers.php
@@ -0,0 +1,176 @@
+
+
+
+
+
+
+
+
+
+
+VOUCHERS
+
+
+
+
+
+
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+
+ $sql_1 = "drop table radcheck";
+ $sql_2 = "drop table radusergroup";
+
+ if ($conn->query($sql_1) == FALSE & $conn->query($sql_2) == FALSE) {
+ die("Query \"$sql_1\" or \"$sql_2\" failed!");
+ } else {
+ $sql_3 = "CREATE TABLE radcheck (
+ id int(11) unsigned NOT NULL auto_increment,
+ username varchar(64) NOT NULL default '',
+ attribute varchar(64) NOT NULL default '',
+ op char(2) NOT NULL DEFAULT '==',
+ value varchar(253) NOT NULL default '',
+ PRIMARY KEY (id),
+ KEY username (username(32))
+ )";
+ $sql_4 = "CREATE TABLE radusergroup (
+ username varchar(64) NOT NULL default '',
+ groupname varchar(64) NOT NULL default '',
+ priority int(11) NOT NULL default '1',
+ KEY username (username(32))
+ )";
+ if ($conn->query($sql_3) == FALSE & $conn->query($sql_4) == FALSE) {
+ die("Query \"$sql_3\" or \"$sql_4\" failed!");
+ } else {
+ echo "
+ Vouchers flushed!
+
";
+ }
+ }
+
+ $conn->close();
+
+}
+?>
+
+
+
+