From d52454c1907aa344db4aabbd1ae9bd1e83d83e4f Mon Sep 17 00:00:00 2001 From: Isabel Jenkins Date: Sat, 30 Sep 2017 23:50:28 +0100 Subject: [PATCH 1/6] Update .gitlab-ci.yml --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 99f5a07..297b3bc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,7 @@ build-release: deploy-release: stage: deploy script: + - echo "Hello World!" only: - release environment: release -- GitLab From 9982d30b7bc1d6523ee6b697142a7db221b909a8 Mon Sep 17 00:00:00 2001 From: Isabel Jenkins Date: Sun, 1 Oct 2017 00:25:58 +0100 Subject: [PATCH 2/6] Update .gitlab-ci.yml --- .gitlab-ci.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 297b3bc..0c237f5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,9 +3,38 @@ #image: debian:jessie stages: + - test - build - deploy +test-master: + stage: test + script: + - apt-get clean + - apt-get update + - apt-get install -y curl gnupg + - curl -sL https://deb.nodesource.com/setup_8.x | bash - + - apt-get install -y nodejs + - npm install + - npm run test + only: + - master + environment: master + +build-master: + stage: build + script: + - apt-get clean + - apt-get update + - apt-get install -y curl gnupg + - curl -sL https://deb.nodesource.com/setup_8.x | bash - + - apt-get install -y nodejs + - npm install + - npm run build + only: + - master + environment: master + build-release: stage: build script: -- GitLab From 4010a82f25d352e10baa667e76992dfa95c16559 Mon Sep 17 00:00:00 2001 From: Isabel Jenkins Date: Sun, 1 Oct 2017 00:47:08 +0100 Subject: [PATCH 3/6] =?UTF-8?q?We=20don't=20actually=20have=20any=20automa?= =?UTF-8?q?ted=20test=20yet=20so=20=C2=AF\=5F(=C2=B0=5F=C2=B0)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0c237f5..f1ef27c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,24 +3,9 @@ #image: debian:jessie stages: - - test - build - deploy -test-master: - stage: test - script: - - apt-get clean - - apt-get update - - apt-get install -y curl gnupg - - curl -sL https://deb.nodesource.com/setup_8.x | bash - - - apt-get install -y nodejs - - npm install - - npm run test - only: - - master - environment: master - build-master: stage: build script: -- GitLab From ca6062006773e06146aeec26bc756eb4ca3ad587 Mon Sep 17 00:00:00 2001 From: Isabel Jenkins Date: Sun, 1 Oct 2017 14:59:44 +0100 Subject: [PATCH 4/6] Fix for patchy connections --- src/components/chat.vue | 14 ++++++++++++-- src/components/login.vue | 2 +- src/components/topbar.vue | 2 +- src/mixins/mw-sync.js | 12 +++++++++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/chat.vue b/src/components/chat.vue index 5a8aceb..6769f38 100644 --- a/src/components/chat.vue +++ b/src/components/chat.vue @@ -25,6 +25,7 @@ import getImage from '../mixins/get-image.js' const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig let room = 0 let msgCount = 0 +let previousOnline = true export default { name: 'chat', @@ -53,7 +54,16 @@ export default { msgCount -= msgNum }) - var ctx = this + window.bus.$on('online', (online) => { + if (!previousOnline && online) { + let timestamp = (this.$ls.get('lastmsg-' + room) + 1) + this.sendCmd('replay since ' + timestamp) + } + + previousOnline = online + }) + + let ctx = this setInterval(function () { ctx.sync(ctx, ctx.$ls.get('token'), ctx.onMsg) }, 1000) } }, @@ -79,7 +89,7 @@ export default { this.$ls.set('lastmsg-' + room, timestamp) } - var timestamp = (this.$ls.get('lastmsg-' + room) + 1) + let timestamp = (this.$ls.get('lastmsg-' + room) + 1) this.sendCmd('replay since ' + timestamp) }, onMsg: function (msg) { diff --git a/src/components/login.vue b/src/components/login.vue index 0a53c2e..0c34342 100644 --- a/src/components/login.vue +++ b/src/components/login.vue @@ -34,7 +34,7 @@ export default { var user = document.getElementById('login-user').value var pass = document.getElementById('login-pass').value - axios.post('https://chat.sucs.org/php', { username: user, password: pass, action: 'login' }) + axios.post('https://chat.sucs.org/php/', { username: user, password: pass, action: 'login' }) .then(function (response) { if (typeof response.data === 'string') { if (response.data.startsWith('success:')) { diff --git a/src/components/topbar.vue b/src/components/topbar.vue index 88b2ee4..96ddf62 100644 --- a/src/components/topbar.vue +++ b/src/components/topbar.vue @@ -28,7 +28,7 @@ export default { }, methods: { logout: function (event) { - this.$ls.clear() + this.$ls.remove('token') this.$clearStorage() location.reload() }, diff --git a/src/mixins/mw-sync.js b/src/mixins/mw-sync.js index 83678c1..78ef03b 100644 --- a/src/mixins/mw-sync.js +++ b/src/mixins/mw-sync.js @@ -1,7 +1,7 @@ import axios from 'axios' import getImage from '../mixins/get-image.js' -var profileImages = {} +let profileImages = {} export default { mixins: [getImage], @@ -9,7 +9,13 @@ export default { sync: function (ctx, token, callback) { axios.get('https://chat.sucs.org/php/poll.php', { params: { mwsess: token }, timeout: 1000 }) .then((msg) => { ctx.response(msg, callback) }).catch(function (error) { - error // Yea this counts as handling the error + if (error.message.indexOf('Network Error') !== -1) { + window.bus.$emit('online', false) + } else if (error.message.indexOf('timeout of') !== -1) { + window.bus.$emit('online', true) + } else { + error // 'Handle' the error + } }) }, response: async function (msg, callback) { @@ -145,7 +151,7 @@ export default { default: if (typeof msg[one].text === 'undefined') { // We've been timed out :( - this.$ls.clear() + this.$ls.remove('token') this.$clearStorage() location.reload() } -- GitLab From 588532c0730cb900ec691d67a0a382e98f6fc93b Mon Sep 17 00:00:00 2001 From: matstn Date: Mon, 2 Oct 2017 17:17:50 +0100 Subject: [PATCH 5/6] Resolved moz scrolling issue --- src/App.vue | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index bc4699e..10eba10 100644 --- a/src/App.vue +++ b/src/App.vue @@ -25,8 +25,17 @@ body { -moz-osx-font-smoothing: grayscale; } +/* Moz has no support for custom scrollbars. Default to plain */ .scroll { - overflow-y: hidden; + overflow-y: scroll; +} + +/* Chrome 29+ (Only) */ +@supports (-webkit-appearance:none) and (not (overflow:-webkit-marquee)) +and (not (-ms-ime-align:auto)) and (not (-moz-appearance:none)) { + .scroll { + overflow-y: hidden; + } } @media only screen and (max-width: 800px) { -- GitLab From 7c6c58f14e1c395f391200858ec4265807a73418 Mon Sep 17 00:00:00 2001 From: Isabel Jenkins Date: Mon, 2 Oct 2017 22:23:39 +0100 Subject: [PATCH 6/6] Merged https://projects.sucs.org/unreturnable/webmw and https://projects.sucs.org/imranh/webmw --- .gitlab-ci.yml | 10 +++- README.md | 2 +- php/.htaccess | 1 + php/README | 24 ++++++++ php/config.php | 11 ++++ php/index.php | 32 +++++++++++ php/poll.php | 53 ++++++++++++++++++ php/send.php | 84 ++++++++++++++++++++++++++++ php/startup.php | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 361 insertions(+), 2 deletions(-) create mode 100644 php/.htaccess create mode 100644 php/README create mode 100644 php/config.php create mode 100644 php/index.php create mode 100644 php/poll.php create mode 100644 php/send.php create mode 100644 php/startup.php diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f1ef27c..9a4d5f7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,6 +16,10 @@ build-master: - apt-get install -y nodejs - npm install - npm run build + - cp -rv php dist/ + artifacts: + paths: + - dist/ only: - master environment: master @@ -30,10 +34,14 @@ build-release: - apt-get install -y nodejs - npm install - npm run build + - cp -rv php dist/ + artifacts: + paths: + - dist/ only: - release environment: release - + deploy-release: stage: deploy script: diff --git a/README.md b/README.md index 3c8488b..9ec615c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # webmw -> A Vue.js project +> Web client for Milliways. ## Build Setup diff --git a/php/.htaccess b/php/.htaccess new file mode 100644 index 0000000..f289550 --- /dev/null +++ b/php/.htaccess @@ -0,0 +1 @@ +Header set Access-Control-Allow-Origin "*" diff --git a/php/README b/php/README new file mode 100644 index 0000000..2e394a5 --- /dev/null +++ b/php/README @@ -0,0 +1,24 @@ +This is the web client for milliways talker. + +It works by running a background task that connects to the server +and appears as a standard client, buffering up messages until it is +polled by the web interface. + + +once you have the username & password (or existing sucssite token) +you launch mwpoll, this authenticates the user, puts itself into +the background, and gives you a socket address to communicate with it. + +the html code can then make ajax calls to poll.php, which will talk +to mwpoll through the socket, retrieving any new messages that are +waiting, if there are none it will pause for upto 60 seconds in a +"long poll". + +all messages (or an empty list) are returned in json format + +when the user has a command or message to send, an ajax call is placed +to send.php any immediate response from the command will be returned +as a json message + +in the current implimentation most of the decoding of the json messages +is handled by say.js in the browser diff --git a/php/config.php b/php/config.php new file mode 100644 index 0000000..5e7980b --- /dev/null +++ b/php/config.php @@ -0,0 +1,11 @@ + diff --git a/php/index.php b/php/index.php new file mode 100644 index 0000000..cb0aab8 --- /dev/null +++ b/php/index.php @@ -0,0 +1,32 @@ + diff --git a/php/poll.php b/php/poll.php new file mode 100644 index 0000000..a9d7783 --- /dev/null +++ b/php/poll.php @@ -0,0 +1,53 @@ + diff --git a/php/send.php b/php/send.php new file mode 100644 index 0000000..19e112e --- /dev/null +++ b/php/send.php @@ -0,0 +1,84 @@ + diff --git a/php/startup.php b/php/startup.php new file mode 100644 index 0000000..0e9781a --- /dev/null +++ b/php/startup.php @@ -0,0 +1,146 @@ + 'username and password must both be not empty']); + exit; + } + + if (ctype_alnum($username) === FALSE) { + echo json_encode((object) ['error' => 'alphanumeric usernames only']); + exit; + } +} + +// Have we been asked to create a new Milliways account? +// If so, make sure that the password supplied is suitable. +if ($action=="create") { + $pass1 = @$_REQUEST['password1']; + $pass2 = @$_REQUEST['password2']; + + if ($pass1 != $pass2) { + echo json_encode((object) ['error' => 'Passwords don\'t match - please try again']); + exit; + } + + if (empty($pass1)) { + echo json_encode((object) ['error' => 'Password cannot be blank']); + exit; + } + + if (ctype_alnum($pass1) === FALSE) { + echo json_encode((object) ['error' => 'Milliways passwords can only contain alphanumeric characters']); + exit; + } + + if (strlen($pass1) < 6) { + echo json_encode((object) ['error' => 'Milliways passwords must be 6 characters or more']); + exit; + } +} + +$desc = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w"), +); +$pipes = array(); + +// Have we got SUCSsite cookies? +// And no login attempt? +// If so, fetch the user details and try to log in without a password. +if (@$_REQUEST['sucssite_loggedin']=="true" && empty($username)) { + + // Do we appear to be in the SUCSsite environment? + // There's only any point trying if we do. + if (file_exists("../settings.php")) { + // Do the bare minimum of SUCSsite init to retrieve the username for the session we've been passed + include("../settings.php"); + // Initialise the database + require("/usr/share/php/adodb/adodb.inc.php"); + $DB = NewADOConnection('postgres9'); + $DB->Connect('dbname='.$dbname.' user=apache'); + $DB->SetFetchMode(ADODB_FETCH_ASSOC); + + // Include the session library + require($base."lib/session.php"); + $session = new Session; + // $smarty->assign("session", $session); // This line might be useful? + $realuser = $session->username; + + if ($action == "create") { + $p = proc_open($mwpoll." -q -a -u ".$realuser." -s", $desc, $pipes); + } else { + $p = proc_open($mwpoll." -q -u ".$realuser." -s", $desc, $pipes); + } + $mode = "sucssite"; + } +} else { + // If not, try logging in with a password. + $p = proc_open($mwpoll." -q -u $username", $desc, $pipes); + $mode = "password"; +} + +if (empty($p)) { + echo "

No

"; + exit; +} + +if ($p === FALSE) { + echo json_encode((object) ['error' => 'failed to exec mwpoll']); + exit; +} + +if ($mode == "sucssite" && @$_REQUEST['sucssite_loggedin']=="true" && empty($username)) { + // If we have a sucssite session cookie, use that + fwrite($pipes[0], trim($_REQUEST['sucssite_session'])."\n"); + if ($action="create") { + fwrite($pipes[0], $pass1."\n"); + } +} else { + // Try logging on using username and password + if (fwrite($pipes[0], $password."\n") === FALSE) { + echo "Error writing to mwpoll\n"; + } +} + +$pid = fgets($pipes[1]); +if ($pid === FALSE) { + echo "error reading pid.\n"; +} + +$pid = trim($pid); +if (!is_numeric($pid)) { + if (substr($pid, -10) =="not found.") { + // User doesn't exist - ask for a Milliways password so we can create them! + echo json_encode((object) ['error' => $pid]); + exit; + } + + echo json_encode((object) ['error' => 'Bad response: pid=$pid']); + exit; +} + +$auth = fgets($pipes[1]); + +if ($auth === FALSE) { + echo "Error reading auth string\n"; +} + +$sess = array ( + "pid" => $pid, + "auth" => $auth, + "username" => $username +); + +$mwsess = serialize($sess); +echo "success:" . $mwsess; +?> -- GitLab