Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90704810
webaccessadmin.in
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 4, 00:46
Size
3 KB
Mime Type
text/x-python
Expires
Wed, Nov 6, 00:46 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22122190
Attached To
R3600 invenio-infoscience
webaccessadmin.in
View Options
#!@PYTHON@
## -*- mode: python; coding: utf-8; -*-
##
## $Id$
##
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002, 2003, 2004, 2005, 2006 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.
"""WebAccess Admin -- reset or add default authorization settings"""
__version__ = "$Id$"
try:
import getpass
import sys
from cdsware.config import supportemail
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] <command>\n" % sys.argv[0])
sys.stderr.write("Command options:\n")
sys.stderr.write(" <command> = reset-default-settings\n")
sys.stderr.write(" <command> = 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 alen > 1 and sys.argv[1] in ["-h", "--help"]:
usage(0)
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 == supportemail:
perform = run_sql("""select * from user where email = '%s' and password = '%s' """ % (supportemail, 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([supportemail])
elif sys.argv[1] == 'add-default-settings':
action = 'added'
acc_add_default_settings([supportemail])
# 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()
Event Timeline
Log In to Comment