Beispiel #1
0
def on_internet_available(ui, config, log):
    if config['twitter']['enabled'] and log.is_new() and log.handshakes > 0:
        try:
            import tweepy
        except ImportError:
            logging.error("Couldn't import tweepy")
            return

        logging.info("detected a new session and internet connectivity!")

        picture = '/dev/shm/pwnagotchi.png'

        ui.on_manual_mode(log)
        ui.update(force=True)
        ui.image().save(picture, 'png')
        ui.set('status', 'Tweeting...')
        ui.update(force=True)

        try:
            auth = tweepy.OAuthHandler(config['twitter']['consumer_key'], config['twitter']['consumer_secret'])
            auth.set_access_token(config['twitter']['access_token_key'], config['twitter']['access_token_secret'])
            api = tweepy.API(auth)

            tweet = Voice(lang=config['main']['lang']).on_log_tweet(log)
            api.update_with_media(filename=picture, status=tweet)
            log.save_session_id()

            logging.info("tweeted: %s" % tweet)
        except Exception as e:
            logging.exception("error while tweeting")
Beispiel #2
0
def on_internet_available(agent):
    config = agent.config()
    display = agent.view()
    last_session = agent.last_session

    if last_session.is_new() and last_session.handshakes > 0:
        try:
            import tweepy
        except ImportError:
            logging.error("Couldn't import tweepy")
            return

        logging.info("detected a new session and internet connectivity!")

        picture = '/dev/shm/pwnagotchi.png'

        display.on_manual_mode(last_session)
        display.update(force=True)
        display.image().save(picture, 'png')
        display.set('status', 'Tweeting...')
        display.update(force=True)

        try:
            auth = tweepy.OAuthHandler(OPTIONS['consumer_key'], OPTIONS['consumer_secret'])
            auth.set_access_token(OPTIONS['access_token_key'], OPTIONS['access_token_secret'])
            api = tweepy.API(auth)

            tweet = Voice(lang=config['main']['lang']).on_last_session_tweet(last_session)
            api.update_with_media(filename=picture, status=tweet)
            last_session.save_session_id()

            logging.info("tweeted: %s" % tweet)
        except Exception as e:
            logging.exception("error while tweeting")
    def on_internet_available(self, agent):
        config = agent.config()
        display = agent.view()
        last_session = agent.last_session

        if last_session.is_new() and last_session.handshakes > 0:
            try:
                import tweepy
            except ImportError:
                logging.error("[twitter] Couldn't import tweepy.")
                return

            logging.info("[twitter] Detected a new session and internet connectivity!")

            picture = '/var/tmp/pwnagotchi/pwnagotchi.png' if os.path.exists("/var/tmp/pwnagotchi/pwnagotchi.png") else '/root/pwnagotchi.png'

            display.on_manual_mode(last_session)
            display.update(force=True)
            display.image().save(picture, 'png')
            display.set('status', 'Tweeting...')
            display.update(force=True)

            try:
                auth = tweepy.OAuthHandler(self.options['consumer_key'], self.options['consumer_secret'])
                auth.set_access_token(self.options['access_token_key'], self.options['access_token_secret'])
                api = tweepy.API(auth)

                tweet = Voice(lang=config['main']['lang']).on_last_session_tweet(last_session)
                api.update_with_media(filename=picture, status=tweet)
                last_session.save_session_id()

                logging.info(f"[twitter] Tweeted: {tweet}")
            except Exception as e:
                logging.exception(f"[twitter] Error while tweeting: {e}")
Beispiel #4
0
    def on_internet_available(self, agent):
        if not self.ready:
            return

        config = agent.config()
        display = agent.view()
        last_session = agent.last_session

        if last_session.is_new() and last_session.handshakes > 0:
            try:
                import telegram
            except ImportError as e:
                logging.error("[telegram] Couldn't import python library.")
                logging.debug(e)
                return

            logging.info(
                "[telegram] Detected new activity and internet, time to send a message!"
            )

            picture = '/var/tmp/pwnagotchi/pwnagotchi.png' if os.path.exists(
                "/var/tmp/pwnagotchi/pwnagotchi.png"
            ) else '/root/pwnagotchi.png'
            display.on_manual_mode(last_session)
            display.image().save(picture, 'png')
            display.update(force=True)

            try:
                logging.info("[telegram] Connecting to Telegram...")

                message = Voice(lang=config['main']
                                ['lang']).on_last_session_tweet(last_session)
                bot = telegram.Bot(self.options['bot_token'])

                if self.options['send_picture'] is True:
                    logging.info("[telegram] Sending picture...")
                    bot.sendPhoto(chat_id=self.options['chat_id'],
                                  photo=open(picture, 'rb'))
                    logging.info("[telegram] Picture sent.")

                if self.options['send_message'] is True:
                    logging.info("[telegram] Sending message...")
                    bot.sendMessage(chat_id=self.options['chat_id'],
                                    text=message,
                                    disable_web_page_preview=True)
                    logging.info(f"[telegram] Message sent: {message}")

                last_session.save_session_id()
                display.set('status', 'Telegram notification sent!')
                display.update(force=True)
            except Exception as e:
                logging.exception(
                    f"[telegram] An error occurred in the Telegram plugin: {e}"
                )
                display.set('face', faces.BROKEN)
                display.set('status',
                            'An error occured in the Telegram plugin.')
                display.update(force=True)
    def on_internet_available(self, agent):
        config = agent.config()
        display = agent.view()
        last_session = agent.last_session
        api_base_url = self.options['instance_url']
        email = self.options['email']
        password = self.options['password']
        visibility = self.options['visibility']
        client_cred = '/root/.mastodon.client.secret'
        user_cred = '/root/.mastodon.user.secret'

        if last_session.is_new() and last_session.handshakes > 0:
            logging.info('[mastodon] Detected internet and new activity: time to post!')

            if not os.path.isfile(user_cred) or not os.path.isfile(client_cred):
                # Runs only if there are any missing credential files
                Mastodon.create_app(
                    config['main']['name'],
                    api_base_url=api_base_url,
                    to_file=client_cred
                )
            picture = '/root/pwnagotchi.png'
            display.on_manual_mode(last_session)
            display.image().save(picture, 'png')
            display.update(force=True)

            try:
                logging.info('[mastodon] Connecting to Mastodon API')
                mastodon = Mastodon(
                    client_id=client_cred,
                    api_base_url=api_base_url
                )
                mastodon.log_in(
                    email,
                    password,
                    to_file=user_cred
                )
                mastodon = Mastodon(
                    access_token=user_cred,
                    api_base_url=api_base_url
                )
                message = Voice(lang=config['main']['lang']).on_last_session_tweet(last_session)
                mastodon.status_post(
                    message,
                    media_ids=mastodon.media_post(picture),
                    visibility=visibility
                )

                last_session.save_session_id()
                logging.info('[mastodon] posted: %s', message)
                display.set('status', 'Posted!')
                display.update(force=True)
            except Exception as ex:
                logging.exception('[mastodon] error while posting: %s', ex)
Beispiel #6
0
    def on_internet_available(self, agent):
        if not self.ready:
            return

        config = agent.config()
        display = agent.view()
        last_session = agent.last_session

        if last_session.is_new() and last_session.handshakes > 0:
            try:
                from discord import Webhook, RequestsWebhookAdapter, File
            except ImportError as e:
                logging.error("Discord: couldn't import discord.py")
                logging.debug(e)
                return

            logging.info(
                "Discord: detected new activity and internet, time to send a message!"
            )

            picture = '/var/tmp/pwnagotchi/pwnagotchi.png' if os.path.exists(
                "/var/tmp/pwnagotchi/pwnagotchi.png"
            ) else '/root/pwnagotchi.png'
            display.on_manual_mode(last_session)
            display.image().save(picture, 'png')
            display.update(force=True)

            try:
                logging.info("Discord: sending message...")

                message = Voice(lang=config['main']
                                ['lang']).on_last_session_tweet(last_session)
                url = self.options['webhook_url']
                username = self.options['username']

                webhook = Webhook.from_url(url,
                                           adapter=RequestsWebhookAdapter())
                webhook.send(message, username=username, file=File(picture))
                logging.info("Discord: message sent: %s" % message)

                last_session.save_session_id()
                display.set('status', 'Discord notification sent!')
                display.update(force=True)
            except Exception as e:
                logging.exception("Discord: error while sending message")
                logging.debug(e)
Beispiel #7
0
    def on_internet_available(self, agent):
        config = agent.config()
        display = agent.view()
        last_session = agent.last_session

        if last_session.is_new() and last_session.handshakes > 0:

            try:
                import telegram
            except ImportError:
                logging.error('[telegram] Couldn\'t import telegram')
                return

            logging.info(
                '[telegram] Detected new activity and internet, time to send a message!'
            )

            picture = '/root/pwnagotchi.png'
            display.on_manual_mode(last_session)
            display.image().save(picture, 'png')
            display.update(force=True)

            try:
                logging.info('[telegram] Connecting to Telegram...')

                message = Voice(lang=config['main']
                                ['lang']).on_last_session_tweet(last_session)

                bot = telegram.Bot(self.options['bot_token'])
                if self.options['send_picture'] is True:
                    bot.sendPhoto(chat_id=self.options['chat_id'],
                                  photo=open(picture, 'rb'))
                    logging.info('[telegram] picture sent')
                if self.options['send_message'] is True:
                    bot.sendMessage(chat_id=self.options['chat_id'],
                                    text=message,
                                    disable_web_page_preview=True)
                    logging.info('[telegram] message sent: %s', message)

                last_session.save_session_id()
                display.set('status', 'Telegram notification sent!')
                display.update(force=True)
            except Exception as ex:
                logging.exception(
                    '[telegram] Error while sending on Telegram: %s', ex)
Beispiel #8
0
 def __init__(self, config):
     self.config = config
     self.voice = Voice(lang=config['main']['lang'])
     self.path = config['main']['log']['path']
     self.last_session = []
     self.last_session_id = ''
     self.last_saved_session_id = ''
     self.duration = ''
     self.duration_human = ''
     self.deauthed = 0
     self.associated = 0
     self.handshakes = 0
     self.epochs = 0
     self.train_epochs = 0
     self.min_reward = 1000
     self.max_reward = -1000
     self.avg_reward = 0
     self.parsed = False
Beispiel #9
0
 def __init__(self, config):
     self.config = config
     self.voice = Voice(lang=config['main']['lang'])
     self.path = config['main']['log']
     self.last_session = None
     self.last_session_id = ''
     self.last_saved_session_id = ''
     self.duration = ''
     self.duration_human = ''
     self.deauthed = 0
     self.associated = 0
     self.handshakes = 0
     self.peers = 0
     self.last_peer = None
     self._peer_parser = re.compile(
         'detected unit (.+)@(.+) \(v.+\) on channel \d+ \(([\d\-]+) dBm\) \[sid:(.+) pwnd_tot:(\d+) uptime:(\d+)\]'
     )
     self.last_session = []
     self.last_session_id = None
     self.last_saved_session_id = None
     self.parsed = False
Beispiel #10
0
    def __init__(self, config):
        self.config = config
        self.voice = Voice(lang=config['main']['lang'])
        self.path = config['main']['log']
        self.last_session = None
        self.last_session_id = ''
        self.last_saved_session_id = ''
        self.duration = ''
        self.duration_human = ''
        self.deauthed = 0
        self.associated = 0
        self.handshakes = 0
        self.peers = 0
        self.last_peer = None
        self._peer_parser = re.compile(
            'detected unit (.+)@(.+) \(v.+\) on channel \d+ \(([\d\-]+) dBm\) \[sid:(.+) pwnd_tot:(\d+) uptime:(\d+)\]'
        )

        lines = []

        if os.path.exists(self.path):
            with FileReadBackwards(self.path, encoding="utf-8") as fp:
                for line in fp:
                    line = line.strip()
                    if line != "" and line[0] != '[':
                        continue
                    lines.append(line)
                    if SessionParser.START_TOKEN in line:
                        break
            lines.reverse()

        if len(lines) == 0:
            lines.append("Initial Session")

        self.last_session = lines
        self.last_session_id = hashlib.md5(lines[0].encode()).hexdigest()
        self.last_saved_session_id = self._get_last_saved_session_id()

        self._parse_stats()
    def on_internet_available(self, agent):
        config = agent.config()
        display = agent.view()
        last_session = agent.last_session

        if last_session.is_new() and last_session.handshakes > 0:
            try:
                import tweepy
            except ImportError as ie:
                logging.error('[twitter] Couldn\'t import tweepy (%s)', ie)
                return

            logging.info(
                '[twitter] detected a new session and internet connectivity!')

            picture = '/root/pwnagotchi.png'

            display.on_manual_mode(last_session)
            with display.block_update(force=True):
                display.image().save(picture, 'png')
            display.set('status', 'Tweeting...')
            display.update(force=True)

            try:
                auth = tweepy.OAuthHandler(self.options['consumer_key'],
                                           self.options['consumer_secret'])
                auth.set_access_token(self.options['access_token_key'],
                                      self.options['access_token_secret'])
                api = tweepy.API(auth)

                tweet = Voice(lang=config['main']
                              ['lang']).on_last_session_tweet(last_session)
                api.update_with_media(filename=picture, status=tweet)
                last_session.save_session_id()

                logging.info('[twitter] tweeted: %s', tweet)
            except Exception as e:
                logging.exception('[twitter] error while tweeting (%s)', e)
Beispiel #12
0
    def __init__(self, config, impl, state=None):
        global ROOT

        # setup faces from the configuration in case the user customized them
        faces.load_from_config(config['ui']['faces'])

        self._agent = None
        self._render_cbs = []
        self._config = config
        self._canvas = None
        self._frozen = False
        self._lock = Lock()
        self._voice = Voice(lang=config['main']['lang'])
        self._implementation = impl
        self._layout = impl.layout()
        self._width = self._layout['width']
        self._height = self._layout['height']
        self._state = State(state={
            'channel': LabeledValue(color=BLACK, label='CH', value='00', position=self._layout['channel'],
                                    label_font=fonts.Bold,
                                    text_font=fonts.Medium),
            'aps': LabeledValue(color=BLACK, label='APS', value='0 (00)', position=self._layout['aps'],
                                label_font=fonts.Bold,
                                text_font=fonts.Medium),

            'uptime': LabeledValue(color=BLACK, label='UP', value='00:00:00', position=self._layout['uptime'],
                                   label_font=fonts.Bold,
                                   text_font=fonts.Medium),

            'line1': Line(self._layout['line1'], color=BLACK),
            'line2': Line(self._layout['line2'], color=BLACK),

            'face': Text(value=faces.SLEEP, position=self._layout['face'], color=BLACK, font=fonts.Huge),

            'friend_face': Text(value=None, position=self._layout['friend_face'], font=fonts.Bold, color=BLACK),
            'friend_name': Text(value=None, position=self._layout['friend_name'], font=fonts.BoldSmall,
                                color=BLACK),

            'name': Text(value='%s>' % 'pwnagotchi', position=self._layout['name'], color=BLACK, font=fonts.Bold),

            'status': Text(value=self._voice.default(),
                           position=self._layout['status']['pos'],
                           color=BLACK,
                           font=self._layout['status']['font'],
                           wrap=True,
                           # the current maximum number of characters per line, assuming each character is 6 pixels wide
                           max_length=self._layout['status']['max']),

            'shakes': LabeledValue(label='PWND ', value='0 (00)', color=BLACK,
                                   position=self._layout['shakes'], label_font=fonts.Bold,
                                   text_font=fonts.Medium),
            'mode': Text(value='AUTO', position=self._layout['mode'],
                         font=fonts.Bold, color=BLACK),
        })

        if state:
            for key, value in state.items():
                self._state.set(key, value)

        plugins.on('ui_setup', self)

        if config['ui']['fps'] > 0.0:
            _thread.start_new_thread(self._refresh_handler, ())
            self._ignore_changes = ()
        else:
            logging.warning("ui.fps is 0, the display will only update for major changes")
            self._ignore_changes = ('uptime', 'name')

        ROOT = self
Beispiel #13
0
    def __init__(self, config, state={}):
        self._render_cbs = []
        self._config = config
        self._canvas = None
        self._lock = Lock()
        self._voice = Voice(lang=config['main']['lang'])

        self._width, self._height, \
        face_pos, name_pos, status_pos = setup_display_specifics(config)

        self._state = State(
            state={
                'channel':
                LabeledValue(color=BLACK,
                             label='CH',
                             value='00',
                             position=(0, 0),
                             label_font=fonts.Bold,
                             text_font=fonts.Medium),
                'aps':
                LabeledValue(color=BLACK,
                             label='APS',
                             value='0 (00)',
                             position=(30, 0),
                             label_font=fonts.Bold,
                             text_font=fonts.Medium),

                # 'epoch': LabeledValue(color=BLACK, label='E', value='0000', position=(145, 0), label_font=fonts.Bold,
                #                      text_font=fonts.Medium),
                'uptime':
                LabeledValue(color=BLACK,
                             label='UP',
                             value='00:00:00',
                             position=(self._width - 65, 0),
                             label_font=fonts.Bold,
                             text_font=fonts.Medium),
                'line1':
                Line([
                    0,
                    int(self._height * .12), self._width,
                    int(self._height * .12)
                ],
                     color=BLACK),
                'line2':
                Line([
                    0, self._height -
                    int(self._height * .12), self._width, self._height -
                    int(self._height * .12)
                ],
                     color=BLACK),
                'face':
                Text(value=faces.SLEEP,
                     position=face_pos,
                     color=BLACK,
                     font=fonts.Huge),
                'friend_face':
                Text(
                    value=None, position=(0,
                                          90), font=fonts.Bold, color=BLACK),
                'friend_name':
                Text(value=None,
                     position=(40, 93),
                     font=fonts.BoldSmall,
                     color=BLACK),
                'name':
                Text(value='%s>' % 'pwnagotchi',
                     position=name_pos,
                     color=BLACK,
                     font=fonts.Bold),
                'status':
                Text(
                    value=self._voice.default(),
                    position=status_pos,
                    color=BLACK,
                    font=fonts.Medium,
                    wrap=True,
                    # the current maximum number of characters per line, assuming each character is 6 pixels wide
                    max_length=(self._width - status_pos[0]) // 6),
                'shakes':
                LabeledValue(label='PWND ',
                             value='0 (00)',
                             color=BLACK,
                             position=(0, self._height -
                                       int(self._height * .12) + 1),
                             label_font=fonts.Bold,
                             text_font=fonts.Medium),
                'mode':
                Text(value='AUTO',
                     position=(self._width - 25,
                               self._height - int(self._height * .12) + 1),
                     font=fonts.Bold,
                     color=BLACK),
            })

        for key, value in state.items():
            self._state.set(key, value)

        plugins.on('ui_setup', self)

        if config['ui']['fps'] > 0.0:
            _thread.start_new_thread(self._refresh_handler, ())
            self._ignore_changes = ()
        else:
            logging.warning(
                "ui.fps is 0, the display will only update for major changes")
            self._ignore_changes = ('uptime', 'name')
Beispiel #14
0
            picture = '/dev/shm/pwnagotchi.png'

            display.update()
            display.image().save(picture, 'png')
            display.set('status', 'Tweeting...')
            display.update()

            try:
                auth = tweepy.OAuthHandler(
                    config['twitter']['consumer_key'],
                    config['twitter']['consumer_secret'])
                auth.set_access_token(config['twitter']['access_token_key'],
                                      config['twitter']['access_token_secret'])
                api = tweepy.API(auth)

                tweet = Voice(lang=config['main']['lang']).on_log_tweet(log)
                api.update_with_media(filename=picture, status=tweet)
                log.save_session_id()

                core.log("tweeted: %s" % tweet)
            except Exception as e:
                core.log("error: %s" % e)

    quit()

core.logfile = config['main']['log']

agent.start_ai()
agent.setup_events()
agent.set_ready()
agent.start_monitor_mode()
Beispiel #15
0
    def __init__(self, config, state={}):
        self._render_cbs = []
        self._config = config
        self._canvas = None
        self._lock = Lock()
        self._voice = Voice(lang=config['main']['lang'])

        self._width, self._height, \
        face_pos, name_pos, status_pos = setup_display_specifics(config)

        self._state = State(
            state={
                'channel':
                LabeledValue(color=BLACK,
                             label='CH',
                             value='00',
                             position=(0, 0),
                             label_font=fonts.Bold,
                             text_font=fonts.Medium),
                'aps':
                LabeledValue(color=BLACK,
                             label='APS',
                             value='0 (00)',
                             position=(30, 0),
                             label_font=fonts.Bold,
                             text_font=fonts.Medium),

                # 'epoch': LabeledValue(color=BLACK, label='E', value='0000', position=(145, 0), label_font=fonts.Bold,
                #                      text_font=fonts.Medium),
                'uptime':
                LabeledValue(color=BLACK,
                             label='UP',
                             value='00:00:00',
                             position=(self._width - 65, 0),
                             label_font=fonts.Bold,
                             text_font=fonts.Medium),

                # 'square':  Rect([1, 11, 124, 111]),
                'line1':
                Line([
                    0,
                    int(self._height * .12), self._width,
                    int(self._height * .12)
                ],
                     color=BLACK),
                'line2':
                Line([
                    0, self._height -
                    int(self._height * .12), self._width, self._height -
                    int(self._height * .12)
                ],
                     color=BLACK),

                # 'histogram': Histogram([4, 94], color = BLACK),
                'face':
                Text(value=faces.SLEEP,
                     position=face_pos,
                     color=BLACK,
                     font=fonts.Huge),
                'friend_face':
                Text(
                    value=None, position=(0,
                                          90), font=fonts.Bold, color=BLACK),
                'friend_name':
                Text(value=None,
                     position=(40, 93),
                     font=fonts.BoldSmall,
                     color=BLACK),
                'name':
                Text(value='%s>' % 'pwnagotchi',
                     position=name_pos,
                     color=BLACK,
                     font=fonts.Bold),
                # 'face2':   Bitmap( '/root/pwnagotchi/data/images/face_happy.bmp', (0, 20)),
                'status':
                Text(value=self._voice.default(),
                     position=status_pos,
                     color=BLACK,
                     font=fonts.Medium),
                'shakes':
                LabeledValue(label='PWND ',
                             value='0 (00)',
                             color=BLACK,
                             position=(0, self._height -
                                       int(self._height * .12) + 1),
                             label_font=fonts.Bold,
                             text_font=fonts.Medium),
                'mode':
                Text(value='AUTO',
                     position=(self._width - 25,
                               self._height - int(self._height * .12) + 1),
                     font=fonts.Bold,
                     color=BLACK),
            })

        for key, value in state.items():
            self._state.set(key, value)

        _thread.start_new_thread(self._refresh_handler, ())