imrasya commited on
Commit
917cec6
1 Parent(s): 67ff62f
Files changed (3) hide show
  1. Dockerfile +23 -0
  2. main.py +51 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu
2
+
3
+ RUN apt-get update && \
4
+ apt-get install -y \
5
+ ffmpeg \
6
+ imagemagick \
7
+ webp && \
8
+ apt-get upgrade -y && \
9
+ rm -rf /var/lib/apt/lists/*
10
+
11
+ WORKDIR /app
12
+
13
+ COPY requirements.txt .
14
+
15
+ RUN pip install -r requirements.txt
16
+
17
+ COPY . .
18
+
19
+ EXPOSE 7860
20
+
21
+ RUN chmod -R 777 /app
22
+
23
+ CMD ["python", "main.py"]
main.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import paramiko
2
+ import os
3
+ from flask import Flask
4
+ import threading
5
+
6
+ # Install OpenSSH Server
7
+ os.system('sudo apt update && sudo apt install -y openssh-server')
8
+
9
+ # Start the SSH service and enable it to start on boot
10
+ os.system('sudo systemctl start ssh && sudo systemctl enable ssh')
11
+
12
+ # Ubah port SSH menjadi 7860
13
+ os.system("sudo sed -i 's/#Port 22/Port 7860/' /etc/ssh/sshd_config")
14
+
15
+ # Restart SSH service untuk menerapkan perubahan
16
+ os.system('sudo systemctl restart ssh')
17
+
18
+ # Inisialisasi aplikasi Flask
19
+ app = Flask(__name__)
20
+
21
+ @app.route('/')
22
+ def index():
23
+ return 'Hello, this is a simple Flask server running concurrently with SSH connection!'
24
+
25
+ def ssh_connection():
26
+ hostname = '107.23.216.183'
27
+ port = 7860 # Port SSH yang telah diubah
28
+ username = 'root'
29
+ password = 'pass'
30
+
31
+ # Membuat instance SSHClient
32
+ client = paramiko.SSHClient()
33
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
34
+
35
+ # Menghubungkan ke server SSH menggunakan password
36
+ try:
37
+ client.connect(hostname, port, username, password)
38
+
39
+ # Menjalankan perintah di server
40
+ stdin, stdout, stderr = client.exec_command('ls -la')
41
+ print(stdout.read().decode())
42
+ finally:
43
+ client.close()
44
+
45
+ # Jalankan koneksi SSH di thread terpisah
46
+ ssh_thread = threading.Thread(target=ssh_connection)
47
+ ssh_thread.start()
48
+
49
+ # Jalankan aplikasi Flask
50
+ if __name__ == '__main__':
51
+ app.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Flask
2
+ paramiko