コード例 #1
0
ファイル: auth.py プロジェクト: pepijnd1/pushbullet510s
    def do_GET(self):
        if self.path == '/auth':
            self.send_response(302)
            self.send_header('Location', auth_redirect.format(settings.read('apiaccess', 'client_id'), 
                                                              settings.read('apiaccess', 'redirect_uri')))
            self.end_headers()

        if self.path == '/auth-action':
            response = self.template.servepage('authpage.html')
            self.send_response(200)
            self.end_headers()
            self.wfile.write(response)

        if self.path.split('?', 1)[0] == '/auth-token':
            self.send_response(200)
            self.end_headers()
            tokendata = self.path.split('?', 1)[1]
            tokendata = tokendata.split('=', 1)
            if tokendata[0] != 'access_token':
                raise Exception('invalid token')
            else:
                token = tokendata[1]
                if self.ontokenget:
                    self.ontokenget(token)
        else:
            return
コード例 #2
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
 def decrypt(self):
     password = settings.read('api', 'password')
     key = encryption.get_key(password, get_salt())
     message_decoded = encryption.decrypt(key, self.data.ciphertext)
     push_data = json.loads(message_decoded.decode(settings.read('general', 'encoding')))
     for i, value in enumerate(self.pushData):
         if value in push_data:
             setattr(self.data, value, push_data[value])
         else:
             setattr(self.data, value, '')
コード例 #3
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
def api_post_request(api_url, extra_payload={}, extra_headers={}):
    token = settings.read('api', 'access_token')
    if not token:
        token = get_token()
        settings.write('api', 'access_token', token)

    headers = {'Access-Token': token,
               'Content-Type': 'application/json'}

    payload = {}
    if extra_headers:
        headers.update(extra_headers)
    if extra_payload:
        payload.update(extra_payload)

    r = requests.post(api_url, data=json.dumps(payload), headers=headers)
    if r.status_code != 200:
        log_msg = 'api post error: {0}\n{1}\napi url: {2}\npayload: {3}'.format(r.status_code,
                                                                                r.text,
                                                                                api_url,
                                                                                payload)
        log(log_msg)
        raise PbApiException()
    else:
        return r.json()
コード例 #4
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
def dismiss_push(push):
    if push.data.type == 'note' or push.data.type == 'link':
        api_url = settings.read('api', 'pushapi_url')
        payload = {'dismissed': True}
        if push.data.iden:
            api_post_request('{0}/{1}'.format(api_url, push.data.iden), payload)

    if push.data.type == 'mirror':
        api_url = settings.read('api', 'ephemeralapi_url')
        payload = {'push':
                       {'dismissed': True,
                        'notification_id': push.data.notification_id,
                        'notification_tag': push.data.notification_tag,
                        'package_name': push.data.package_name,
                        'source_user_iden': push.data.source_user_iden,
                        'type': 'dismissal'},
                   'type': 'push'}
        api_post_request(api_url, payload)
コード例 #5
0
    def __init__(self):
        super().__init__()

        # app stuff
        self.push = pbapi.Push(None)
        self.pushCount = 0
        self.pushList = []
        self.app = pylogilcd.app("Pushbullet")
        self.register(Event(self.update_info))

        # pushbullet client
        self.client = pbapi.RTESClient()
        self.client.update = self.update_info

        # inheriting the client event_mgr
        if settings.read('client', 'thread_rtes') == 'true':
            log('starting rtes_client thread')
            self.client_thread = threading.Thread(target=self.client.start)
            self.client_thread.start()
        else:
            log('inheriting rtes_client')
            self.client_thread = None
            self.inherit(self.client)
        self.register(Event(self.mainloop))
        self.register(Event(self.update))

        # app main loop
        self.running = True
        self.app.update()

        # option menu
        self.window_list = ListWindow(self)
        self.window_list.list_options = [('test_' + str(i), None) for i in range(10)]

        self.window_main = MainWindow(self)

        self.window_option = OptionWindow(self)
        self.window_option.list_options = [('Dismiss All', self.dismiss_all),
                                           ('History', self.view_history),
                                           ('Exit', self.exit)]

        self.window_history = HistoryWindow(self)
        self.window_history.list_options = []

        self.pushToView = pbapi.Push()
        self.window_view_push = ViewPushWindow(self)

        # menu stuff
        self.buttonTimeout = time.time()
        self.buttonTimeReset = 0.5
        self.selected = 0
        self.currentWindow = self.window_main
コード例 #6
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
def get_pushes(active=True):
    get_push_api = settings.read('api', 'pushapi_url')
    payload = {'active': 'true',
               'limit': '10'}

    pushes = api_get_request(get_push_api, payload)
    if not pushes:
        return []
    else:
        push_list = PushList(pushes)
        active_push_list = []
        for push in push_list.pushes:
            if push.data.type == 'note' or push.data.type == 'link':
                if not push.data.dismissed or not active:
                    active_push_list.append(push)
        return active_push_list
コード例 #7
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
    def __init__(self):
        EventMgr.__init__(self)
        self.running = True
        self.token = settings.read('api', 'access_token')
        self.pushStream = []

        self.do_exit = False
        self.wss = None
        self.pong = False
        self.pongTime = time.time()
        self.maxPongTime = 40
        self.connected = False
        self.disconnectCount = 0

        if not self.token:
            self.token = get_token()
            settings.write('api', 'access_token', self.token)

        self.register(Event(self.connect))
コード例 #8
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
 def connect(self):
     if not self.connected:
         log('connecting to server')
         wss_url = settings.read('api', 'rtes_url') + self.token
         try:
             self.wss = websocket.create_connection(wss_url)
         except socket.gaierror as e:
             log(str(repr(e)))
             self.wss = None
     else:
         log('already connected, not connecting again')
     if self.wss:
         log('connected to server')
         self.pong = True
         self.connected = True
         self.disconnectCount = 0
         self.register(Event(self.listen))
         self.register(Event(self.keep_connection))
     else:
         log('something went wrong when connecting to websocket')
         self.disconnect(graceful=False)
         self.register(Event(self.reconnect))
コード例 #9
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
def api_get_request(api_url, extra_payload={}, extra_headers={}):
    token = settings.read('api', 'access_token')
    if not token:
        token = get_token()
        settings.write('api', 'access_token', token)

    headers = {'Access-Token': token}
    payload = {}
    if extra_headers:
        headers.update(extra_headers)
    if extra_payload:
        payload.update(extra_payload)

    r = requests.get(api_url, params=extra_payload, headers=headers)
    if r.status_code != 200:
        log_msg = 'api get error: {0}\n{1}\napi url: {2}\npayload: {3}'.format(r.status_code,
                                                                               r.text,
                                                                               api_url,
                                                                               payload)
        log(log_msg)
        raise PbApiException()
    else:
        return r.json()
コード例 #10
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
def get_me():
    get_push_api = settings.read('api', 'users_me_url')
    me = api_get_request(get_push_api)
    return me
コード例 #11
0
ファイル: pbapi.py プロジェクト: pepijnd1/pushbullet510s
def get_salt():
    salt = settings.read('api', 'user_iden')
    if not salt:
        salt = get_me()['iden']
        settings.write('api', 'user_iden', salt)
    return salt
コード例 #12
0
ファイル: auth.py プロジェクト: pepijnd1/pushbullet510s
 def __init__(self, request, client_address, server, ontokenget):
     self.ontokenget = ontokenget
     self.template = template(settings.read('apiaccess', 'templatedir'))
     http.server.BaseHTTPRequestHandler.__init__(self, request, client_address, server)
コード例 #13
0
ファイル: auth.py プロジェクト: pepijnd1/pushbullet510s
 def servepage(self, filename):
     filepath = os.path.join(self.templatedir, filename)
     with open(filepath, 'r') as f:
         return bytes(f.read(), settings.read('general', 'encoding'))