Imported (not touched since 2020 lol)

This commit is contained in:
flash 2023-06-24 00:27:57 +00:00
commit 39981857bf
8 changed files with 321 additions and 0 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
* text=auto

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.debug
.DS_Store
[Tt]humbs.db
desktop.ini

11
LICENSE Normal file
View file

@ -0,0 +1,11 @@
Copyright (c) 2020-2023, flashwave <me@flash.moe>
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.

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# ip.flash.moe
Utility for finding your IP quickly !

40
index.html Normal file
View file

@ -0,0 +1,40 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Your IP Addresses</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link href="/style.css" type="text/css" rel="stylesheet"/>
<link href="//flash.moe/css/electrolize/style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<noscript>
<div class="fullscreen-overlay">
<div class="ipbox nojs">
<div class="ipbox-background"></div>
<div class="ipbox-content">
<div class="ipbox-title">This Website</div>
<div class="ipbox-address">needs javascript</div>
</div>
</div>
</div>
</noscript>
<div class="boxgrid">
<div class="ipbox ipv4">
<div class="ipbox-background"></div>
<div class="ipbox-content">
<div class="ipbox-title">Your IPv4 is</div>
<div class="ipbox-address" data-ipv="4">loading...</div>
</div>
</div>
<div class="ipbox ipv6">
<div class="ipbox-background"></div>
<div class="ipbox-content">
<div class="ipbox-title">Your IPv6 is</div>
<div class="ipbox-address" data-ipv="6">loading...</div>
</div>
</div>
</div>
<script src="/script.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

82
public/index.php Normal file
View file

@ -0,0 +1,82 @@
<?php
if($_SERVER['REQUEST_METHOD'] !== 'GET') {
http_response_code(405);
header('Content-Type: text/plain');
echo 'Unsupported request method.';
return;
}
$reqPath = '/' . trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if($_SERVER['HTTP_HOST'] !== 'ip.flash.moe') {
$address = $_SERVER['REMOTE_ADDR'];
$version = (int)substr($_SERVER['HTTP_HOST'], 3, 1);
$packed = bin2hex(inet_pton($address));
if($reqPath === '/json') {
header('Access-Control-Allow-Origin: *');
header('Cache-Control: no-cache');
header('Content-Type: application/json; charset=utf-8');
echo json_encode([
'a' => $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.';

87
script.js Normal file
View file

@ -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 || {});

93
style.css Normal file
View file

@ -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;
}