From 39981857bff781dbf13d90173df37c84d9ed73f7 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 24 Jun 2023 00:27:57 +0000 Subject: [PATCH] Imported (not touched since 2020 lol) --- .gitattributes | 1 + .gitignore | 4 +++ LICENSE | 11 ++++++ README.md | 3 ++ index.html | 40 +++++++++++++++++++++ public/index.php | 82 ++++++++++++++++++++++++++++++++++++++++++ script.js | 87 ++++++++++++++++++++++++++++++++++++++++++++ style.css | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 321 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 index.html create mode 100644 public/index.php create mode 100644 script.js create mode 100644 style.css diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..49fdfe9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.debug +.DS_Store +[Tt]humbs.db +desktop.ini diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1c35b9a --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +Copyright (c) 2020-2023, flashwave + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f814dae --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# ip.flash.moe + +Utility for finding your IP quickly ! diff --git a/index.html b/index.html new file mode 100644 index 0000000..13191f7 --- /dev/null +++ b/index.html @@ -0,0 +1,40 @@ + + + + + Your IP Addresses + + + + + + +
+
+
+
+
Your IPv4 is
+
loading...
+
+
+
+
+
+
Your IPv6 is
+
loading...
+
+
+
+ + + diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..86b2958 --- /dev/null +++ b/public/index.php @@ -0,0 +1,82 @@ + $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/script.js b/script.js new file mode 100644 index 0000000..0fac93c --- /dev/null +++ b/script.js @@ -0,0 +1,87 @@ +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 || {}); diff --git a/style.css b/style.css new file mode 100644 index 0000000..2d82533 --- /dev/null +++ b/style.css @@ -0,0 +1,93 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; + position: relative; + outline-style: none; + user-select: none; +} + +html, +body { + width: 100%; + height: 100%; +} + +body { + font: 12px/20px Tahoma, Geneva, 'Dejavu Sans', Arial, Helvetica, sans-serif; + background-color: #111; + color: #fff; +} + +code { + font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; +} + +.fullscreen-overlay { + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + background-color: #000; + background-image: repeating-linear-gradient(-45deg, #440, #440 10px, #000 10px, #000 20px); + z-index: 20001; + display: flex; + justify-content: center; + align-items: center; +} + +.ipv4 { --ipv-colour: #437675; /*margin-left: 22px !important;*/ } +.ipv6 { --ipv-colour: #66678d; /*margin-left: -22px !important;*/ } + +.ipbox { + max-width: 600px; + width: 100%; + margin: 8px 0; + cursor: pointer; + filter: drop-shadow(0 1px 5px #000); +} +.ipbox-content { + padding: 5px 25px; + overflow: hidden; +} +.ipbox-title { + font-size: 1.4em; + line-height: 1.5em; +} +.ipbox-address { + font-size: 2em; + line-height: 1.3em; + font-family: 'Electrolize', Verdana, 'Dejavu Sans', Arial, Helvetica, sans-serif; + user-select: text; + overflow: hidden; + word-break: break-word; +} +.ipbox-background { + position: absolute; + top: 0; + left: 0; + width: calc(100% - 20px); + height: 100%; + background-image: linear-gradient(0deg, #1118 0%, #2228 50%, #3338 50%, #5558 100%); + transform: skew(-15deg); + background-color: var(--ipv-colour); + margin: 0 10px; +} +.ipbox:not(.nojs):active .ipbox-background { + background-image: linear-gradient(0deg, #1118 0%, #2228 50%, #3338 50%, #3338 100%); +} + +.boxgrid { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100%; + margin: 0 15px; +} + +.nojs { + --ipv-colour: #933; + cursor: not-allowed; +}