From e35f2ab4d6d2f0695a2e21719ee31492a7faa69c Mon Sep 17 00:00:00 2001
From: Jeremy Mahieu
Date: Wed, 18 Dec 2019 01:06:03 +0100
Subject: [PATCH] Fix atob error, add url params
---
index.html | 27 ++++++++++++++++++++++++++-
js/glowingbear.js | 30 +++++++++++++++++++-----------
2 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/index.html b/index.html
index e031aa1..22a0cb6 100644
--- a/index.html
+++ b/index.html
@@ -12,6 +12,7 @@
+
@@ -230,7 +231,10 @@ chown -R username :username ~username
Setting a custom path
- To connect to the weechat relay service we connect using a URL. A typical URL consists of 4 parts. {scheme}://{host}:{port}/{path}
. The path can be changed by enterying the relay's full URL (except the scheme).
+ The hostname field can be used to set a custom path. Or a URL parameter can be used see section 'URL Parameters'.
+
+
+ To connect to the weechat relay service we connect using a URL. A typical URL consists of 4 parts. {scheme}://{host}:{port}/{path}
. The path can be changed by entering the relay's full URL (except the scheme).
scheme : The scheme must never be input. The scheme is "ws" if TLS isn't used and it is "wss" if TLS is used.
@@ -263,6 +267,27 @@ chown -R username :username ~username
2001:db8:85a3::8a2e:370:7334 (must wrap IPv6 address in square brackets)
2001:db8:85a3::8a2e:370:7334:8000 (must wrap IPv6 address in square brackets)
+ URL Parameters
+
+ Parameters can be passed in the URL to prefill the fields. This can be useful when you have multiple relays and want to use bookmarks to manage them.
+ We do not recommend passing the password in this was as it will be visible in plain text and stored in the bookmark but it is possible. Special characters should be URL encoded .
+
+
+ If we want just the path for example: https://glowing-bear.org/?path=weechat2
+
+
+ An example: https://glowing-bear.org/?host=my.domain.com&port=8000&password=hunter2&autoconnect=true
+
+
+ Available parameters:
+
+ host
+ port
+ path
+ password
+ autoconnect
+
+
diff --git a/js/glowingbear.js b/js/glowingbear.js
index 5111d52..a738361 100644
--- a/js/glowingbear.js
+++ b/js/glowingbear.js
@@ -8,9 +8,12 @@ document.addEventListener("deviceready", function () {
}
}, false);
-var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'bufferResume', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch'], ['$compileProvider', function($compileProvider) {
+var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'bufferResume', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch'], ['$compileProvider', '$locationProvider', function($compileProvider, $locationProvider) {
// hacky way to be able to find out if we're in debug mode
weechat.compileProvider = $compileProvider;
+
+ //remove hashbang from url
+ $locationProvider.html5Mode(true).hashPrefix('');
}]);
weechat.config(['$compileProvider', function ($compileProvider) {
// hack to determine whether we're executing the tests
@@ -19,8 +22,8 @@ weechat.config(['$compileProvider', function ($compileProvider) {
}
}]);
-weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'bufferResume', 'connection', 'notifications', 'utils', 'settings',
- function ($rootScope, $scope, $store, $timeout, $log, models, bufferResume, connection, notifications, utils, settings)
+weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout','$location', '$log', 'models', 'bufferResume', 'connection', 'notifications', 'utils', 'settings',
+ function ($rootScope, $scope, $store, $timeout, $location, $log, models, bufferResume, connection, notifications, utils, settings)
{
window.openBuffer = function(channel) {
@@ -699,6 +702,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
};
$scope.connect = function() {
+
notifications.requestNotificationPermission();
$rootScope.sslError = false;
$rootScope.securityError = false;
@@ -973,14 +977,15 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.init = function() {
$scope.parseHost();
+
+ //Fill in url parameters, they take precedence over the stored settings, but store them
+ if($location.search().host) { $scope.settings.host = $location.search().host; $scope.settings.hostField = $location.search().host;}
+ if($location.search().port) { $scope.settings.port = parseInt($location.search().port);}
+ if($location.search().path) { $scope.settings.path = $location.search().path;}
+ if($location.search().password) { $scope.settings.password = $location.search().password;}
+ if($location.search().autoconnect) { $scope.settings.autoconnect = $location.search().autoconnect === 'true';}
+
if (window.location.hash) {
- var rawStr = atob(window.location.hash.substring(1));
- window.location.hash = "";
- var spl = rawStr.split(":");
- settings.host = spl[0];
- settings.port = parseInt(spl[1]);
- var password = spl[2];
- var ssl = spl.length > 3;
notifications.requestNotificationPermission();
$rootScope.sslError = false;
$rootScope.securityError = false;
@@ -988,7 +993,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope.bufferBottom = true;
$scope.connectbutton = 'Connecting';
$scope.connectbuttonicon = 'glyphicon-chevron-right';
- $scope.parseHost();
connection.connect(settings.host, settings.port, settings.path, password, ssl);
}
};
@@ -1000,6 +1004,10 @@ weechat.config(['$routeProvider',
$routeProvider.when('/', {
templateUrl: 'index.html',
controller: 'WeechatCtrl'
+ })
+ //for legacy reasons redirect the /#! to /
+ .otherwise({
+ redirectTo: '/'
});
}
]);