INNER CODE UNIT · Python
do_POST
sailor-sh/CK-X · remote-desktop/agent.py:14
def do_POST(self):
if self.path == '/clipboard-paste':
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length).decode("utf-8")
try:
data = json.loads(post_data)
clipboard_content = data.get("content")
if not clipboard_content:
self.respond(400, {"error": "Missing clipboard content"})
return
clipboard_content = clipboard_content.replace("'", "'\\''")
command = "echo -n '" + clipboard_content + "' | xclip -selection clipboard &"
subprocess.Popen(command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
self.respond(200, {})
except Exception as e: