Ejemplo n.º 1
0
    def negative_word(self):
        negative_word = self.session.query(NegativeWord.word).first()
        if not negative_word:
            LOG.error("get negative word failed.")
            return None

        return negative_word.word
Ejemplo n.º 2
0
    def user_get(self, username):
        user = self.session.query(
            User.name, User.monitor_keyword).filter_by(name=username).first()
        if not user:
            LOG.error("username %s not exist." % (username))
            return None

        return user
Ejemplo n.º 3
0
    def user_email(self, username):
        result = self.session.query(
            User.email).filter_by(name=username).first()
        if not result:
            LOG.error("user %s do not setting email" % (username))
            return None

        return result.email
Ejemplo n.º 4
0
    def add_result(self,user_name,url,source_url,keyword):
        user_id=self.session.query(User.id).filter_by(name=user_name).first()
        if not user_id:
            LOG.error("user_name: %s not found in db"%(user_name))
            return

        self.session.add(Result(user_id=user_id.id,url=url,
                            source_url=source_url,keyword=keyword,
                            datetime=datetime.datetime.now()))
        self.session.commit()
Ejemplo n.º 5
0
    def add_user(self, username):
        if len(self.se_mgr.stats_get()) == 0:
            LOG.info("not search engine.")
            return

        if self.se_mgr.user_exist(username):
            return

        se_key = self.filter.select(self.se_mgr.stats_get())
        if not se_key:
            LOG.error("filter do not select useful search engine for user:%s" %
                      (username))
            return

        self.se_mgr.add_user(se_key, username)
Ejemplo n.º 6
0
    def user_update(self, username, password, email, mobile_phone, permission,
                    company, monitor_keyword):
        user = self.session.query(User).filter_by(name=username).first()
        if not user:
            LOG.error("user %s not exist" % (username))
            return False

        user.password = password
        user.email = email
        user.mobile_phone = mobile_phone
        user.permission = permission
        user.company = company
        user.monitor_keyword = monitor_keyword
        self.session.commit()

        return True
Ejemplo n.º 7
0
    def user_add(self, username, password, email, mobile_phone, permission,
                 company, monitor_keyword):
        user_id = self.session.query(User.id).filter_by(name=username).first()
        if user_id:
            LOG.error("user %s already exist." % (username))
            return False

        self.session.add(
            User(name=username,
                 password=password,
                 email=email,
                 mobile_phone=mobile_phone,
                 permission=permission,
                 company=company,
                 monitor_keyword=monitor_keyword))
        self.session.commit()

        return True
Ejemplo n.º 8
0
    def _send_user_info(self, key, username_list):
        negative_word = self.db.negative_word()
        if not negative_word:
            LOG.error("no negative word. so no need dispatch user.")
            return

        user_info_list = []
        for username in username_list:
            user_info = self.db.user_get(username)
            if not user_info:
                continue

            user_info_list.append({
                sec.USERNAME: user_info.name,
                sec.KEYWORD: user_info.monitor_keyword,
                sec.NEGATIVE_WORD: negative_word.split(',')
            })

        self.mq.send_user_info(key, user_info_list)
Ejemplo n.º 9
0
    def _build_msg(self, report, sendto, sendfrom, report_format):
        try:
            f = open(report, 'rb')
        except IOError as e:
            LOG.error("open report %s failed. except:%s" % (report, e))
            return None

        msg = MIMEMultipart()
        attach = MIMEText(f.read(), 'base64', 'utf-8')
        attach['Content-Type'] = 'application/octet-stream'
        attach['Content-Disposition'] = 'attachment; filename="报告.%s"' % (
            report_format)
        msg.attach(attach)

        msg['to'] = sendto
        msg['from'] = sendfrom
        msg['subject'] = '报告'

        return msg
Ejemplo n.º 10
0
    def _gen_result(self,username,result_list):
        self.ready(username)
        for result in result_list:
            self.add(result)
        file_name=self.finish(username)
        
        user_email=self.db.user_email(username)
        if not user_email:
            LOG.error("username %s get email failed."%(username))
            os.unlink(file_name)
            return False

        if not self.notify.send(file_name,self.format(),user_email):
            LOG.error("username %s send email failed."%(username))
            os.unlink(file_name)
            return False 
       
        os.unlink(file_name)
        
        return True
Ejemplo n.º 11
0
    def send(self, report, report_format, sendto):
        setting = self.db.global_setting()
        if not setting:
            LOG.error('email not set')
            return False

        msg = self._build_msg(report, sendto, setting.email, report_format)
        if not msg:
            return False

        try:
            smtp = smtplib.SMTP()
            smtp.connect(setting.smtp_server, setting.smtp_port)
            smtp.login(setting.smtp_username, setting.smtp_password)
            smtp.sendmail(setting.email, sendto, msg.as_string())
            smtp.close()

            return True

        except Exception as e:
            LOG.error("send mail to %s failed. exception: %s" % (sendto, e))
            return False