Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- Dockerfile +33 -0
- app.py +79 -0
Dockerfile
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM ubuntu:20.04
|
2 |
+
|
3 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
4 |
+
|
5 |
+
RUN apt-get update && apt-get install -y --fix-missing --assume-yes \
|
6 |
+
tzdata \
|
7 |
+
xfce4 xfce4-goodies \
|
8 |
+
tightvncserver wget sudo curl python3 unzip xauth \
|
9 |
+
--no-install-recommends && apt-get clean
|
10 |
+
|
11 |
+
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && dpkg-reconfigure --frontend noninteractive tzdata
|
12 |
+
|
13 |
+
RUN useradd -m rdpuser && echo "rdpuser:123456" | chpasswd && adduser rdpuser sudo
|
14 |
+
|
15 |
+
RUN wget --no-check-certificate https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip \
|
16 |
+
&& unzip ngrok-stable-linux-amd64.zip \
|
17 |
+
&& mv ngrok /usr/local/bin/
|
18 |
+
|
19 |
+
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
|
20 |
+
&& apt-get install -y ./google-chrome-stable_current_amd64.deb \
|
21 |
+
&& rm google-chrome-stable_current_amd64.deb
|
22 |
+
|
23 |
+
RUN wget https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb \
|
24 |
+
&& apt-get install -y ./chrome-remote-desktop_current_amd64.deb \
|
25 |
+
&& rm chrome-remote-desktop_current_amd64.deb
|
26 |
+
|
27 |
+
|
28 |
+
COPY app.py /app.py
|
29 |
+
RUN chmod +x /app.py
|
30 |
+
|
31 |
+
EXPOSE 5901
|
32 |
+
|
33 |
+
CMD ["python3", "/app.py"]
|
app.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
import time
|
4 |
+
import threading
|
5 |
+
import logging
|
6 |
+
|
7 |
+
# إعداد logging لتوجيه الخرج إلى الـ console
|
8 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler()])
|
9 |
+
|
10 |
+
def setup_vnc():
|
11 |
+
os.makedirs("/home/rdpuser/.vnc", exist_ok=True)
|
12 |
+
|
13 |
+
vncpasswd_process = subprocess.Popen(['vncpasswd', '-f'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
14 |
+
vncpasswd_process.stdin.write(b'123456\n')
|
15 |
+
vncpasswd_process.stdin.close()
|
16 |
+
|
17 |
+
with open("/home/rdpuser/.vnc/passwd", "wb") as passwd_file:
|
18 |
+
passwd_file.write(vncpasswd_process.stdout.read())
|
19 |
+
|
20 |
+
os.chown("/home/rdpuser/.vnc/passwd", os.getuid(), os.getgid())
|
21 |
+
os.chmod("/home/rdpuser/.vnc/passwd", 0o600)
|
22 |
+
|
23 |
+
os.environ['USER'] = 'rdpuser'
|
24 |
+
|
25 |
+
# إنشاء ملف .Xauthority
|
26 |
+
subprocess.run(["touch", "/home/rdpuser/.Xauthority"])
|
27 |
+
|
28 |
+
# بدء TightVNC server
|
29 |
+
subprocess.run(["tightvncserver", ":1", "-geometry", "1280x800", "-depth", "24", "-dpi", "96"])
|
30 |
+
|
31 |
+
# def setup_ngrok():
|
32 |
+
# subprocess.run(["ngrok", "authtoken", "2eBbhxI0Cfq5Pl1t9GrXqe3SBhH_6XhF4gELgRpuaCGRoXRNq"])
|
33 |
+
|
34 |
+
# # بدء ngrok في عملية منفصلة وقراءة الخرج تدريجياً
|
35 |
+
# ngrok_process = subprocess.Popen(["ngrok", "tcp", "5901"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
36 |
+
|
37 |
+
# logging.info("Starting ngrok...")
|
38 |
+
# line = ngrok_process.stdout.readline()
|
39 |
+
# logging.info(line)
|
40 |
+
# while True:
|
41 |
+
# line = ngrok_process.stdout.readline()
|
42 |
+
# logging.info(line)
|
43 |
+
# if "tcp://" in line:
|
44 |
+
# logging.info(f"Ngrok is running. Access your VNC at: {line.strip()}")
|
45 |
+
# break
|
46 |
+
# if ngrok_process.poll() is not None:
|
47 |
+
# logging.error("Ngrok process ended unexpectedly")
|
48 |
+
# break
|
49 |
+
# time.sleep(1) # أضف تأخيراً لتجنب استخدام المعالج بشكل مفرط
|
50 |
+
|
51 |
+
# ngrok_process.stdout.close()
|
52 |
+
# ngrok_process.stderr.close()
|
53 |
+
|
54 |
+
# تشغيل إعداد VNC في thread تفرعي
|
55 |
+
# vnc_thread = threading.Thread(target=setup_vnc)
|
56 |
+
# vnc_thread.start()
|
57 |
+
|
58 |
+
# تشغيل إعداد ngrok وطباعة الرابط في الـ log على الـ main thread
|
59 |
+
# setup_ngrok()
|
60 |
+
|
61 |
+
# إبقاء الحاوية تعمل
|
62 |
+
# subprocess.run(["tail", "-f", "/dev/null"])
|
63 |
+
|
64 |
+
import os
|
65 |
+
import subprocess
|
66 |
+
import time
|
67 |
+
import threading
|
68 |
+
import logging
|
69 |
+
|
70 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler()])
|
71 |
+
|
72 |
+
def setup_chrome_remote_desktop():
|
73 |
+
subprocess.run(["/opt/google/chrome-remote-desktop/start-host", "--code=4/0AQlEd8xwsVmNvkm6m3vFqTE5xAFC9g9taQM622D5ds7vxMt38f9xlxZNuCR4QirnK9ulPA", "--redirect-url=https://remotedesktop.google.com/_/oauthredirect", "--name=MyRemoteDesktop", "--pin=123456"])
|
74 |
+
|
75 |
+
vnc_thread = threading.Thread(target=setup_chrome_remote_desktop)
|
76 |
+
vnc_thread.start()
|
77 |
+
|
78 |
+
subprocess.run(["tail", "-f", "/dev/null"])
|
79 |
+
|