-
Notifications
You must be signed in to change notification settings - Fork 13
/
include.php
88 lines (73 loc) · 1.67 KB
/
include.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
<?
define("INT_DAILY", 60*60*24*2);
define("INT_WEEKLY", 60*60*24*8);
define("INT_MONTHLY", 60*60*24*35);
define("INT_YEARLY", 60*60*24*400);
define("XOFFSET", 90);
define("YOFFSET", 45);
$config_conf_key = 1;
require("config.php");
/**
* trims all $_GET inputs
*/
function trim_get ()
{
//trim all inputs
foreach ($_GET as $key => $value) {
$_GET[$key] = trim($_GET[$key]);
}
}
/**
*
* @param string (IP) $given_ip
* @return string (sanitized IP)
*/
function sanitize_ip ($given_ip)
{
if (preg_match("/(1?[1-9]?[0-9]|2?(?:[0-4]?[0-9]|5[0-5]))\.(1?[1-9]?[0-9]|2?(?:[0-4]?[0-9]|5[0-5]))\.(1?[1-9]?[0-9]|2?(?:[0-4]?[0-9]|5[0-5]))\.(1?[1-9]?[0-9]|2?(?:[0-4]?[0-9]|5[0-5]))(\/[0-9]{1,2})?\b/", $given_ip,$ip))
{
return $ip[0];
}
else
{
return "0.0.0.0/0";
}
}
function ConnectDb()
{
global $db_connect_string;
$db = pg_pconnect($db_connect_string);
if (!$db)
{
printf("DB Error, could not connect to database");
exit(1);
}
return($db);
}
function fmtb($kbytes)
{
$Max = 1024;
$Output = $kbytes;
$Suffix = 'K';
if ($Output > $Max)
{
$Output /= 1024;
$Suffix = 'M';
}
if ($Output > $Max)
{
$Output /= 1024;
$Suffix = 'G';
}
if ($Output > $Max)
{
$Output /= 1024;
$Suffix = 'T';
}
//return(sprintf("<td sort='%d' align=right><tt>%d</td>",$kbytes, $kbytes));
return(sprintf("<td class='%d' style='text-align:right;'>%.1f%s</td>",$kbytes, $Output, $Suffix));
}
//TODO check for needed functions and extensions. e.g. imagecreate / PHP5_GD
$starttime = time();
set_time_limit(300);
?>