<?php
function wake($ip, $mac, $port)
{
$mac = str_replace("-", "", $mac);
if(strlen($mac)<12) return false;
$mac = chr(hexdec(substr($mac,0,2))).chr(hexdec(substr($mac,2,2))).chr(hexdec(substr($mac,4,2))).chr(hexdec(substr($mac,6,2))).chr(hexdec(substr($mac,8,2))).chr(hexdec(substr($mac,10,2)));
$nic = fsockopen("udp://" . $ip, $port);
if($nic)
{
$packet = chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF);
$packet .= $mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac.$mac;
}
$ret = fwrite($nic, $packet);
fclose($nic);
if($ret) return true;
return false;
}
function loaddata($file)
{
if (file_exists($file))
{
$fp = fopen($file, "r");
$inhalt = fread ($fp, filesize($file));
fclose($fp);
$data=explode("\n",$inhalt);
return $data;
}
}
function savedata($file,$data,$password)
{
if (!((count($_GET) == 1) && isset($_GET['pw'])) && (count($_GET) > 0))
{
if (($password == "") || ($_GET['pw'] == $password))
{
if ($fp = fopen($file, "w"))
{
fwrite($fp,implode("\n",$data));
fclose($fp);
return true;
}
else return false;
}
else
{
header('Content-type: text/html; charset="utf-8"');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
echo '<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Externe IP-Adresse des DSL-Zugangs zuhause</title>
</head>
<body>
<h1>Zugriff verweigert! Werte nicht gespeichert!</h1>
</body>
</html>
';
exit(0);
}
}
}
function getparameters($data)
{
global $params;
if(isset($_GET['n'])) $counter = $_GET['n'];
if($counter == "") $counter = 1;
if($_GET['del']) $counter = $_GET['del'];
for ($i = 0; $i <= ($params-1); $i++ )
{
if(!isset($data[(($counter-1)*$params)+$i])) $data[(($counter-1)*$params)+$i] = "";
}
if(isset($_GET['comment']))
{
$data[(($counter-1)*$params)+0] = $_GET['comment'];
}
if (count($_GET) > 0)
{
$data[(($counter-1)*$params)+1] = strftime('%d.%m.%Y, %H:%M Uhr',time());
}
if (isset($_GET['myip']))
{
$data[(($counter-1)*$params)+2] = $_GET['myip'];
if ($data[(($counter-1)*$params)+2] == "") $data[(($counter-1)*$params)+2] = $_SERVER['REMOTE_ADDR'];
}
if(isset($_GET['ftp']))
{
if($_GET['ftp']) $data[(($counter-1)*$params)+3] = $_GET['ftp'];
}
if(isset($_GET['web']))
{
if($_GET['web']) $data[(($counter-1)*$params)+4] = $_GET['web'];
}
if(isset($_GET['web']))
{
if($_GET['webs']) $data[(($counter-1)*$params)+5] = $_GET['webs'];
}
//if(isset($_GET['wake']))
//{
//if($_GET['wake'])
//{
//$data[(($counter-1)*$params)+5] = $_GET['wake'];
//}
//}
//if(isset($_GET['wakeip']))
//{
//if($_GET['wakeip']) $data[(($counter-1)*$params)+6] = $_GET['wakeip'];
//}
ksort($data);
if(isset($_GET['del']))
{
if($deleteentry) $counter = $deleteentry;
for ($i = ($params-1); $i >= 0; $i-- )
{
unset($data[(($counter-1)*$params)+$i]);
}
}
return explode("\n",implode("\n",$data));
}
function showdata($data,$rpass,$wpass)
{
global $params;
global $FTP_PRE;
global $HTTP_PRE;
global $HTTPS_PRE;
header('Content-type: text/html; charset="utf-8"');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
echo '<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Externe IP-Adresse des DSL-Zugangs zuhause</title>
<style type="text/css">
';
if (($rpass == "") || ($_GET['pw'] == $rpass))
{
echo 'th{text-align:left;padding:0 0 0 3em;color:#666;vertical-align:top;width:15em;}
td{font-weight:bold;font-family:monospace;padding:0;}
table{width:100%;}
a{text-decoration: none;color:#000;display:block;}
a:hover{color:#00D;background-color:#DDD;}
small a{color:#CCC;display:inline;font-size:0.5em;}
small a:hover{color:#F00;background-color:transparent;font-size:0.8em;}
</style>
</head>
<body>
<small><a href="README.txt">Hilfe</a></small>
';
if(isset($_GET['del'])) print "<h3>Status: Eintrag gelöscht!</h3><hr \>";
//if(isset($_GET['wake']) && ($_GET['wake'] == "")) print "<h3>Status: Wake-on-LAN Paket verschickt!</h3><hr \>";
$i = 1;
do
{
$ipaddress = $data[(($i-1)*$params)+2];
$ftpaddress = $ipaddress;
$webaddress = $ipaddress;
$httpsaddress = $ipaddress;
//$woladdress = $ipaddress;
echo '<h2>Eintrag '.$i.': <small><a href="'.$_SERVER['PHP_SELF'].'?del='.$i.'&pw='.$wpass.'">LÖSCHEN</a></small></h2>
<table>
<tr><th>Kommentar:</th><td>'.$data[(($i-1)*$params)+0].'</td></tr>
<tr><th>Stand von:</th><td>'.$data[(($i-1)*$params)+1].'</td></tr>
<tr><th>WAN IP-Adresse:</th><td>'.$ipaddress.'</td></tr>
';
if ($data[(($i-1)*$params)+3] != "") $ftpaddress = $data[(($i-1)*$params)+3];
echo '<tr><th>FTP IP-Adresse:</th><td><a href="'.$FTP_PRE.''.$ftpaddress.'" title="Mit FTP verbinden">'.$FTP_PRE.''.$ftpaddress.'</a></td></tr>
';
if ($data[(($i-1)*$params)+4] != "") $webaddress = $data[(($i-1)*$params)+4];
if ($data[(($i-1)*$params)+5] != "") $httpsaddress = $data[(($i-1)*$params)+5];
//preg_match('@^(?:[a-z]:)?([^:]+)@i',$webaddress, $treffer);
//$httpsaddress = $treffer[1];
echo '<tr><th>Webserver IP-Adresse:</th><td><a href="'.$HTTP_PRE.''.$webaddress.'" title="Mit Webserver verbinden">'.$HTTP_PRE.''.$webaddress.'</a></td></tr>
<tr><th>Gesicherter Webserver:</th><td><a href="'.$HTTPS_PRE.''.$httpsaddress.'" title="Mit gesichertem Webserver verbinden">'.$HTTPS_PRE.''.$httpsaddress.'</a></td></tr>
';
//if ($data[(($i-1)*$params)+6] != "") $woladdress = $data[(($i-1)*$params)+6];
//if ($data[(($i-1)*$params)+5] == "") $woladdress = "";
//echo '<tr><th>Wake-on-LAN MAC-Adresse:</th><td><a href="'.$_SERVER['PHP_SELF'].'?wake&n='.$i.'&pw='.$wpass.'" title="Wake-on-LAN Paket an '.$woladdress.' senden">'.$data[(($i-1)*$params)+5].'</a></td></tr>
//<tr><th>Wake-on-LAN IP-Adresse:</th><td><a href="'.$_SERVER['PHP_SELF'].'?wake&n='.$i.'&pw='.$wpass.'" title="Wake-on-LAN Paket an '.$woladdress.' senden">'.$woladdress.'</a></td></tr>
echo '</table>
';
$i++;
}
while (($i*$params)<= count($data));
}
else
{
echo '</style>
</head>
<body>
<h1>Zugriff verweigert!</h1>
';
}
echo '</body>
</html>
';
}
function doaction($data)
{
global $params;
if(isset($_GET['n'])) $counter = $_GET['n'];
if($counter == "") $counter = 1;
if(((isset($_GET['ftp']) && (count($_GET) == 1)) || (isset($_GET['ftp']) && isset($_GET['n']) && (count($_GET) == 2))) && ($_GET['ftp'] == ""))
{
header("Location: ftp://".$data[(($counter-1)*$params)+3]);
exit();
}
if(((isset($_GET['web']) && (count($_GET) == 1)) || (isset($_GET['web']) && isset($_GET['n']) && (count($_GET) == 2))) && ($_GET['web'] == ""))
{
header("Location: http://".$data[(($counter-1)*$params)+4]);
exit();
}
//if((isset($_GET['wake']) && (count($_GET) == 1)) || (isset($_GET['wake']) && isset($_GET['n']) && (count($_GET) == 2)) && ($_GET['wake'] == ""))
//{
//wake($data[(($counter-1)*$params)+6], $data[(($counter-1)*$params)+5], 9);
//}
}
?>