This commit is contained in:
Nayef Alebrahim 2020-01-18 13:37:51 +00:00 committed by GitHub
commit 82a986c01b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 4 deletions

View File

@ -30,7 +30,7 @@
/**
* Current PSM version
*/
define('PSM_VERSION', '3.4.5');
define('PSM_VERSION', '3.5.0');
/**
* URL to check for updates. Will not be checked if turned off on config page.

View File

@ -182,6 +182,7 @@ $sm_lang = array(
'fieldset_permissions' => 'Permissions',
'permissions' => 'Server will be visible for the following users',
'port' => 'Port',
'protocol' => 'Protocol',
'custom_port' => 'Custom Port',
'popular_ports' => 'Popular Ports',
'request_method' => 'Request method',

View File

@ -61,6 +61,7 @@ abstract class AbstractServerController extends AbstractController
`s`.`server_id`,
`s`.`ip`,
`s`.`port`,
`s`.`protocol`,
`s`.`request_method`,
`s`.`post_field`,
`s`.`type`,
@ -111,6 +112,7 @@ abstract class AbstractServerController extends AbstractController
*/
protected function formatServer($server)
{
$server['protocol'] = strtoupper($server['protocol']);
$server['rtime'] = round((float) $server['rtime'], 4);
$server['last_online'] = psm_timespan($server['last_online']);
$server['last_offline'] = psm_timespan($server['last_offline']);

View File

@ -195,6 +195,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_protocol' => $edit_server['protocol'],
'edit_value_request_method' => $edit_server['request_method'],
'edit_value_post_field' => $edit_server['post_field'],
'edit_value_timeout' => $edit_server['timeout'],
@ -269,6 +270,8 @@ class ServerController extends AbstractServerController
'website_username' => psm_POST('website_username'),
'website_password' => $encrypted_password,
'port' => intval(psm_POST('port', 0)),
'protocol' => in_array($_POST['protocol'], array('tcp', 'udp')) ?
$_POST['protocol'] : 'tcp',
'request_method' => empty(psm_POST('request_method')) ? null : psm_POST('request_method'),
'post_field' => empty(psm_POST('post_field')) ? null : psm_POST('post_field'),
'type' => psm_POST('type', ''),
@ -514,6 +517,7 @@ class ServerController extends AbstractServerController
'label_fieldset_permissions' => psm_get_lang('servers', 'fieldset_permissions'),
'label_permissions' => psm_get_lang('servers', 'permissions'),
'label_port' => psm_get_lang('servers', 'port'),
'label_protocol' => psm_get_lang('servers', 'protocol'),
'label_custom_port' => psm_get_lang('servers', 'custom_port'),
'label_popular_ports' => psm_get_lang('servers', 'popular_ports'),
'label_request_method' => psm_get_lang('servers', 'request_method'),

View File

@ -239,6 +239,7 @@ class Installer
`server_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ip` varchar(500) NOT NULL,
`port` int(5) NOT NULL,
`protocol` enum('tcp','udp') NOT NULL default 'tcp',
`request_method` varchar(50) NULL,
`label` varchar(255) NOT NULL,
`type` enum('ping','service','website') NOT NULL default 'service',
@ -341,6 +342,9 @@ class Installer
if (version_compare($version_from, '3.4.2', '<')) {
$this->upgrade342();
}
if (version_compare($version_from, '3.5.0', '<')) {
$this->upgrade350();
}
psm_update_conf('version', $version_to);
}
@ -655,4 +659,20 @@ class Installer
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `last_output` `last_output` TEXT;";
$this->execSQL($queries);
}
/**
* Upgrade for v3.5.0 release
*/
protected function upgrade350()
{
/**
* Adds a protocol column which defaults to TCP
* This sets the field to TCP on older installations
* ensuring they do not break
*/
$queries = array();
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD COLUMN `protocol` ENUM( 'tcp','udp' )
NOT NULL DEFAULT 'tcp' AFTER `port`;";
$this->execSQL($queries);
}
}

View File

@ -92,7 +92,7 @@ class StatusUpdater
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
'server_id' => $server_id,
), array(
'server_id', 'ip', 'port', 'request_method', 'label',
'server_id', 'ip', 'port', 'protocol', 'request_method', 'label',
'type', 'pattern', 'pattern_online', 'post_field',
'allow_http_status', 'redirect_check', 'header_name',
'header_value', 'status', 'active', 'warning_threshold',
@ -222,7 +222,13 @@ class StatusUpdater
// save response time
$starttime = microtime(true);
$fp = @fsockopen($this->server['ip'], $this->server['port'], $errno, $this->error, $timeout);
$fp = @fsockopen(
$this->server['protocol'] . '://' . $this->server['ip'],
$this->server['port'],
$errno,
$this->error,
$timeout
);
$status = ($fp === false) ? false : true;
$this->rtime = (microtime(true) - $starttime);

View File

@ -7,7 +7,8 @@
<!--class="d-none d-lg-table-cell"-->
<th scope="col">{{ label_label }}</th>
<th scope="col">{{ label_domain }}</th>
<th scope="col" style="width: 5%;">{{ label_port }}</th>
<th scope="col" style="width: 5%;">{{ label_port }}</th>
<th scope="col" style="width: 8%;">{{ label_protocol }}</th>
<th scope="col" style="width: 8%;">{{ label_type }}</th>
<th scope="col" style="width: 8%;">{{ label_rtime }}</th>
<th scope="col" style="width: 10%;">{{ label_last_online }}</th>
@ -40,6 +41,7 @@
</th>
<td><div class="content">{{ server.ip|raw }}</div></td>
<td>{{ server.port }}</td>
<td>{{ server.protocol }}</td>
<td>{{ server.type }}</td>
<td>{{ server.rtime }}</td>
<td><div class="content">{{ server.last_online }}</div></td>

View File

@ -45,6 +45,15 @@
</optgroup>
</select>
</div>
<!-- Protocol -->
<div class="form-group types typeService">
<label for="protocol">{{ label_protocol }}</label>
<select id="protocol" name="protocol" class="custom-select">
<!-- Lets assume TCP by default, no need for js to autoselect as some ports can be UDP or TCP -->
<option {% if not edit_value_protocol %}selected {% elseif edit_value_protocol|lower=='tcp' %}selected {% endif %}value="tcp">TCP</option>
<option {% if edit_value_protocol|lower=='udp' %}selected {% endif %}value="udp">UDP</option>
</select>
</div>
<!-- Custom port -->
{{ macro.input_field("number", "port", "port types typeService", "port", label_custom_port, edit_value_port, null, "5") }}
<!-- Request method -->

View File

@ -37,6 +37,12 @@
<dd class="col-md-8">{{ port }}</dd>
</dl>
</li>
<li class="list-group-item">
<dl class="row">
<dt class="col-md-4">{{ label_protocol }}:</dt>
<dd class="col-md-8">{{ protocol }}</dd>
</dl>
</li>
{% endif %}
<li class="list-group-item">
<dl class="row">