-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
241 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,16 @@ name = "loadaverage" | |
|
||
[version] | ||
major = "2" | ||
minor = "0" | ||
build = "1" | ||
date = "20170119" | ||
minor = "1" | ||
build = "0" | ||
date = "20241212" | ||
|
||
[depends] | ||
core = "2.5.0" | ||
core = "2.16.3" | ||
|
||
[author] | ||
name = "InstantMedia Team" | ||
url = "https://instantvideo.ru/" | ||
email = "[email protected]" | ||
|
||
[description] | ||
text[] = "Pauses the site at a given load threshold." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,16 @@ name = "loadaverage" | |
|
||
[version] | ||
major = "2" | ||
minor = "0" | ||
build = "1" | ||
date = "20170119" | ||
minor = "1" | ||
build = "0" | ||
date = "20241212" | ||
|
||
[depends] | ||
core = "2.5.0" | ||
core = "2.16.3" | ||
|
||
[author] | ||
name = "InstantMedia Team" | ||
url = "https://instantvideo.ru/" | ||
email = "[email protected]" | ||
|
||
[description] | ||
text[] = "Приостанавливает работу сайта при" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
<?php | ||
/******************************************************************************/ | ||
// // | ||
// InstantMedia 2017 // | ||
// https://instantvideo.ru/, [email protected] // | ||
// written by Fuze // | ||
// https://instantvideo.ru/copyright.html // | ||
// // | ||
/******************************************************************************/ | ||
|
||
class backendLoadaverage extends cmsBackend { | ||
|
||
public $useDefaultOptionsAction = true; | ||
protected $useOptions = true; | ||
protected $useOptions = true; | ||
|
||
public function getOptionsToolbar() { | ||
|
||
if(file_exists($this->cms_config->cache_path.'is_temporary_unavailable_email_me')){ | ||
return [[ | ||
'class' => 'refresh', | ||
'title' => LANG_LA_CLEAR_SEND_EMAIL, | ||
'href' => $this->cms_template->href_to('clear_send_email') | ||
]]; | ||
} | ||
} | ||
|
||
public function actionIndex(){ | ||
$this->redirectToAction('options'); | ||
public function actionIndex() { | ||
return $this->redirectToAction('options'); | ||
} | ||
|
||
public function getCurrentloadAverage($sensor) { | ||
|
||
$la = sys_getloadavg(); | ||
|
||
return round(100*($la[$sensor]/$this->options['cpu_count'])); | ||
|
||
return round(100 * ($la[$sensor] / $this->options['cpu_count'])); | ||
} | ||
|
||
public function actionClearSendEmail(){ | ||
public function actionClearSendEmail() { | ||
|
||
@unlink($this->cms_config->cache_path.'is_temporary_unavailable_email_me'); | ||
@unlink($this->cms_config->cache_path . 'is_temporary_unavailable_email_me'); | ||
|
||
cmsUser::addSessionMessage(LANG_LA_CLEAR_SUCCESS, 'success'); | ||
|
||
$this->redirectToAction('options'); | ||
|
||
return $this->redirectToAction('options'); | ||
} | ||
|
||
public function actionDeleteComponent(){ | ||
public function actionDeleteComponent() { | ||
|
||
$model = new cmsModel(); | ||
|
||
|
@@ -44,8 +46,7 @@ public function actionDeleteComponent(){ | |
|
||
cmsUser::addSessionMessage(sprintf(LANG_CP_COMPONENT_IS_DELETED, LANG_LOADAVERAGE_CONTROLLER), 'success'); | ||
|
||
$this->redirectTo('admin', 'controllers'); | ||
|
||
return $this->redirectTo('admin', 'controllers'); | ||
} | ||
|
||
} |
104 changes: 45 additions & 59 deletions
104
package/system/controllers/loadaverage/backend/forms/form_options.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,82 @@ | ||
<?php | ||
/******************************************************************************/ | ||
// // | ||
// InstantMedia 2017 // | ||
// https://instantvideo.ru/, [email protected] // | ||
// written by Fuze // | ||
// https://instantvideo.ru/copyright.html // | ||
// // | ||
/******************************************************************************/ | ||
|
||
class formLoadaverageOptions extends cmsForm { | ||
|
||
public function init() { | ||
|
||
$cpu_count = get_cpu_count(); | ||
|
||
return array( | ||
|
||
array( | ||
'type' => 'fieldset', | ||
'childs' => array( | ||
|
||
new fieldNumber('max_load', array( | ||
return [ | ||
[ | ||
'type' => 'fieldset', | ||
'childs' => [ | ||
new fieldNumber('max_load', [ | ||
'title' => LANG_LA_MAX_LOAD, | ||
'units' => '%', | ||
'hint' => LANG_LA_MAX_LOAD_HINT, | ||
'default' => 90 | ||
)), | ||
|
||
new fieldString('cpu_count', array( | ||
]), | ||
new fieldString('cpu_count', [ | ||
'title' => LANG_LA_CPU_COUNT, | ||
'hint' => LANG_LA_CPU_COUNT_HINT, | ||
'suffix' => ($cpu_count ? html_bool_span('<span title="' . LANG_LA_AUTO_PATH_CLICK . '" class="auto_copy tooltip" data-path="' . $cpu_count . '">' . LANG_LA_AUTO_PATH . ' ' . $cpu_count . '</span>', true) : html_bool_span(LANG_LA_NO_AUTO_PATH, false)), | ||
'suffix' => ($cpu_count ? '<span title="' . LANG_LA_AUTO_PATH_CLICK . '" class="auto_copy_value" data-value="' . $cpu_count . '">' . LANG_LA_AUTO_PATH . ' ' . $cpu_count . '</span>' : LANG_LA_NO_AUTO_PATH), | ||
'default' => ($cpu_count ? $cpu_count : 1), | ||
'rules' => array( | ||
array('number'), | ||
array('min', 1) | ||
) | ||
)), | ||
|
||
new fieldList('sensor', array( | ||
'title' => LANG_LA_SENSOR, | ||
'items' => array( | ||
'rules' => [ | ||
['number'], | ||
['min', 1] | ||
] | ||
]), | ||
new fieldList('sensor', [ | ||
'title' => LANG_LA_SENSOR, | ||
'items' => [ | ||
LANG_LA_SENSOR1, | ||
LANG_LA_SENSOR5, | ||
LANG_LA_SENSOR15 | ||
), | ||
], | ||
'default' => 2 | ||
)), | ||
|
||
new fieldList('action', array( | ||
'title' => LANG_LA_ACTION, | ||
'is_multiple' => true, | ||
'items' => array( | ||
LANG_LA_ACTION0, | ||
LANG_LA_ACTION1 | ||
), | ||
'default' => array(0) | ||
)), | ||
|
||
new fieldString('email', array( | ||
]), | ||
new fieldCheckbox('action:block', [ | ||
'title' => LANG_LA_ACTION0, | ||
'default' => 1 | ||
]), | ||
new fieldCheckbox('action:email', [ | ||
'title' => LANG_LA_ACTION1, | ||
'default' => 0 | ||
]), | ||
new fieldString('email', [ | ||
'title' => LANG_LA_EMAIL, | ||
'hint' => LANG_LA_EMAIL_HINT, | ||
'rules' => array( | ||
array('email') | ||
) | ||
)) | ||
|
||
) | ||
) | ||
|
||
); | ||
|
||
'rules' => [ | ||
['email'] | ||
], | ||
'visible_depend' => ['action:email' => ['show' => ['1']]] | ||
]) | ||
] | ||
] | ||
]; | ||
} | ||
|
||
} | ||
|
||
function get_cpu_count(){ | ||
if(!function_exists('exec') || !function_exists('sys_getloadavg')){ | ||
function get_cpu_count() { | ||
|
||
if (!function_exists('exec') || !function_exists('sys_getloadavg')) { | ||
return false; | ||
} | ||
$buffer = array(); | ||
|
||
$buffer = []; | ||
$err = ''; | ||
$result = exec("grep -P '^physical id' /proc/cpuinfo|wc -l", $buffer, $err); | ||
if($err !== 127){ | ||
if(!isset($buffer[0])){ | ||
if ($err !== 127) { | ||
if (!isset($buffer[0])) { | ||
$buffer[0] = $result; | ||
} | ||
$b = mb_strtolower($buffer[0]); | ||
if(mb_strstr($b,'error') || mb_strstr($b,' no ') || mb_strstr($b,'not found') || mb_strstr($b,'No such file or directory')){ | ||
if (mb_strstr($b, 'error') || mb_strstr($b, ' no ') || mb_strstr($b, 'not found') || mb_strstr($b, 'No such file or directory')) { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
return (int)$buffer[0]; | ||
return (int) $buffer[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
<?php | ||
/******************************************************************************/ | ||
// // | ||
// InstantMedia 2017 // | ||
// https://instantvideo.ru/, [email protected] // | ||
// written by Fuze // | ||
// https://instantvideo.ru/copyright.html // | ||
// InstantMedia // | ||
// http://instantmedia.ru/ // | ||
// written by Fuze // | ||
// // | ||
/******************************************************************************/ | ||
|
||
class loadaverage extends cmsFrontend { | ||
|
||
protected $useOptions = true; | ||
|
||
public function displayPeekError() { | ||
|
||
if (href_to('auth', 'login') != href_to_current()){ | ||
if (href_to('auth', 'login') !== href_to_current()) { | ||
|
||
if (!cmsUser::isAdmin()) { | ||
|
||
if (cmsUser::isLogged()){ | ||
if (cmsUser::isLogged()) { | ||
|
||
cmsUser::addSessionMessage(LANG_LOGIN_ADMIN_ONLY, 'error'); | ||
|
||
cmsUser::logout(); | ||
$this->redirectToHome(); | ||
|
||
return $this->redirectToHome(); | ||
} | ||
|
||
header('HTTP/1.0 503 Too busy, try again later'); | ||
header('Status: 503 Too busy, try again later'); | ||
if (isset($this->cms_core->response)) { | ||
|
||
$this->cms_core->response->setStatusCode(503); | ||
|
||
} else { | ||
http_response_code(503); | ||
} | ||
|
||
$this->cms_template->setContext($this); | ||
|
||
return $this->cms_template->renderPlain('temporary_unavailable'); | ||
|
||
} | ||
} | ||
|
||
|
@@ -38,37 +46,37 @@ public function getCurrentloadAverage($sensor) { | |
|
||
$la = sys_getloadavg(); | ||
|
||
return round(100*($la[$sensor]/$this->options['cpu_count'])); | ||
|
||
return round(100 * ($la[$sensor] / $this->options['cpu_count'])); | ||
} | ||
|
||
public function fixOverload($current_load_average) { | ||
|
||
$model = new cmsModel(); | ||
|
||
$model->insert('load_average_peak', array( | ||
'value'=>$current_load_average | ||
)); | ||
$model->insert('load_average_peak', [ | ||
'value' => $current_load_average | ||
]); | ||
|
||
return $this; | ||
|
||
} | ||
|
||
public function sendEmail($emails, $current_load_average){ | ||
public function sendEmail($emails, $current_load_average) { | ||
|
||
$emails = explode(',', $emails); | ||
|
||
$letter_text = cmsCore::getLanguageTextFile('letters/temporary_unavailable'); | ||
if (!$letter_text){ return false; } | ||
if (!$letter_text) { | ||
return false; | ||
} | ||
|
||
$letter_text = string_replace_keys_values($letter_text, array( | ||
'site' => $this->cms_config->sitename, | ||
'host' => $this->cms_config->host, | ||
'ip' => $_SERVER['SERVER_ADDR'], | ||
'la' => $current_load_average, | ||
'date' => html_date(), | ||
'time' => html_time() | ||
)); | ||
$letter_text = string_replace_keys_values($letter_text, [ | ||
'site' => $this->cms_config->sitename, | ||
'host' => $this->cms_config->host, | ||
'ip' => $_SERVER['SERVER_ADDR'], | ||
'la' => $current_load_average, | ||
'date' => html_date(), | ||
'time' => html_time() | ||
]); | ||
|
||
foreach ($emails as $email) { | ||
|
||
|
@@ -81,11 +89,9 @@ public function sendEmail($emails, $current_load_average){ | |
$mailer->setBodyHTML(nl2br($letter_text))->send(); | ||
|
||
$mailer->clearTo()->clearAttachments(); | ||
|
||
} | ||
|
||
return $this; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.