From: Simo Sorce Date: Mon, 7 Apr 2014 20:02:20 +0000 (-0400) Subject: Rename scripts and mark them as such X-Git-Tag: v0.2.2~33 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=commitdiff_plain;h=904898b83d90d3d7f83c574b27a79b98a23e3734;ds=sidebyside Rename scripts and mark them as such Mark actual top level scripts as such instead of disguising them as modules. Also remove __init__.py from ipsilon/install as this is not a module just the place where install scripts are kept, for now. Note: Scripts are installed in the bin directory but the contrib spec file moves them to sbin. Signed-off-by: Simo Sorce --- diff --git a/contrib/fedora/ipsilon.spec b/contrib/fedora/ipsilon.spec index d5be793..cdce10d 100644 --- a/contrib/fedora/ipsilon.spec +++ b/contrib/fedora/ipsilon.spec @@ -37,12 +37,8 @@ CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build mkdir -p %{buildroot}%{_sbindir} install -d -m 0700 %{buildroot}%{_sharedstatedir}/ipsilon install -d -m 0700 %{buildroot}%{_sharedstatedir}/ipsilon/sessions -ln -s ../..%{python2_sitelib}/ipsilon/idpserver.py \ - %{buildroot}/%{_sbindir}/ipsilon -chmod +x %{buildroot}%{python2_sitelib}/ipsilon/idpserver.py -ln -s ../..%{python2_sitelib}/ipsilon/install/server.py \ - %{buildroot}/%{_sbindir}/ipsilon-server-install -chmod +x %{buildroot}%{python2_sitelib}/ipsilon/install/server.py +mv %{buildroot}/%{_bindir}/ipsilon %{buildroot}/%{_sbindir} +mv %{buildroot}/%{_bindir}/ipsilon-server-install %{buildroot}/%{_sbindir} install -d -m 0700 %{buildroot}%{_sysconfdir}/ipsilon %pre diff --git a/ipsilon/idpserver.py b/ipsilon/idpserver.py deleted file mode 100755 index 9fa370e..0000000 --- a/ipsilon/idpserver.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/python -# -# Copyright (C) 2013 Simo Sorce -# -# see file 'COPYING' for use and warranty information -# -# This program 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 3 of the License, or -# (at your option) any later version. -# -# This program 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 this program. If not, see . - -import sys -sys.stdout = sys.stderr - -import os -import atexit -import cherrypy -from ipsilon.util.data import Store -from ipsilon.util import page -from ipsilon.root import Root -from jinja2 import Environment, FileSystemLoader - -cfgfile = None -if (len(sys.argv) > 1): - cfgfile = sys.argv[-1] -elif os.path.isfile('ipsilon.conf'): - cfgfile = 'ipsilon.conf' -elif os.path.isfile('/etc/ipsilon/ipsilon.conf'): - cfgfile = '/etc/ipsilon/ipsilon.conf' -else: - raise IOError("Configuration file not found") - -cherrypy.config.update(cfgfile) - -datastore = Store() -admin_config = datastore.get_admin_config() -for option in admin_config: - cherrypy.config[option] = admin_config[option] - -cherrypy.tools.protect = cherrypy.Tool('before_handler', page.protect) - -templates = os.path.join(cherrypy.config['base.dir'], 'templates') -template_env = Environment(loader=FileSystemLoader(templates)) - -if __name__ == "__main__": - conf = {'/': {'tools.staticdir.root': os.getcwd()}, - '/ui': {'tools.staticdir.on': True, - 'tools.staticdir.dir': 'ui'}} - cherrypy.quickstart(Root('default', template_env), - cherrypy.config['base.mount'], conf) - -else: - cherrypy.config['environment'] = 'embedded' - - if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0: - cherrypy.engine.start(blocking=False) - atexit.register(cherrypy.engine.stop) - - application = cherrypy.Application(Root('default', template_env), - script_name=None, config=None) diff --git a/ipsilon/install/__init__.py b/ipsilon/install/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ipsilon/install/ipsilon-server-install b/ipsilon/install/ipsilon-server-install new file mode 100755 index 0000000..4ae0c8f --- /dev/null +++ b/ipsilon/install/ipsilon-server-install @@ -0,0 +1,223 @@ +#!/usr/bin/python +# +# Copyright (C) 2014 Simo Sorce +# +# see file 'COPYING' for use and warranty information +# +# This program 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 this program. If not, see . + +from ipsilon.login.common import LoginMgrsInstall +from ipsilon.providers.common import ProvidersInstall +from ipsilon.util.data import Store +import argparse +import cherrypy +import logging +import os +import pwd +import shutil +import socket +import sys +import time + + +TEMPLATES = '/usr/share/ipsilon/templates/install' +CONFDIR = '/etc/ipsilon' +HTTPDCONFD = '/etc/httpd/conf.d' + + +class ConfigurationError(Exception): + + def __init__(self, message): + super(ConfigurationError, self).__init__(message) + self.message = message + + def __str__(self): + return repr(self.message) + + +#Silence cherrypy logging to screen +cherrypy.log.screen = False + +# Regular logging +LOGFILE = '/var/log/ipsilon-install.log' +logger = logging.getLogger() + + +def openlogs(): + global logger # pylint: disable=W0603 + if os.path.isfile(LOGFILE): + try: + created = '%s' % time.ctime(os.path.getctime(LOGFILE)) + shutil.move(LOGFILE, '%s.%s' % (LOGFILE, created)) + except IOError: + pass + logger = logging.getLogger() + try: + lh = logging.FileHandler(LOGFILE) + except IOError, e: + print >> sys.stderr, 'Unable to open %s (%s)' % (LOGFILE, str(e)) + lh = logging.StreamHandler(sys.stderr) + formatter = logging.Formatter('[%(asctime)s] %(message)s') + lh.setFormatter(formatter) + logger.addHandler(lh) + + +def install(plugins, args): + logger.info('Installation initiated') + now = time.strftime("%Y%m%d%H%M%S", time.gmtime()) + + logger.info('Installing default config files') + ipsilon_conf = os.path.join(CONFDIR, 'ipsilon.conf') + idp_conf = os.path.join(CONFDIR, 'idp.conf') + args['httpd_conf'] = os.path.join(HTTPDCONFD, 'idp.conf') + if os.path.exists(ipsilon_conf): + shutil.move(ipsilon_conf, '%s.bakcup.%s' % (ipsilon_conf, now)) + if os.path.exists(idp_conf): + shutil.move(idp_conf, '%s.backup.%s' % (idp_conf, now)) + shutil.copy(os.path.join(TEMPLATES, 'ipsilon.conf'), CONFDIR) + shutil.copy(os.path.join(TEMPLATES, 'idp.conf'), CONFDIR) + if not os.path.exists(args['httpd_conf']): + os.symlink(idp_conf, args['httpd_conf']) + # Load the cherrypy config from the newly installed file so + # that db paths and all is properly set before configuring + # components + cherrypy.config.update(ipsilon_conf) + + # Move pre-existing admin db away + admin_db = cherrypy.config['admin.config.db'] + if os.path.exists(admin_db): + shutil.move(admin_db, '%s.backup.%s' % (admin_db, now)) + + # Rebuild user db + users_db = cherrypy.config['user.prefs.db'] + if os.path.exists(users_db): + shutil.move(users_db, '%s.backup.%s' % (users_db, now)) + db = Store() + db.save_user_preferences(args['admin_user'], {'is_admin': 1}) + + logger.info('Configuring login managers') + for plugin_name in args['lm_order']: + plugin = plugins['Login Managers'][plugin_name] + plugin.configure(args) + + logger.info('Configuring Authentication Providers') + for plugin_name in plugins['Auth Providers']: + plugin = plugins['Auth Providers'][plugin_name] + plugin.configure(args) + + +def uninstall(plugins, args): + logger.info('Uninstallation initiated') + raise Exception('Not Implemented') + + +def find_plugins(): + plugins = { + 'Login Managers': LoginMgrsInstall().plugins, + 'Auth Providers': ProvidersInstall().plugins + } + return plugins + + +def parse_args(plugins): + parser = argparse.ArgumentParser(description='Ipsilon Install Options') + parser.add_argument('--version', + action='version', version='%(prog)s 0.1') + parser.add_argument('-o', '--login-managers-order', dest='lm_order', + help='Comma separated list of login managers') + parser.add_argument('--hostname', + help="Machine's fully qualified host name") + parser.add_argument('--system-user', default='ipsilon', + help="User account used to run the server") + parser.add_argument('--admin-user', default='admin', + help="User account that is assigned admin privileges") + parser.add_argument('--ipa', choices=['yes', 'no'], default='yes', + help='Detect and use an IPA server for authentication') + parser.add_argument('--uninstall', action='store_true', + help="Uninstall the server and all data") + + lms = [] + + for plugin_group in plugins: + group = parser.add_argument_group(plugin_group) + for plugin_name in plugins[plugin_group]: + plugin = plugins[plugin_group][plugin_name] + if plugin.ptype == 'login': + lms.append(plugin.name) + plugin.install_args(group) + + args = vars(parser.parse_args()) + + if not args['hostname']: + args['hostname'] = socket.getfqdn() + + if len(args['hostname'].split('.')) < 2: + raise ConfigurationError('Hostname: %s is not a FQDN') + + try: + pwd.getpwnam(args['system_user']) + except KeyError: + raise ConfigurationError('User: %s not found on the system') + + if args['lm_order'] is None: + args['lm_order'] = [] + for name in lms: + if args[name] == 'yes': + args['lm_order'].append(name) + else: + args['lm_order'] = args['lm_order'].split(',') + + if len(args['lm_order']) == 0: + #force the basic pam provider if nothing else is selected + if 'pam' not in args: + parser.print_help() + sys.exit(-1) + args['lm_order'] = ['pam'] + args['pam'] = 'yes' + + return args + +if __name__ == '__main__': + opts = [] + out = 0 + openlogs() + try: + fplugins = find_plugins() + opts = parse_args(fplugins) + + logger.setLevel(logging.DEBUG) + + logger.info('Intallation arguments:') + for k in sorted(opts.iterkeys()): + logger.info('%s: %s', k, opts[k]) + + if 'uninstall' in opts and opts['uninstall'] is True: + uninstall(fplugins, opts) + + install(fplugins, opts) + except Exception, e: # pylint: disable=broad-except + logger.exception(e) + if 'uninstall' in opts and opts['uninstall'] is True: + print 'Uninstallation aborted.' + else: + print 'Installation aborted.' + print 'See log file %s for details' % LOGFILE + out = 1 + finally: + if out == 0: + if 'uninstall' in opts and opts['uninstall'] is True: + print 'Uninstallation complete.' + else: + print 'Installation complete.' + sys.exit(out) diff --git a/ipsilon/install/server.py b/ipsilon/install/server.py deleted file mode 100755 index 4ae0c8f..0000000 --- a/ipsilon/install/server.py +++ /dev/null @@ -1,223 +0,0 @@ -#!/usr/bin/python -# -# Copyright (C) 2014 Simo Sorce -# -# see file 'COPYING' for use and warranty information -# -# This program 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 3 of the License, or -# (at your option) any later version. -# -# This program 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 this program. If not, see . - -from ipsilon.login.common import LoginMgrsInstall -from ipsilon.providers.common import ProvidersInstall -from ipsilon.util.data import Store -import argparse -import cherrypy -import logging -import os -import pwd -import shutil -import socket -import sys -import time - - -TEMPLATES = '/usr/share/ipsilon/templates/install' -CONFDIR = '/etc/ipsilon' -HTTPDCONFD = '/etc/httpd/conf.d' - - -class ConfigurationError(Exception): - - def __init__(self, message): - super(ConfigurationError, self).__init__(message) - self.message = message - - def __str__(self): - return repr(self.message) - - -#Silence cherrypy logging to screen -cherrypy.log.screen = False - -# Regular logging -LOGFILE = '/var/log/ipsilon-install.log' -logger = logging.getLogger() - - -def openlogs(): - global logger # pylint: disable=W0603 - if os.path.isfile(LOGFILE): - try: - created = '%s' % time.ctime(os.path.getctime(LOGFILE)) - shutil.move(LOGFILE, '%s.%s' % (LOGFILE, created)) - except IOError: - pass - logger = logging.getLogger() - try: - lh = logging.FileHandler(LOGFILE) - except IOError, e: - print >> sys.stderr, 'Unable to open %s (%s)' % (LOGFILE, str(e)) - lh = logging.StreamHandler(sys.stderr) - formatter = logging.Formatter('[%(asctime)s] %(message)s') - lh.setFormatter(formatter) - logger.addHandler(lh) - - -def install(plugins, args): - logger.info('Installation initiated') - now = time.strftime("%Y%m%d%H%M%S", time.gmtime()) - - logger.info('Installing default config files') - ipsilon_conf = os.path.join(CONFDIR, 'ipsilon.conf') - idp_conf = os.path.join(CONFDIR, 'idp.conf') - args['httpd_conf'] = os.path.join(HTTPDCONFD, 'idp.conf') - if os.path.exists(ipsilon_conf): - shutil.move(ipsilon_conf, '%s.bakcup.%s' % (ipsilon_conf, now)) - if os.path.exists(idp_conf): - shutil.move(idp_conf, '%s.backup.%s' % (idp_conf, now)) - shutil.copy(os.path.join(TEMPLATES, 'ipsilon.conf'), CONFDIR) - shutil.copy(os.path.join(TEMPLATES, 'idp.conf'), CONFDIR) - if not os.path.exists(args['httpd_conf']): - os.symlink(idp_conf, args['httpd_conf']) - # Load the cherrypy config from the newly installed file so - # that db paths and all is properly set before configuring - # components - cherrypy.config.update(ipsilon_conf) - - # Move pre-existing admin db away - admin_db = cherrypy.config['admin.config.db'] - if os.path.exists(admin_db): - shutil.move(admin_db, '%s.backup.%s' % (admin_db, now)) - - # Rebuild user db - users_db = cherrypy.config['user.prefs.db'] - if os.path.exists(users_db): - shutil.move(users_db, '%s.backup.%s' % (users_db, now)) - db = Store() - db.save_user_preferences(args['admin_user'], {'is_admin': 1}) - - logger.info('Configuring login managers') - for plugin_name in args['lm_order']: - plugin = plugins['Login Managers'][plugin_name] - plugin.configure(args) - - logger.info('Configuring Authentication Providers') - for plugin_name in plugins['Auth Providers']: - plugin = plugins['Auth Providers'][plugin_name] - plugin.configure(args) - - -def uninstall(plugins, args): - logger.info('Uninstallation initiated') - raise Exception('Not Implemented') - - -def find_plugins(): - plugins = { - 'Login Managers': LoginMgrsInstall().plugins, - 'Auth Providers': ProvidersInstall().plugins - } - return plugins - - -def parse_args(plugins): - parser = argparse.ArgumentParser(description='Ipsilon Install Options') - parser.add_argument('--version', - action='version', version='%(prog)s 0.1') - parser.add_argument('-o', '--login-managers-order', dest='lm_order', - help='Comma separated list of login managers') - parser.add_argument('--hostname', - help="Machine's fully qualified host name") - parser.add_argument('--system-user', default='ipsilon', - help="User account used to run the server") - parser.add_argument('--admin-user', default='admin', - help="User account that is assigned admin privileges") - parser.add_argument('--ipa', choices=['yes', 'no'], default='yes', - help='Detect and use an IPA server for authentication') - parser.add_argument('--uninstall', action='store_true', - help="Uninstall the server and all data") - - lms = [] - - for plugin_group in plugins: - group = parser.add_argument_group(plugin_group) - for plugin_name in plugins[plugin_group]: - plugin = plugins[plugin_group][plugin_name] - if plugin.ptype == 'login': - lms.append(plugin.name) - plugin.install_args(group) - - args = vars(parser.parse_args()) - - if not args['hostname']: - args['hostname'] = socket.getfqdn() - - if len(args['hostname'].split('.')) < 2: - raise ConfigurationError('Hostname: %s is not a FQDN') - - try: - pwd.getpwnam(args['system_user']) - except KeyError: - raise ConfigurationError('User: %s not found on the system') - - if args['lm_order'] is None: - args['lm_order'] = [] - for name in lms: - if args[name] == 'yes': - args['lm_order'].append(name) - else: - args['lm_order'] = args['lm_order'].split(',') - - if len(args['lm_order']) == 0: - #force the basic pam provider if nothing else is selected - if 'pam' not in args: - parser.print_help() - sys.exit(-1) - args['lm_order'] = ['pam'] - args['pam'] = 'yes' - - return args - -if __name__ == '__main__': - opts = [] - out = 0 - openlogs() - try: - fplugins = find_plugins() - opts = parse_args(fplugins) - - logger.setLevel(logging.DEBUG) - - logger.info('Intallation arguments:') - for k in sorted(opts.iterkeys()): - logger.info('%s: %s', k, opts[k]) - - if 'uninstall' in opts and opts['uninstall'] is True: - uninstall(fplugins, opts) - - install(fplugins, opts) - except Exception, e: # pylint: disable=broad-except - logger.exception(e) - if 'uninstall' in opts and opts['uninstall'] is True: - print 'Uninstallation aborted.' - else: - print 'Installation aborted.' - print 'See log file %s for details' % LOGFILE - out = 1 - finally: - if out == 0: - if 'uninstall' in opts and opts['uninstall'] is True: - print 'Uninstallation complete.' - else: - print 'Installation complete.' - sys.exit(out) diff --git a/ipsilon/ipsilon b/ipsilon/ipsilon new file mode 100755 index 0000000..9fa370e --- /dev/null +++ b/ipsilon/ipsilon @@ -0,0 +1,68 @@ +#!/usr/bin/python +# +# Copyright (C) 2013 Simo Sorce +# +# see file 'COPYING' for use and warranty information +# +# This program 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 this program. If not, see . + +import sys +sys.stdout = sys.stderr + +import os +import atexit +import cherrypy +from ipsilon.util.data import Store +from ipsilon.util import page +from ipsilon.root import Root +from jinja2 import Environment, FileSystemLoader + +cfgfile = None +if (len(sys.argv) > 1): + cfgfile = sys.argv[-1] +elif os.path.isfile('ipsilon.conf'): + cfgfile = 'ipsilon.conf' +elif os.path.isfile('/etc/ipsilon/ipsilon.conf'): + cfgfile = '/etc/ipsilon/ipsilon.conf' +else: + raise IOError("Configuration file not found") + +cherrypy.config.update(cfgfile) + +datastore = Store() +admin_config = datastore.get_admin_config() +for option in admin_config: + cherrypy.config[option] = admin_config[option] + +cherrypy.tools.protect = cherrypy.Tool('before_handler', page.protect) + +templates = os.path.join(cherrypy.config['base.dir'], 'templates') +template_env = Environment(loader=FileSystemLoader(templates)) + +if __name__ == "__main__": + conf = {'/': {'tools.staticdir.root': os.getcwd()}, + '/ui': {'tools.staticdir.on': True, + 'tools.staticdir.dir': 'ui'}} + cherrypy.quickstart(Root('default', template_env), + cherrypy.config['base.mount'], conf) + +else: + cherrypy.config['environment'] = 'embedded' + + if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0: + cherrypy.engine.start(blocking=False) + atexit.register(cherrypy.engine.stop) + + application = cherrypy.Application(Root('default', template_env), + script_name=None, config=None) diff --git a/setup.py b/setup.py index 7dd021d..846698b 100755 --- a/setup.py +++ b/setup.py @@ -27,8 +27,7 @@ setup( version = '0.1', license = 'GPLv3+', packages = ['ipsilon', 'ipsilon.admin', 'ipsilon.login', 'ipsilon.util', - 'ipsilon.providers', 'ipsilon.providers.saml2', - 'ipsilon.install'], + 'ipsilon.providers', 'ipsilon.providers.saml2'], data_files = [('share/man/man7', ["man/ipsilon.7"]), ('share/doc/ipsilon', ['COPYING']), ('share/doc/ipsilon/examples', ['examples/ipsilon.conf', @@ -43,6 +42,7 @@ setup( (DATA+'templates/install', glob('templates/install/*.conf')), (DATA+'templates/admin/providers', glob('templates/admin/providers/*.html')), - ] + ], + scripts = ['ipsilon/ipsilon', 'ipsilon/install/ipsilon-server-install'] )