diff --git a/modules/webaccess/bin/webaccessadmin.in b/modules/webaccess/bin/webaccessadmin.in index 635994dd4..dbdec966f 100644 --- a/modules/webaccess/bin/webaccessadmin.in +++ b/modules/webaccess/bin/webaccessadmin.in @@ -1,116 +1,116 @@ ## $Id$ ## WebAccess Admin -- reset or add default authorization settings ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## The CDSware is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" #include "cdswmllib.wml" ## start Python: #! ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """WebAccess Admin -- reset or add default authorization settings""" __version__ = "<: print generate_pretty_version_string('$Id$'); :>" ## fill config variables: pylibdir = "/python" try: import getpass import sys sys.path.append('%s' % pylibdir) from cdsware.access_control_admin import acc_reset_default_settings from cdsware.access_control_admin import acc_add_default_settings from cdsware.dbquery import run_sql except ImportError, e: print "Error: %s" % e import sys sys.exit(1) def usage(code, msg=''): """Print usage info.""" if msg: sys.stderr.write("Error: %s.\n" % msg) sys.stderr.write("WebAccess Admin -- reset or add default authorization settings\n") sys.stderr.write("Usage: %s [options] \n" % sys.argv[0]) sys.stderr.write("Command options:\n") sys.stderr.write(" = reset-default-settings\n") sys.stderr.write(" = add-default-settings\n") sys.stderr.write("General options:\n") sys.stderr.write(" -h, --help \t\t Print this help.\n") sys.stderr.write(" -V, --version \t\t Print version information.\n") sys.exit(code) def main(): """CLI to acc_authorize_action. The function finds the needed arguments in sys.argv. If the number of arguments is wrong it prints help. Return 1 on success, 0 on failure. """ alen = len(sys.argv) action = '' # print help if wrong arguments - if sys.argv[1] in ["-h", "--help"]: + if alen > 1 and sys.argv[1] in ["-h", "--help"]: usage(0) - elif sys.argv[1] in ["-V", "--version"]: + elif alen > 1 and sys.argv[1] in ["-V", "--version"]: print __version__ sys.exit(0) if alen != 2 or sys.argv[1] not in ['reset-default-settings', 'add-default-settings']: usage(1) # getting input from user print 'User: ', user = raw_input() password = getpass.getpass() # validating input perform = 0 # check password if user == '': perform = run_sql("""select * from user where email = '%s' and password = '%s' """ % ('', password)) and 1 or 0 if not perform: # wrong password or user not recognized print 'User not authorized' return perform # perform chosen action, add all users above as superusers if sys.argv[1] == 'reset-default-settings': action = 'reset' acc_reset_default_settings(['']) elif sys.argv[1] == 'add-default-settings': action = 'added' acc_add_default_settings(['']) # notify of success if action: print '\nOkay, the default authorization settings have been __%s__.' % (action, ) else: print 'Requested action failed.' return perform if __name__ == '__main__': main() diff --git a/modules/webaccess/bin/webaccessadmin.wml b/modules/webaccess/bin/webaccessadmin.wml index 635994dd4..dbdec966f 100644 --- a/modules/webaccess/bin/webaccessadmin.wml +++ b/modules/webaccess/bin/webaccessadmin.wml @@ -1,116 +1,116 @@ ## $Id$ ## WebAccess Admin -- reset or add default authorization settings ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002 CERN. ## ## The CDSware is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## The CDSware is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDSware; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## read config variables: #include "config.wml" #include "configbis.wml" #include "cdswmllib.wml" ## start Python: #! ## $Id$ ## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. """WebAccess Admin -- reset or add default authorization settings""" __version__ = "<: print generate_pretty_version_string('$Id$'); :>" ## fill config variables: pylibdir = "/python" try: import getpass import sys sys.path.append('%s' % pylibdir) from cdsware.access_control_admin import acc_reset_default_settings from cdsware.access_control_admin import acc_add_default_settings from cdsware.dbquery import run_sql except ImportError, e: print "Error: %s" % e import sys sys.exit(1) def usage(code, msg=''): """Print usage info.""" if msg: sys.stderr.write("Error: %s.\n" % msg) sys.stderr.write("WebAccess Admin -- reset or add default authorization settings\n") sys.stderr.write("Usage: %s [options] \n" % sys.argv[0]) sys.stderr.write("Command options:\n") sys.stderr.write(" = reset-default-settings\n") sys.stderr.write(" = add-default-settings\n") sys.stderr.write("General options:\n") sys.stderr.write(" -h, --help \t\t Print this help.\n") sys.stderr.write(" -V, --version \t\t Print version information.\n") sys.exit(code) def main(): """CLI to acc_authorize_action. The function finds the needed arguments in sys.argv. If the number of arguments is wrong it prints help. Return 1 on success, 0 on failure. """ alen = len(sys.argv) action = '' # print help if wrong arguments - if sys.argv[1] in ["-h", "--help"]: + if alen > 1 and sys.argv[1] in ["-h", "--help"]: usage(0) - elif sys.argv[1] in ["-V", "--version"]: + elif alen > 1 and sys.argv[1] in ["-V", "--version"]: print __version__ sys.exit(0) if alen != 2 or sys.argv[1] not in ['reset-default-settings', 'add-default-settings']: usage(1) # getting input from user print 'User: ', user = raw_input() password = getpass.getpass() # validating input perform = 0 # check password if user == '': perform = run_sql("""select * from user where email = '%s' and password = '%s' """ % ('', password)) and 1 or 0 if not perform: # wrong password or user not recognized print 'User not authorized' return perform # perform chosen action, add all users above as superusers if sys.argv[1] == 'reset-default-settings': action = 'reset' acc_reset_default_settings(['']) elif sys.argv[1] == 'add-default-settings': action = 'added' acc_add_default_settings(['']) # notify of success if action: print '\nOkay, the default authorization settings have been __%s__.' % (action, ) else: print 'Requested action failed.' return perform if __name__ == '__main__': main()