Example #1
0
    def __init__(self):

        # SQLAlchemy connect
        self.dbsession = orm.create_session()

        site_handlers = get_handlers()
        tornado.web.Application.__init__(self, site_handlers, **tornado_settings)
Example #2
0
def start_filesysmail():

    dbsession = orm.create_session()
    db = dbsession()

    fm = FileSysMail.get_instance()

    smtp_server = SiteConfig.get(
        db, 'notice.smtp.server', '127.0.0.1')
    smtp_port = int(SiteConfig.get(
            db, 'notice.smtp.port', 25 ))
    smtp_username = SiteConfig.get(
        db, 'notice.smtp.username', None)
    smtp_password = SiteConfig.get(
        db, 'notice.smtp.password', None)

    mail_dir = SiteConfig.get(
        db, 'site.send_mail.dir', '/opt/LuoYun/run/email/')

    print 'smtp_server   = ', smtp_server
    print 'smtp_port     = ', smtp_port
    print 'smtp_username = '******'smtp_password = ', smtp_password

    fm.init( smtp_server, smtp_username, smtp_password,
             smtp_port = smtp_port, store_path = mail_dir )

    fm.start()

    dbsession.remove()
Example #3
0
def start_filesysmail():

    dbsession = orm.create_session()
    db = dbsession()

    fm = FileSysMail.get_instance()

    smtp_server = SiteConfig.get(db, 'notice.smtp.server', '127.0.0.1')
    smtp_port = int(SiteConfig.get(db, 'notice.smtp.port', 25))
    smtp_username = SiteConfig.get(db, 'notice.smtp.username', None)
    smtp_password = SiteConfig.get(db, 'notice.smtp.password', None)

    mail_dir = SiteConfig.get(db, 'site.send_mail.dir',
                              '/opt/LuoYun/run/email/')

    dbsession.remove()

    print 'smtp_server   = ', smtp_server
    print 'smtp_port     = ', smtp_port
    print 'smtp_username = '******'smtp_password = '******'mail_dir      = ', mail_dir

    if fm.init(smtp_server,
               smtp_username,
               smtp_password,
               smtp_port=smtp_port,
               store_path=mail_dir):
        logging.info('FileSysMail init success.')
        fm.start()
        return True

    else:
        logging.error('FileSysMail init failed.')
        return False
Example #4
0
    def __init__(self):

        # SQLAlchemy connect
        self.dbsession = orm.create_session()

        site_handlers = get_handlers()
        tornado.web.Application.__init__(self, site_handlers,
                                         **tornado_settings)
Example #5
0
def mailto_address(data):

    data = data.get('msg', {})
    #    logging.debug('mailto_address: data = %s' % data)

    dbsession = orm.create_session()
    db = dbsession()

    to = data.get('to', None)
    to_user_id = data.get('to_user_id', None)
    subject = data.get('subject', None)
    body = data.get('body', None)
    adr_from = SiteConfig.get(db, 'notice.smtp.fromaddr', 'admin@localhost')

    if not (to or to_user_id):
        logging.error(_('mailto_address: no address find'))
        return

    mail_total = SiteConfig.get(db, 'site.send_mail.total', 0)
    if not mail_total:
        SiteConfig.set(db, 'site.send_mail.total', 0)

    mail_total = db.query(SiteConfig).filter_by(
        key='site.send_mail.total').first()

    fm = FileSysMail.get_instance()

    if to:
        username = to.split('@')[0]

    if to_user_id:
        U = db.query(User).get(to_user_id)
        if U:
            username = U.nickname if U.nickname else U.username
            to = U.email
            if not to:
                logging.error(
                    _('mailto_address: %s(%s) have not email address') %
                    (username, U.id))
                return

    d = {'subject': subject, 'BODY_HTML': body, 'username': username}

    body = render_template('custom/mail_template.html', **d)

    if body:
        e = Email(subject=subject,
                  text=body,
                  adr_to=to,
                  adr_from=adr_from,
                  mime_type='html')

        mail_total.value = int(mail_total.value) + 1
        fm.send(e, '%s-mail' % mail_total.value)

    else:
        logging.error(_('render email body for html failed.'))
Example #6
0
def mailto_address( data ):

    data = data.get('msg', {})
#    logging.debug('mailto_address: data = %s' % data)

    dbsession = orm.create_session()
    db = dbsession()

    to = data.get('to', None)
    to_user_id = data.get('to_user_id', None)
    subject = data.get('subject', None)
    body = data.get('body', None)
    adr_from = SiteConfig.get(
        db, 'notice.smtp.fromaddr', 'admin@localhost')

    if not (to or to_user_id):
        logging.error( _('mailto_address: no address find') )
        return

    mail_total = SiteConfig.get( db, 'site.send_mail.total', 0 )
    if not mail_total:
        SiteConfig.set(db, 'site.send_mail.total', 0)

    mail_total = db.query(SiteConfig).filter_by(
        key = 'site.send_mail.total').first()

    fm = FileSysMail.get_instance()

    if to:
        username = to.split('@')[0]

    if to_user_id:
        U = db.query(User).get( to_user_id )
        if U:
            username = U.nickname if U.nickname else U.username
            to = U.email
            if not to:
                logging.error( _('mailto_address: %s(%s) have not email address') % (username, U.id) )
                return


    d = { 'subject': subject, 'BODY_HTML': body,
          'username': username }

    body = render_template('custom/mail_template.html', **d)

    if body:
        e = Email( subject = subject, text = body,
                   adr_to = to,
                   adr_from = adr_from, mime_type = 'html' )

        mail_total.value = int(mail_total.value) + 1
        fm.send( e, '%s-mail' % mail_total.value )

    else:
        logging.error( _('render email body for html failed.') )
Example #7
0
    def __init__(self):

        # SQLAlchemy connect
        self.dbsession = orm.create_session()

        # TODO: TEST db connect

        site_handlers = get_handlers()
        self.init_runtime_data()

        tornado.web.Application.__init__(
            self, site_handlers, **tornado_settings )
Example #8
0
def get_site_config(key, default_value=None):

    dbsession = runtime_data.get('dbsession')
    if not dbsession:
        dbsession = orm.create_session()
        runtime_data['dbsession'] = dbsession

    db = dbsession()
    v = SiteConfig.get(db, key, default_value)

    dbsession.remove()

    return v
Example #9
0
def start_filesysmail():

    dbsession = orm.create_session()
    db = dbsession()

    fm = FileSysMail.get_instance()

    smtp_server = SiteConfig.get(
        db, 'notice.smtp.server', '127.0.0.1')
    smtp_port = int(SiteConfig.get(
            db, 'notice.smtp.port', 25 ))
    smtp_username = SiteConfig.get(
        db, 'notice.smtp.username', None)
    smtp_password = SiteConfig.get(
        db, 'notice.smtp.password', None)

    mail_dir = SiteConfig.get(
        db, 'site.send_mail.dir', '/opt/LuoYun/run/email/')

    dbsession.remove()

    print 'smtp_server   = ', smtp_server
    print 'smtp_port     = ', smtp_port
    print 'smtp_username = '******'smtp_password = '******'mail_dir      = ', mail_dir

    if fm.init( smtp_server, smtp_username, smtp_password,
                smtp_port = smtp_port, store_path = mail_dir ):
        logging.info('FileSysMail init success.')
        fm.start()
        return True

    else:
        logging.error('FileSysMail init failed.')
        return False
Example #10
0
import gettext
# TODO: i18n
import __builtin__
__builtin__.__dict__['_'] = lambda s: s

for m in settings.app:
    try:
        exec "from %s.models import *" % m
    except ImportError:
        pass
    except Exception, e:
        logging.error('from %s import table failed: %s' % (m, e))


from yweb.orm import create_session
dbsession = create_session()
db = dbsession()

from app.network.models import NetworkPool, IPPool
from IPy import IP


def add_to_ippool(N):

    start, end = IP( N.start ), IP( N.end )
    exclude_ips = N.exclude_ips

    NETWORK = '%s/%s' % (N.start, N.netmask)
    for x in IP(NETWORK, make_net=True):
        cur_ip = IP(x)
        if cur_ip > end:
Example #11
0
sys.path.insert(0, os.path.join(PROJECT_ROOT, '../'))
sys.path.insert(0, os.path.join(PROJECT_ROOT, '../lib'))
sys.path.insert(0, '/opt/LuoYun/web/')

# TODO: i18n is too ugly yet
import __builtin__
__builtin__.__dict__['_'] = lambda s: s

import logging
from threading import Thread

from app.auth.models import User
from app.site.models import SiteJob, SiteConfig
from yweb import orm

dbsession = orm.create_session()
db = dbsession()

from yweb.quemail import QueMail, Email


def init_quemail():

    qm = QueMail.get_instance()

    smtp_server = SiteConfig.get(db, 'notice.smtp.server', '127.0.0.1')
    smtp_port = int(SiteConfig.get(db, 'notice.smtp.port', 25))
    smtp_username = SiteConfig.get(db, 'notice.smtp.username', None)
    smtp_password = SiteConfig.get(db, 'notice.smtp.password', None)

    print 'smtp_server   = ', smtp_server
# TODO: i18n
import __builtin__

__builtin__.__dict__['_'] = lambda s: s

for m in settings.app:
    try:
        exec "from %s.models import *" % m
    except ImportError:
        pass
    except Exception, e:
        logging.error('from %s import table failed: %s' % (m, e))

from yweb.orm import create_session

dbsession = create_session()
db = dbsession()

from app.network.models import NetworkPool, IPPool
from IPy import IP


def add_to_ippool(N):

    start, end = IP(N.start), IP(N.end)
    exclude_ips = N.exclude_ips

    NETWORK = '%s/%s' % (N.start, N.netmask)
    for x in IP(NETWORK, make_net=True):
        cur_ip = IP(x)
        if cur_ip > end:
Example #13
0
def mailto_user_list( data ):

    data = data.get('msg', {})
#    logging.debug('mailto_user_list: data = %s' % data)

    dbsession = orm.create_session()
    db = dbsession()

    UID_LIST = data.get('ID_LIST', [])
    uid = data.get('uid', None)
    subject = data.get('subject', None)
    body = data.get('body', None)
    adr_from = SiteConfig.get(
        db, 'notice.smtp.fromaddr', 'admin@localhost')

    job = SiteJob( uid, _('send mail to user list.') )
    job.set_started()
    db.add( job )
    db.commit()

    if UID_LIST:
        USER_LIST = []
        for ID in UID_LIST:
            U = db.query(User).get( ID )
            if U:
                USER_LIST.append( U )
    else:
        USER_LIST = db.query(User)

    mail_total = SiteConfig.get( db, 'site.send_mail.total', 0 )
    if not mail_total:
        SiteConfig.set(db, 'site.send_mail.total', 0)

    mail_total = db.query(SiteConfig).filter_by(
        key = 'site.send_mail.total').first()

    fm = FileSysMail.get_instance()

    for U in USER_LIST:

        text = _('send mail to %s: %s (%s)') % (U.id, U.username, U.email)

        logging.debug( text )

        job.update_status( text )
        db.commit()

#        time.sleep(1)

        if not (U and U.email and U.email_valid):
            continue

        d = { 'subject': subject, 'BODY_HTML': body,
              'username': U.nickname if U.nickname else U.username }

        body_html = render_template('custom/mail_template.html', **d)

        if body_html:

            e = Email( subject = subject, text = body_html,
                       adr_to = U.email,
                       adr_from = adr_from, mime_type = 'html' )

            mail_total.value = int(mail_total.value) + 1
            fm.send( e, '%s-mail' % mail_total.value )

        else:
            logging.error( _('render email body for html failed.') )

    job.set_ended()
    db.commit()
    dbsession.remove()
Example #14
0
sys.path.insert(0, os.path.join(PROJECT_ROOT, '../lib'))
sys.path.insert(0, '/opt/LuoYun/web/')

# TODO: i18n is too ugly yet
import __builtin__
__builtin__.__dict__['_'] = lambda s: s


import logging
from threading import Thread

from app.auth.models import User
from app.site.models import SiteJob, SiteConfig
from yweb import orm

dbsession = orm.create_session()
db = dbsession()

from yweb.quemail import QueMail, Email

def init_quemail():

    qm = QueMail.get_instance()

    smtp_server = SiteConfig.get(
        db, 'notice.smtp.server', '127.0.0.1')
    smtp_port = int(SiteConfig.get(
            db, 'notice.smtp.port', 25 ))
    smtp_username = SiteConfig.get(
        db, 'notice.smtp.username', None)
    smtp_password = SiteConfig.get(
Example #15
0
def mailto_user_list(data):

    data = data.get('msg', {})
    #    logging.debug('mailto_user_list: data = %s' % data)

    dbsession = orm.create_session()
    db = dbsession()

    UID_LIST = data.get('ID_LIST', [])
    uid = data.get('uid', None)
    subject = data.get('subject', None)
    body = data.get('body', None)
    adr_from = SiteConfig.get(db, 'notice.smtp.fromaddr', 'admin@localhost')

    job = SiteJob(uid, _('send mail to user list.'))
    job.set_started()
    db.add(job)
    db.commit()

    if UID_LIST:
        USER_LIST = []
        for ID in UID_LIST:
            U = db.query(User).get(ID)
            if U:
                USER_LIST.append(U)
    else:
        USER_LIST = db.query(User)

    mail_total = SiteConfig.get(db, 'site.send_mail.total', 0)
    if not mail_total:
        SiteConfig.set(db, 'site.send_mail.total', 0)

    mail_total = db.query(SiteConfig).filter_by(
        key='site.send_mail.total').first()

    fm = FileSysMail.get_instance()

    for U in USER_LIST:

        text = _('send mail to %s: %s (%s)') % (U.id, U.username, U.email)

        logging.debug(text)

        job.update_status(text)
        db.commit()

        #        time.sleep(1)

        if not (U and U.email and U.email_valid):
            continue

        d = {
            'subject': subject,
            'BODY_HTML': body,
            'username': U.nickname if U.nickname else U.username
        }

        body_html = render_template('custom/mail_template.html', **d)

        if body_html:

            e = Email(subject=subject,
                      text=body_html,
                      adr_to=U.email,
                      adr_from=adr_from,
                      mime_type='html')

            mail_total.value = int(mail_total.value) + 1
            fm.send(e, '%s-mail' % mail_total.value)

        else:
            logging.error(_('render email body for html failed.'))

    job.set_ended()
    db.commit()
    dbsession.remove()