-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
73 lines (73 loc) · 2 KB
/
functions.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
<?php
function isValidDomain($domain){
$pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/';
return preg_match($pattern, $domain);
}
function isUp($domain){
$curl = curl_init($domain);
$returned = 0;
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if(curl_getinfo($curl, CURLINFO_HTTP_CODE) == 404){
$returned = 2;
}else{
$returned = $response ? 1 : 0;
}
curl_close($curl);
return $returned;
}
function easteregg($domain){
$response = '';
switch($domain){
case $_SERVER['SERVER_NAME']:
$response = 'If you can see this, we are up.';
break;
case '127.0.0.1':
case 'localhost':
$response = 'Party at 127.0.0.1!';
break;
case 'nebkat':
$response = 'YES, HE IS UP UP AND HIGH ON CRYSTAL WEED!';
break;
case 'datagutt':
$response = 'Javascript all teh things!';
break;
case 'canada':
$response = 'Hi Chad.';
break;
case 'Baskey':
$response = 'LEGALIZE CRYSTAL ZLOTY';
break;
case 'easteregg':
case 'easter egg':
$response = 'ORLY? TRY /help eastereggs';
break;
case '/help eastereggs':
$response = "<a href=\"http://goo.gl/v7dIR\">List of easter eggs</a>";
break;
}
return $response;
}
function getResponse($domain){
if(empty($domain)){
$response = 'I can feel the emptiness inside...';
}else if(!isValidDomain($domain)){
// Check if there is an easteregg
$easteregg = easteregg($domain);
if(!empty($easteregg)){
$response = $easteregg;
}else{
$response = 'That is not a valid domain.';
}
}else{
$response = (string) isUp($domain);
}
if(isset($_REQUEST['json']) && $_REQUEST['json'] == '1'){
return "{domain: '$domain', status: '$response'}";
}else{
return $response;
}
}