예제 #1
0
파일: iplist.py 프로젝트: spot5418/CDS
    def __init__(self):
        self.whitelist = []
        self.blacklist = []
        self.unusedIP = []
        self.tracklist = []

        # white list
        local_db = database.DB("local")
        local_db.Execute("SET NAMES 'utf8'")
        results = local_db.Select("select * from whitelist;")
        for result in results:
            self.whitelist.append(result[0])
        # black list
        local_db.Execute("delete from blacklist where last_updated < " \
                         "ADDDATE(NOW(), INTERVAL -7 DAY)")
        results = local_db.Select("select * from blacklist;")
        for result in results:
            self.blacklist.append(result[0])
        # unused IP list
        results = local_db.Select("select * from unusedIP;")
        for result in results:
            self.unusedIP.append(result[0])
        # track list
        #local_db.Execute("delete from tracklist where last_updated < " \
        #                 " ADDDATE(NOW(), INTERVAL -1 HOUR)")
        #results = local_db.Select("select * from tracklist;")
        #for result in results:
        #    self.tracklist.append(result[0])

        local_db.CloseDB()
예제 #2
0
def HandlerSensor(serial1, temp, humi):
    db = database.DB(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB)
    trave = ""
    stype = serial1[0:3]
    dvid = db.GetDeviceIdFromSerial(serial1)
    if (stype == "THS"):
        db.UpdateTempValue(serial1, temp)
        db.UpdateHumiValue(serial1, humi)
        if (db.CheckHumiInRange(serial1, humi)
                or db.CheckTempInRange(serial1, temp)):
            if (db.GetSetting('alert')):
                warning_content = db.GetDeviceNameFromId(
                    dvid) + '\nNhiet do: ' + temp + db.RangeTempToString(
                        serial1) + '\nDo am: ' + humi + db.RangeHumiToString(
                            serial1)
                db.UpdateWarningLog(dvid, warning_content)
            if (db.GetSetting('sms') and not (db.GetSetting('bell'))):
                db.SetSetting('sms_pending', 1)
            if (db.GetSetting('email') and not (db.GetSetting('bell'))):
                db.SetSetting('email_pending', 1)
            if (db.GetSetting('ring')):
                db.SetSetting('bell', 1)
            trave = "alert>ON&&"
        else:
            trave = "alert>OFF&&"
    db.CloseDb()
    return trave
예제 #3
0
    def __init__(self, db=None, ctx=None, txn=None):
        # it can cause circular imports if this is at the top level of the module
        import database
        db = db or database.DB()

        self._db = db
        self._ctx = ctx
        self._txn = txn
예제 #4
0
파일: rule.py 프로젝트: spot5418/CDS
 def getRulesFromDB(self):
     local_db = database.DB("local")
     rules = local_db.Select("select * from rules;")
     for rule in rules:
         self.rules["".join(rule[4:8])] = \
             {"event":rule[1],"threshold":rule[2], "suprathreshold":rule[3]}
     local_db.CloseDB()
     return self.rules
예제 #5
0
파일: tracklist.py 프로젝트: spot5418/CDS
 def cleanTrackList(self):
     """
     Clean all cache in TrackList
     """
     local_db = database.DB("local")
     local_db.Execute("SET NAMES 'utf8'")
     sql = "truncate table tracklist;"
     local_db.Execute(sql)
예제 #6
0
def login(username, password):

    if username == None or password == None:
        return False

    db = database.DB()

    return db.login(username, password)
예제 #7
0
 def UpdateIndicator(self):
     db = database.DB("localhost", "root", "!()(!(*(", "hbiot")
     al = db.GetSetting('alert')
     sm = db.GetSetting('sms')
     ri = db.GetSetting('ring')
     self.SetLed(self.alert_led, al)
     self.SetLed(self.sms_led, sm)
     self.SetLed(self.ring_led, ri)
     db.CloseDb()
예제 #8
0
 def UpdateSms(self, chanel):
     db = database.DB("localhost", "root", "!()(!(*(", "hbiot")
     if (db.GetSetting('sms')):
         db.SetSetting('sms', 0)
         self.SetLed(self.sms_led, db.GetSetting('sms'))
     else:
         db.SetSetting('sms', 1)
         self.SetLed(self.sms_led, db.GetSetting('sms'))
     db.CloseDb()
예제 #9
0
 def __init__(self, title):
     super().__init__()
     self.db = database.DB()
     
     self.set_main_window(title)
     self.menu = self.create_menu()
     self.tv = self.create_treeview()
     self.tv.bind("<Button-3>", self.create_context_menu)
     self.tv.bind("<Button-1>", self.left_button_click)