Implement proxy

This commit is contained in:
Benjamin Drieu 2023-07-03 16:41:56 +02:00 committed by Benjamin Drieu
parent 9ae23885de
commit d57264db3e
4 changed files with 22 additions and 8 deletions

View File

@ -29,10 +29,9 @@ inside of the gnome-shell panel (this could not be developed).
Things I plan to add at some point or another:
* Buttons to operate on services à la nagstamon (recheck, connect via SSH, etc.)
* Buttons to operate on services à la nagstamon (connect via SSH, etc.)
* Filters to hide services (handled, scheduled downtime, host down, ...)
* Support for other free (as in free speech) monitoring servers
* Choose which columns are shown in services result
Things I will be unlikely to add unless a patch is provided:

View File

@ -67,6 +67,7 @@ const prefs = [
{ type: Gtk.Entry, category: 'Settings', label: _('Password'), key: 'password' },
{ type: Gtk.Entry, category: 'Settings', label: _('Web URL'), key: 'url' },
{ type: Gtk.Entry, category: 'Settings', label: _('CGI / API URL'), key: 'urlcgi' },
{ type: Gtk.Entry, category: 'Settings', label: _('Proxy URL'), key: 'proxy' },
{ type: Gtk.Switch, category: 'Settings', label: _('Check SSL certificate'), key: 'strict-ssl', align: Gtk.Align.START },
{ type: Gtk.ColorButton, category: 'Colors', label: _('OK background color'), key: 'ok-color', align: Gtk.Align.START },
{ type: Gtk.ColorButton, category: 'Colors', label: _('Warning background color'), key: 'warning-color', align: Gtk.Align.START },

View File

@ -89,6 +89,10 @@
<default>''</default>
</key>
<key name="proxy" type="s">
<default>''</default>
</key>
<key name="strict-ssl" type="b">
<default>true</default>
</key>

View File

@ -20,7 +20,7 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
const { Soup } = imports.gi;
const { Soup, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Lang = imports.lang;
@ -62,7 +62,8 @@ var GenericServer = class {
this.strict_ssl != this._settings.get_boolean ( "strict-ssl" ) ||
this.name != this._settings.get_string ( "name" ) ||
this.password != this._settings.get_string ( "password" ) ||
this.urlcgi != this._settings.get_string ( "urlcgi" ) )
this.urlcgi != this._settings.get_string ( "urlcgi" ) ||
this.proxy != this._settings.get_string ( "proxy" ) )
{
this.type = this._settings.get_string ( "type" );
this.username = this._settings.get_string ( "username" );
@ -70,6 +71,7 @@ var GenericServer = class {
this.name = this._settings.get_string ( "name" );
this.password = this._settings.get_string ( "password" );
this.urlcgi = this._settings.get_string ( "urlcgi" );
this.proxy = this._settings.get_string ( "proxy" );
this._httpSession = null;
this.monitoLog ( 'Refreshing URL parameters' );
}
@ -86,7 +88,15 @@ var GenericServer = class {
{
if ( this._httpSession == null ) {
this.monitoLog ( 'Preparing new HTTP with strict SSL ' + this.strict_ssl );
this._httpSession = new Soup.Session();
this._httpSession = new Soup.SessionSync();
this._httpSession.timeout = 5;
if ( this.proxy )
{
this.monitoLog ( 'monito Proxy ' + this.proxy + ' for ' + this.name );
let proxy = new Gio.SimpleProxyResolver ( { default_proxy: 'socks://127.0.0.1:3128' } );
this._httpSession.proxy_resolver = proxy;
}
// Soup.Session.prototype.add_feature.call(this._httpSession, new Soup.SimpleProxyResolver());
this._httpSession.ssl_strict = this.strict_ssl;
this._httpSession.user_agent = Me.metadata.uuid;
}
@ -112,9 +122,9 @@ var GenericServer = class {
// this.monitoLog ( message.status_code );
// this.monitoLog ( message.response_body );
message.response_headers.foreach ((name, val) => {
this.monitoLog (name, val);
});
// message.response_headers.foreach ((name, val) => {
// this.monitoLog (name, val);
// });
// this.monitoLog ( message.response_body.data );
if ( message.status_code != Soup.Status.OK )