示例#1
0
文件: digest.py 项目: araymund/karl
def digest(root, closer, registry, frequency):
    if not is_normal_mode(registry):
        log.info("Cannot send mails; running in maintenance mode.")
        sys.exit(1)
    alerts = Alerts()
    freq = frequency
    alerts.send_digests(root, freq)
示例#2
0
def digest(root, closer, registry, frequency):
    if not is_normal_mode(registry):
        log.info("Cannot send mails; running in maintenance mode.")
        sys.exit(1)
    alerts = Alerts()
    freq = frequency
    alerts.send_digests(root, freq)
示例#3
0
文件: mailin.py 项目: araymund/karl
def main(argv=sys.argv):
    default_interval = 300
    parser = create_karl_argparser(description='Process incoming mail.')
    parser.add_argument('-d',
                        '--daemon',
                        action='store_true',
                        help="Run in daemon mode.")
    parser.add_argument('-i',
                        '--interval',
                        type=int,
                        default=default_interval,
                        help="Interval in seconds between executions in "
                        "daemon mode.  Default is %d." % default_interval)

    args = parser.parse_args(sys.argv[1:])

    env = args.bootstrap(args.config_uri)

    if not is_normal_mode(env['registry']):
        log.info("Cannot run mailin: Running in maintenance mode.")
        sys.exit(2)

    try:
        if args.daemon:
            daemonize_function(mailin, args.interval)(args, env, parser)
        else:
            mailin(args, env, parser)
    finally:
        env['closer']()
示例#4
0
文件: gsa_sync.py 项目: iotest3/new
def main(argv=sys.argv):
    default_interval = 120
    parser = create_karl_argparser(
        description='Sync staff profiles and login to OSI GSA.'
        )
    parser.add_argument('-d', '--daemon', action='store_true',
                        help="Run in daemon mode.")
    parser.add_argument('-i', '--interval', type=int, default=default_interval,
                        help="Interval in seconds between executions in "
                        "daemon mode.  Default is %d." % default_interval)
    parser.add_argument('-u', '--user', help='Login username for GSA.')
    parser.add_argument('-p', '--password', help='Password for GSA.')
    parser.add_argument('-x', '--check-last-sync',
                        default=None,
                        help='Check that last sync w/ GSA happened w/in a'
                             'given interval (in minutes).  If not, exit with '
                             'a non-zero status code;  if os, exit normally.')
    parser.add_argument('url', help='URL of GSA datasource.')
    parser.add_argument('-t', '--timeout',
                        default=90,
                        help='Timeout for GSA request (default 15 sec).')

    args = parser.parse_args(sys.argv[1:])

    env = args.bootstrap(args.config_uri)
    
    if not is_normal_mode(env['registry']):
        log.info("Cannot run mailin: Running in maintenance mode.")
        sys.exit(2)

    f = only_one(_sync, env['registry'], 'gsa_sync')
    if args.daemon:
        daemonize_function(f, args.interval)(args, env)
    else:
        f(args, env)
示例#5
0
    def __init__(self, context, request, page_title=None):
        self.settings = dict(get_settings(context))
        self.settings.update(self.config_settings)
        self.site = site = find_site(context)
        self.context = context
        self.request = request
        self.userid = authenticated_userid(request)
        self.app_url = app_url = request.application_url
        self.profile_url = app_url + '/profiles/%s' % self.userid
        self.here_url = self.context_url = resource_url(context, request)
        self.view_url = resource_url(context, request, request.view_name)
        self.read_only = not is_normal_mode(request.registry)
        self.static_url = get_static_url(request)
        self.resource_devel_mode = is_resource_devel_mode()
        self.browser_upgrade_url = request.registry.settings.get(
            'browser_upgrade_url', '')

        # this data will be provided for the client javascript
        self.karl_client_data = {}

        # Provide a setting in the INI to fully control the entire URL
        # to the static.  This is when the proxy runs a different port
        # number, or to "pipeline" resources on a different URL path.
        full_static_path = self.settings.get('full_static_path', False)
        if full_static_path:
            if '%d' in full_static_path:
                # XXX XXX note self._start_time is needed... and not _start_time
                # XXX XXX since this was a trivial bug, there is chance that
                # XXX XXX this actually never runs! TODO testing???
                full_static_path = full_static_path % self._start_time
            self.static_url = full_static_path
        self.page_title = page_title
        self.system_name = self.title = self.settings.get('title', 'KARL')
        self.user_is_admin = 'group.KarlAdmin' in effective_principals(request)
        self.can_administer = has_permission('administer', site, request)
        self.can_email = has_permission('email', site, request)
        self.admin_url = resource_url(site, request, 'admin.html')
        date_format = get_user_date_format(context, request)
        self.karl_client_data['date_format'] = date_format
        # XXX XXX XXX This will never work from peoples formish templates
        # XXX XXX XXX (edit_profile and derivates) because, in those form
        # XXX XXX XXX controllers, the api is instantiated from __init__,
        # XXX XXX XXX where request.form is still unset!!! (From all other
        # XXX XXX XXX formcontrollers the api is instantiated from __call__,
        # XXX XXX XXX which is why this works. A chicken-and-egg problem, really.
        if hasattr(request, 'form') and getattr(request.form, 'errors', False):
            # This is a failed form submission request, specify an error message
            self.error_message = u'Please correct the indicated errors.'

        self.site_announcements = getattr(self.site, "site_announcements", [])
        profiles = find_profiles(self.site)
        profile = profiles is not None and profiles.get(self.userid,
                                                        None) or None
        self.unseen_site_announcements = []
        if profile is not None and hasattr(profile, "_seen_announcements") \
                and hasattr(site, "site_announcements"):
            for item in site.site_announcements:
                if item['hash'] not in profile._seen_announcements:
                    self.unseen_site_announcements.append(item)
示例#6
0
文件: api.py 项目: lslaz1/karl
    def __init__(self, context, request, page_title=None):
        self.settings = dict(get_settings(context))
        self.settings.update(self.config_settings)
        self.site = site = find_site(context)
        self.context = context
        self.request = request
        self.userid = authenticated_userid(request)
        self.app_url = app_url = request.application_url
        self.profile_url = app_url + "/profiles/%s" % self.userid
        self.here_url = self.context_url = resource_url(context, request)
        self.view_url = resource_url(context, request, request.view_name)
        self.read_only = not is_normal_mode(request.registry)
        self.static_url = get_static_url(request)
        self.resource_devel_mode = is_resource_devel_mode()
        self.browser_upgrade_url = request.registry.settings.get("browser_upgrade_url", "")

        # this data will be provided for the client javascript
        self.karl_client_data = {}

        # Provide a setting in the INI to fully control the entire URL
        # to the static.  This is when the proxy runs a different port
        # number, or to "pipeline" resources on a different URL path.
        full_static_path = self.settings.get("full_static_path", False)
        if full_static_path:
            if "%d" in full_static_path:
                # XXX XXX note self._start_time is needed... and not _start_time
                # XXX XXX since this was a trivial bug, there is chance that
                # XXX XXX this actually never runs! TODO testing???
                full_static_path = full_static_path % self._start_time
            self.static_url = full_static_path
        self.page_title = page_title
        self.system_name = self.title = self.settings.get("title", "KARL")
        self.user_is_admin = "group.KarlAdmin" in effective_principals(request)
        self.can_administer = has_permission("administer", site, request)
        self.can_email = has_permission("email", site, request)
        self.admin_url = resource_url(site, request, "admin.html")
        date_format = get_user_date_format(context, request)
        self.karl_client_data["date_format"] = date_format
        # XXX XXX XXX This will never work from peoples formish templates
        # XXX XXX XXX (edit_profile and derivates) because, in those form
        # XXX XXX XXX controllers, the api is instantiated from __init__,
        # XXX XXX XXX where request.form is still unset!!! (From all other
        # XXX XXX XXX formcontrollers the api is instantiated from __call__,
        # XXX XXX XXX which is why this works. A chicken-and-egg problem, really.
        if hasattr(request, "form") and getattr(request.form, "errors", False):
            # This is a failed form submission request, specify an error message
            self.error_message = u"Please correct the indicated errors."

        self.site_announcements = getattr(self.site, "site_announcements", [])
        profiles = find_profiles(self.site)
        profile = profiles is not None and profiles.get(self.userid, None) or None
        self.unseen_site_announcements = []
        if profile is not None and hasattr(profile, "_seen_announcements") and hasattr(site, "site_announcements"):
            for item in site.site_announcements:
                if item["hash"] not in profile._seen_announcements:
                    self.unseen_site_announcements.append(item)
示例#7
0
文件: login.py 项目: araymund/karl
def remember_login(context, request, userid, max_age):
    remember_headers = remember(request, userid, max_age=max_age)

    # log the time on the user's profile, unless in read only mode
    read_only = not is_normal_mode(request.registry)
    if not read_only:
        profiles = find_profiles(context)
        if profiles is not None:
            profile = profiles.get(userid)
            if profile is not None:
                profile.last_login_time = datetime.utcnow()

    # and redirect
    came_from = request.session.pop('came_from')
    return HTTPFound(headers=remember_headers, location=came_from)
示例#8
0
def remember_login(context, request, userid, max_age):
    remember_headers = remember(request, userid, max_age=max_age)

    # log the time on the user's profile, unless in read only mode
    read_only = not is_normal_mode(request.registry)
    if not read_only:
        profiles = find_profiles(context)
        if profiles is not None:
            profile = profiles.get(userid)
            if profile is not None:
                profile.last_login_time = datetime.utcnow()

    # redirect
    came_from = request.session.pop('came_from', request.application_url)
    return HTTPFound(headers=remember_headers, location=came_from)
示例#9
0
def _update_feeds(args, env):
    registry = env['registry']
    root = env['root']
    if not is_normal_mode(registry):
        log.info("Cannot update feeds: Running in maintenance mode.")
        return
    container = root.get('feeds')
    if container is None:
        return

    force = args.force

    for name in sorted(container.keys()):
        feed = container.get(name)
        log.info("Updating feed: %s: %s", name, feed.url)
        _update_feed(feed, log, force)
    transaction.commit()
示例#10
0
文件: mailin.py 项目: araymund/karl
def main(argv=sys.argv):
    default_interval = 300
    parser = create_karl_argparser(description='Process incoming mail.')
    parser.add_argument('-d', '--daemon', action='store_true',
                        help="Run in daemon mode.")
    parser.add_argument('-i', '--interval', type=int, default=default_interval,
                        help="Interval in seconds between executions in "
                        "daemon mode.  Default is %d." % default_interval)

    args = parser.parse_args(sys.argv[1:])

    env = args.bootstrap(args.config_uri)

    if not is_normal_mode(env['registry']):
        log.info("Cannot run mailin: Running in maintenance mode.")
        sys.exit(2)

    try:
        if args.daemon:
            daemonize_function(mailin, args.interval)(args, env, parser)
        else:
            mailin(args, env, parser)
    finally:
        env['closer']()
示例#11
0
文件: api.py 项目: iotest3/new
    def __init__(self, context, request, page_title=None):
        self.settings = get_settings() or {}
        self.site = site = find_site(context)
        self.context = context
        self.request = request
        self.userid = authenticated_userid(request)
        self.app_url = app_url = request.application_url
        self.profile_url = app_url + '/profiles/%s' % self.userid
        self.here_url = self.context_url = resource_url(context, request)
        self.view_url = resource_url(context, request, request.view_name)
        self.js_devel_mode = asbool(self.settings.get('js_devel_mode', None))
        self.read_only = not is_normal_mode(request.registry)
        self.static_url = '%s/static/%s' % (
            app_url, request.registry.settings.get('static_rev'))
        self.browser_upgrade_url = request.registry.settings.get('browser_upgrade_url', '')

        # this data will be provided for the client javascript
        self.karl_client_data = {}

        # Provide a setting in the INI to fully control the entire URL
        # to the static.  This is when the proxy runs a different port
        # number, or to "pipeline" resources on a different URL path.
        full_static_path = self.settings.get('full_static_path', False)
        if full_static_path:
            if '%d' in full_static_path:
                # XXX XXX note self._start_time is needed... and not _start_time
                # XXX XXX since this was a trivial bug, there is chance that
                # XXX XXX this actually never runs! TODO testing???
                full_static_path = full_static_path % self._start_time
            self.static_url = full_static_path
        self.page_title = page_title
        self.system_name = self.settings.get('system_name', 'KARL')
        self.user_is_admin = 'group.KarlAdmin' in effective_principals(request)
        self.can_administer = has_permission('administer', site, request)
        self.can_email = has_permission('email', site, request)
        self.admin_url = resource_url(site, request, 'admin.html')
        self.site_announcement = getattr(site, 'site_announcement', '')
        date_format = get_user_date_format(context, request)
        self.karl_client_data['date_format'] = date_format
        # XXX XXX XXX This will never work from peoples formish templates
        # XXX XXX XXX (edit_profile and derivates) because, in those form
        # XXX XXX XXX controllers, the api is instantiated from __init__,
        # XXX XXX XXX where request.form is still unset!!! (From all other
        # XXX XXX XXX formcontrollers the api is instantiated from __call__,
        # XXX XXX XXX which is why this works. A chicken-and-egg problem, really.
        if hasattr(request, 'form') and getattr(request.form, 'errors', False):
            # This is a failed form submission request, specify an error message
            self.error_message = u'Please correct the indicated errors.'

        if self.settings:
            self.kaltura_info = dict(
                enabled =  self.settings.get(
                    'kaltura_enabled', False) in ('true', 'True'),
                partner_id = self.settings.get('kaltura_partner_id', ''),
                sub_partner_id = self.settings.get(
                    'kaltura_sub_partner_id', ''),
                admin_secret = self.settings.get('kaltura_admin_secret', ''),
                user_secret = self.settings.get('kaltura_user_secret', ''),
                kcw_uiconf_id = self.settings.get(
                    'kaltura_kcw_uiconf_id', '1000741'),
                player_uiconf_id = self.settings.get(
                    'kaltura_player_uiconf_id', ''),
                player_cache_st = self.settings.get(
                    'kaltura_player_cache_st', ''),
                local_user = self.userid,
            )
            if not self.settings.get(
                'kaltura_client_session', False) in ('true', 'True'):
                # Secrets will not be sent to client, instead session is handled on the server.
                self.kaltura_info['session_url'] = app_url + '/' + 'kaltura_create_session.json'
        else:
            self.kaltura_info = dict(
                enabled = False,
                )

        # propagate the head data to the client
        d = self.karl_client_data['kaltura'] = dict(self.kaltura_info)
        # remove secrets if needed
        if 'session_url' in d:
            # server side session management, do not send secrets to client
            del d['user_secret']
            del d['admin_secret']
示例#12
0
文件: api.py 项目: araymund/karl
    def __init__(self, context, request, page_title=None):
        self.settings = get_settings() or {}
        self.site = site = find_site(context)
        self.context = context
        self.request = request
        self.userid = authenticated_userid(request)
        self.app_url = app_url = request.application_url
        self.profile_url = app_url + '/profiles/%s' % self.userid
        self.here_url = self.context_url = resource_url(context, request)
        self.view_url = resource_url(context, request, request.view_name)
        self.js_devel_mode = asbool(self.settings.get('js_devel_mode', None))
        self.read_only = not is_normal_mode(request.registry)
        self.static_url = '%s/static/%s' % (
            app_url, request.registry.settings.get('static_rev'))
        self.browser_upgrade_url = request.registry.settings.get('browser_upgrade_url', '')

        # this data will be provided for the client javascript
        self.karl_client_data = {}

        # Provide a setting in the INI to fully control the entire URL
        # to the static.  This is when the proxy runs a different port
        # number, or to "pipeline" resources on a different URL path.
        full_static_path = self.settings.get('full_static_path', False)
        if full_static_path:
            if '%d' in full_static_path:
                # XXX XXX note self._start_time is needed... and not _start_time
                # XXX XXX since this was a trivial bug, there is chance that
                # XXX XXX this actually never runs! TODO testing???
                full_static_path = full_static_path % self._start_time
            self.static_url = full_static_path
        self.page_title = page_title
        self.system_name = self.settings.get('system_name', 'KARL')
        self.user_is_admin = 'group.KarlAdmin' in effective_principals(request)
        self.can_administer = has_permission('administer', site, request)
        self.can_email = has_permission('email', site, request)
        self.admin_url = resource_url(site, request, 'admin.html')
        self.site_announcement = getattr(site, 'site_announcement', '')
        date_format = get_user_date_format(context, request)
        self.karl_client_data['date_format'] = date_format
        # XXX XXX XXX This will never work from peoples formish templates
        # XXX XXX XXX (edit_profile and derivates) because, in those form
        # XXX XXX XXX controllers, the api is instantiated from __init__,
        # XXX XXX XXX where request.form is still unset!!! (From all other
        # XXX XXX XXX formcontrollers the api is instantiated from __call__,
        # XXX XXX XXX which is why this works. A chicken-and-egg problem, really.
        if hasattr(request, 'form') and getattr(request.form, 'errors', False):
            # This is a failed form submission request, specify an error message
            self.error_message = u'Please correct the indicated errors.'

        if self.settings:
            self.kaltura_info = dict(
                enabled =  self.settings.get(
                    'kaltura_enabled', False) in ('true', 'True'),
                partner_id = self.settings.get('kaltura_partner_id', ''),
                sub_partner_id = self.settings.get(
                    'kaltura_sub_partner_id', ''),
                admin_secret = self.settings.get('kaltura_admin_secret', ''),
                user_secret = self.settings.get('kaltura_user_secret', ''),
                kcw_uiconf_id = self.settings.get(
                    'kaltura_kcw_uiconf_id', '1000741'),
                player_uiconf_id = self.settings.get(
                    'kaltura_player_uiconf_id', ''),
                player_cache_st = self.settings.get(
                    'kaltura_player_cache_st', ''),
                local_user = self.userid,
            )
            if not self.settings.get(
                'kaltura_client_session', False) in ('true', 'True'):
                # Secrets will not be sent to client, instead session is handled on the server.
                self.kaltura_info['session_url'] = app_url + '/' + 'kaltura_create_session.json'
        else:
            self.kaltura_info = dict(
                enabled = False,
                )

        # propagate the head data to the client
        d = self.karl_client_data['kaltura'] = dict(self.kaltura_info)
        # remove secrets if needed
        if 'session_url' in d:
            # server side session management, do not send secrets to client
            del d['user_secret']
            del d['admin_secret']