51950980dbad1976a2fc48f776ffbdcf8a740693
[feed/packages.git] / utils / bandwidthd / files / phphtdocs-sqlite / include.php
1 <?php
2 error_reporting(E_ALL & ~(E_NOTICE|E_STRICT));
3 define("INT_DAILY", 60*60*24*2);
4 define("INT_WEEKLY", 60*60*24*8);
5 define("INT_MONTHLY", 60*60*24*35);
6 define("INT_YEARLY", 60*60*24*400);
7
8 define("XOFFSET", 90);
9 define("YOFFSET", 45);
10
11 require("config.conf.php");
12
13 function ConnectDb() {
14 global $db_connect_string;
15 try {
16 $db = new PDO($db_connect_string);
17 } catch (PDOException $ex) {
18 die("DB Error, could not connect to database: " . $ex->getMessage());
19 }
20 return $db;
21 }
22
23 function fmtb($kbytes)
24 {
25 $Max = 1024;
26 $Output = $kbytes;
27 $Suffix = 'K';
28
29 if ($Output > $Max)
30 {
31 $Output /= 1024;
32 $Suffix = 'M';
33 }
34
35 if ($Output > $Max)
36 {
37 $Output /= 1024;
38 $Suffix = 'G';
39 }
40
41 if ($Output > $Max)
42 {
43 $Output /= 1024;
44 $Suffix = 'T';
45 }
46
47 return(sprintf("<td align=right><tt>%.1f%s</td>", $Output, $Suffix));
48 }
49
50 function ip2s32($ip) {
51 $i = ip2long($ip);
52 return ($i & 0x80000000 ? '-' . ((~$i & 0x7fffffff)+1) : ''. ($i & 0x7fffffff));
53 }
54
55 function prepare_sql_subnet($subnet) {
56 list($snet, $smask) = explode('/', $subnet);
57 $inet = ip2s32($snet);
58 if($smask > 0 && $smask < 32) {
59 $mask = -1 << (32 - (int)$smask);
60 return "and (ip & $mask = $inet)";
61 } elseif ($inet) {
62 return "and ip = " . $inet;
63 }
64 return "";
65 }
66
67 $starttime = time();
68 set_time_limit(300);
69 ?>