commit 069a2115289913fdf7ea5ef3e82b4ecd2d687cf7 Author: Bram Prieshof Date: Sun Jul 9 02:03:41 2023 +0200 inital commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b23222 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# ignore accidentally generated vendor directory and composer.lock file, just in case... +/vendor/ +/composer.lock +# Ignore personal config file +config.php \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..087f4ca --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "brammp/basic-external-unifi-portal", + "description": "Basic Unifi Portal", + "type": "project", + "require": { + "art-of-wifi/unifi-api-client": "^1.1" + }, + "license": [ + "Unlicense" + ], + "authors": [ + { + "name": "brammp", + "email": "bram@bprieshof.nl" + } + ] +} diff --git a/config.example.php b/config.example.php new file mode 100644 index 0000000..d2cd571 --- /dev/null +++ b/config.example.php @@ -0,0 +1,8 @@ +:8443'); +define('controllerValidateSSL',false); +define('siteId','default'); +define('controllerVersion','7.4.156'); \ No newline at end of file diff --git a/public/auth.php b/public/auth.php new file mode 100644 index 0000000..00dd87b --- /dev/null +++ b/public/auth.php @@ -0,0 +1,57 @@ +login(); + + +// authorize_guest Params: DeviceMac ExpireTime(Minutes) UploadSpeedLimit DownloadSpeedLimit DataCap ApMac +//Send AuthRequest +$auth_result = $unifi_connection->authorize_guest($clientMac, '2000', $uploadSpeed, $downloadSpeed, null, $apMac); + +//Check if unsucsessfull +if ($auth_result == false) { + http_response_code(500); +} + +//provide feedback in json format +//error_log (json_encode($auth_result, JSON_PRETTY_PRINT)); diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..eee4ba1 --- /dev/null +++ b/public/css/style.css @@ -0,0 +1,110 @@ +.loginPage { + padding: 8% 0 0; + margin: auto; + max-width: 600px + } + +.form { + position: relative; + z-index: 1; + background: #FFFFFF; + margin: 0 auto 100px; + padding: 45px; + text-align: center; + border-radius: 20px; + box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24); +} +.form input { + border-radius: 5px; + outline: 0; + background: #f2f2f2; + width: 100%; + border: 0; + margin: 0 0 15px; + padding: 20px; + box-sizing: border-box; + font-size: 18px; +} +.button { + position: relative; + outline: 0; + background: #0081ff; + width: 100%; + border: 0; + padding: 15px; + color: #FFFFFF; + border-radius: 50px; + font-size: 20px; + -webkit-transition: all 0.3 ease; + transition: all 0.3 ease; + cursor: pointer; +} +.button:hover,.button:active,button:focus { + background: #0000ff; +} +.button:disabled { + background: gray; +} + +.buttonText { + color: #ffffff; + transition: all 0.2s; +} + +.buttonLoading .buttonText { + visibility: hidden; + opacity: 0; +} + +.buttonLoading::after { + content: ""; + position: absolute; + width: 20px; + height: 20px; + top: 0; + left: 0; + right: 0; + bottom: 0; + margin: auto; + border: 4px solid transparent; + border-top-color: #ffffff; + border-radius: 50%; + animation: button-loading-spinner 1s linear infinite; +} + +@keyframes button-loading-spinner { + from { + transform: rotate(0turn); + } + to { + transform: rotate(1turn); + } +} + +#responseMessage { + color: red; + font-weight: bold; +} + +body { + background: #090979; /* fallback for old browsers */ + background: rgb(9,9,121); + background: linear-gradient(90deg, rgba(0,129,255,100) 0%, rgba(9,9,121,1) 50%); + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + font-family: Arial, Helvetica, sans-serif; + font-size: 18px; +} + +@media only screen and (max-width: 1000px), only screen and (max-device-width: 1000px){ + .button { + font-size: 40px; + } + .form input, body { + font-size: 35px; + } + .buttonLoading::after { + width: 40px; + height: 40px; + } +} diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..22f6148 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..604fa74 --- /dev/null +++ b/public/index.php @@ -0,0 +1,35 @@ + + + + +Portal + + + +
+ +

Welcome

+

Connecting to:" . htmlspecialchars(trim($_GET['ssid'])) ."

+

+ + + +
"; + } else { + // URL parameter does not exist + echo '

Something went wrong

'; + http_response_code(400); + } + ?> + + + diff --git a/public/js/app.js b/public/js/app.js new file mode 100644 index 0000000..27c4e48 --- /dev/null +++ b/public/js/app.js @@ -0,0 +1,69 @@ +// Retrieving the form data +var accesCode = document.getElementById("accesCode"); +var submitButton = document.getElementById("submitButton"); +var responseMessage = document.getElementById("responseMessage") +var redirectURL = document.getElementById("redirectURL").value +//var redirectURL = "https://Domain.tld/page" +var buttonLocked = false + +function submitFormAjax() { + if (buttonLocked === true){return}; + buttonLocked = true + responseMessage.innerHTML = "" + submitButton.classList.add("buttonLoading"); + if(accesCode == ""){ + responseMessage.innerHTML = "

Please enter your accesCode.

"; + return; + } + submitButton.disabled = true; + accesCode.disabled = true; + var xmlhttp = new XMLHttpRequest(); + + // Instantiating the request object + xmlhttp.open("POST", "auth.php", true); + // Defining event listener for readystatechange event + xmlhttp.onreadystatechange = function() { + console.log(this.readyState + " status:" + this.status) + if (this.readyState === 4 && this.status === 200) { + submitButton.classList.remove("buttonLoading"); + submitButton.style.backgroundColor = "green"; + document.getElementById("buttonText").innerHTML = "Connected" + accesCode.style.display = "none"; + window.setTimeout(redirectUser, 1500); + }else { + if (this.readyState === 4 && this.status === 403) { + responseMessage.innerHTML = "Acces code incorrect"; + enableButton() + } else if (this.readyState === 4) { + responseMessage.innerHTML = "Something went wrong"; + enableButton() + } + } + } + //console.log (document.getElementById("accesCode").value); + var params = "accesCode=" + encodeURIComponent(accesCode.value) + "&apMac=" + encodeURIComponent(document.getElementById("apMac").value) + "&clientMac=" + encodeURIComponent(document.getElementById("clientMac").value); + + //Setting headers + xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + + // Sending the request to the server + xmlhttp.send(params); +} + +function enableButton(){ + buttonLocked = false + submitButton.disabled = false; + accesCode.disabled = false; + submitButton.classList.remove("buttonLoading"); + accesCode.focus(); +} + +function inputEntry(){ + if(accesCode.value != "") + submitButton.disabled = false; + else + submitButton.disabled = true; +} +function redirectUser(){ + window.location.href = redirectURL +} \ No newline at end of file diff --git a/public/js/favicon.ico b/public/js/favicon.ico new file mode 100644 index 0000000..22f6148 Binary files /dev/null and b/public/js/favicon.ico differ