Added the option to specify the request method (#631)
parent
7aa7ec363b
commit
72b262c706
|
@ -5,6 +5,7 @@ Changelog
|
|||
Not yet released
|
||||
----------------
|
||||
|
||||
* #631: Added option to specify the request method.
|
||||
* #628: Added the option to mark specific HTTP status codes as online.
|
||||
* #640: Removed () after last offline value when the last offline duration is unknown.
|
||||
* #637: Added php extensions to composer required list, spelling fixes in changelog and composer update.
|
||||
|
|
|
@ -343,9 +343,10 @@ function psm_parse_msg($status, $type, $vars) {
|
|||
* @param boolean $add_agent add user agent?
|
||||
* @param string|bool $website_username Username website
|
||||
* @param string|bool $website_password Password website
|
||||
* @param string|bool $request_method Request method like GET, POST etc.
|
||||
* @return string cURL result
|
||||
*/
|
||||
function psm_curl_get($href, $header = false, $body = true, $timeout = null, $add_agent = true, $website_username = false, $website_password = false) {
|
||||
function psm_curl_get($href, $header = false, $body = true, $timeout = null, $add_agent = true, $website_username = false, $website_password = false, $request_method = null) {
|
||||
$timeout = $timeout == null ? PSM_CURL_TIMEOUT : intval($timeout);
|
||||
|
||||
$ch = curl_init();
|
||||
|
@ -358,6 +359,10 @@ function psm_curl_get($href, $header = false, $body = true, $timeout = null, $ad
|
|||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||
|
||||
if (!empty($request_method)) {
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_method);
|
||||
}
|
||||
|
||||
if ($website_username !== false && $website_password !== false && !empty($website_username) && !empty($website_password)) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $website_username.":".$website_password);
|
||||
|
|
|
@ -48,6 +48,7 @@ $sm_lang = array(
|
|||
'go_back' => 'Go back',
|
||||
'ok' => 'OK',
|
||||
'cancel' => 'Cancel',
|
||||
'none' => 'None',
|
||||
'activate' => 'Activate',
|
||||
// date/time format according the strftime php function format parameter http://php.net/manual/function.strftime.php
|
||||
'short_day_format' => '%B %e',
|
||||
|
@ -160,6 +161,9 @@ $sm_lang = array(
|
|||
'port' => 'Port',
|
||||
'custom_port' => 'Custom Port',
|
||||
'popular_ports' => 'Popular Ports',
|
||||
'request_method' => 'Request method',
|
||||
'custom_request_method' => 'Custom request method',
|
||||
'popular_request_methods' => 'Popular request methods',
|
||||
'please_select' => 'Please select',
|
||||
'type' => 'Type',
|
||||
'type_website' => 'Website',
|
||||
|
|
|
@ -61,6 +61,7 @@ abstract class AbstractServerController extends AbstractController {
|
|||
`s`.`server_id`,
|
||||
`s`.`ip`,
|
||||
`s`.`port`,
|
||||
`s`.`request_method`,
|
||||
`s`.`type`,
|
||||
`s`.`label`,
|
||||
`s`.`pattern`,
|
||||
|
|
|
@ -196,6 +196,7 @@ class ServerController extends AbstractServerController {
|
|||
'edit_value_label' => $edit_server['label'],
|
||||
'edit_value_ip' => $edit_server['ip'],
|
||||
'edit_value_port' => $edit_server['port'],
|
||||
'edit_value_request_method' => $edit_server['request_method'],
|
||||
'edit_value_timeout' => $edit_server['timeout'],
|
||||
'default_value_timeout' => PSM_CURL_TIMEOUT,
|
||||
'edit_value_pattern' => $edit_server['pattern'],
|
||||
|
@ -265,6 +266,7 @@ class ServerController extends AbstractServerController {
|
|||
'website_username' => psm_POST('website_username'),
|
||||
'website_password' => $encrypted_password,
|
||||
'port' => intval(psm_POST('port', 0)),
|
||||
'request_method' => empty(psm_POST('request_method')) ? null : psm_POST('request_method'),
|
||||
'type' => psm_POST('type', ''),
|
||||
'pattern' => psm_POST('pattern', ''),
|
||||
'pattern_online' => in_array($_POST['pattern_online'], array('yes', 'no')) ? $_POST['pattern_online'] : 'yes',
|
||||
|
@ -465,8 +467,12 @@ class ServerController extends AbstractServerController {
|
|||
'label_fieldset_permissions' => psm_get_lang('servers', 'fieldset_permissions'),
|
||||
'label_port' => psm_get_lang('servers', 'port'),
|
||||
'label_custom_port' => psm_get_lang('servers', 'custom_port'),
|
||||
'label_please_select' => psm_get_lang('servers', 'please_select'),
|
||||
'label_popular_ports' => psm_get_lang('servers', 'popular_ports'),
|
||||
'label_request_method' => psm_get_lang('servers', 'request_method'),
|
||||
'label_custom_request_method' => psm_get_lang('servers', 'custom_request_method'),
|
||||
'label_popular_request_methods' => psm_get_lang('servers', 'popular_request_methods'),
|
||||
'label_none' => psm_get_lang('system', 'none'),
|
||||
'label_please_select' => psm_get_lang('servers', 'please_select'),
|
||||
'label_type' => psm_get_lang('servers', 'type'),
|
||||
'label_website' => psm_get_lang('servers', 'type_website'),
|
||||
'label_service' => psm_get_lang('servers', 'type_service'),
|
||||
|
|
|
@ -225,6 +225,7 @@ class Installer {
|
|||
`server_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`ip` varchar(500) NOT NULL,
|
||||
`port` int(5) unsigned NOT NULL,
|
||||
`request_method` varchar(50) unsigned NULL,
|
||||
`label` varchar(255) NOT NULL,
|
||||
`type` enum('ping','service','website') NOT NULL default 'service',
|
||||
`pattern` varchar(255) NOT NULL default '',
|
||||
|
@ -550,8 +551,8 @@ class Installer {
|
|||
*/
|
||||
protected function upgrade340() {
|
||||
$queries = array();
|
||||
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER j`pattern_online`;";
|
||||
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `request_method` varchar(50) NULL AFTER `port`;";
|
||||
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pattern_online`;";
|
||||
$this->execSQL($queries);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ class StatusUpdater {
|
|||
$this->server = $this->db->selectRow(PSM_DB_PREFIX.'servers', array(
|
||||
'server_id' => $server_id,
|
||||
), array(
|
||||
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'pattern_online', 'allow_http_status', 'header_name', 'header_value', 'status', 'active', 'warning_threshold',
|
||||
'server_id', 'ip', 'port', 'request_method', 'label', 'type', 'pattern', 'pattern_online', 'allow_http_status', 'header_name', 'header_value', 'status', 'active', 'warning_threshold',
|
||||
'warning_threshold_counter', 'timeout', 'website_username', 'website_password', 'last_offline'
|
||||
));
|
||||
if (empty($this->server)) {
|
||||
|
@ -229,7 +229,8 @@ class StatusUpdater {
|
|||
$this->server['timeout'],
|
||||
true,
|
||||
$this->server['website_username'],
|
||||
psm_password_decrypt($this->server['server_id'].psm_get_conf('password_encrypt_key'), $this->server['website_password'])
|
||||
psm_password_decrypt($this->server['server_id'].psm_get_conf('password_encrypt_key'), $this->server['website_password']),
|
||||
$this->server['request_method']
|
||||
);
|
||||
|
||||
$this->rtime = (microtime(true) - $starttime);
|
||||
|
|
|
@ -59,6 +59,32 @@
|
|||
<input class="input-mini" type="text" id="port" name="port" value="{{ edit_value_port }}" maxlength="5" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group popularRequestMethodsGroup types typeWebsite">
|
||||
<label class="control-label" for="popularRequestMethods">{{ label_request_method }}</label>
|
||||
<div class="controls">
|
||||
<select id="popularRequestMethods" name="popularRequestMethods">
|
||||
<option value="">{{ label_none }}</option>
|
||||
<optgroup label="{{ label_popular_request_methods }}">
|
||||
<option value="GET">GET</option>
|
||||
<option value="HEAD">HEAD</option>
|
||||
<option value="POST">POST</option>
|
||||
<option value="PUT">PUT</option>
|
||||
<option value="DELETE">DELETE</option>
|
||||
<option value="CONNECT">CONNECT</option>
|
||||
<option value="OPTIONS">OPTIONS</option>
|
||||
<option value="TRACE">TRACE</option>
|
||||
<option value="PATCH">PATCH</option>
|
||||
</optgroup>
|
||||
<option value="custom">{{ label_custom_request_method }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group requestMethodGroup types typeWebsite">
|
||||
<label class="control-label" for="requestMethod">{{ label_custom_request_method }}</label>
|
||||
<div class="controls">
|
||||
<input class="input" type="text" id="requestMethod" name="request_method" value="{{ edit_value_request_method }}" maxlength="50" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group types typeWebsite">
|
||||
<label class="control-label" for="pattern">{{ label_pattern }}</label>
|
||||
<div class="controls">
|
||||
|
|
|
@ -6,11 +6,11 @@ $().ready(function() {
|
|||
}
|
||||
var $modal_id = $this.attr('data-modal-id') || 'main';
|
||||
var $modal = $('#' + $modal_id + 'Modal');
|
||||
if($modal.length) {
|
||||
if ($modal.length) {
|
||||
$modal.find('.modalOKButton').data('modal-origin', $this);
|
||||
|
||||
var param = $this.attr('data-modal-param');
|
||||
if(param) {
|
||||
if (param) {
|
||||
var ary = param.split(',');
|
||||
for (var index = 0; index < ary.length && index < 9; ++index) {
|
||||
var value = ary[index];
|
||||
|
@ -56,25 +56,42 @@ $().ready(function() {
|
|||
|
||||
if (portInput != '') {
|
||||
var findPopularPorts = $('#popularPorts').find('option[value=' + portInput + ']');
|
||||
if(findPopularPorts.length) {
|
||||
if (findPopularPorts.length) {
|
||||
$(findPopularPorts).attr("selected", "selected");
|
||||
} else {
|
||||
$('#popularPorts').find('option[value=custom]').attr("selected", "selected");
|
||||
$('.portGroup').slideDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$('#popularPorts').change(function () {
|
||||
changePopularPorts($(this).val(), false, $('#type').val());
|
||||
changePopular($(this).val(), $('#type').val());
|
||||
});
|
||||
|
||||
// popularRequestMethods
|
||||
// initial
|
||||
$('.requestMethodGroup').hide();
|
||||
var requestMethodInput = $('#requestMethod').val();
|
||||
|
||||
if (requestMethodInput != '') {
|
||||
var findPopularRequestMethods = $('#popularRequestMethods').find('option[value=' + requestMethodInput + ']');
|
||||
if (findPopularRequestMethods.length) {
|
||||
$(findPopularRequestMethods).attr("selected", "selected");
|
||||
} else {
|
||||
$('#popularRequestMethods').find('option[value=custom]').attr("selected", "selected");
|
||||
$('.requestMethodGroup').slideDown();
|
||||
}
|
||||
}
|
||||
|
||||
$('#popularRequestMethods').change(function () {
|
||||
changePopular($(this).val(), $('#type').val());
|
||||
});
|
||||
// server type
|
||||
$('.types').hide();
|
||||
changeTypeSwitch($('#type').val());
|
||||
|
||||
$('#type').change(function () {
|
||||
changeTypeSwitch($('#type').val());
|
||||
changePopularPorts($('#popularPorts').val(), true, $('#type').val());
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -83,34 +100,34 @@ function changeTypeSwitch(typeInput) {
|
|||
case 'service':
|
||||
$('.types').slideUp();
|
||||
$('.typeService').slideDown();
|
||||
changePopular($('#popularPorts').val(), typeInput, true);
|
||||
break;
|
||||
|
||||
case 'website':
|
||||
$('.types').slideUp();
|
||||
$('.typeWebsite').slideDown();
|
||||
changePopular($('#popularRequestMethods').val(), typeInput, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
$('.types').hide();
|
||||
$('.types').slideUp();
|
||||
}
|
||||
}
|
||||
|
||||
function changePopularPorts(popularPorts, changeType, typeInput) {
|
||||
if (changeType === true) {
|
||||
if (typeInput == 'service') {
|
||||
if (popularPorts == 'custom') {
|
||||
$('.portGroup').slideDown();
|
||||
} else {
|
||||
$('.portGroup').hide();
|
||||
}
|
||||
}
|
||||
function changePopular(inputValue, typeInput, changedType = false) {
|
||||
if (typeInput == 'website') {
|
||||
htmlClass = '.requestMethodGroup';
|
||||
htmlID = '#requestMethod';
|
||||
} else if (typeInput == 'service') {
|
||||
htmlClass = '.portGroup';
|
||||
htmlID = '#port';
|
||||
}
|
||||
|
||||
if (inputValue == 'custom') {
|
||||
$(htmlClass).slideDown();
|
||||
} else {
|
||||
if (popularPorts == 'custom') {
|
||||
$('.portGroup').slideDown();
|
||||
} else {
|
||||
$('#port').val(popularPorts);
|
||||
$('.portGroup').slideUp();
|
||||
}
|
||||
changedType ? $(htmlClass).hide() : $(htmlClass).slideUp();
|
||||
$(htmlID).val(inputValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,14 +190,14 @@ function rtrim(str) {
|
|||
|
||||
function psm_flash_message(message) {
|
||||
var flashmessage = $('#flashmessage');
|
||||
if(flashmessage.length){
|
||||
if(typeof message != 'undefined') {
|
||||
if (flashmessage.length) {
|
||||
if (typeof message != 'undefined') {
|
||||
flashmessage.html(message);
|
||||
}
|
||||
var t = flashmessage.html();
|
||||
var c = trim(t);
|
||||
var t = c.replace(' ', '');
|
||||
if(t){
|
||||
if (t) {
|
||||
flashmessage.slideDown();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue