Browse Source

most likely fixed the telnet log

master
Christian Voigt 1 year ago
parent
commit
78f8672bd7
6 changed files with 41 additions and 19 deletions
  1. +28
    -0
      bot/modules/dom/callback_dict.py
  2. +2
    -2
      bot/modules/telnet/__init__.py
  3. +4
    -6
      bot/modules/telnet/widgets/telnet_log_widget.py
  4. +5
    -6
      bot/modules/webserver/__init__.py
  5. +1
    -4
      bot/modules/webserver/static/socketio.js
  6. +1
    -1
      requirements.txt

+ 28
- 0
bot/modules/dom/callback_dict.py View File

@@ -13,6 +13,34 @@ class CallbackDict(dict, object):
def __setitem__(self, key, value):
super().__setitem__(key, value)

def append(self, updated_values_dict, dict_to_update=None):
if dict_to_update is None:
dict_to_update = self

for k, v in updated_values_dict.items():
if len(self.registered_callbacks) >= 1 and k in self.registered_callbacks.keys():
Thread(
target=self.registered_callbacks[k]["callback"],
args=(
self.registered_callbacks[k]["module"], CallbackDict(updated_values_dict), dict_to_update
)
).start()

try:
dict_to_update[k].append(v)
except KeyError:
dict_to_update[k] = []
dict_to_update[k].append(v)
except AttributeError:
pass

return

d_v = dict_to_update.get(k)
if isinstance(v, Mapping) and isinstance(d_v, Mapping):
self.append(v, d_v)


def upsert(self, updated_values_dict, dict_to_update=None, overwrite=False):
if dict_to_update is None:
dict_to_update = self


+ 2
- 2
bot/modules/telnet/__init__.py View File

@@ -284,9 +284,9 @@ class Telnet(Module):
self.valid_telnet_lines.append(valid_telnet_line)

if len(self.webserver.connected_clients) >= 1:
self.dom.data.upsert({
self.dom.data.append({
self.get_module_identifier(): {
"telnet_lines": self.valid_telnet_lines
"telnet_lines": valid_telnet_line
}
})



+ 4
- 6
bot/modules/telnet/widgets/telnet_log_widget.py View File

@@ -35,12 +35,10 @@ def main_widget(module):

def update_widget(module, updated_values_dict, old_values_dict):
telnet_log_line = module.templates.get_template('telnet_log_widget_log_line.html')
data_to_emit = ""
reversed_logs = reversed(updated_values_dict["telnet_lines"])
for telnet_line in reversed_logs:
data_to_emit += telnet_log_line.render(
log_line=telnet_line
)

data_to_emit = telnet_log_line.render(
log_line=updated_values_dict["telnet_lines"]
)

module.webserver.send_data_to_client(
method="prepend",


+ 5
- 6
bot/modules/webserver/__init__.py View File

@@ -1,11 +1,7 @@
""" some IDE's will throw 'PEP 8' warnings for imports, but this has to happen early, I think """
#if not debug:
from gevent import monkey
print("monkey-patching status: {}".format(monkey.patch_all()))

#if not debug:
#import eventlet
#eventlet.monkey_patch()
monkey.patch_all()

from os import path, chdir
root_dir = path.dirname(path.abspath(__file__))
@@ -25,7 +21,7 @@ from flask_login import LoginManager, login_required, login_user, current_user,
from flask_socketio import SocketIO, emit, disconnect
from requests import post
from urllib.parse import urlencode
from collections import KeysView
from collections import KeysView, Mapping


class Webserver(Module):
@@ -122,6 +118,9 @@ class Webserver(Module):
pass

for data_package in data_packages_to_send:
if not isinstance(data_package[0]["event_data"], list):
print(len(data_package[0]["event_data"].encode('utf-8')))
print(data_package[0]["event_data"])
self.websocket.emit(
'data',
data_package[0],


+ 1
- 4
bot/modules/webserver/static/socketio.js View File

@@ -120,10 +120,7 @@ $(document).ready(function() {
$el.append(data["event_data"]);
} else if (data["method"] === "prepend") {
$el.find(target_element_type).prepend(data["event_data"]);
let entries = $el.find('li');
if (entries.length >= 50) {
entries.last().remove();
}
$('#telnet_log_widget ul li').length = 10;
}
} else if (data["data_type"] === "status_message") {
console.log("received status '" + data['status'] + "' for event '" + data['event_data'][0] + "' from server");


+ 1
- 1
requirements.txt View File

@@ -3,4 +3,4 @@ flask
flask_login
flask_socketio
requests
eventlet
gevent

Loading…
Cancel
Save