forked from nonlin-lin-chaos-order-etc-etal/dns.chudo.i2p
-
Notifications
You must be signed in to change notification settings - Fork 1
/
request.php
102 lines (92 loc) · 3.11 KB
/
request.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php include('templates/header.php');?>
<?php
function request(){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
require_once("classes/base64_class.php");
include("classes/sam.php");
require_once('classes/addressbook_class_mysql.php');
$test = new addressbook_service();
//$test->addFromHostFile('hosts.txt');
//$test->clearDB();
//search domain
if ( isset($_GET['d']) ){
echo "<div id='domains'>";
$alldomains=true;
if( isset($_GET['all_domains']) && $_GET['all_domains'] == 'y') $alldomains=false;
//print($alldomains?"true":'false');
$domains= $alldomains ? $test->getDomain($_GET['d'],true) : $test->getDomain($_GET['d']);
$co=false;
if ( isset($_GET['check_online']) && $_GET['check_online'] == 'y') $co=true;
$sam=null;
foreach( $domains as $value){
$host=$value['host'];
$b64=$value['b64'];
$desc=$value['description'];
$b32 = (new b32_b64())->b32from64($b64) . ".b32.i2p";
$last_online="";//last_online
if($co){
$cache=$test->existOnlineStatus($host);
if( $cache === false){// if not exist online status in 'cache'
if( $sam == null) $sam = new SAM(SAMHOST,SAMPORT);
$online = $sam->check_online("$b64");
$test->addOnlineStatus($host,$online);
if($online)
$last_online="now: ".date("F j, Y, g:i a");
else $last_online="NaN";
}else{// if exists in 'cache'
if( $test->diffRequestAndOnlineStatus($host) ){ // '>5 minutes ago checked'
if( $sam == null ) $sam = new SAM(SAMHOST,SAMPORT);
//print("<!-- >5minutes -->");
$online = $sam->check_online("$b64");
$test->UpdateOnlineStatusIfNeed($host,$online);
if($online)
$last_online="now: ".date("F j, Y, g:i a");
else $last_online= $cache['last_online'];
}else//get from DB
$last_online= $cache['last_online'];
}//end of exist in cache
}//end if check online
if( strlen($desc) ) $desc = "-".$desc;
$last_online = $co ? "(Last seen: $last_online)": "";
echo "<a href='http://$host/?i2paddresshelper=$b64'>$host $last_online</a> $desc <br/>($b32)<hr/>";
}//foreach
echo "<a href=index.php>back</a>";
echo "</div>";
return true;
}
//add domain
if( isset_all($_GET, 'host','b64','desc') ){
$host=$_GET['host'];
$b64=$_GET['b64'];
$desc=$_GET['desc'];
echo "<center><a href=index.php>back</a><br/>";
if(!$test->checkIsB64($b64))die("uncorrect b64");
$sam = new SAM(SAMHOST,SAMPORT);
$online = $sam->check_online("$b64");
if(!$online)die("your service is down!");
if( $test->isSubDomain($host) ){
try{
$res=$test->regSubDomain($host,$b64,$desc,I2PHTTPPROXY);
if($res !== TRUE){
die("Create file on url->".$res);
}
}catch(Exception $e){
die($e->getMessage());
}
//die("is subdomain of exists domain. support must be added later");
}else{
try{
$test->addDomain($host,$b64,$desc);
}catch (Exception $e){
echo "".$e->getMessage();
return true;
}
}
echo "Added!<hr/></center>";
}
}
request();
?>
<?php include('templates/footer.php');?>