-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverloaded.class.php
105 lines (77 loc) · 2.48 KB
/
overloaded.class.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
103
104
105
<?php
class overloaded{
public $type_msg = 'html'; //html, text (file will be available in the next version)
private $debug = false; //available in the next version
private $language = 'en';
private $load;
private $autoreload = 0; //the page reloads automatically in $autoreload seconds (only in output in html)
function get_server_load() {
if (strpos(strtolower(PHP_OS), 'win') !== false){
//if is a windows system
$wmi = new COM("Winmgmts://");
$server = $wmi->execquery("SELECT LoadPercentage FROM Win32_Processor");
$cpu_num = 0;
$load_total = 0;
foreach($server as $cpu){
$cpu_num++;
$load_total += $cpu->loadpercentage;
}
$load = round($load_total/$cpu_num);
} else {
//if is a linux system
$sys_load = sys_getloadavg();
$load = $sys_load[0];
}
return (int) $load;
}//get_server_load end
function show_msg(){
if(!is_file('language/'.$this->language.'.php')){
//language was not found, set the default
$this->set_language('en');
}
//load the language
require 'language/'.$this->language.'.php';
if('html' == $this->type_msg){
//html
echo "<div style='text-align:center;'><h1>".OVERLOADED_MESSAGE."</h1></div>";
if($autoreload > 0){
echo "<meta http-equiv='refresh' content='".$autoreload."'>";
}
}else{
//txt
echo OVERLOADED_MESSAGE;
}
}//show_msg end
function check($max_proces){
$this->load = $this->get_server_load();
if($this->load >= $max_proces){
if(!$this->debug){
error_reporting(0); //Turn off all error reporting
}
$this->show_msg(); //show the error message
break;
}
}//check end
function set_language($newlanguage){
//It is filtered to prevent users with less experience leave the system vulnerable
$newlanguage = strip_tags($newlanguage);
$newlanguage = str_replace('/','',$newlanguage);
$newlanguage = str_replace('\\','',$newlanguage);
$newlanguage = str_replace('.','',$newlanguage);
$newlanguage = str_replace(',','',$newlanguage);
$this->language = $newlanguage;
}//set_language end
function set_autoreload($autoreload){
if($autoreload < 0){
$autoreload = $autoreload*(-1);
}
if($autoreload != 0){
$this->autoreload = $autoreload;
}else{
if($this->debug){
echo AUTORLD_ERROR;
}
}
}//set_autoreload end
}//class end
?>