Example #1
0
 def setAccessCode(self, code):
     """Set twitter access code to get user key and secret
        @param code: code provided by twitter """
     if code and len(code)>0:
         try:
             if not self.__auth:
                 self.__auth = tweepy.OAuthHandler(self.consumerKey, self.consumerSecret)
                 self.__auth.secure = True
             #get token
             token = self.__auth.get_access_token(code)
             #save token internally
             self.key = token.key
             self.secret = token.secret
             #save token in config file
             if agoclient.set_config_option('twitter', 'key', self.key, 'alert') and agoclient.set_config_option('twitter', 'secret', self.secret, 'alert'):
                 self.__configured = True
                 client.emit_event('alertcontroller', "event.device.statechanged", STATE_TWITTER_CONFIGURED, "")
                 return {'error':0, 'msg':''}
             else:
                 return {'error':0, 'msg':'Unable to save Twitter token in config file.'}
         except Exception as e:
             logging.error('Twitter: config exception [%s]' % str(e))
             return {'error':1, 'msg':'Internal error'}
     else:
         logging.error('Twitter: code is mandatory')
         return {'error':1, 'msg':'Internal error'}
Example #2
0
 def setConfig(self, smtp, sender, login, password, tls):
     """set config
        @param smtp: smtp server address
        @param sender: mail sender""" 
     if not smtp or len(smtp)==0 or not sender or len(sender)==0:
         logging.error('Mail: all parameters are mandatory')
         return False
     if not agoclient.set_config_option('mail', 'smtp', smtp, 'alert') or not agoclient.set_config_option('mail', 'sender', sender, 'alert') or not agoclient.set_config_option('mail', 'login', login, 'alert') or not agoclient.set_config_option('mail', 'password', password, 'alert') or not agoclient.set_config_option('mail', 'tls', tls, 'alert'):
         logging.error('Mail: unable to save config')
         return False
     self.smtp = smtp
     self.sender = sender
     self.login = login
     self.password = password
     self.tls = False
     if tls=='1':
         self.tls = True
     self.__configured = True
     client.emit_event('alertcontroller', "event.device.statechanged", STATE_MAIL_CONFIGURED, "")
     return True
Example #3
0
 def setConfig(self, apikeys):
     """set config
        @param apikey: notifymyandroid apikey (available on https://www.notifymyandroid.com/account.jsp)"""
     if not apikeys or len(apikeys)==0:
         logging.error('Notifymyandroid: all parameters are mandatory')
         return False
     if not agoclient.set_config_option('push','provider','notifymyandroid','alert') or not agoclient.set_config_option('notifymyandroid', 'apikeys', json.dumps(apikeys) , 'alert'):
         logging.error('Notifymyandroid: unable to save config')
         return False
     self.apikeys = apikeys
     self.__configured = True
     client.emit_event('alertcontroller', "event.device.statechanged", STATE_PUSH_CONFIGURED, "")
     return True
Example #4
0
 def setConfig(self, userid):
     """set config
        @param userid: pushover userid (available on https://pushover.net/dashboard)"""
     if not userid or len(userid)==0:
         logging.error('Pushover: all parameters are mandatory')
         return False
     if not agoclient.set_config_option('push','provider','pushover','alert') or not agoclient.set_config_option('pushover', 'userid', userid, 'alert'):
         logging.error('Pushover: unable to save config')
         return False
     self.userid = userid
     self.__configured = True
     client.emit_event('alertcontroller', "event.device.statechanged", STATE_PUSH_CONFIGURED, "")
     return True
Example #5
0
 def setConfig(self, username, password):
     """Set config
        @param username: 12voip username
        @param password: 12voip password"""
     if not username or len(username)==0 or not password or len(password)==0:
         logging.error('SMS12voip: invalid parameters')
         return False
     if not agoclient.set_config_option('12voip', 'username', username, 'alert') or not agoclient.set_config_option('12voip', 'password', password, 'alert'):
         logging.error('SMS12voip: unable to save config')
         return False
     self.username = username
     self.password = password
     self.__configured = True
     client.emit_event('alertcontroller', "event.device.statechanged", STATE_SMS_NOT_CONFIGURED, "")
     return True
Example #6
0
 def setConfig(self, username, password):
     """set gtalk config
        @param username: must be your google username (ending with @gmail.com)
        @param password: your password or 2-step verification token
        @info generate token here : https://www.google.com/settings/security""" 
     if not username or len(username)==0 or not password or len(password)==0:
         logging.error('GTalk: Unable to add SMS because all parameters are mandatory')
         return False
     if not agoclient.set_config_option('gtalk', 'username', username, 'alert') or not agoclient.set_config_option('gtalk', 'password', password, 'alert'):
         logging.error('GTalk: unable to save config')
         return False
     self.username = username
     self.password = password
     self.__configured = True
     client.emit_event('alertcontroller', "event.device.statechanged", STATE_GTALK_CONFIGURED, "")
     return True
Example #7
0
 def setConfig(self, apikey, devices):
     """set config
        @param apikey: pushbullet apikey (available on https://www.pushbullet.com/account)
        @param devices: array of devices (id) to send notifications """
     if not apikey or len(apikey)==0 or not devices or len(devices)==0:
         logging.error('Pushbullet: all parameters are mandatory')
         return False
     if not agoclient.set_config_option('push', 'provider', 'pushbullet','alert') or not agoclient.set_config_option('pushbullet', 'apikey', apikey, 'alert') or not agoclient.set_config_option('pushbullet', 'devices', json.dumps(devices), 'alert'):
         logging.error('Pushbullet: unable to save config')
         return False
     self.apikey = apikey
     self.devices = devices
     self.pbdevices = {}
     self.pushbullet = PushBullet(self.apikey)
     self.__configured = True
     client.emit_event('alertcontroller', "event.device.statechanged", STATE_PUSH_CONFIGURED, "")
     return True
Example #8
0
def saveSchedules():
    """save schedules to config file"""
    global allSchedules
    if not agoclient.set_config_option('agoscheduler', 'all', json.dumps(allSchedules.get_values(itemgetter(1)))):
        logging.exception('Unable to load config file')