This repository has been archived by the owner on Jan 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebalizerphp.php
89 lines (62 loc) · 1.76 KB
/
webalizerphp.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
<?php
// webalizerphp.php
class webalizerphp {
const loginkey = 'loggedin';
private $loggedin = FALSE;
private $webalizerpath = '';
public function __construct() {
session_start();
if (isset($_SESSION[self::loginkey])) {
$this->loggedin = TRUE;
$this->webalizerpath = $_SESSION[self::loginkey];
}
}
public function renderstats() {
if (isset($_POST['logout'])) {
// logout user
unset($_SESSION[self::loginkey]);
$this->redirecttohome();
return;
}
if (!$this->loggedin) {
// present login screen
$userlogin = new userlogin();
$userlogin->execute();
if ($userlogin->getloggedin()) {
// user has logged in
$this->loggedin = TRUE;
$this->webalizerpath = $userlogin->getwebalizerpath();
// save webalizer path to session variable
$_SESSION[self::loginkey] = $userlogin->getwebalizerpath();
// redirect back to the start to avoid "post content's again?" browser prompts when jumping back/forth between webalizer pages
$this->redirecttohome();
return;
}
} else {
// render stats page
$renderstatpage = new renderstatpage($this->webalizerpath);
if (isset($_GET['m'])) {
$renderstatpage->setmonth($_GET['m']);
}
$renderstatpage->execute();
}
}
public function displaypng() {
if (
(!$this->loggedin) ||
(!isset($_GET['i'])) ||
(!is_file($this->webalizerpath . $_GET['i'] . '.png'))
) {
return;
}
$filename = $this->webalizerpath . $_GET['i'] . '.png';
// send content headers
header('Content-Type: image/png');
header('Content-Length: ' . filesize($filename));
// dump the picture
readfile($filename);
}
private function redirecttohome() {
header('Location: http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']),'/') . '/');
}
}