Skip to content

Commit

Permalink
remove local ip detection (outdated), add translation to en for other…
Browse files Browse the repository at this point in the history
… languages than de, add browser language detection
  • Loading branch information
sebastianhegge committed Apr 23, 2020
1 parent 7dfcd4b commit 4edf424
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 70 deletions.
31 changes: 18 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
]
];

$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if($lang != 'de'){
$lang = 'en';
}

if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'curl')!==false){
print($_SERVER['REMOTE_ADDR']."\n");
if($_SERVER['REMOTE_ADDR'] != gethostbyaddr($_SERVER['REMOTE_ADDR'])){
Expand All @@ -25,7 +30,7 @@
else {
?>
<!doctype html>
<html lang="de">
<html lang="<?php print($lang); ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
Expand All @@ -51,7 +56,7 @@
<table class="table table-striped">
<tbody>
<tr>
<th scope="row">Verbindung über:</th>
<th scope="row"><?php print(($lang == 'de')?('Verbindung über'):('Connection via')); ?>:</th>
<td id="content-ip-version"><?php if(strpos($_SERVER['REMOTE_ADDR'], ":")){print('IPv6');} else{print('IPv4');} ?></td>
</tr>
<tr>
Expand All @@ -62,34 +67,34 @@
<th scope="row">EDNS-Subnetz:</th>
<td id="content-edns"><img src="loader.gif" width="16" height="16" id="loader-dns"></td>
</tr>
<tr>
<th scope="row">Lokale IPs:</th>
<td id="content-local-ip"><img src="loader.gif" width="16" height="16" id="loader-local-ip"></td>
</tr>
<tr>
<th scope="row">MTU:</th>
<td id="content-mtu"><img src="loader.gif" width="16" height="16" id="loader-mtu"></td>
</tr>
<tr>
<th scope="row">Anschluss-Typ:</th>
<th scope="row"><?php print(($lang == 'de')?('Anschluss-Typ'):('Connection type')); ?>:</th>
<td id="content-link-type"><img src="loader.gif" width="16" height="16" id="loader-link-type"></td>
</tr>
<tr>
<th scope="row">User-Agent:</th>
<td id="content-user-agent"><small><?php print($_SERVER['HTTP_USER_AGENT']); ?></small></td>
</tr>
<tr>
<th scope="row">Geräte-Typ:</th>
<td id="content-os"><?php print($browscap_translation['device_type'][$browscap['device_type']]); ?></td>
<th scope="row"><?php print(($lang == 'de')?('Geräte-Typ'):('Device type')); ?>:</th>
<td id="content-os"><?php print(($lang == 'de')?($browscap_translation['device_type'][$browscap['device_type']]):($browscap['device_type'])); ?></td>
</tr>
<tr>
<th scope="row">Betriebssystem:</th>
<th scope="row"><?php print(($lang == 'de')?('Betriebssystem'):('Operating system')); ?>:</th>
<td id="content-os"><?php print($browscap['platform']); ?></td>
</tr>
<tr>
<th scope="row">Browser:</th>
<td id="content-os"><?php print($browscap['browser']); ?></td>
</tr>
<tr>
<th scope="row"><?php print(($lang == 'de')?('Sprache'):('Language')); ?>:</th>
<td id="content-os"><?php print(locale_get_display_language(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2))); ?> <img src="flags/<?php print(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)); ?>.svg" width="20" height="16" style="margin-bottom: 2px;"></td>
</tr>
</tbody>
</table>
</div>
Expand All @@ -112,7 +117,7 @@
<td id="content-ipv4-hostname"><img src="loader.gif" width="16" height="16" id="loader-ipv4-hostname"></td>
</tr>
<tr>
<th scope="row">IP-Netz:</th>
<th scope="row"><?php print(($lang == 'de')?('IP-Netz'):('IP network')); ?>:</th>
<td id="content-ipv4-ip-network"><img src="loader.gif" width="16" height="16" id="loader-ipv4-ip"></td>
</tr>
<tr>
Expand Down Expand Up @@ -147,7 +152,7 @@
<td id="content-ipv6-hostname"><img src="loader.gif" width="16" height="16" id="loader-ipv6-hostname"></td>
</tr>
<tr>
<th scope="row">IP-Netz:</th>
<th scope="row"><?php print(($lang == 'de')?('IP-Netz'):('IP network')); ?>:</th>
<td id="content-ipv6-ip-network"><img src="loader.gif" width="16" height="16" id="loader-ipv6-ip"></td>
</tr>
<tr>
Expand All @@ -168,7 +173,7 @@
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="card mt-4">
<div class="card-header card-header-no-border text-center">
&copy; Sebastian Hegge &middot; <a href="https://heg.ge/impressum" target="_blank">Impressum & Datenschutz</a> &middot; <a href="https://github.com/sebastianhegge/iptest" target="_blank">Source on GitHub</a> &middot; v2.1
&copy; Sebastian Hegge &middot; <a href="https://heg.ge/impressum" target="_blank"><?php print(($lang == 'de')?('Impressum & Datenschutz'):('Imprint & Privacy policy')); ?></a> &middot; <a href="https://github.com/sebastianhegge/iptest" target="_blank"><?php print(($lang == 'de')?('Quellcode auf GitHub'):('Source on GitHub')); ?></a> &middot; v2.2
</div>
</div>
</div>
Expand Down
86 changes: 29 additions & 57 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,39 @@ function init_map_ipv6(lat, lng) {
}

function translate_link_type(link_type){
link_types = {
'Ethernet or modem': 'Netzwerk oder Modem (vermutlich)',
'PPPoE': 'PPPoE (vermutlich)',
'L2TP': 'L2TP oder PPPoE (vermutlich)',
'GIF': 'GIF (vermutlich)',
'Probably IPsec or other VPN': 'IPsec oder anderes VPN (vermutlich)',
'generic tunnel or VPN': 'Generischer Tunnel, VPN oder LTE (vermutlich)',
'IPSec or GRE': 'IPSec oder Generic Routing Encapsulation (vermutlich)',
'IPIP or SIT': 'IPIP oder SIT (vermutlich)',
'': '-'
var lang = navigator.language || navigator.userLanguage;
lang = lang.substr(0,2);
if(lang == 'de'){
var link_types = {
'Ethernet or modem': 'Netzwerk oder Modem',
'L2TP': 'L2TP oder PPPoE',
'Probably IPsec or other VPN': 'IPsec oder anderes VPN',
'generic tunnel or VPN': 'Generischer Tunnel, VPN oder LTE',
'IPSec or GRE': 'IPSec oder Generic Routing Encapsulation',
'IPIP or SIT': 'IPIP oder SIT',
'': '-'
}
} else {
var link_types = {
'Ethernet or modem': 'Netzwerk or Modem',
'L2TP': 'L2TP or PPPoE',
'Probably IPsec or other VPN': 'IPsec or other VPN',
'generic tunnel or VPN': 'Generic Tunnel, VPN or LTE',
'IPSec or GRE': 'IPSec or Generic Routing Encapsulation',
'': '-'
}
}
if(lang == 'de'){
var probably = ' (vermutlich)';
} else {
var probably = ' (probably)';
}

if (link_types[link_type] == undefined){
return link_type + ' (vermutlich)';
return link_type + probably;
}
else{
return link_types[link_type];
return link_types[link_type] + probably;
}
}

Expand Down Expand Up @@ -159,7 +176,6 @@ $(document).ready(function(){
});

get_dns_data();
get_local_ip();
get_fingerprint();

function get_ipv4_host() {
Expand Down Expand Up @@ -310,48 +326,4 @@ $(document).ready(function(){
}
});
};

function get_local_ip() {
var RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
if (RTCPeerConnection) (function () {
var rtc = new RTCPeerConnection({iceServers:[]});
if (1 || window.mozRTCPeerConnection) {
rtc.createDataChannel('', {reliable:false});
};

rtc.onicecandidate = function (evt) {
if (evt.candidate) grepSDP('a='+evt.candidate.candidate);
};
rtc.createOffer(function (offerDesc) {
grepSDP(offerDesc.sdp);
rtc.setLocalDescription(offerDesc);
}, function (e) { console.warn('offer failed', e); });

var addrs = [];
function updateDisplay(newAddr) {
if (newAddr != '0.0.0.0' && newAddr.indexOf('-') == -1 && addrs.indexOf(newAddr) == -1) {
addrs.push(newAddr);
}
$('#content-local-ip').text(addrs.join(', ') || '-');
}

function grepSDP(sdp) {
var hosts = [];
sdp.split('\r\n').forEach(function (line) {
if (~line.indexOf('a=candidate')) {
var parts = line.split(' '),
addr = parts[4],
type = parts[7];
if (type === 'host') updateDisplay(addr);
} else if (~line.indexOf('c=')) {
var parts = line.split(' '),
addr = parts[2];
updateDisplay(addr);
}
});
}
})(); else {
$('#content-local-ip').text('-');
}
};
});

0 comments on commit 4edf424

Please sign in to comment.