cfdlbrz commited on
Commit
bab5cff
·
verified ·
1 Parent(s): 5fd09be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -16
app.py CHANGED
@@ -1,19 +1,32 @@
1
  import subprocess
2
  import re
 
3
  import requests
 
 
 
4
  from flask import Flask, request
5
- from apscheduler.schedulers.asyncio import AsyncIOScheduler
6
  app = Flask(__name__)
7
 
8
- scheduler = AsyncIOScheduler()
9
- scheduler.start()
10
- def check(ip,user,pas):
11
- print("شروع")
12
- command = ["hydra", "-t", "4", "-l", f"{user}", "-p", f"{pas}", f"rdp://{ip}"]
13
- result = subprocess.run(command, capture_output=True, text=True)
14
- output = result.stdout
15
- print(output)
16
- return
 
 
 
 
 
 
 
 
 
 
17
 
18
  @app.route('/', methods=['GET'])
19
  def index():
@@ -24,15 +37,22 @@ def go():
24
  ip = request.args.get('ip')
25
  user = request.args.get('user')
26
  pas = request.args.get('pas')
27
- job = scheduler.add_job(check, 'interval', seconds=0,args=[ip, user, pas])
28
- return job.id
29
-
 
 
30
 
31
  @app.route('/del', methods=['GET'])
32
  def killjob():
33
- id = request.args.get('id')
34
- scheduler.remove_job(id)
35
- return "OK"
 
 
 
 
 
36
 
37
  if __name__ == '__main__':
38
  app.run(host="0.0.0.0", port=7860)
 
1
  import subprocess
2
  import re
3
+ from time import sleep
4
  import requests
5
+ import asyncio
6
+ import threading
7
+ import time
8
  from flask import Flask, request
 
9
  app = Flask(__name__)
10
 
11
+ task_ids = {} # دیکشنری برای ذخیره ایدی و thread object ها
12
+
13
+ async def test_function(ip,user,pas,task_id):
14
+ while task_id in task_ids:
15
+ command = ["hydra", "-t", "4", "-l", f"{user}", "-p", f"{pas}", f"rdp://{ip}"]
16
+ result = subprocess.run(command, capture_output=True, text=True)
17
+
18
+ async def ejra(ip,user,pas,task_id):
19
+ task_ids[task_id] = asyncio.create_task(test_function(ip,user,pas,task_id))
20
+
21
+ def stop_task(task_id):
22
+ if task_id in task_ids:
23
+ task = task_ids[task_id]
24
+ task.cancel()
25
+ del task_ids[task_id]
26
+ print(f"Task {task_id} stopped.")
27
+ else:
28
+ print(f"Task {task_id} not found.")
29
+
30
 
31
  @app.route('/', methods=['GET'])
32
  def index():
 
37
  ip = request.args.get('ip')
38
  user = request.args.get('user')
39
  pas = request.args.get('pas')
40
+
41
+ task_id = len(task_ids) + 1
42
+ threading.Thread(target=lambda: asyncio.run(ejra(ip,user,pas,task_id))).start()
43
+
44
+ return f"Job started with ID: {task_id}"
45
 
46
  @app.route('/del', methods=['GET'])
47
  def killjob():
48
+ task_id = int(request.args.get('id'))
49
+ if task_id in task_ids:
50
+ task = task_ids[task_id]
51
+ task.cancel()
52
+ del task_ids[task_id]
53
+ return f"Task {task_id} stopped."
54
+ else:
55
+ return f"Task {task_id} not found."
56
 
57
  if __name__ == '__main__':
58
  app.run(host="0.0.0.0", port=7860)