implement cnc dump log

This commit is contained in:
Daniel afx 2020-10-25 22:05:46 +02:00
parent 866d41bf98
commit a9e884c4fa
6 changed files with 46 additions and 19 deletions

View file

@ -1,6 +1,9 @@
import pydle
import asyncio
from asyncio import new_event_loop, gather, get_event_loop, sleep
import random
import string
import time
CNC_HOST='dark.deflax.net'
CNC_CHANNEL='#izba'
@ -25,14 +28,12 @@ class ForestBot(pydle.Client):
See pydle's documentation on blocking functionality for details.
"""
admin = False
# Check the WHOIS info to see if the source has identified with NickServ.
# This is a blocking operation, so use yield.
if nickname in ADMIN_NICKNAMES:
info = await self.whois(nickname)
print('] Detected privileged request from {}'.format(info))
admin = info['identified']
return admin
async def on_message(self, target, source, message):
@ -43,6 +44,7 @@ class ForestBot(pydle.Client):
await self.message(target, '] cnc usage:')
await self.message(target, '] help - displays help')
await self.message(target, '] id - cnc user info')
await self.message(target, '] dump - dump cnc log')
# Show user info
if message.startswith('id {}'.format(self.nickname)):
@ -52,10 +54,34 @@ class ForestBot(pydle.Client):
else:
await self.message(target, '] You are NOT an administrator. :('.format(source))
def CnCApp():
cnc = ForestBot('cnc_' + get_random_string(6))
cnc.run(CNC_HOST, tls=False, tls_verify=False)
if message.startswith('dump {}'.format(self.nickname)):
admin = await self.is_admin(source)
if admin:
await self.dumplog(target)
async def dumplog(self, target):
while True:
msg = self.queue.get()
time.sleep(1)
await self.message(target, msg)
if len(msg) == 0:
break
def run(self, *args, **kwargs):
self.queue = kwargs['extqueue']
""" Connect and run bot in event loop. """
#self.eventloop.run_until_complete(self.connect(*args, **kwargs))
self.eventloop.run_until_complete(self.connect(*args))
try:
self.eventloop.run_forever()
finally:
self.eventloop.stop()
def CnCApp(queue):
botnick = 'cnc_' + get_random_string(8)
botnick_fallback = [botnick + '_re']
cnc = ForestBot(botnick, botnick_fallback, botnick, botnick, None)
cnc.run(CNC_HOST, tls=False, tls_verify=False, extqueue=queue)
if __name__ == '__main__':
CnCApp()

View file

@ -11,10 +11,10 @@
max_zoom: 17
snap_to_zoom: True
pause_on_action: True
#on_zoom:
on_zoom:
#self.zoom = 10 if self.zoom < 10 else self.zoom
#self.print_current_zoom(self.zoom)
#self.zoom = 17
self.print_current_zoom(self.zoom)
on_lat:
self.start_get_fov_trees()
on_lon:

View file

@ -13,6 +13,7 @@ class ForestMapView(MapView):
def print_current_zoom(self, *args):
print("] Zoom level: " + str(self.zoom))
#pqueue.put("] Zoom level: " + str(self.zoom))
def start_get_fov_trees(self):
# After one second get the trees in field of view
@ -34,7 +35,7 @@ class ForestMapView(MapView):
trees = app.cursor.fetchall()
for tree in trees:
name = tree[0]
#print("] Fountain detected: " + str(tree))
#print("] Tree detected: " + str(tree))
if name in self.tree_names:
continue
else:

10
main.py
View file

@ -2,13 +2,11 @@ __author__ = "afx"
__version__ = "0.2"
# Import system modules
import multiprocessing
from multiprocessing import Process, Queue
import random
import sqlite3
# Import Kivy modules
#from kivy.app import App
#from kivy.app import async_runTouchApp
from kivymd.app import MDApp
from kivy.lang import Builder
@ -71,6 +69,7 @@ class MainApp(MDApp):
def on_start(self):
# Welcome
print(MOTD)
queue.put('] Framework started.')
self.theme_cls.primary_palette = 'BlueGray'
@ -86,7 +85,8 @@ class MainApp(MDApp):
if __name__ == '__main__':
# Start the Command and Control bot. Mainly for reporting.
cnc = multiprocessing.Process(target=CnCApp)
queue = Queue()
cnc = Process(target=CnCApp, args=((queue),))
cnc.start()
# Start the Kivy Framework main loop
@ -94,5 +94,5 @@ if __name__ == '__main__':
kivyapp.run()
# Cleanup subprocesses
print('] Terminating subprocesses.')
print('] Framework terminated.')
cnc.kill()

View file

@ -1,5 +1,5 @@
Kivy==2.0.0rc4
pydle
ffpyplayer
sqlite_utils
mapview
pure-sasl

View file

@ -1,2 +1,2 @@
<TreeMarker>:
source: 'assets/images/markers/fountain.png'
source: 'assets/images/markers/tree.png'