implement cnc dump log
This commit is contained in:
parent
866d41bf98
commit
a9e884c4fa
6 changed files with 46 additions and 19 deletions
42
cncbot.py
42
cncbot.py
|
@ -1,6 +1,9 @@
|
||||||
import pydle
|
import pydle
|
||||||
|
import asyncio
|
||||||
|
from asyncio import new_event_loop, gather, get_event_loop, sleep
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
import time
|
||||||
|
|
||||||
CNC_HOST='dark.deflax.net'
|
CNC_HOST='dark.deflax.net'
|
||||||
CNC_CHANNEL='#izba'
|
CNC_CHANNEL='#izba'
|
||||||
|
@ -12,7 +15,7 @@ def get_random_string(length):
|
||||||
result_str = ''.join(random.choice(letters) for i in range(length))
|
result_str = ''.join(random.choice(letters) for i in range(length))
|
||||||
return result_str
|
return result_str
|
||||||
|
|
||||||
class ForestBot(pydle.Client):
|
class ForestBot(pydle.Client):
|
||||||
async def on_connect(self):
|
async def on_connect(self):
|
||||||
await super().on_connect()
|
await super().on_connect()
|
||||||
await self.join(CNC_CHANNEL)
|
await self.join(CNC_CHANNEL)
|
||||||
|
@ -25,14 +28,12 @@ class ForestBot(pydle.Client):
|
||||||
See pydle's documentation on blocking functionality for details.
|
See pydle's documentation on blocking functionality for details.
|
||||||
"""
|
"""
|
||||||
admin = False
|
admin = False
|
||||||
|
|
||||||
# Check the WHOIS info to see if the source has identified with NickServ.
|
# Check the WHOIS info to see if the source has identified with NickServ.
|
||||||
# This is a blocking operation, so use yield.
|
# This is a blocking operation, so use yield.
|
||||||
if nickname in ADMIN_NICKNAMES:
|
if nickname in ADMIN_NICKNAMES:
|
||||||
info = await self.whois(nickname)
|
info = await self.whois(nickname)
|
||||||
print('] Detected privileged request from {}'.format(info))
|
print('] Detected privileged request from {}'.format(info))
|
||||||
admin = info['identified']
|
admin = info['identified']
|
||||||
|
|
||||||
return admin
|
return admin
|
||||||
|
|
||||||
async def on_message(self, target, source, message):
|
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, '] cnc usage:')
|
||||||
await self.message(target, '] help - displays help')
|
await self.message(target, '] help - displays help')
|
||||||
await self.message(target, '] id - cnc user info')
|
await self.message(target, '] id - cnc user info')
|
||||||
|
await self.message(target, '] dump - dump cnc log')
|
||||||
|
|
||||||
# Show user info
|
# Show user info
|
||||||
if message.startswith('id {}'.format(self.nickname)):
|
if message.startswith('id {}'.format(self.nickname)):
|
||||||
|
@ -51,11 +53,35 @@ class ForestBot(pydle.Client):
|
||||||
await self.message(target, '] You are an administrator. :)'.format(source))
|
await self.message(target, '] You are an administrator. :)'.format(source))
|
||||||
else:
|
else:
|
||||||
await self.message(target, '] You are NOT an administrator. :('.format(source))
|
await self.message(target, '] You are NOT an administrator. :('.format(source))
|
||||||
|
|
||||||
def CnCApp():
|
if message.startswith('dump {}'.format(self.nickname)):
|
||||||
cnc = ForestBot('cnc_' + get_random_string(6))
|
admin = await self.is_admin(source)
|
||||||
cnc.run(CNC_HOST, tls=False, tls_verify=False)
|
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__':
|
if __name__ == '__main__':
|
||||||
CnCApp()
|
CnCApp()
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
max_zoom: 17
|
max_zoom: 17
|
||||||
snap_to_zoom: True
|
snap_to_zoom: True
|
||||||
pause_on_action: True
|
pause_on_action: True
|
||||||
#on_zoom:
|
on_zoom:
|
||||||
#self.zoom = 10 if self.zoom < 10 else self.zoom
|
#self.zoom = 10 if self.zoom < 10 else self.zoom
|
||||||
#self.print_current_zoom(self.zoom)
|
|
||||||
#self.zoom = 17
|
#self.zoom = 17
|
||||||
|
self.print_current_zoom(self.zoom)
|
||||||
on_lat:
|
on_lat:
|
||||||
self.start_get_fov_trees()
|
self.start_get_fov_trees()
|
||||||
on_lon:
|
on_lon:
|
||||||
|
|
|
@ -13,6 +13,7 @@ class ForestMapView(MapView):
|
||||||
|
|
||||||
def print_current_zoom(self, *args):
|
def print_current_zoom(self, *args):
|
||||||
print("] Zoom level: " + str(self.zoom))
|
print("] Zoom level: " + str(self.zoom))
|
||||||
|
#pqueue.put("] Zoom level: " + str(self.zoom))
|
||||||
|
|
||||||
def start_get_fov_trees(self):
|
def start_get_fov_trees(self):
|
||||||
# After one second get the trees in field of view
|
# After one second get the trees in field of view
|
||||||
|
@ -34,7 +35,7 @@ class ForestMapView(MapView):
|
||||||
trees = app.cursor.fetchall()
|
trees = app.cursor.fetchall()
|
||||||
for tree in trees:
|
for tree in trees:
|
||||||
name = tree[0]
|
name = tree[0]
|
||||||
#print("] Fountain detected: " + str(tree))
|
#print("] Tree detected: " + str(tree))
|
||||||
if name in self.tree_names:
|
if name in self.tree_names:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|
12
main.py
12
main.py
|
@ -2,13 +2,11 @@ __author__ = "afx"
|
||||||
__version__ = "0.2"
|
__version__ = "0.2"
|
||||||
|
|
||||||
# Import system modules
|
# Import system modules
|
||||||
import multiprocessing
|
from multiprocessing import Process, Queue
|
||||||
import random
|
import random
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
# Import Kivy modules
|
# Import Kivy modules
|
||||||
#from kivy.app import App
|
|
||||||
#from kivy.app import async_runTouchApp
|
|
||||||
from kivymd.app import MDApp
|
from kivymd.app import MDApp
|
||||||
from kivy.lang import Builder
|
from kivy.lang import Builder
|
||||||
|
|
||||||
|
@ -71,6 +69,7 @@ class MainApp(MDApp):
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
# Welcome
|
# Welcome
|
||||||
print(MOTD)
|
print(MOTD)
|
||||||
|
queue.put('] Framework started.')
|
||||||
|
|
||||||
self.theme_cls.primary_palette = 'BlueGray'
|
self.theme_cls.primary_palette = 'BlueGray'
|
||||||
|
|
||||||
|
@ -84,9 +83,10 @@ class MainApp(MDApp):
|
||||||
# Instantiate SearchPopupMenu
|
# Instantiate SearchPopupMenu
|
||||||
#self.search_menu = SearchPopupMenu()
|
#self.search_menu = SearchPopupMenu()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Start the Command and Control bot. Mainly for reporting.
|
# Start the Command and Control bot. Mainly for reporting.
|
||||||
cnc = multiprocessing.Process(target=CnCApp)
|
queue = Queue()
|
||||||
|
cnc = Process(target=CnCApp, args=((queue),))
|
||||||
cnc.start()
|
cnc.start()
|
||||||
|
|
||||||
# Start the Kivy Framework main loop
|
# Start the Kivy Framework main loop
|
||||||
|
@ -94,5 +94,5 @@ if __name__ == '__main__':
|
||||||
kivyapp.run()
|
kivyapp.run()
|
||||||
|
|
||||||
# Cleanup subprocesses
|
# Cleanup subprocesses
|
||||||
print('] Terminating subprocesses.')
|
print('] Framework terminated.')
|
||||||
cnc.kill()
|
cnc.kill()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Kivy==2.0.0rc4
|
Kivy==2.0.0rc4
|
||||||
pydle
|
|
||||||
ffpyplayer
|
ffpyplayer
|
||||||
sqlite_utils
|
sqlite_utils
|
||||||
mapview
|
mapview
|
||||||
|
pure-sasl
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
<TreeMarker>:
|
<TreeMarker>:
|
||||||
source: 'assets/images/markers/fountain.png'
|
source: 'assets/images/markers/tree.png'
|
Loading…
Reference in a new issue