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:
SpudGunMan
2025-10-02 18:58:27 -07:00
parent b47c13503b
commit 2e8206d4ec
5 changed files with 37 additions and 1 deletions
+26 -1
View File
@@ -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"
+1
View File
@@ -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
+4
View File
@@ -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(", ")