Example #1
0
def _plain_send_mail(sender, recipient, subject, body):
    header_charset = 'ISO-8859-1'
    for body_charset in 'US-ASCII', 'ISO-8859-1', 'UTF-8':
        try:
            body.encode(body_charset)
        except UnicodeError:
            pass
        else:
            break

    sender_name, sender_addr = parseaddr(sender)
    recipient_name, recipient_addr = parseaddr(recipient)

    sender_name = str(Header(unicode(sender_name), header_charset))
    recipient_name = str(Header(unicode(recipient_name), header_charset))

    sender_addr = sender_addr.encode('ascii')
    recipient_addr = recipient_addr.encode('ascii')

    msg = MIMEText(body.encode(body_charset), 'plain', body_charset)
    msg['From'] = formataddr((sender_name, sender_addr))
    msg['To'] = formataddr((recipient_name, recipient_addr))
    msg['Subject'] = Header(unicode(subject), header_charset)

    smtp = SMTP(config.get('registration.smtp_host', 'localhost'))
    if config.get('registration.smtp_login'):
        try:
            smtp.starttls()
        except:
            pass
        smtp.login(config.get('registration.smtp_login'), config.get('registration.smtp_passwd'))
    smtp.sendmail(sender, recipient, msg.as_string())
    smtp.quit()
Example #2
0
    def command(self):
        config=load_config(self.args)
        if self.options.export:
            f = open(config.get('starlogic.out'),'w')
            fs = open(config.get('starlogic.sincro'))
            sincro = 0
            for i in  fs.readlines():
                sincro = i.strip()
                sincro = int(sincro)
            fs.close()
            ps = DBSession.query(Eanprodotti)
            if not self.options.all:
                ps = ps.filter(Eanprodotti.sincrofield>sincro)
            ps = ps.order_by(Eanprodotti.sincrofield).all()

            for p in ps:
                codart = p.prodotto.eans[0].ean
                desc = p.prodotto.prodotto.encode('ascii', 'ignore')
                prezzo = p.prodotto.prezzo            
                sincro = p.sincrofield
                print >> f, "%s;%s;%s;%s;%s"%(codart, p.ean, desc, prezzo,0)
                
                if len(p.aliases)>0:
                    for alias in p.aliases:
                        print >> f, "%s;%s;%s;%s;%s"%(codart, alias.alias, desc, prezzo,1)
            f.close()
            f = open(config.get('starlogic.sincro'),'w')
            print >>  f, sincro		        
            f.close()
Example #3
0
 def _toPrintshop( self, hdr, subject, content, files = [] ):
     defaultsendto = config.get( "default_email_sendto", "" ).split( ";" )
     if hdr.printShopId and hdr.printShop.email: to = hdr.printShop.email
     else: to = []
     sendto = defaultsendto + to
     cc = config.get( "default_email_cc", "" ).split( ";" )
     if config.get( "sendout_email", None ) != 'F': sendEmail( DEFAULT_SENDER, sendto, subject, '\n'.join( content ), cc, files )
Example #4
0
 def _toVendor( self, hdr , subject, content, files = [] ):
     defaultsendto = config.get( "default_email_sendto", "" ).split( ";" )
     if hdr.createBy.email_address:  to = hdr.createBy.email_address.split( ";" )
     else: to = []
     sendto = defaultsendto + to
     cc = config.get( "default_email_cc", "" ).split( ";" )
     if config.get( "sendout_email", None ) != 'F': sendEmail( DEFAULT_SENDER, sendto, subject, '\n'.join( content ), cc, files )
Example #5
0
    def grid(self, cls, **params):

        rp    = get_paramw(params, 'rp', int, opcional=True, por_defecto=int(config.get('grid.default_rp', 10)))
        pag_n = get_paramw(params, 'pag_n', int, opcional=True, por_defecto=1)

        ds = self.grid_data(cls, **params)

        # Reading global settings
        ds.date_fmt = date_fmt
        ds.time_fmt = config.get('formats.time', default='%H:%M')
        ds.datetime_fmt = config.get('formats.datetime', default='%m/%d/%Y %H:%M')
        ds.true_const = _('Yes')
        ds.false_const = _('No')

        ds.float_fmt = app_cfg.format_float

        cols = []
        for col in ds.labels:
            w = 850 / len(ds.labels)
            if col == 'id':
                w = 60

            cols.append(dict(title=col, width=w, align='center'))

        this_page, total_pag = pagination(rp, pag_n, ds.count)

        return dict(status=True, cols=cols, data=ds.to_data(),
                    this_page=this_page, total_count=ds.count, total_pag=total_pag)
Example #6
0
    def __init__(self, *args, **kw):
        super(ChatController, self).__init__(*args, **kw)
        self.config = {}
        backend = config.get('chat.backend')
        if not backend:
            log.info('No `chat.backend` defined; disabling chat functionality')
            return
        backend = urlparse.urlparse(backend)
        if hasattr(backend, 'scheme'): # Python 2.5+
            self.config['backendProtocol'] = backend.scheme
            self.config['backendAddr'] = [backend.hostname, backend.port]
        else: # Python 2.4
            self.config['backendProtocol'] = backend[0]
            host, port = backend[1].split(':')
            self.config['backendAddr'] = [host, port]
        self.config['startBuiltin'] = config.get('chat.builtin', False)
        self.config['rooms'] = {}
        display_opts = {
                'floating': True, 'floatingToggle': False, 'width': 400 ,
                'height': 300, 'theme': 'simple', 'resizable': True,
                'greeting': 'Moksha Chat',
                }
        for room in config['chat.rooms'].replace(',', ' ').split():
            self.config['rooms'][room] = {'display': {}}
            for display_opt, default in display_opts.items():
                self.config['rooms'][room]['display'][display_opt] = \
                        config.get('chat.%s.display.%s' % (room, display_opt),
                                   default)
            self.config['rooms'][room]['roomAssignmentMode'] = \
                    config.get('chat.%s.roomAssignmentMode' % room, 'static')
            self.config['rooms'][room]['staticRoomName'] = \
                    config.get('chat.%s.staticRoomName' % room, room)

        log.debug('Chat config = %r' % self.config)
Example #7
0
 def export(self, **kw):
     try:
         current = dt.now()
         dateStr = current.strftime("%Y%m%d")
         fileDir = os.path.join(config.get("public_dir"), "report", 'ci', dateStr)
         if not os.path.exists(fileDir):
             os.makedirs(fileDir)
         templatePath = os.path.join(config.get("public_dir"), 'TEMPLATE', "CI_TEMPLATE.xlsx")
         tempFileName = os.path.join(fileDir, "tmp_%s.xlsx" % current.strftime("%Y%m%d%H%M%S"))
         realFileName = os.path.join(fileDir, "inventory_report_%s.xlsx" % current.strftime("%Y%m%d%H%M%S"))
         shutil.copy(templatePath, tempFileName)
         report_xls = InventoryExcel(templatePath=tempFileName, destinationPath=realFileName)
         data = []
         if kw:
             data = self._query_ci_result(kw)
         report_xls.inputData(data=data)
         report_xls.outputData()
         try:
             os.remove(tempFileName)
         except:
             pass
         return serveFile(unicode(realFileName))
     except:
         traceback.print_exc()
         flash("Export Fail.")
         redirect("/cireport/index")
Example #8
0
    def after_init_config(self):

        from tg import config as tgconf

        if tgconf.get('debug', False):
            # Always show warnings for the sauce module
            import warnings
            warnings.filterwarnings(action='once', module='sauce')
            warnings.filterwarnings(action='once', module='.*mak')

        _locale = tgconf.get('locale')

        try:
            locale.setlocale(locale.LC_ALL, _locale)
        except Exception:  # pragma: no cover
            log.exception('Could not set locale: %s', _locale)
        else:
            log.debug('Locale set to: %s', _locale)

        for fmt in ('D_FMT', 'T_FMT', 'D_T_FMT'):
            fmtstr = tgconf.get(fmt, None)
            if fmtstr:
                # Self-baked %-escaping
                fmtstr = fmtstr.replace('%%', '%')
            if not fmtstr:
                fmtstr = locale.nl_langinfo(getattr(locale, fmt))
                log.debug('Format string for %s read from locale: %s', (fmt, fmtstr))
            setattr(tgconf, fmt, fmtstr)
Example #9
0
 def _check_context(self, parsed_args):
     if config.get('auth_type') == LDAPAuth.name:
         auth_instance = config.get('auth_instance')
         if not auth_instance.ldap_auth.user_exist(parsed_args.login):
             raise LDAPUserUnknown(
                 "LDAP is enabled and user with login/email \"%s\" not found in LDAP" % parsed_args.login
             )
Example #10
0
    def register(cls):
        cls._base_url = config.get('fedoracommunity.connector.kojihub.baseurl',
                                   'http://koji.fedoraproject.org/kojihub')

        cls._koji_url = config.get('fedoracommunity.connector.koji.baseurl',
                                   'http://koji.fedoraproject.org/koji')

        cls._koji_pkg_url = config.get(
            'fedoracommunity.connector.koji.pkgurl',
            'http://koji.fedoraproject.org/packages')

        cls._rpm_cache = config.get('fedoracommunity.rpm_cache',
                                    None)
        if not cls._rpm_cache:
            print "You must specify fedoracommunity.rpm_cache in you .ini file"
            exit(-1)

        cls.register_query_builds()
        cls.register_query_packages()
        cls.register_query_changelogs()
        cls.register_query_provides()
        cls.register_query_requires()
        cls.register_query_conflicts()
        cls.register_query_obsoletes()

        cls.register_method('get_error_log', cls.call_get_error_log)
        cls.register_method(
            'get_latest_changelog', cls.call_get_latest_changelog)
        cls.register_method('get_file_tree', cls.call_get_file_tree)
Example #11
0
def sendmail(to_addrs, subject, text):

    server = config.get('smtp_server')
    use_tls = asbool(config.get('smtp_use_tls'))
    username = config.get('smtp_username')
    password = config.get('smtp_password')
    from_addr = config.get('admin_email_from')

    log.debug('Sending mail via %s' % server)

    if use_tls:
        s = SMTP_SSL()
    else:
        s = SMTP()
    s.connect(server)
    if username:
        s.login(username, password)
    msg = MIMEText(text, _charset='utf-8')
    msg['From'] = from_addr
    msg['Reply-To'] = from_addr
    if isinstance(to_addrs, basestring):
        msg['To'] = to_addrs
    else:
        msg['To'] = ', '.join(to_addrs)
    msg['Subject'] = subject
    s.sendmail(from_addr, to_addrs, msg.as_string())
    s.quit()
Example #12
0
 def export(self, **kw):
     try:
         current = dt.now()
         dateStr = current.strftime("%Y%m%d")
         fileDir = os.path.join(config.get("public_dir"), "report", 'ir', dateStr)
         if not os.path.exists(fileDir):
             os.makedirs(fileDir)
         templatePath = os.path.join(config.get("public_dir"), 'TEMPLATE', "IR_TEMPLATE.xlsx")
         tempFileName = os.path.join(fileDir, "tmp_%s.xlsx" % current.strftime("%Y%m%d%H%M%S"))
         realFileName = os.path.join(fileDir, "item_received_report_%s.xlsx" % current.strftime("%Y%m%d%H%M%S"))
         shutil.copy(templatePath, tempFileName)
         report_xls = InventoryExcel(templatePath=tempFileName, destinationPath=realFileName)
         data = []
         if kw:
             rItems = self._query_ir_result(kw)
             for rItem in rItems:
                 data.append((rItem.warehouse.name, rItem.createTime, rItem.item.item_number, rItem.qty, rItem.issuedBy.__unicode__()))
         report_xls.inputData(data=data)
         report_xls.outputData()
         try:
             os.remove(tempFileName)
         except:
             pass
         return serveFile(unicode(realFileName))
     except:
         traceback.print_exc()
         flash("Export Fail.")
         redirect("/irreport/index")
Example #13
0
def recover_user_password(user):
    key = user.generate_recover_key(request.remote_addr)

    text = u"""Hi %s,

you have asked to recover your password (from IP %s).  To enter a new
password, click on the following link:

 http://skylines.xcsoar.org/users/recover?key=%x

The SkyLines Team
""" % (unicode(user), request.remote_addr, key)

    msg = email.mime.text.MIMEText(text.encode('utf-8'), 'plain', 'utf-8')
    msg['Subject'] = 'SkyLines password recovery'
    msg['From'] = config.get('email_from', '*****@*****.**')
    msg['To'] = user.email_address.encode('ascii')
    msg['Date'] = email.Utils.formatdate(localtime=1)

    try:
        smtp = smtplib.SMTP(config.get('smtp_server', 'localhost'))
        smtp.ehlo()
        smtp.sendmail(config.get('email_from', '*****@*****.**').encode('ascii'),
                      user.email_address.encode('ascii'), msg.as_string())
        smtp.quit()
    except:
        raise HTTPServiceUnavailable(explanation=_(
            "The mail server is currently not reachable. "
            "Please try again later or contact the developers."))
Example #14
0
def export(page, plugins_data):
    buf = StringIO()
    quoting = config.get('csv_quoting', 'ALL').upper()
    if quoting not in ('ALL', 'MINIMAL', 'NONNUMERIC', 'NONE'):
        quoting = 'ALL'
    csv_writer = csv.DictWriter(buf,
        config['csv_columns'],
        extrasaction='ignore',
        delimiter=config.get("csv_delimiter_char", ';'),
        escapechar=config.get("csv_escape_char", '\\'),
        quotechar=config.get("csv_quote_char", '"'),
        quoting=getattr(csv, 'QUOTE_%s' % quoting))
    csv_writer.writerow(dict(zip(config['csv_columns'], config['csv_columns'])))

    for item in page.items:
        values = {}
        for plugin_name, plugin_instance in config['columns_plugins']:
            if plugins_data[plugin_name]:
                values[plugin_name] = repr(plugins_data[plugin_name])
            else:
                for data_key, data_value in \
                    plugin_instance.get_data(item).iteritems():
                    # Pour les valeurs en unicode, on convertit en UTF-8.
                    if isinstance(data_value, unicode):
                        values[data_key] = data_value.encode('utf-8')
                    # Pour le reste, on suppose qu'on peut en obtenir une
                    # représentation adéquate dont l'encodage ne posera pas
                    # de problème.
                    else:
                        values[data_key] = data_value
        csv_writer.writerow(values)
    return buf.getvalue()
Example #15
0
    def nav_logo(self):
        logo = dict(
            redirect_link=config.get('logo.link', False),
            image_path=config.get('logo.path', False),
            image_width=config.get('logo.width', False),
            image_height=config.get('logo.height', False)
        )
        if not logo['redirect_link']:
            logo['redirect_link'] = '/'

        if not logo['image_path']:
            log.warning('Image path not set for nav_logo')
            return False

        allura_path = os.path.dirname(os.path.dirname(__file__))
        image_full_path = '%s/public/nf/images/%s' % (
            allura_path, logo['image_path'])

        if not os.path.isfile(image_full_path):
            log.warning('Could not find logo at: %s' % image_full_path)
            return False

        path = 'images/%s' % logo['image_path']
        return {
            "image_path": self.forge_static(path),
            "redirect_link": logo['redirect_link'],
            "image_width": logo['image_width'],
            "image_height": logo['image_height']
        }
    def load_results_page(self, beg_date, end_date):
        log.debug("Trying to load page 1 of ??")

        # Login page
        # TODO -- there are about 6 other counties we can scrape here.
        url = '%s/NY-Monroe/' % self.base
        self.browser.open(url)
        self.browser.follow_link(url_regex=re.compile('.*loginForm.*'))
        self.browser.select_form(nr=0)
        self.browser.form['txtUserName'] = config.get('propertyinfo.username')
        self.browser.form['txtPassword'] = config.get('propertyinfo.password')
        self.browser.submit()

        # Load search page and input criteria
        self.browser.follow_link(url_regex=re.compile('.*=2004.*'))
        self.browser.select_form(name='frmSavedCriteria')
        self.set_hidden_form_value('SearchbyDateFrom', beg_date)
        self.set_hidden_form_value('SearchbyDateTo', end_date)
        # TODO -- there are lots of other doc types we can get here.
        self.set_hidden_form_value('SearchDocType',
                              "NOTICE OF PENDENCY MORTGAGE FORECLOSURE")
        self.browser.form.action = '%s/wam3/SearchSummary.asp' % self.apps_base
        self.browser.submit()

        # Follow an implicit redirect
        try:
            # which, however, will shit the bed if there are no results
            self.browser.select_form(name='frmResult')
            self.browser.submit()
        except mechanize._mechanize.FormNotFoundError:
            log.debug("No results found for %s to %s" % (beg_date, end_date))
            return None
        def _generator():
            while True:
                from pymongo import MongoClient
                from tg import config
                client = MongoClient("%s%s" % (config.get('ming.url'), config.get('ming.db')))
                db = client.spacehackaton
                '''
                data_to_deactivate = db.node.find(
                    {
                        'update_time': {
                            '$lt': datetime.datetime.utcnow()-datetime.timedelta(seconds=10)
                        }
                    }
                )

                for item_to_deactivate in data_to_deactivate:
                    db.node.update({'name': item_to_deactivate.get('name')}, {'$set': {'status': 'INACTIVE'}})
                '''
                data_to_return = db.node.find()
                json_data = json.dumps([self.to_json(x) for x in data_to_return], sort_keys=True, indent=4,
                                       default=json_util.default)
                event = "data: %s\n\n" % json.loads(json_data)
                sleep(1)
                #print "Nodes", event.replace("u'", "'").replace("'", "\"")
                client.close()
                yield event.replace("u'", "'").replace("'", "\"").encode('utf-8')
Example #18
0
 def __call__(self):
     
     lang = init_lang()
     
     vars_ = dict(display_name=self.u.display_name,
                  user_name=self.u.user_name,
                  new_password=self.new_password,
                  app_title=config.get('mail.name').decode('utf-8'),
                  )
     
     asunto = self.env.get_template('sapns/users/forgot_password/%s/subject.txt' % lang)
     asunto = asunto.render(**vars_).encode('utf-8')
     
     mensaje = self.env.get_template('sapns/users/forgot_password/%s/message.txt' % lang)
     mensaje = mensaje.render(**vars_).encode('utf-8')
     
     mensaje_html = self.env.get_template('sapns/users/forgot_password/%s/message.html' % lang)
     mensaje_html = mensaje_html.render(**vars_).encode('utf-8')
     
     email_login = config.get('mail.user')
     email_password = config.get('mail.password')
     
     # send e-mail
     send_mail(self.remitente, self.dst, asunto, mensaje,
               config.get('mail.smtp'), email_login, email_password, 
               html=mensaje_html)
Example #19
0
    def zarkov_event(self, event_type, user=None, neighborhood=None, project=None, app=None, extra=None):
        context = dict(user=None, neighborhood=None, project=None, tool=None, mount_point=None, is_project_member=False)

        if not config.get("zarkov.host"):
            return

        user = user or getattr(c, "user", None)
        project = project or getattr(c, "project", None)
        app = app or getattr(c, "app", None)
        if user:
            context["user"] = user.username
        if project:
            context.update(project=project.shortname, neighborhood=project.neighborhood.url_prefix.strip("/"))
            if user:
                cred = Credentials.get()
                if cred is not None:
                    for pr in cred.user_roles(user._id, project._id).reaching_roles:
                        if pr.get("name") and pr.get("name")[0] != "*":
                            context["is_project_member"] = True
        if app:
            context.update(tool=app.config.tool_name, mount_point=app.config.options.mount_point)

        try:
            if self._zarkov is None:
                self._zarkov = ZarkovClient(config.get("zarkov.host", "tcp://127.0.0.1:6543"))
            self._zarkov.event(event_type, context, extra)
        except Exception, ex:
            self._zarkov = None
            log.error("Error sending zarkov event(%r): %r", ex, dict(type=event_type, context=context, extra=extra))
 def test_register_private_ok(self):
     r = self.app.post(
         '/p/register',
         params=dict(
             project_unixname='mymoz',
             project_name='My Moz',
             project_description='',
             neighborhood='Projects',
             private_project='on',
             tools='wiki'),
         antispam=True,
         extra_environ=dict(username='******'),
         status=302)
     assert config.get('auth.login_url', '/auth/') not in r.location, r.location
     r = self.app.get(
         '/p/mymoz/wiki/',
         extra_environ=dict(username='******')).follow(extra_environ=dict(username='******'), status=200)
     r = self.app.get(
         '/p/mymoz/wiki/',
         extra_environ=dict(username='******'),
         status=302)
     assert config.get('auth.login_url', '/auth/') in r.location, r.location
     self.app.get(
         '/p/mymoz/wiki/',
         extra_environ=dict(username='******'),
         status=403)
Example #21
0
 def _sendEmail(self, subject, to, content):
     defaultsendto = config.get("default_email_sendto", "").split(";")
     sendto = defaultsendto + to
     cc = config.get("default_email_cc", "").split(";")
     content.extend(EMAIL_SUFFIX)
     if config.get("sendout_email", None) != 'F':
         sendEmail(EMAIL_SENDFROM, sendto, subject, '\n'.join(content), cc)
Example #22
0
    def production_export( self, **kw ):
        ws = [Item.active == 0, Item.status == STATUS_APPROVE, ]
        if kw.get( "jobNo", False ) : ws.append( Item.jobNo.op( "ilike" )( "%%%s%%" % kw["jobNo"] ) )
        if kw.get( "systemNo", False ) : ws.append( Item.systemNo.op( "ilike" )( "%%%s%%" % kw["systemNo"] ) )
        if kw.get( "desc", False ) : ws.append( Item.desc.op( "ilike" )( "%%%s%%" % kw["desc"] ) )
        if kw.get( "approve_time_from", False ) : ws.append( Item.approveTime >= kw["approve_time_from"] )
        if kw.get( "approve_time_to", False ) : ws.append( Item.approveTime <= kw["approve_time_to"] )
        result = qry( Item ).filter( and_( *ws ) ).order_by( desc( Item.createTime ) ).all()

        data = []
        for h in  qry( Item ).filter( and_( *ws ) ).order_by( desc( Item.createTime ) ):
            data.append( map( unicode, [ h.systemNo, h.jobNo, h.desc, h.createTime.strftime( "%Y/%m/%d %H:%M" ),
                                      h.showStatus(),
                                      h.approveTime.strftime( "%Y/%m/%d %H:%M" ) if h.approveTime else '',
                                     ] ) )

        try:
            v = getExcelVersion()
            if not v : raise ReportGenerationException()
            if v <= "2003" :  # version below 2003
                templatePath = os.path.join( config.get( "public_dir" ), "TEMPLATE", "CAB_PRODUCTION_REPORT_TEMPLATE.xls" )
            else :  # version above 2003
                templatePath = os.path.join( config.get( "public_dir" ), "TEMPLATE", "CAB_PRODUCTION_REPORT_TEMPLATE.xlsx" )

            tempFileName, realFileName = self._getReportFilePath( templatePath )
            sdexcel = CABItemReport( templatePath = tempFileName, destinationPath = realFileName )
            sdexcel.inputData( data )
            sdexcel.outputData()
        except:
            traceback.print_exc()
            logError()
            if sdexcel:sdexcel.clearData()
            raise ReportGenerationException()
        else:
            return serveFile( realFileName )
Example #23
0
def get_form():
    registration_form = config.get('registration.form_instance')
    if not registration_form:
        form_path = config.get('registration.form', 'registration.lib.forms.RegistrationForm')
        root_module, path = form_path.split('.', 1)
        form_class = reduce(getattr, path.split('.'), sys.modules[root_module])
        registration_form = config['registration.form_instance'] = form_class()
    return registration_form
Example #24
0
 def __init__(self, hub):
     enabled = asbool(config.get('moksha.feedaggregator', False))
     if not enabled:
         log.info('Moksha Feed Aggregator disabled')
         return
     else:
         self.frequency = int(config.get('feed.poll_frequency', 900))
     super(MokshaFeedStream, self).__init__(hub)
Example #25
0
 def __init__(self):
     """Initialize global variables"""
     here = config.get('here', '')
     cache_dir = config.get('cache.dir', '')
     self.upload_dir = config.get('upload_dir', '%s/upload' % cache_dir)
     self.upload_prefix = config.get('upload_prefix', 'upload')
     themes_dir = os.path.join(here, 'tagger', 'public', 'themes')
     self.themes = [d for d in os.listdir(themes_dir)]
Example #26
0
 def email_address(self):
     if self.discussion_disabled:
         return tg_config.get("forgemail.return_path")
     if c.app.config.options.get("AllowEmailPosting", True):
         domain = self.email_domain
         return "%s@%s%s" % (self.ticket_num, domain, config.common_suffix)
     else:
         return tg_config.get("forgemail.return_path")
Example #27
0
    def register(cls):
        cls._base_url = config.get('fedoracommunity.connector.bodhi.baseurl',
                                   'https://admin.fedoraproject.org/updates')

        check_certs = asbool(config.get('fedora.clients.check_certs', True))
        cls._insecure = not check_certs

        cls.register_query_updates()
        cls.register_query_active_releases()
Example #28
0
    def _check_security(self):
        require_authenticated()

        enable_editing = config.get('trovecategories.enableediting', 'false')
        if enable_editing == 'admin':
            with h.push_context(config.get('site_admin_project', 'allura'),
                                neighborhood=config.get('site_admin_project_nbhd', 'Projects')):
                require_access(c.project, 'admin')
        elif enable_editing != 'true':
            raise HTTPForbidden()
Example #29
0
    def create_comment(self, **kw):         
        try:
            #check if this user can create a comment in this topic
            #for now every member of the topic can create a comment
            creator = DBSession.query(MemberTopic).\
                           filter(MemberTopic.topic_id==kw['topic_id'], 
                                  MemberTopic.member_id==request.identity['user'].user_id).\
                           first()      
            
            if not creator:
                #TODO: this should never happen, log this event and return only False
                return dict(success=False, error_code=ErrorCode.UNAUTHORIZED)
            
            comment = Comment()
            comment.subject_id = kw['subject_id']
            comment.creator_id = request.identity['user'].user_id
            comment.content = kw['content']
            
            DBSession.add(comment)
            DBSession.flush()
            
            #TODO: should not query then update, should only update
            topic = DBSession.query(Topic).\
                            filter(Topic.uid==kw['topic_id']).first()
            #TODO: need to rethink this time var, how about subject update_time
            topic.update_time = comment.time                
                            
            log.info("User %s creates comment %s"%(comment.creator_id, comment))
            
            subject_title = DBSession.query(Subject.title).\
                            filter(Subject.uid==kw['subject_id']).first()[0]
                            
            members = DBSession.query(User.email_address).\
                           filter(MemberTopic.topic_id==kw['topic_id'],
                                  MemberTopic.member_id!=creator.member_id, 
                                  MemberTopic.deleted==False,
                                  MemberSubject.subject_id==kw['subject_id'],
                                  MemberSubject.muted==False).\
                           join(MemberTopic,MemberSubject).\
                           all()
            member_emails = [member[0] for member in members]
                           
            #send notification to users
            notif=dict(type='new_comment',topic=topic.title,subject=subject_title,comment=comment.content,
                       registered_users=member_emails,user_name=request.identity['user'].user_name)
            log.info('Sending SNS notification: %s'%notif)
            sns=SNSConnection(config.get('AWS_ACCESS_KEY_ID'), config.get("AWS_SECRET_ACCESS_KEY"))
            sns.publish(config.get('sqs_user_notification'),js.dumps(notif))

            return dict(success=True, comment=dict(uid=comment.uid, time=comment.time))
                        
        except Exception as e:
            log.exception('Got exception %s'%e)
            #traceback.print_exc(file=sys.stdout)
            return dict(success=False)  
Example #30
0
 def oauth_callback(self, **kw):
     client_id = config.get("github_importer.client_id")
     secret = config.get("github_importer.client_secret")
     if not client_id or not secret:
         return  # GitHub app is not configured
     oauth = OAuth2Session(client_id, state=session.get("github.oauth.state"))
     token = oauth.fetch_token(
         "https://github.com/login/oauth/access_token", client_secret=secret, authorization_response=request.url
     )
     c.user.set_tool_data("GitHubProjectImport", token=token["access_token"])
     redirect(session.get("github.oauth.redirect", "/"))
Example #31
0
 def handle_paging(self, limit, page, default=25):
     limit = self.manage_paging_preference(limit, default)
     limit = max(int(limit), 1)
     limit = min(limit, asint(config.get('limit_param_max', 500)))
     page = max(int(page), 0)
     start = page * int(limit)
     return (limit, page, start)
Example #32
0
    def enforce_limit(self, project):
        """
        Enforce rate limiting of tool imports on a given project.

        Returns False if limit is met / exceeded.  Otherwise, increments the
        count of pending / in-progress imports and returns True.
        """
        limit = config.get('tool_import.rate_limit', 1)
        pending_key = 'tool_data.%s.pending' % self.classname
        modified_project = M.Project.query.find_and_modify(
            query={
                '_id': project._id,
                '$or': [
                    {
                        pending_key: None
                    },
                    {
                        pending_key: {
                            '$lt': limit
                        }
                    },
                ],
            },
            update={'$inc': {
                pending_key: 1
            }},
            new=True,
        )
        return modified_project is not None
Example #33
0
    def __init__(self):
        engine = sqlalchemy.engine.create_engine(config.get('sqlalchemy.url'))
        engine.connect()
        model.init_model(engine)

        self._repo = None
        self._logger = logging.getLogger(__name__)
Example #34
0
def warn_externalauth(self, *args, **kw):
    if config.get('externalauth', False):
        s = request.controller_state.controller
        if s.model == User:
            flash(
                'Profile changes are not possible because external authentication is used!',
                'error')
Example #35
0
    def render_bars(self, response):
        page = response.get('response')
        if (not page or not isinstance(page, unicode_text)
                or 'text/html' not in response['content_type'] or
                request.headers.get('X-Requested-With') == 'XMLHttpRequest'):

            if config.get('debugbar.enable_logs', False):
                for section in __sections__:
                    if hasattr(section, 'log_content'):
                        section.log_content()

            return

        pos_head = page.find('</head>')
        if pos_head > 0:
            pos_body = page.find('</body>', pos_head + 7)
            if pos_body > 0:
                response['response'] = ''.join([
                    page[:pos_head],
                    Markup(self.css_link % url(self.css_path)),
                    page[pos_head:pos_body],
                    Markup(
                        render(
                            dict(sections=__sections__),
                            config['debugbar.engine'],
                            self.template,
                        ).split('\n', 1)[-1]), page[pos_body:]
                ])
Example #36
0
def load_default_drivers():
    stores = OrderedDict()
    store_list = [ x.strip() for x in config.get('bisque.blob_service.stores','').split(',') ]
    log.debug ('requested stores = %s' , store_list)
    for store in store_list:
        # pull out store related params from config
        params = dict ( (x[0].replace('bisque.stores.%s.' % store, ''), x[1])
                        for x in  config.items() if x[0].startswith('bisque.stores.%s.' % store))
        if 'mounturl' not in params:
            if 'path' in params:
                path = params.pop ('path')
                params['mounturl'] = string.Template(path).safe_substitute(OLDPARMS)
                log.warn ("Use of deprecated path (%s) in  %s driver . Please change to mounturl and remove any from %s", path, store, OLDPARMS.keys())
                log.info ("using mounturl = %s", params['mounturl'])
            else:
                log.error ('cannot configure %s without the mounturl parameter' , store)
                continue
        #if 'top' not in params:
        #    params['top'] = params['mounturl'].split ('$user')[0]
        #    log.warn ("top for %s was not set.  Using %s", params['mounturl'], params['top'])
        log.debug("params = %s" , params)
        #driver = make_storage_driver(params.pop('path'), **params)
        #if driver is None:
        #    log.error ("failed to configure %s.  Please check log for errors " , str(store))
        #    continue
        stores[store] = params
    return stores
Example #37
0
    def icon_url(self, gravatar_default_url=None, return_more=False):
        icon_url = None
        try:
            private_project = self.private_project()
        except:
            log.warn('Error getting/creating user-project for %s',
                     self.username, exc_info=True)
            private_project = None
        icon_source = None
        if private_project and private_project.icon:
            icon_url = self.url() + 'user_icon'
            icon_source = 'local'
        elif self.preferences.email_address:
            gravatar_args = {}
            if gravatar_default_url:
                gravatar_args['d'] = gravatar_default_url
            icon_url = g.gravatar(self.preferences.email_address, **gravatar_args)
            icon_source = 'gravatar'
        elif config.get('default_avatar_image'):
            icon_url = config['default_avatar_image']
            icon_source = 'default'

        if return_more:
            return icon_url, private_project, icon_source
        else:
            return icon_url
Example #38
0
def add_sentry_middleware(app, error_middleware=False):
    '''Add Sentry middleware no matter what

    In full stack mode, it wraps just before the ErrorMiddleware,
    else it wraps in the after_config hook.
    '''
    from tg import config as tgconf
    fullstack = asbool(tgconf.get('fullstack'))
    if error_middleware or not fullstack:
        try:
            if tgconf.get('sentry.dsn', None):  # pragma: no cover
                from raven.contrib.pylons import Sentry as SentryMiddleware
                app = SentryMiddleware(app, tgconf)
        except ImportError:  # pragma: no cover
            pass
    return app
Example #39
0
    def __init__(self):
        logger.info('Loading settings...')

        # postgresql://postgres:mypassword@localhost:5432/mydb
        m_session = re.search(r'://(\w+):(\w+)@(\w+)(:\d+)?/(\w+)',
                              unicode(config.get('sqlalchemy.url')))
        if m_session:
            self.user = m_session.group(1)
            self.password = m_session.group(2)
            self.host = m_session.group(3)
            self.port = m_session.group(4)
            self.db = m_session.group(5)
            self.pg_path = config.get('pg_path', '/usr/bin/')

        else:
            raise Exception('It was not possible to get connection data')
Example #40
0
    def writeSummary(self, flist, archiver):
        summary = etree.Element('resource', type='bisque_package')
        etree.SubElement(summary,
                         'tag',
                         name='origin',
                         value=config.get('bisque.root', request.host))
        etree.SubElement(summary, 'tag', name='version', value=__VERSION__)
        etree.SubElement(summary,
                         'tag',
                         name='datetime',
                         value=str(datetime.datetime.now()))

        index = 0
        for f in flist:
            log.debug('writeSummary: %s', f)
            if f.get('dataset') is None and f.get('path') is None:
                log.debug('writeSummary Adding: %s', f)
                v = etree.SubElement(summary,
                                     'value',
                                     index='%s' % index,
                                     type='object')
                v.text = f.get('outpath')
                index += 1

        flist.append(
            dict(name='.bisque.xml',
                 content=etree.tostring(summary),
                 outpath='.bisque.xml'))

        return flist
Example #41
0
 def prepare(self):
     super(ReleaseFilter, self).prepare()
     releases = []
     top_repo = os.path.join(config.get('git_repo_path'), self.package)
     pkgdb = get_connector('pkgdb')
     collections = pkgdb.get_collection_table(active_only=True)
     for id, collection in collections.iteritems():
         name = collection['name']
         ver = collection['version']
         label = "%s %s" % (name, ver)
         value = ""
         branchname = collection['branchname']
         if branchname:
             repo_path = os.path.join(top_repo, branchname)
             if not os.path.isdir(repo_path):
                 continue
             value = branchname
         if label != 'Fedora devel' and name in ('Fedora', 'Fedora EPEL'):
             releases.append({
                 'label': label,
                 'value': value,
                 'version': ver,
                 })
     self.releases_table = sorted(releases, reverse=True,
             cmp=lambda x, y: cmp(x['version'], y['version']))
     self.releases_table.insert(0, {'label': 'Rawhide', 'value': 'master'})
Example #42
0
    def director(self):
        """Return activitystream director"""
        if asbool(config.get('activitystream.recording.enabled', False)):
            return activitystream.director()
        else:

            class NullActivityStreamDirector(object):
                def connect(self, *a, **kw):
                    pass

                def disconnect(self, *a, **kw):
                    pass

                def is_connected(self, *a, **kw):
                    return False

                def create_activity(self, *a, **kw):
                    pass

                def create_timeline(self, *a, **kw):
                    pass

                def create_timelines(self, *a, **kw):
                    pass

                def get_timeline(self, *a, **kw):
                    return []

            return NullActivityStreamDirector()
Example #43
0
def patch_global_registration():
    global Registration
    use_sqlalchemy = config.get('use_sqlalchemy')
    if use_sqlalchemy:
        from .sqla_models import Registration
    else:
        from .ming_models import Registration
Example #44
0
 def overview(self, **kw):
     c.markdown_editor = W.markdown_editor
     c.metadata_admin = W.metadata_admin
     c.explain_export_modal = W.explain_export_modal
     show_export_control = asbool(config.get('show_export_control', False))
     allow_project_delete = asbool(config.get('allow_project_delete', True))
     explain_export_text = '''The purpose of this section is to determine whether your project is subject to the provisions of the
     US Export Administration Regulations. You should consult section 734.4 and Supplement 2 to Part 734 for information on such items
     and the calculation of U.S. controlled content.
     <a href="http://www.bis.doc.gov/encryption/default.htm" target="_blank">http://www.bis.doc.gov/encryption/default.htm</a>'''
     if 'us_export_contact' in config:
         explain_export_text += 'If you have additional questions, please contact <a href="mailto:{contact}">{contact}</a>.'.format(
             contact=config['us_export_contact'])
     return dict(show_export_control=show_export_control,
                 allow_project_delete=allow_project_delete,
                 explain_export_text=explain_export_text)
Example #45
0
 def fields(self):
     username = ew.TextField(name='username',
                             label='Desired Username',
                             validator=fev.Regex(h.re_project_name))
     username.validator._messages['invalid'] = (
         'Usernames must include only small letters, numbers, and dashes.'
         ' They must also start with a letter and be at least 3 characters'
         ' long.')
     fields = [
         ew.TextField(name='display_name',
                      label='Displayed Name',
                      validator=fev.UnicodeString(not_empty=True)),
         username,
     ]
     if asbool(config.get('auth.require_email_addr', False)):
         fields.append(
             ew.TextField(name='email',
                          label='Your e-mail',
                          validator=fev.Email(not_empty=True)))
     fields += [
         ew.PasswordField(
             name='pw',
             label='New Password',
             validator=fev.UnicodeString(
                 not_empty=True,
                 min=asint(tg.config.get('auth.min_password_len', 6)),
                 max=asint(tg.config.get('auth.max_password_len', 30)))),
         ew.PasswordField(name='pw2',
                          label='New Password (again)',
                          validator=fev.UnicodeString(not_empty=True)),
     ]
     return fields
Example #46
0
 def fields(self):
     username = ew.TextField(
         name='username',
         label='Desired Username',
         validator=plugin.AuthenticationProvider.get(None).username_validator(),
     )
     fields = [
         ew.TextField(
             name='display_name',
             label='Displayed Name',
             validator=V.UnicodeString(not_empty=True)),
         username,
     ]
     if asbool(config.get('auth.require_email_addr', False)):
         fields.append(ew.TextField(
             name='email',
             label='Your e-mail',
             validator=fev.Email(not_empty=True)))
     fields += [
         ew.PasswordField(
             name='pw',
             label='New Password',
             attrs=dict(minlength=asint(tg.config.get('auth.min_password_len', 6)), maxlength=asint(tg.config.get('auth.max_password_len', 30))),
             validator=V.UnicodeString(
                 not_empty=True,
                 min=asint(tg.config.get('auth.min_password_len', 6)),
                 max=asint(tg.config.get('auth.max_password_len', 30)))),
         ew.PasswordField(
             name='pw2',
             label='New Password (again)',
             validator=V.UnicodeString(not_empty=True)),
     ]
     return fields
Example #47
0
class MailFooter(object):
    view = jinja2.Environment(
        loader=jinja2.PackageLoader('allura', 'templates'),
        auto_reload=asbool(config.get('auto_reload_templates', True)),
    )

    @classmethod
    def _render(cls, template, **kw):
        return cls.view.get_template(template).render(kw)

    @classmethod
    def standard(cls, notification, allow_email_posting=True, **kw):
        return cls._render('mail/footer.txt',
                           domain=config['domain'],
                           notification=notification,
                           prefix=config['forgemail.url'],
                           allow_email_posting=allow_email_posting,
                           **kw)

    @classmethod
    def monitored(cls, toaddr, app_url, setting_url):
        return cls._render('mail/monitor_email_footer.txt',
                           domain=config['domain'],
                           email=toaddr,
                           app_url=app_url,
                           setting_url=setting_url)
Example #48
0
 def _rewrite(self, tag, attr):
     val = tag.get(attr)
     if val is None:
         return
     if ' ' in val:
         # Don't urllib.quote to avoid possible double-quoting
         # just make sure no spaces
         val = val.replace(' ', '%20')
         tag[attr] = val
     if '://' in val:
         for domain in re.split(r'\s*,\s*',
                                config.get('nofollow_exempt_domains', '')):
             if domain and domain in val:
                 return
         tag['rel'] = 'nofollow'
         return
     if val.startswith('/'):
         return
     if val.startswith('.'):
         return
     if val.startswith('mailto:'):
         return
     if val.startswith('#'):
         return
     tag[attr] = '../' + val
Example #49
0
    def prepare(self):
        super(ReleaseFilter, self).prepare()
        releases = []
        top_repo = os.path.join(config.get('git_repo_path'), self.package)
        bodhi = get_connector('bodhi')

        for collection in bodhi.get_all_releases():
            if collection['state'] != 'current':
                continue
            name = collection['id_prefix']
            ver = collection['version']
            label = collection['long_name']
            value = ""
            branchname = collection['branch']
            if branchname:
                repo_path = os.path.join(top_repo, branchname)
                if not os.path.isdir(repo_path):
                    continue
                value = branchname
            if label != 'Fedora devel' and name in ('FEDORA', 'FEDORA-EPEL'):
                releases.append({
                    'label': label,
                    'value': value,
                    'version': ver,
                    })
        self.releases_table = sorted(releases, reverse=True,
                cmp=lambda x, y: cmp(x['version'], y['version']))
        self.releases_table.insert(0, {'label': 'Rawhide', 'value': 'master'})
Example #50
0
 def __init__(self):
     if not asbool(config.get('moksha.metrics_stream', False)):
         log.info('Moksha Metrics Stream disabled')
         return
     self.programs = self._find_programs()
     self.processors = self._find_processors()
     super(MokshaMetricsDataStream, self).__init__()
Example #51
0
 def get(cls):
     '''
     :rtype: RecoveryCodeService
     '''
     method = config.get('auth.multifactor.recovery_code.service',
                         'mongodb')
     return g.entry_points['multifactor_recovery_code'][method]()
Example #52
0
    def complete_registration(cls, registration):
        # Force resolution of lazy property
        registration.activation_link
        registration_config = config.get('_pluggable_registration_config')
        mail_body = registration_config.get(
            'mail_body',
            _('Please click on this link to confirm your registration'))
        if '%(activation_link)s' not in mail_body:
            mail_body += '\n \n %(activation_link)s'

        email_data = {
            'sender':
            config['registration.email_sender'],
            'subject':
            registration_config.get('mail_subject',
                                    _('Please confirm your registration')),
            'body':
            mail_body,
            'rich':
            registration_config.get('mail_rich', '')
        }

        hooks.notify('registration.on_complete', (registration, email_data))

        email_data['body'] = email_data['body'] % registration.dictified
        email_data['rich'] = email_data['rich'] % registration.dictified

        send_email(registration.email_address, **email_data)
        return email_data
Example #53
0
 def oauth_callback(self, **kw):
     client_id = config.get('github_importer.client_id')
     secret = config.get('github_importer.client_secret')
     if not client_id or not secret:
         return  # GitHub app is not configured
     oauth = OAuth2Session(
         client_id, state=session.get('github.oauth.state'))
     token = oauth.fetch_token(
         'https://github.com/login/oauth/access_token',
         client_secret=secret,
         authorization_response=request.url
     )
     c.user.set_tool_data('GitHubProjectImport',
                          token=token['access_token'])
     self.oauth_callback_complete()
     redirect(session.get('github.oauth.redirect', '/'))
Example #54
0
def main(options):
    log.addHandler(logging.StreamHandler(sys.stdout))
    log.setLevel(getattr(logging, options.log_level.upper()))
    log.debug(options)

    nbhd = M.Neighborhood.query.get(name=options.neighborhood)
    if not nbhd:
        return 'Invalid neighborhood "%s".' % options.neighborhood
    admin = M.User.query.get(
        username=config.get('sfx.api.siteadmin', 'sf-robot'))

    data = json.load(open(options.file, 'r'))
    project = Project()
    project.add(
        col.SchemaNode(col.Sequence(),
                       col.SchemaNode(Award(nbhd)),
                       name='awards',
                       missing=[]))
    schema = col.SchemaNode(col.Sequence(), project, name='project')
    projects = schema.deserialize(data)
    log.debug(projects)

    chunks = [projects[i::options.nprocs] for i in range(options.nprocs)]
    jobs = []
    for i in range(options.nprocs):
        p = multiprocessing.Process(target=create_projects,
                                    args=(chunks[i], nbhd, admin, options),
                                    name='worker-' + str(i + 1))
        jobs.append(p)
        p.start()

    for j in jobs:
        j.join()
        if j.exitcode <> 0: return j.exitcode
    return 0
Example #55
0
 def checkout_url(self):
     return dict(
         app=self.app,
         merge_allowed=not asbool(
             config.get('scm.merge.{}.disabled'.format(
                 self.app.config.tool_name))),
     )
Example #56
0
 def email_address(self):
     if self.config.options.get('AllowEmailPosting', True):
         domain = self.email_domain
         return '%s@%s%s' % (self.title.replace(
             '/', '.'), domain, config.common_suffix)
     else:
         return tg_config.get('forgemail.return_path')
Example #57
0
class SiteNotification(MappedClass):
    """
    Storage for site-wide notification.
    """
    class __mongometa__:
        session = main_orm_session
        name = str('site_notification')
        indexes = [
            ('active', '_id'),
        ]

    _id = FieldProperty(S.ObjectId)
    content = FieldProperty(str, if_missing='')
    active = FieldProperty(bool, if_missing=True)
    impressions = FieldProperty(
        int, if_missing=lambda: config.get('site_notification.impressions', 0))
    user_role = FieldProperty(str, if_missing=None)
    page_regex = FieldProperty(str, if_missing=None)
    page_tool_type = FieldProperty(str, if_missing=None)

    def __json__(self):
        return dict(
            _id=str(self._id),
            content=self.content,
            active=self.active,
            impressions=self.impressions,
            user_role=self.user_role if self.user_role else '',
            page_regex=self.page_regex if self.page_regex else '',
            page_tool_type=self.page_tool_type if self.page_tool_type else '')

    @classmethod
    def actives(cls):
        return cls.query.find({'active': True}).sort('_id', -1).all()
Example #58
0
 def oauth_begin(self, scope=None):
     client_id = config.get('github_importer.client_id')
     secret = config.get('github_importer.client_secret')
     if not client_id or not secret:
         return  # GitHub app is not configured
     if c.user.get_tool_data('GitHubProjectImport', 'token'):
         return  # token already exists, nothing to do
     redirect_uri = request.url.rstrip('/') + '/oauth_callback'
     oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scope)
     auth_url, state = oauth.authorization_url(
         'https://github.com/login/oauth/authorize')
     # Used in callback to prevent CSRF
     session['github.oauth.state'] = state
     session['github.oauth.redirect'] = request.url
     session.save()
     redirect(auth_url)
Example #59
0
 def email_address(self):
     if c.app.config.options.get('AllowEmailPosting', True):
         domain = self.email_domain
         local_part = self.shortname.replace('/', '.')
         return '%s@%s%s' % (local_part, domain, config.common_suffix)
     else:
         return tg_config.get('forgemail.return_path')
Example #60
0
def add_global_template_variables():
    return dict(today=JalaliDate.today().strftime('%A %d %B %Y'),
                session=session,
                base_url=config.get('base_url'),
                pictures=DBSession.query(Picture).all(),
                categories=DBSession.query(Category).options(
                    joinedload('subcategory')).all())