From 4a3136a766a4c54c7a2bc99b196b299b69d14843 Mon Sep 17 00:00:00 2001 From: inportb Date: Mon, 29 May 2023 18:32:13 -0400 Subject: [PATCH] Authentication result parsing --- htdocs/Login.vue | 12 +++++++----- htdocs/ViewOrderDialog.vue | 6 +++--- htdocs/tplfs.mjs | 2 +- htdocs/vista.mjs | 6 +++--- htdocs/vistax.mjs | 8 +++++--- main.py | 6 +++--- rpc.py | 12 ++++-------- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/htdocs/Login.vue b/htdocs/Login.vue index dc39ded..f5ef20f 100644 --- a/htdocs/Login.vue +++ b/htdocs/Login.vue @@ -81,6 +81,7 @@ x_server: this.server, x_user: this.user, banner: null, + authinfo: null, accesscode: null, verifycode: null }; @@ -121,7 +122,7 @@ this.logout(); if(this.x_client = await (this.host ? vistax.Client.fromCookie(this.secret, this.host) : vistax.Client.fromCookie(this.secret))) { this.banner = await this.x_client.XUS_INTRO_MSG(); - if((await this.x_client.userinfo()).result) try { + if((this.authinfo = await this.x_client.authinfo()).success) try { var user = await this.x_client.XUS_GET_USER_INFO(); this.x_user = user[0] ? user : null } catch(ex) { @@ -136,20 +137,21 @@ } else { this.fail = true; this.host = undefined; + this.authinfo = null; } }, async login(evt) { if(this.x_client) { - var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate()); - if(!!res.result[0]) { + this.authinfo = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate()); + if(this.authinfo.duz) { var user = await this.x_client.XUS_GET_USER_INFO(); this.x_user = user[0] ? user : null } else this.x_user = null; this.$emit('update:user', this.x_user); this.show = !this.x_user; this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result); - console.log('Authenticate', res); - } + console.log('Authenticate', this.authinfo); + } else this.authinfo = null; }, async logout(evt) { if(this.x_client) { diff --git a/htdocs/ViewOrderDialog.vue b/htdocs/ViewOrderDialog.vue index eda7a83..4d2d6ee 100644 --- a/htdocs/ViewOrderDialog.vue +++ b/htdocs/ViewOrderDialog.vue @@ -40,7 +40,7 @@ methods: { async submit(payload) { if((this.ien) && (this.dfn) && (payload)) { - var user_ien = (await this.client.userinfo()).result[0]; + var user_ien = (await this.client.authinfo()).duz; var dgrp = await this.client.ORWDX_DGRP(this.dlgname.BaseDialogName); var res = await client.ORWDX_SAVE(this.dfn, 0/*user_ien*/, 0/*location_ien*/, this.dlgname.BaseDialogName, dgrp, this.dlgname.BaseDialogIEN, ''/*order_ifn*/, payload, '', '', '', 0); console.log(res); @@ -52,8 +52,8 @@ () => (this.client, this.ien, {}), async () => { if((this.client) && (this.ien)) { - var userinfo = await this.client.userinfo(); - var user_ien = userinfo && userinfo.result ? userinfo.result[0] : ''; + var authinfo = await this.client.authinfo(); + var user_ien = authinfo && authinfo.success ? authinfo.duz : ''; this.dlgname = await this.client.ORWDXM_DLGNAME(this.ien); if(this.dlgname.BaseDialogIEN != this.ien) console.warn('IEN =', this.ien, '|', 'BaseDialogIEN =', this.dlgname.BaseDialogIEN); this.dlgdef = await this.client.ORWDX_DLGDEF(this.dlgname.BaseDialogName); diff --git a/htdocs/tplfs.mjs b/htdocs/tplfs.mjs index 794a57a..f85b6af 100644 --- a/htdocs/tplfs.mjs +++ b/htdocs/tplfs.mjs @@ -217,7 +217,7 @@ export function TplFS(client, parent, desc) { } TplFS.fromUser = async function(client, user_ien=null) { - if(!user_ien) user_ien = (await client.userinfo()).result[0]; + if(!user_ien) user_ien = (await client.authinfo()).duz; return new TplFS(client, null, (await client.TIU_TEMPLATE_GETPROOT(user_ien))[0]); }; diff --git a/htdocs/vista.mjs b/htdocs/vista.mjs index fbb3a08..109ee32 100644 --- a/htdocs/vista.mjs +++ b/htdocs/vista.mjs @@ -30,8 +30,8 @@ export async function serverinfo(cid) { })).json(); } -export async function userinfo(cid) { - return await (await fetch('/v1/vista/' + cid + '/userinfo', { +export async function authinfo(cid) { + return await (await fetch('/v1/vista/' + cid + '/authinfo', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' @@ -47,5 +47,5 @@ export async function authenticate(cid, avcode=null) { } export default window.vista = { - connect, close, call, serverinfo, userinfo, authenticate + connect, close, call, serverinfo, authinfo, authenticate }; diff --git a/htdocs/vistax.mjs b/htdocs/vistax.mjs index 01edd3d..941ff7a 100644 --- a/htdocs/vistax.mjs +++ b/htdocs/vistax.mjs @@ -48,6 +48,8 @@ export const d_parse_boolean = data => data != '0'; export const d_parse_text = data => data !== '' ? data.join('\r\n') : data; export const d_parse_array = data => data !== '' ? data : []; +export const d_parse_authinfo = data => data ? { duz: data[0] != '0' ? data[0] : null, device_lock: data[1] != '0', change_verify: data[2] != '0', message: data[3], reserved: data[4], greeting_lines: data[5], greeting: data.slice(6), success: (data[0] != '0') && (data[2] == '0') } : { success: false } + export const d_parse_orderdialogs = (data, columns=['IEN', 'windowFormId', 'displayGroupId', 'type', 'displayText']) => data.map(function(row) { row = row.split('^'); row = [...row[0].split(';'), row[1]]; @@ -240,11 +242,11 @@ export function Client(cid, secret) { return heartbeat = window.setInterval(this.XWB_IM_HERE, interval); } this.serverinfo = () => vista.serverinfo(cid); - this.userinfo = () => vista.userinfo(cid); - this.authenticate = (avcode=null) => vista.authenticate(cid, avcode); + this.authinfo = aflow(() => vista.authinfo(cid), d_unwrap, d_parse_authinfo); + this.authenticate = aflow((avcode=null) => vista.authenticate(cid, avcode), d_unwrap, d_parse_authinfo); if(!localstate.encfs) localstate.encfs = tplfs_randpassword(); - this.tplfs = async () => this._tplfs ? this._tplfs : (this._tplfs = await TplFS.fromUser(this, (await this.userinfo()).result[0])); + this.tplfs = async () => this._tplfs ? this._tplfs : (this._tplfs = await TplFS.fromUser(this, (await this.authinfo()).duz)); this.encfs = async () => this._encfs ? this._encfs : (this._encfs = await EncFS.fromPassword(await this.tplfs(), localstate.encfs)); this.remotestate = reactive({}); diff --git a/main.py b/main.py index 02ebda9..9384b97 100644 --- a/main.py +++ b/main.py @@ -92,11 +92,11 @@ def application(): logger.exception(request.url) return jsonify_error(ex, id=request.json.get('id')) - @app.post('/v1/vista//userinfo') - def cb_userinfo(cid): + @app.post('/v1/vista//authinfo') + def cb_authinfo(cid): try: client = clients[cid] - return jsonify_result(client._obj._user, id=request.json.get('id')) + return jsonify_result(client._obj._auth, id=request.json.get('id')) except Exception as ex: logger.exception(request.url) return jsonify_error(ex, id=request.json.get('id')) diff --git a/rpc.py b/rpc.py index d0adafe..c438191 100644 --- a/rpc.py +++ b/rpc.py @@ -112,7 +112,7 @@ class ClientSync(object): self.recv_rpc_msg = recv_rpc_msg(self.sock) self.lock = threading.Lock() self._server = { 'host': host, 'port': port } - self._user = None + self._auth = None self.context = 'XUS SIGNON' if TCPConnect and (res := self.TCPConnect(self.sock.getsockname()[0], '0', socket.gethostname())) != 'accept': raise RPCExcInvalidResult('TCPConnect', self.sock.getsockname()[0], '0', socket.gethostname(), res) @@ -148,9 +148,7 @@ class ClientSync(object): res = self('XUS ESSO VALIDATE', RPCType(tuple(identity[i:i+200] for i in range(0, len(identity), 200)), RPCType.GLOBAL)) else: res = self('XUS AV CODE', XWBHash_encrypt(identity)) - if res[0] == '0' or res[2] != '0': - raise RPCExcAuth(res[3], res) - self._user = res + self._auth = res if res[0] != '0' else None return res def keepalive(self, interval=None, *, context=('XUS SIGNON',)): import time @@ -188,7 +186,7 @@ class ClientAsync(object): self.arecv_rpc_msg = arecv_rpc_msg(self.reader) self.lock = asyncio.Lock() self._server = { 'host': host, 'port': port, 'info': None } - self._user = None + self._auth = None self.context = 'XUS SIGNON' if TCPConnect and (res := await self.TCPConnect(self.writer.get_extra_info('sockname')[0], '0', socket.gethostname())) != 'accept': raise RPCExcInvalidResult('TCPConnect', self.writer.get_extra_info('sockname')[0], '0', socket.gethostname(), res) @@ -229,9 +227,7 @@ class ClientAsync(object): res = await self('XUS ESSO VALIDATE', RPCType(tuple(identity[i:i+200] for i in range(0, len(identity), 200)), RPCType.GLOBAL)) else: res = await self('XUS AV CODE', XWBHash_encrypt(identity)) - if res[0] == '0' or res[2] != '0': - raise RPCExcAuth(res[3], res) - self._user = res + self._auth = res if res[0] != '0' else None return res async def keepalive(self, interval=None, *, context=('XUS SIGNON',)): interval = interval or 0.45*float((await self.XWB_GET_BROKER_INFO(context=context))[0])