Update main.py
Browse files
main.py
CHANGED
|
@@ -10,11 +10,8 @@ B_T = os.getenv("BOT_TOKEN")
|
|
| 10 |
S_K = os.getenv("PANEL_SECRET")
|
| 11 |
A_T = os.getenv("ADMIN_TELE_ID")
|
| 12 |
|
| 13 |
-
if C_V != K_I:
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
if not all([B_T, S_K, A_T]):
|
| 17 |
-
sys.exit(1)
|
| 18 |
|
| 19 |
app = FastAPI()
|
| 20 |
sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins="*")
|
|
@@ -24,43 +21,31 @@ A_I = int(A_T)
|
|
| 24 |
|
| 25 |
@bot.message_handler(commands=['start'])
|
| 26 |
def _s(m):
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
"π οΈ **MENU UTAMA:**\n"
|
| 30 |
-
"β `/daftar [user] [pass]`\n"
|
| 31 |
-
"β `/hapus [user]`\n"
|
| 32 |
-
"β `/list` (Admin Only)\n"
|
| 33 |
-
"β `/status` (Check System)\n\n"
|
| 34 |
-
"π **PANEL:** `READY`"
|
| 35 |
-
)
|
| 36 |
-
bot.reply_to(m, msg, parse_mode="Markdown")
|
| 37 |
|
| 38 |
@bot.message_handler(commands=['daftar'])
|
| 39 |
def _r(m):
|
| 40 |
try:
|
| 41 |
a = m.text.split()
|
| 42 |
if len(a) < 3: return
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
bot.reply_to(m, f"β
{u.upper()} AUTHORIZED.")
|
| 46 |
-
else:
|
| 47 |
-
bot.reply_to(m, "β ERROR.")
|
| 48 |
except: pass
|
| 49 |
|
| 50 |
@bot.message_handler(commands=['hapus'])
|
| 51 |
def _d(m):
|
| 52 |
if m.from_user.id != A_I: return
|
| 53 |
try:
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
bot.reply_to(m, "ποΈ DELETED.")
|
| 57 |
except: pass
|
| 58 |
|
| 59 |
@bot.message_handler(commands=['list'])
|
| 60 |
def _l(m):
|
| 61 |
if m.from_user.id != A_I: return
|
| 62 |
u = database.list_users()
|
| 63 |
-
bot.reply_to(m, "π₯ **
|
| 64 |
|
| 65 |
def _bt():
|
| 66 |
try:
|
|
@@ -69,7 +54,7 @@ def _bt():
|
|
| 69 |
except: pass
|
| 70 |
|
| 71 |
@app.on_event("startup")
|
| 72 |
-
async def
|
| 73 |
if not os.path.exists(W_R): os.makedirs(W_R, exist_ok=True)
|
| 74 |
await database.init_db()
|
| 75 |
threading.Thread(target=_bt, daemon=True).start()
|
|
@@ -84,7 +69,7 @@ def _au(r):
|
|
| 84 |
return None
|
| 85 |
|
| 86 |
@app.get("/")
|
| 87 |
-
def
|
| 88 |
|
| 89 |
@app.post("/login_api")
|
| 90 |
async def _lg(u: str = Form(...), p: str = Form(...)):
|
|
@@ -124,8 +109,7 @@ async def _ul(r: Request, f: UploadFile = File(...)):
|
|
| 124 |
if not u: return
|
| 125 |
w = _gw(u)
|
| 126 |
d = os.path.join(w, os.path.basename(f.filename))
|
| 127 |
-
with open(d, "wb") as o:
|
| 128 |
-
shutil.copyfileobj(f.file, o)
|
| 129 |
if d.endswith(".zip"):
|
| 130 |
try:
|
| 131 |
with zipfile.ZipFile(d, 'r') as z: z.extractall(w)
|
|
@@ -136,8 +120,7 @@ async def _mv(r: Request, d: dict):
|
|
| 136 |
u = _au(r)
|
| 137 |
if not u: return
|
| 138 |
w = _gw(u)
|
| 139 |
-
s = os.path.join(w, d['src'])
|
| 140 |
-
t = os.path.join(w, d['dst'])
|
| 141 |
if os.path.exists(s): shutil.move(s, t)
|
| 142 |
|
| 143 |
@app.delete("/api/delete/{n}")
|
|
@@ -164,7 +147,7 @@ async def _cn(sid, env):
|
|
| 164 |
os.chdir(w)
|
| 165 |
os.execvpe("bash", ["bash"], {**os.environ, "HOME": w, "TERM": "xterm-256color"})
|
| 166 |
_fm[sid] = fd
|
| 167 |
-
async def
|
| 168 |
while sid in _fm:
|
| 169 |
await asyncio.sleep(3)
|
| 170 |
await sio.emit('stats', {'cpu': psutil.cpu_percent(), 'ram': psutil.virtual_memory().percent}, room=sid)
|
|
@@ -173,7 +156,7 @@ async def _cn(sid, env):
|
|
| 173 |
await asyncio.sleep(0.01)
|
| 174 |
if _fm[sid] and select.select([_fm[sid]], [], [], 0)[0]:
|
| 175 |
await sio.emit('o', os.read(_fm[sid], 2048).decode(errors='ignore'), room=sid)
|
| 176 |
-
sio.start_background_task(
|
| 177 |
sio.start_background_task(_rp)
|
| 178 |
|
| 179 |
@sio.on('i')
|
|
|
|
| 10 |
S_K = os.getenv("PANEL_SECRET")
|
| 11 |
A_T = os.getenv("ADMIN_TELE_ID")
|
| 12 |
|
| 13 |
+
if C_V != K_I: sys.exit(1)
|
| 14 |
+
if not all([B_T, S_K, A_T]): sys.exit(1)
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
app = FastAPI()
|
| 17 |
sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins="*")
|
|
|
|
| 21 |
|
| 22 |
@bot.message_handler(commands=['start'])
|
| 23 |
def _s(m):
|
| 24 |
+
l = "β‘ **AQSO CORE** β‘\n\nβ `/daftar [user] [pass]`\nβ `/hapus [user]`\nβ `/list`"
|
| 25 |
+
bot.reply_to(m, l, parse_mode="Markdown")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
@bot.message_handler(commands=['daftar'])
|
| 28 |
def _r(m):
|
| 29 |
try:
|
| 30 |
a = m.text.split()
|
| 31 |
if len(a) < 3: return
|
| 32 |
+
if database.add_user(a[1], a[2]): bot.reply_to(m, "β
OK.")
|
| 33 |
+
else: bot.reply_to(m, "β ERROR.")
|
|
|
|
|
|
|
|
|
|
| 34 |
except: pass
|
| 35 |
|
| 36 |
@bot.message_handler(commands=['hapus'])
|
| 37 |
def _d(m):
|
| 38 |
if m.from_user.id != A_I: return
|
| 39 |
try:
|
| 40 |
+
database.del_user(m.text.split()[1])
|
| 41 |
+
bot.reply_to(m, "ποΈ OK.")
|
|
|
|
| 42 |
except: pass
|
| 43 |
|
| 44 |
@bot.message_handler(commands=['list'])
|
| 45 |
def _l(m):
|
| 46 |
if m.from_user.id != A_I: return
|
| 47 |
u = database.list_users()
|
| 48 |
+
bot.reply_to(m, "π₯ **USERS:**\n" + "\n".join(u) if u else "EMPTY")
|
| 49 |
|
| 50 |
def _bt():
|
| 51 |
try:
|
|
|
|
| 54 |
except: pass
|
| 55 |
|
| 56 |
@app.on_event("startup")
|
| 57 |
+
async def _os():
|
| 58 |
if not os.path.exists(W_R): os.makedirs(W_R, exist_ok=True)
|
| 59 |
await database.init_db()
|
| 60 |
threading.Thread(target=_bt, daemon=True).start()
|
|
|
|
| 69 |
return None
|
| 70 |
|
| 71 |
@app.get("/")
|
| 72 |
+
def _id(): return HTMLResponse(ui_templates.PANEL_UI)
|
| 73 |
|
| 74 |
@app.post("/login_api")
|
| 75 |
async def _lg(u: str = Form(...), p: str = Form(...)):
|
|
|
|
| 109 |
if not u: return
|
| 110 |
w = _gw(u)
|
| 111 |
d = os.path.join(w, os.path.basename(f.filename))
|
| 112 |
+
with open(d, "wb") as o: shutil.copyfileobj(f.file, o)
|
|
|
|
| 113 |
if d.endswith(".zip"):
|
| 114 |
try:
|
| 115 |
with zipfile.ZipFile(d, 'r') as z: z.extractall(w)
|
|
|
|
| 120 |
u = _au(r)
|
| 121 |
if not u: return
|
| 122 |
w = _gw(u)
|
| 123 |
+
s, t = os.path.join(w, d['src']), os.path.join(w, d['dst'])
|
|
|
|
| 124 |
if os.path.exists(s): shutil.move(s, t)
|
| 125 |
|
| 126 |
@app.delete("/api/delete/{n}")
|
|
|
|
| 147 |
os.chdir(w)
|
| 148 |
os.execvpe("bash", ["bash"], {**os.environ, "HOME": w, "TERM": "xterm-256color"})
|
| 149 |
_fm[sid] = fd
|
| 150 |
+
async def _st():
|
| 151 |
while sid in _fm:
|
| 152 |
await asyncio.sleep(3)
|
| 153 |
await sio.emit('stats', {'cpu': psutil.cpu_percent(), 'ram': psutil.virtual_memory().percent}, room=sid)
|
|
|
|
| 156 |
await asyncio.sleep(0.01)
|
| 157 |
if _fm[sid] and select.select([_fm[sid]], [], [], 0)[0]:
|
| 158 |
await sio.emit('o', os.read(_fm[sid], 2048).decode(errors='ignore'), room=sid)
|
| 159 |
+
sio.start_background_task(_st)
|
| 160 |
sio.start_background_task(_rp)
|
| 161 |
|
| 162 |
@sio.on('i')
|