mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-07-06 01:41:45 +02:00
x:ShellCommands
this x: is a direct shell access from DM, to enable it needs the enable_runShellCmd, allowXcmd, xcmdChannel set. Make sure your secure.
This commit is contained in:
+26
-1
@@ -82,4 +82,29 @@ def call_external_script(message, script="script/runShell.sh"):
|
||||
except Exception as e:
|
||||
logger.warning(f"FileMon: Error calling external script: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def handleShellCmd(message, message_from_id, channel_number, isDM, deviceID):
|
||||
if not allowXcmd:
|
||||
return "x: command is disabled"
|
||||
|
||||
if str(message_from_id) not in bbs_admin_list:
|
||||
logger.warning(f"FileMon: Unauthorized x: command attempt from {message_from_id}")
|
||||
return "x: command not authorized"
|
||||
|
||||
if not isDM:
|
||||
return "x: command not authorized in group chat"
|
||||
|
||||
if enable_runShellCmd:
|
||||
command = message.removeprefix("x: ").strip()
|
||||
try:
|
||||
logger.info(f"FileMon: Running shell command from {message_from_id}: {command}")
|
||||
output = os.popen(command).read().encode('utf-8').decode('utf-8')
|
||||
if output:
|
||||
return output
|
||||
else:
|
||||
return "x: command returned no output"
|
||||
except Exception as e:
|
||||
logger.warning(f"FileMon: Error running shell command: {e}")
|
||||
return "x: command error"
|
||||
else:
|
||||
return "x: command is disabled"
|
||||
@@ -357,6 +357,7 @@ try:
|
||||
news_file_path = config['fileMon'].get('news_file_path', 'news.txt') # default news.txt
|
||||
news_random_line_only = config['fileMon'].getboolean('news_random_line', False) # default False
|
||||
enable_runShellCmd = config['fileMon'].getboolean('enable_runShellCmd', False) # default False
|
||||
allowXcmd = config['fileMon'].getboolean('allowXcmd', False) # default False
|
||||
|
||||
# games
|
||||
game_hop_limit = config['messagingSettings'].getint('game_hop_limit', 5) # default 3 hops
|
||||
|
||||
@@ -260,6 +260,10 @@ if file_monitor_enabled or read_news_enabled or bee_enabled:
|
||||
# Bee Configuration uses file monitor module
|
||||
if bee_enabled:
|
||||
trap_list = trap_list + ("🐝",)
|
||||
# x: command for shell access
|
||||
if enable_runShellCmd and allowXcmd:
|
||||
trap_list = trap_list + ("x:",)
|
||||
help_message = help_message + ", x:"
|
||||
|
||||
# clean up the help message
|
||||
help_message = help_message.split(", ")
|
||||
|
||||
Reference in New Issue
Block a user