1 # -----------------------------------------------------------------------
2 # Copyright (C) 2010 Equinox Software, Inc.
3 # Bill Erickson <berick@esilibrary.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 # -----------------------------------------------------------------------
16 from oils.utils.utils import md5sum
19 def handle_login(srfsh, args):
25 seed = srfsh.handle_request([
27 'open-ils.auth.authenticate.init',
31 password = md5sum(seed + md5sum(password))
33 response = srfsh.handle_request([
35 'open-ils.auth.authenticate.complete',
38 { # handle_request accepts json-encoded params
39 'username' : username,
40 'password' : password,
41 'type' : args[2] if len(args) > 2 else None,
42 'workstation' : args[3] if len(args) > 3 else None
47 def handle_auth_verify(srfsh, args):
48 ''' Verify auth w/ args '''
53 seed = srfsh.handle_request([
55 'open-ils.auth.authenticate.init',
59 password = md5sum(seed + md5sum(password))
61 response = srfsh.handle_request([
63 'open-ils.auth.authenticate.verify',
66 { # handle_request accepts json-encoded params
67 'username' : username,
68 'password' : password,
69 'type' : args[2] if len(args) > 2 else None,
75 def handle_org_setting(srfsh, args):
76 ''' Retrieves the requested org setting.
86 srfsh.handle_request([
88 'open-ils.actor.ou_setting.ancestor_default',
93 def handle_idl(srfsh, args):
94 ''' Handles the 'idl' command.
96 Argument options inlude:
97 idl show class <classname>
100 # all IDL commands require the IDL to be present
101 if oils.utils.idl.IDLParser._global_parser is None:
102 srfsh.report("Loading and parsing IDL...", True, True)
103 oils.utils.idl.IDLParser.parse()
104 srfsh.report("OK\n", True, True)
106 if args[0] == 'show':
108 if args[1] == 'class':
110 srfsh.report(str(oils.utils.idl.IDLParser.get_class(class_)))
113 def load(srfsh, config):
114 ''' Srfsh plugin loader '''
117 if config.get("load_idl", "") == "true":
118 oils.utils.idl.IDLParser.parse()
120 # register custom commands
121 srfsh.add_command(command = 'login', handler = handle_login)
122 srfsh.add_command(command = 'auth_verify', handler = handle_auth_verify)
123 srfsh.add_command(command = 'idl', handler = handle_idl)
124 srfsh.add_command(command = 'org_setting', handler = handle_org_setting)
126 # add some service names to the tab complete word bank
127 srfsh.tab_complete_words.append('open-ils.auth')
128 srfsh.tab_complete_words.append('open-ils.cstore')
129 # TODO: load services for tab-complete from opensrf settings...