From 3d6d5b87abfdfbb273faff4d8b7ca496d05dba13 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 24 Jun 2023 01:43:26 +0000 Subject: [PATCH] Removed PHP dependency and useless API-like endpoints, visual redo coming later, probably. --- nginx.conf | 12 +++++ index.html => public/index.html | 19 ++++--- public/index.php | 82 ------------------------------ public/script.js | 90 +++++++++++++++++++++++++++++++++ style.css => public/style.css | 4 +- script.js | 87 ------------------------------- 6 files changed, 113 insertions(+), 181 deletions(-) create mode 100644 nginx.conf rename index.html => public/index.html (68%) delete mode 100644 public/index.php create mode 100644 public/script.js rename style.css => public/style.css (93%) delete mode 100644 script.js diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..65612d2 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,12 @@ +server { + server_name ipv4.flash.moe ipv6.flash.moe; + + location / { + default_type 'text/plain; charset=utf-8'; + + add_header Access-Control-Allow-Origin '*'; + add_header Cache-Control 'no-cache'; + + return 200 $remote_addr; + } +} diff --git a/index.html b/public/index.html similarity index 68% rename from index.html rename to public/index.html index 13191f7..855337f 100644 --- a/index.html +++ b/public/index.html @@ -1,11 +1,10 @@ - + Your IP Addresses - - - + +
-
+
-
Your IPv4 is
-
loading...
+
Your IPv4 address is
+
loading...
-
+
-
Your IPv6 is
-
loading...
+
Your IPv6 address is
+
loading...
diff --git a/public/index.php b/public/index.php deleted file mode 100644 index 86b2958..0000000 --- a/public/index.php +++ /dev/null @@ -1,82 +0,0 @@ - $address, - 'h' => $packed, - 'v' => $version, - ]); - return; - } - - if($reqPath === '/xml') { - header('Access-Control-Allow-Origin: *'); - header('Cache-Control: no-cache'); - header('Content-Type: application/xml; charset=utf-8'); - $document = new DOMDocument('1.0', 'utf-8'); - $root = $document->appendChild(new DOMElement('IPAddress')); - $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); - $root->setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); - - $root->setAttribute('version', $version); - $root->setAttribute('packed', $packed); - $root->appendChild(new DOMText($address)); - - echo $document->saveXML(); - return; - } - - if($reqPath === '/packed') { - header('Access-Control-Allow-Origin: *'); - header('Cache-Control: no-cache'); - header('Content-Type: text/plain'); - echo $packed; - return; - } - - if($reqPath === '/') { - header('Access-Control-Allow-Origin: *'); - header('Cache-Control: no-cache'); - header('Content-Type: text/plain'); - echo $address; - return; - } -} else { - if($reqPath === '/style.css') { - header('Content-Type: text/css; charset=utf-8'); - echo file_get_contents(__DIR__ . '/../style.css'); - return; - } - - if($reqPath === '/script.js') { - header('Content-Type: application/javascript; charset=utf-8'); - echo file_get_contents(__DIR__ . '/../script.js'); - return; - } - - if($reqPath === '/') { - header('Content-Type: text/html; charset=utf-8'); - echo file_get_contents(__DIR__ . '/../index.html'); - return; - } -} - -http_response_code(404); -header('Content-Type: text/plain'); -echo 'Path not found.'; diff --git a/public/script.js b/public/script.js new file mode 100644 index 0000000..5158f36 --- /dev/null +++ b/public/script.js @@ -0,0 +1,90 @@ +var createXHR = function() { + if('all' in document && !('atob' in window) && 'XDomainRequest' in window) + return new XDomainRequest; + + if('XMLHttpRequest' in window) + return new XMLHttpRequest; + + if('ActiveXObject' in window) + try { + return new ActiveXObject('Msxml2.XMLHTTP'); + } catch(e) { + try { + return new ActiveXObject('Microsoft.XMLHTTP'); + } catch(e) {} + } + + return null; +} + +var getRemoteString = function(url, callback) { + var xhr = createXHR(); + xhr.onload = function(ev) { + callback({ success: true, info: ev, text: xhr.responseText }); + }; + xhr.onerror = function(ev) { + callback({ success: false, info: ev }); + }; + xhr.open('GET', url); + xhr.send(); +}; + +var selectTextInElement = function(target) { + // MSIE + if(document.body.createTextRange) { + var range = document.body.createTextRange(); + range.moveToElementText(target); + range.select(); + return; + } + + // Mozilla + if(window.getSelection) { + var select = window.getSelection(), + range = document.createRange(); + range.selectNodeContents(target); + select.removeAllRanges(); + select.addRange(range); + return; + } +}; + +var copySelectedText = function() { + if(document.execCommand) { + document.execCommand('copy'); + return; + } +}; + +(function() { + var fields = [ + { target: 'ipv4', ext: 'v4', clickTarget: 'ipv4-click' }, + { target: 'ipv6', ext: 'v6', clickTarget: 'ipv6-click' }, + ]; + + for(var i in fields) + (function(field) { + var host = location.host.split('.'); + host[0] += field.ext; + var url = location.protocol + '//' + host.join('.') + '/'; + + getRemoteString(url, function(info) { + var target = document.getElementById(field.target), + prop = 'textContent' in target ? 'textContent' : 'innerText'; + + if(info.success) { + target[prop] = info.text; + + if(field.clickTarget) { + var clickTarget = document.getElementById(field.clickTarget); + if(clickTarget) + clickTarget.onclick = function() { + selectTextInElement(target); + copySelectedText(); + }; + } + } else + target[prop] = 'not available'; + }); + })(fields[i]); +})(); diff --git a/style.css b/public/style.css similarity index 93% rename from style.css rename to public/style.css index 2d82533..7847e04 100644 --- a/style.css +++ b/public/style.css @@ -37,8 +37,8 @@ code { align-items: center; } -.ipv4 { --ipv-colour: #437675; /*margin-left: 22px !important;*/ } -.ipv6 { --ipv-colour: #66678d; /*margin-left: -22px !important;*/ } +.ipv4 { --ipv-colour: #437675; margin-left: 22px !important; } +.ipv6 { --ipv-colour: #66678d; margin-left: -22px !important; } .ipbox { max-width: 600px; diff --git a/script.js b/script.js deleted file mode 100644 index 0fac93c..0000000 --- a/script.js +++ /dev/null @@ -1,87 +0,0 @@ -window.fwip = (function() { - this.ipv4s = document.querySelectorAll('[data-ipv="4"]'); - this.ipv6s = document.querySelectorAll('[data-ipv="6"]'); - - this.doAddressLookup = function(version, callback) { - version = parseInt(version || 4).toString(); - var url = '//ipv' + version + '.flash.moe/json'; - - fetch(url) - .then(resp => resp.json()) - .then(data => callback(data)) - .catch(err => callback({error: 'not available'})); - }; - - var lookupCallback = function(set) { - return function(result) { - for(var i = 0; i < set.length; ++i) { - if(!result.a) - set[i].classList.add('ip-lookup-failed'); - else { - var copyTarget = set[i], - clickTarget = set[i].parentNode.parentNode; - clickTarget.onclick = function() { this.doAddressCopy(copyTarget) }.bind(this); - } - set[i].textContent = result.a || result.error || 'gone'; - } - }.bind(this); - }.bind(this); - - this.doAddressLookup(4, lookupCallback(this.ipv4s)); - this.doAddressLookup(6, lookupCallback(this.ipv6s)); - - this.selectTextInElement = function(elem) { - // MSIE - if(document.body.createTextRange) { - var range = document.body.createTextRange(); - range.moveToElementText(elem); - range.select(); - return; - } - - // Mozilla - if(window.getSelection) { - var select = window.getSelection(), - range = document.createRange(); - range.selectNodeContents(elem); - select.removeAllRanges(); - select.addRange(range); - return; - } - - console.warn('Unable to select text.'); - }; - - this.copySelectedText = function() { - if(document.execCommand) { - document.execCommand('copy'); - return; - } - - console.warn('Unable to copy text.'); - }; - - this.selectNothing = function() { - // MSIE - if(document.body.createTextRange) { - document.body.createTextRange().select(); - return; - } - - // Mozilla - if(window.getSelection) { - window.getSelection().removeAllRanges(); - return; - } - - console.warn('Unable to select text.'); - }; - - this.doAddressCopy = function(elem) { - this.selectTextInElement(elem); - this.copySelectedText(); - //this.selectNothing(); - }; - - return this; -}).call(window.fwip || {});