Compare commits
No commits in common. "1a08acdc7c73294e811ca034ea55f1dae13ab550" and "05601e0adb441d37506baf7018c317c6892527c6" have entirely different histories.
1a08acdc7c
...
05601e0adb
@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<div class="container-fluid">
|
||||
<Navbar v-model:server="server" :user="user" />
|
||||
<Navbar :user="user" />
|
||||
<div class="container">
|
||||
<Login :secret="secret" v-model:client="client" v-model:server="server" v-model:user="user" />
|
||||
<router-view v-if="user"></router-view>
|
||||
<Login :secret="secret" v-model:client="client" v-model:user="user" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@ -26,7 +26,6 @@
|
||||
data() {
|
||||
return {
|
||||
client: null,
|
||||
server: null,
|
||||
user: null,
|
||||
heartbeat: null,
|
||||
banner: '',
|
||||
@ -37,7 +36,7 @@
|
||||
store: () => store
|
||||
},
|
||||
watch: {
|
||||
async client(value, oldvalue) {
|
||||
async client(value) {
|
||||
if(this.heartbeat) window.clearInterval(this.heartbeat);
|
||||
else {
|
||||
[
|
||||
@ -48,8 +47,7 @@
|
||||
].forEach(route => this.$root.$router.addRoute(route));
|
||||
await this.$root.$router.replace(this.$route);
|
||||
}
|
||||
if(value) this.heartbeat = await value.heartbeat();
|
||||
if(oldvalue) this.$router.go(); // refresh if changed
|
||||
this.heartbeat = await value.heartbeat();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -104,8 +104,7 @@
|
||||
data() {
|
||||
return {
|
||||
x_range: this.range,
|
||||
x_date: this.date,
|
||||
x_date_end: this.date_end
|
||||
x_date: this.date
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@ -114,10 +113,8 @@
|
||||
return this.x_date.toLocaleDateString('en-CA');
|
||||
},
|
||||
set(value) {
|
||||
if(value.length > 0) {
|
||||
value = value.split('-');
|
||||
if(value[0] >= 1700) this.x_date = new Date(value[0], value[1] - 1, value[2]);
|
||||
}
|
||||
value = value.split('-')
|
||||
this.x_date = new Date(value[0], value[1] - 1, value[2]);
|
||||
}
|
||||
},
|
||||
disp_date_end: {
|
||||
@ -125,10 +122,8 @@
|
||||
return this.x_date_end.toLocaleDateString('en-CA');
|
||||
},
|
||||
set(value) {
|
||||
if(value.length > 0) {
|
||||
value = value.split('-');
|
||||
if(value[0] >= 1700) this.x_date_end = new Date(value[0], value[1] - 1, value[2]);
|
||||
}
|
||||
value = value.split('-')
|
||||
this.x_date_end = new Date(value[0], value[1] - 1, value[2]);
|
||||
}
|
||||
},
|
||||
params() {
|
||||
@ -147,8 +142,6 @@
|
||||
},
|
||||
date(value) { this.x_date = value; },
|
||||
x_date(value) { this.$emit('update:date', value); },
|
||||
date_end(value) { this.x_date_end = value; },
|
||||
x_date_end(value) { this.$emit('update:date_end', value); },
|
||||
range(value) { this.x_range = value; },
|
||||
x_range(value) { this.$emit('update:range', value); }
|
||||
},
|
||||
|
110
htdocs/Login.vue
110
htdocs/Login.vue
@ -1,60 +1,25 @@
|
||||
<template>
|
||||
<div class="accordion mb-3 shadow">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header"><button class="accordion-button" :class="{ testing: (x_server) && (x_server.production != '1') }" type="button" @click="() => show = !show"><template v-if="user">{{user[2]}}<template v-if="server"> @ {{server.domain}}</template></template><template v-else>Login</template></button></h2>
|
||||
<div class="accordion-collapse collapse" :class="{ show }">
|
||||
<div class="accordion-body">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="card-text row"><code class="col" v-if="banner"><pre>{{banner.join('\n')}}</pre></code><code class="col" v-if="user"><pre>{{user.join('\n')}}</pre></code></p>
|
||||
</div>
|
||||
<button class="btn btn-danger" style="width: 100%;" type="button" v-if="user" v-on:click="logout">Logout</button>
|
||||
<div class="input-group flex-nowrap" v-if="!user">
|
||||
<span class="input-group-text">🔑</span>
|
||||
<select class="form-control" v-model="host">
|
||||
<option value="vista.bronx.med.va.gov:19201">Bronx BRX</option>
|
||||
<option value="test.bronx.med.va.gov:19001">Bronx BRX-TEST</option>
|
||||
<option value="vista.east-orange.med.va.gov:19203">East Orange NJH</option>
|
||||
<option value="test.east-orange.med.va.gov:19003">East Orange NJH-TEST</option>
|
||||
<option value="vista.hudson-valley.med.va.gov:19205">Hudson Valley NVH</option>
|
||||
<option value="test.hudson-valley.med.va.gov:19005">Hudson Valley NVH-TEST</option>
|
||||
<option value="vista.brooklyn.med.va.gov:19208">NY Harbor NYH</option>
|
||||
<option value="test.brooklyn.med.va.gov:19008">NY Harbor NYH-TEST</option>
|
||||
<option value="vista.northport.med.va.gov:19209">Northport NOP</option>
|
||||
<option value="test.northport.med.va.gov:19009">Northport NOP-TEST</option>
|
||||
<option value="vista.v02.med.va.gov:19224">VISN 2 V02</option>
|
||||
<option value="test.v02.med.va.gov:19024">VISN 2 V02-TEST</option>
|
||||
</select>
|
||||
<input type="password" class="form-control" placeholder="Access Code" v-model="accesscode" />
|
||||
<input type="password" class="form-control" placeholder="Verify Code" v-model="verifycode" />
|
||||
<button class="btn btn-primary" type="button" v-on:click="login">Login<template v-if="!(accesscode || verifycode)"> (omit AV codes for SAML)</template></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mb-3 shadow">
|
||||
<div class="card-header"><template v-if="user">{{user[2]}}</template><template v-else>Login</template></div>
|
||||
<div class="card-body">
|
||||
<p class="card-text row"><code class="col" v-if="banner"><pre>{{banner.join('\n')}}</pre></code><code class="col" v-if="user"><pre>{{user.join('\n')}}</pre></code></p>
|
||||
</div>
|
||||
<div class="input-group flex-nowrap" v-if="!user">
|
||||
<span class="input-group-text">🔑</span>
|
||||
<input type="password" class="form-control" placeholder="Access Code" v-model="accesscode" />
|
||||
<input type="password" class="form-control" placeholder="Verify Code" v-model="verifycode" />
|
||||
<button class="btn btn-primary" type="button" v-on:click="submit">Login<template v-if="!(accesscode || verifycode)"> (omit AV codes for SAML)</template></button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.accordion-button.testing:not(.collapsed) {
|
||||
color: #e40c63;
|
||||
background-color: #ffe7f1;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
import cookie from './cookie.mjs';
|
||||
import vistax from './vistax.mjs';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
secret: String,
|
||||
client: Object,
|
||||
server: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
user: {
|
||||
type: Array,
|
||||
default: null
|
||||
@ -62,10 +27,6 @@
|
||||
},
|
||||
emits: {
|
||||
'update:client': Object,
|
||||
'update:server': {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
'update:user': {
|
||||
type: Array,
|
||||
default: null
|
||||
@ -73,10 +34,7 @@
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
show: false,
|
||||
host: cookie.get('host'),
|
||||
x_client: this.client,
|
||||
x_server: this.server,
|
||||
x_user: this.user,
|
||||
banner: null,
|
||||
accesscode: null,
|
||||
@ -84,57 +42,33 @@
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
host(value) {
|
||||
cookie.set('host', value);
|
||||
this.logout();
|
||||
},
|
||||
client(value) { this.x_client = value; },
|
||||
x_client(value) { this.$emit('update:client', value); },
|
||||
server(value) { this.x_server = value; },
|
||||
x_server(value) { this.$emit('update:server', value); },
|
||||
user(value) { this.x_user = value; },
|
||||
x_user(value) { this.$emit('update:user', value); }
|
||||
},
|
||||
async mounted() {
|
||||
this.connect();
|
||||
this.x_client = await vistax.Client.fromCookie(this.secret);
|
||||
this.banner = await this.x_client.XUS_INTRO_MSG();
|
||||
if((await this.x_client.userinfo()).result) try {
|
||||
var user = await this.x_client.XUS_GET_USER_INFO();
|
||||
this.x_user = user[0] ? user : null
|
||||
} catch(ex) {
|
||||
this.x_user = null;
|
||||
}
|
||||
this.$emit('update:user', this.x_user);
|
||||
console.log('Backend secret', this.secret);
|
||||
console.log(this.banner);
|
||||
},
|
||||
methods: {
|
||||
async connect() {
|
||||
if(this.x_client) return this.x_client;
|
||||
this.x_client = await vistax.Client.fromCookie(this.secret);
|
||||
this.banner = await this.x_client.XUS_INTRO_MSG();
|
||||
if((await this.x_client.userinfo()).result) try {
|
||||
var user = await this.x_client.XUS_GET_USER_INFO();
|
||||
this.x_user = user[0] ? user : null
|
||||
} catch(ex) {
|
||||
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('Backend secret', this.secret);
|
||||
console.log(this.banner);
|
||||
return this.x_client;
|
||||
},
|
||||
async login(evt) {
|
||||
if(!this.x_client) await this.connect();
|
||||
async submit(evt) {
|
||||
var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
|
||||
if(!!res.result[0]) {
|
||||
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);
|
||||
},
|
||||
async logout(evt) {
|
||||
if(this.x_client) {
|
||||
console.log('Close', await this.x_client.close());
|
||||
this.$emit('update:client', this.x_client = null);
|
||||
this.$emit('update:server', this.x_server = null);
|
||||
this.$emit('update:user', this.x_user = null);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -16,8 +16,8 @@
|
||||
<li class="nav-item">
|
||||
<router-link class="nav-link" to="/recall">Recall</router-link>
|
||||
</li>
|
||||
<li class="nav-item" v-if="server">
|
||||
<a class="nav-link disabled">{{server.domain}}</a>
|
||||
<li class="nav-item" v-if="user">
|
||||
<a class="nav-link disabled">{{user[3]}}</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="d-flex" role="search">
|
||||
@ -34,10 +34,6 @@
|
||||
|
||||
export default {
|
||||
props: {
|
||||
server: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
user: {
|
||||
type: Array,
|
||||
default: null
|
||||
|
@ -6,14 +6,6 @@ export async function connect(secret, host='vista.northport.med.va.gov', port=19
|
||||
})).json();
|
||||
}
|
||||
|
||||
export async function close(cid) {
|
||||
return await (await fetch('/v1/vista/' + cid + '/close', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id: Date.now() })
|
||||
})).json();
|
||||
}
|
||||
|
||||
export async function call(cid, method, ...params) {
|
||||
return await (await fetch('/v1/vista/' + cid, {
|
||||
method: 'POST',
|
||||
@ -55,5 +47,5 @@ export async function authenticate(cid, avcode=null) {
|
||||
}
|
||||
|
||||
export default window.vista = {
|
||||
connect, close, call, callctx, serverinfo, userinfo, authenticate
|
||||
connect, call, callctx, serverinfo, userinfo, authenticate
|
||||
};
|
||||
|
@ -2,8 +2,6 @@ import vista from './vista.mjs';
|
||||
import cookie from './cookie.mjs';
|
||||
import { lab_parse, lab_reparse_results, measurement_parse } from './reportparser.mjs';
|
||||
|
||||
const COOKIE_TIME = 45;
|
||||
|
||||
function RPCError(type, ...args) {
|
||||
this.name = type;
|
||||
this.message = args;
|
||||
@ -77,10 +75,6 @@ export function Client(cid, secret) {
|
||||
this.secret = secret;
|
||||
this.cid = cid;
|
||||
|
||||
this.close = function() {
|
||||
if(heartbeat) window.clearInterval(heartbeat);
|
||||
return vista.close(cid);
|
||||
};
|
||||
this.call = (method, ...params) => vista.call(cid, method, ...params);
|
||||
this.callctx = (context, method, ...params) => vista.callctx(cid, context, method, ...params);
|
||||
this.heartbeat = async function(interval=null) {
|
||||
@ -130,16 +124,13 @@ Client.fromScratch = async function(secret, host='vista.northport.med.va.gov', p
|
||||
if(data.result) return Client.fromID(data.result, secret);
|
||||
};
|
||||
|
||||
Client.fromCookie = async function(secret, defaulthost='vista.northport.med.va.gov:19209') {
|
||||
Client.fromCookie = async function(secret, host='vista.northport.med.va.gov', port=19209) {
|
||||
if(!secret) secret = cookie.get('secret');
|
||||
if(secret) {
|
||||
var host = cookie.get('host');
|
||||
host = (host || defaulthost).split(':');
|
||||
if(secret != cookie.get('secret')) {
|
||||
console.log('Using new secret', secret);
|
||||
var client = await Client.fromScratch(secret, host[0], host[1]);
|
||||
var client = await Client.fromScratch(secret, host, port);
|
||||
if(client) {
|
||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
||||
cookie.set('secret', secret);
|
||||
cookie.set('cid', client.cid);
|
||||
console.log('Established connection', client.cid);
|
||||
@ -152,9 +143,8 @@ Client.fromCookie = async function(secret, defaulthost='vista.northport.med.va.g
|
||||
}
|
||||
} else if(!cookie.get('cid')) {
|
||||
console.log('Using saved secret', secret);
|
||||
var client = await Client.fromScratch(secret, host[0], host[1]);
|
||||
var client = await Client.fromScratch(secret, host, port);
|
||||
if(client) {
|
||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
||||
cookie.set('secret', secret);
|
||||
cookie.set('cid', client.cid);
|
||||
console.log('Established connection', client.cid);
|
||||
@ -169,15 +159,9 @@ Client.fromCookie = async function(secret, defaulthost='vista.northport.med.va.g
|
||||
console.log('Using saved secret and connection', secret);
|
||||
var cid = cookie.get('cid');
|
||||
var client = Client.fromID(cid, secret);
|
||||
if((await vista.call(cid, 'XWB_IM_HERE')).result == '1') {
|
||||
var server = await client.serverinfo();
|
||||
if((host[0] == server.result.host) && (host[1] == server.result.port)) {
|
||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
||||
return client;
|
||||
} else console.log('Rejecting previous connection to different server', server);
|
||||
}
|
||||
if((await vista.call(cid, 'XWB_IM_HERE')).result == '1') return client;
|
||||
cookie.reset('cid');
|
||||
return await Client.fromCookie(secret, host.join(':'));
|
||||
return await Client.fromCookie(secret, host, port);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
17
main.py
17
main.py
@ -62,22 +62,11 @@ def application():
|
||||
else:
|
||||
return jsonify({ 'result': None, 'error': { 'type': 'Unauthorized', 'args': [] }, 'id': request.json.get('id') })
|
||||
|
||||
@app.post('/v1/vista/<cid>/close')
|
||||
def cb_close(cid):
|
||||
try:
|
||||
client = clients[cid]
|
||||
res = client.close()
|
||||
del clients[cid]
|
||||
return jsonify({ 'result': res, 'error': None, 'id': request.json.get('id') })
|
||||
except Exception as ex:
|
||||
logger.exception(request.url)
|
||||
return jsonify({ 'result': None, 'error': { 'type': ex.__class__.__name__, 'args': ex.args }, 'id': request.json.get('id') })
|
||||
|
||||
@app.post('/v1/vista/<cid>/serverinfo')
|
||||
def cb_serverinfo(cid):
|
||||
try:
|
||||
client = clients[cid]
|
||||
return jsonify({ 'result': client._obj._server, 'error': None, 'id': request.json.get('id') })
|
||||
return jsonify({ 'result': client._obj._server._asdict() if client._obj._server else None, 'error': None, 'id': request.json.get('id') })
|
||||
except Exception as ex:
|
||||
logger.exception(request.url)
|
||||
return jsonify({ 'result': None, 'error': { 'type': ex.__class__.__name__, 'args': ex.args }, 'id': request.json.get('id') })
|
||||
@ -98,13 +87,13 @@ def application():
|
||||
client = clients[cid]
|
||||
if 'avcode' in params:
|
||||
user = client.authenticate(params['avcode'])
|
||||
client._cache_persistent(persistent=util.Store(f'cache.{client._server["volume"].lower()}.{client._server["uci"].lower()}.{user[0]}.db', journal_mode='WAL').memo)
|
||||
client._cache_persistent(persistent=util.Store(f'cache.{client._server.volume.lower()}.{client._server.uci.lower()}.{user[0]}.db', journal_mode='WAL').memo)
|
||||
return jsonify({ 'result': user, 'error': None, 'id': request.json.get('id') })
|
||||
else:
|
||||
from auth import XUIAMSSOi_MySsoTokenVBA
|
||||
if token := XUIAMSSOi_MySsoTokenVBA():
|
||||
user = client.authenticate(token)
|
||||
client._cache_persistent(persistent=util.Store(f'cache.{client._server["volume"].lower()}.{client._server["uci"].lower()}.{user[0]}.db', journal_mode='WAL').memo)
|
||||
client._cache_persistent(persistent=util.Store(f'cache.{client._server.volume.lower()}.{client._server.uci.lower()}.{user[0]}.db', journal_mode='WAL').memo)
|
||||
return jsonify({ 'result': user, 'error': None, 'id': request.json.get('id') })
|
||||
else:
|
||||
return jsonify({ 'result': None, 'error': { 'type': 'Unauthorized', 'args': [] }, 'id': request.json.get('id') })
|
||||
|
10
rpc.py
10
rpc.py
@ -99,8 +99,7 @@ class ClientSync(object):
|
||||
self.sock.connect((host, port))
|
||||
self.recv_rpc_msg = recv_rpc_msg(self.sock)
|
||||
self.lock = threading.Lock()
|
||||
self._server = { 'host': host, 'port': port }
|
||||
self._user = None
|
||||
self._server = self._user = 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)
|
||||
@ -130,7 +129,7 @@ class ClientSync(object):
|
||||
self.sock = self.recv_rpc_msg = None
|
||||
return res
|
||||
def authenticate(self, identity: str, *, context=('XUS SIGNON',)):
|
||||
self._server.update(RecordServerInfo(*self('XUS SIGNON SETUP', '', '1', context=context))._asdict())
|
||||
self._server = RecordServerInfo(*self('XUS SIGNON SETUP', '', '1', context=context))
|
||||
res = self('XUS AV CODE', XWBHash_encrypt(identity))
|
||||
if res[0] == '0' or res[2] != '0':
|
||||
raise RPCExcAuth(res[3], res)
|
||||
@ -171,8 +170,7 @@ class ClientAsync(object):
|
||||
self.reader, self.writer = await asyncio.open_connection(host, port)
|
||||
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._server = self._user = 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)
|
||||
@ -207,7 +205,7 @@ class ClientAsync(object):
|
||||
self.reader = self.writer = None
|
||||
return res
|
||||
async def authenticate(self, identity: str, *, context=('XUS SIGNON',)):
|
||||
self._server.update(RecordServerInfo(*await self('XUS SIGNON SETUP', '', '1', context=context))._asdict())
|
||||
self._server = RecordServerInfo(*await self('XUS SIGNON SETUP', '', '1', context=context))
|
||||
res = await self('XUS AV CODE', XWBHash_encrypt(identity))
|
||||
if res[0] == '0' or res[2] != '0':
|
||||
raise RPCExcAuth(res[3], res)
|
||||
|
Loading…
Reference in New Issue
Block a user