Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('Europe/Prague');
- ini_set('default_charset', 'utf-8');
- $okCode = 200;
- $dnsAppUrl = "http://10.0.2.2:8081";
- $domainUrl = "http://localhost:8080/blog";
- $loginPage = "login.php";
- $dnsToken = "xPseeDmvOCdchhodBBGOLaTLe+2SPLLQesAsZdq9JPTgCaOTsvdS/yf+chTWMLyHIYhJbBUUGeIXyvqT6y4f4GnFJNVHP9cLkSDLt5wO7LBTaHI9L36wNBOgBgRRrnbFHqpWsQmeBayTCBO7LPLch0k5XtEYd2DTCx0V7R3zwnWUKjQYNZTNFpl+JBfAC836kWKpy/1Dh28w5DXPfkc1OyWWo0SaNXjZheboTEEeMpN2thuu3moQ52WhWeqfEnaiK0RvwAS9o8wT/bMmmQpaRgU94giEvpQjsIBvDpIZo+4BcZ1qppD8HT5mOtPDgoqeOhBzxd/cxxjP8PIo0MGQ4A==";
- $separator = "/";
- $checkUser = "checkAll";
- $checkPublic = "checkPublicIp";
- $checkLogin = "checkLogin";
- $headerToken = "DNS-TOKEN: ";
- $message = "Not logged";
- $password = "12345";
- $dir = "logs";
- if (isset($_POST['login'])) {
- require_once 'DnsCall.php';
- $dns = new DnsCall($dnsAppUrl, $headerToken, $dnsToken);
- $publicIp = $_COOKIE['publicIP'];
- $privateIp = $_COOKIE['privateIP'];
- $login = $_POST['username'];
- if (empty($publicIp)) {
- $responseCode = $dns->checkLogin($login);
- } elseif (!empty($publicIp)) {
- if (empty($privateIp)) {
- $responseCode = $dns->checkLoginAndPublicIp($login, $publicIp);
- } else {
- $responseCode = $dns->checkUser($login, $publicIp, $privateIp);
- }
- }
- if ($responseCode == $okCode) {
- $message = "Banned";
- } else {
- if ($_POST['password'] != $password) {
- file_put_contents($dir . "/login.log", date("F j, Y, g:i:s a") . " POST 401 /login/auth login:" . $login . " public Ip:" . $publicIp . " " . "private Ip:" . $privateIp . "\n", FILE_APPEND);
- $message = "Wrong password";
- } else {
- $message = "Logged";
- }
- }
- }
- ?>
- <html>
- <head>
- <meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">
- <link rel="stylesheet" href="style.css" type="text/css" >
- <title>Login page</title>
- </head>
- <body background="blue.jpg">
- <div class="LoginPanel">
- <form name="login" method="POST" action="">
- <fieldset>
- <label for="username">Login</label>
- <input type="text" id="username" name="username" placeholder="login" value="" />
- <br/>
- <label for="password">Heslo</label>
- <input type="password" id="password" name="password" placeholder="password" value="" />
- <br/>
- <iframe name="test" id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
- <br/>
- <br/>
- <input type="submit" name="login" accept-charset="utf-8" id="submit" value="Log in" />
- <label id="banned" class="errorMsg"><?php echo $message ?></label>
- </fieldset>
- </form>
- </div>
- </body>
- <script>
- function getUserIps(callback) {
- var publicAndPrivateIp = [];
- window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; //compatibility for firefox and chrome
- noop = function () {
- };
- var mediaConstraints = {
- optional: [{RtpDataChannels: true}]
- };
- var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
- //construct a new RTCPeerConnection
- var pc = new RTCPeerConnection(servers, mediaConstraints);
- pc.createDataChannel(""); //create a bogus data channel
- pc.createOffer(function (result) {
- //trigger the stun server request
- pc.setLocalDescription(result, function () {
- }, function () {
- });
- }, function () {
- });
- pc.onicecandidate = function (ice) { //listen for candidate events
- if (!ice || !ice.candidate || !ice.candidate.candidate) return;
- parseIp(ice.candidate.candidate);
- setTimeout(function () {
- //read candidate info from local description
- var lines = pc.localDescription.sdp.split('\n');
- lines.forEach(function (line) {
- if (line.indexOf('a=candidate:') === 0)
- parseIp(line);
- });
- }, 1000);
- pc.onicecandidate = noop;
- };
- function parseIp(ip) {
- var myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ip)[1];
- console.log('my IP: ', myIP);
- console.log(publicAndPrivateIp);
- if (!isValueInArray(myIP)) {
- callback(myIP);
- }
- publicAndPrivateIp.push(myIP);
- }
- function isValueInArray(value) {
- return publicAndPrivateIp.indexOf(value) > -1;
- }
- }
- getUserIps(function (ip) {
- if (!ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/)) {
- document.getElementById("public").value = ip;
- document.cookie = "publicIP = " + ip;
- }
- else {
- document.cookie = "privateIP = " + ip;
- }
- });
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement