Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91960345
webaccessadmin.py
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
Sat, Nov 16, 03:53
Size
4 KB
Mime Type
text/x-python
Expires
Mon, Nov 18, 03:53 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22354606
Attached To
R3600 invenio-infoscience
webaccessadmin.py
View Options
## This file is part of Invenio.
## Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
## 2012, 2013 CERN.
##
## Invenio 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.
##
## Invenio 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
__revision__
=
"$Id$"
import
getopt
import
sys
from
invenio.base.helpers
import
with_app_context
def
usage
(
exitcode
=
1
,
msg
=
""
):
"""Prints usage info."""
if
msg
:
print
>>
sys
.
stderr
,
"Error:
%s
."
%
msg
print
>>
sys
.
stderr
print
>>
sys
.
stderr
,
"""Usage: %s [options]
General options:
-h, --help\t\tprint this help
-V, --version\t\tprint version number
Authentication options:
-u, --user=USER\tUser name needed to perform the administrative task
Option to administrate authorizations:
-a, --add\t\tadd default authorization settings
-c, --compile\t\tcompile firewall like role definitions (FireRole)
-r, --reset\t\treset to default settings
-D, --demo\t\tto be used with -a or -r in order to consider demo site authorizations
"""
%
sys
.
argv
[
0
]
sys
.
exit
(
exitcode
)
@with_app_context
()
def
main
():
"""Main function that analyzes command line input and calls whatever
is appropriate. """
from
invenio.modules.access.firerole
import
repair_role_definitions
import
invenio.access_control_admin
as
acca
from
invenio.base.globals
import
cfg
from
invenio.bibtask
import
authenticate
from
invenio.modules.access.local_config
import
DEF_DEMO_USER_ROLES
,
\
DEF_DEMO_ROLES
,
DEF_DEMO_AUTHS
## parse command line:
# set user-defined options:
options
=
{
'user'
:
''
,
'reset'
:
0
,
'compile'
:
0
,
'add'
:
0
,
'demo'
:
0
}
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"hVu:racD"
,
[
"help"
,
"version"
,
"user="
,
"reset"
,
"add"
,
"compile"
,
"demo"
])
except
getopt
.
GetoptError
,
err
:
usage
(
1
,
err
)
try
:
for
opt
in
opts
:
if
opt
[
0
]
in
(
"-h"
,
"--help"
):
usage
(
0
)
elif
opt
[
0
]
in
(
"-V"
,
"--version"
):
print
__revision__
sys
.
exit
(
0
)
elif
opt
[
0
]
in
(
"-u"
,
"--user"
):
options
[
"user"
]
=
opt
[
1
]
elif
opt
[
0
]
in
(
"-r"
,
"--reset"
):
options
[
"reset"
]
=
1
elif
opt
[
0
]
in
(
"-a"
,
"--add"
):
options
[
"add"
]
=
1
elif
opt
[
0
]
in
(
"-c"
,
"--compile"
):
options
[
"compile"
]
=
1
elif
opt
[
0
]
in
(
"-D"
,
"--demo"
):
options
[
"demo"
]
=
1
else
:
usage
(
1
)
if
options
[
'add'
]
or
options
[
'reset'
]
or
options
[
'compile'
]:
#if acca.acc_get_action_id('cfgwebaccess'):
# # Action exists hence authentication works :-)
# options['user'] = authenticate(options['user'],
# authorization_msg="WebAccess Administration",
# authorization_action="cfgwebaccess")
if
options
[
'reset'
]
and
options
[
'demo'
]:
acca
.
acc_reset_default_settings
([
cfg
[
'CFG_SITE_ADMIN_EMAIL'
]],
DEF_DEMO_USER_ROLES
,
DEF_DEMO_ROLES
,
DEF_DEMO_AUTHS
)
print
"Reset default demo site settings."
elif
options
[
'reset'
]:
acca
.
acc_reset_default_settings
([
cfg
[
'CFG_SITE_ADMIN_EMAIL'
]])
print
"Reset default settings."
elif
options
[
'add'
]
and
options
[
'demo'
]:
acca
.
acc_add_default_settings
([
cfg
[
'CFG_SITE_ADMIN_EMAIL'
]],
DEF_DEMO_USER_ROLES
,
DEF_DEMO_ROLES
,
DEF_DEMO_AUTHS
)
print
"Added default demo site settings."
elif
options
[
'add'
]:
acca
.
acc_add_default_settings
([
cfg
[
'CFG_SITE_ADMIN_EMAIL'
]])
print
"Added default settings."
if
options
[
'compile'
]:
repair_role_definitions
()
print
"Compiled firewall like role definitions."
else
:
usage
(
1
,
"You must specify at least one command"
)
except
StandardError
,
e
:
from
invenio.ext.logging
import
register_exception
register_exception
()
usage
(
e
)
return
### okay, here we go:
if
__name__
==
'__main__'
:
main
()
Event Timeline
Log In to Comment