העתקת מערכות שלמות
-
אחרי שראיתי שיש דבר ניצרך להעתקת מערכות כתבתי קוד הקוד לפניכם השמח לתגובות
<?php set_time_limit(0); error_reporting(E_ALL); function apiGet($url) { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, ]); $res = curl_exec($ch); curl_close($ch); return json_decode($res, true); } function login($user, $pass) { $res = apiGet("https://call2all.co.il/ym/api/Login?path=ivr2:/&username=$user&password=$pass"); if (!isset($res['responseStatus']) || $res['responseStatus'] !== 'OK') { die("שגיאה בהתחברות"); } return $res['token']; } function uploadFile($token, $dstPath, $fileName, $content) { $url = "https://call2all.co.il/ym/api/UploadFile?path=$dstPath/$fileName&token=$token"; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $content, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, ]); curl_exec($ch); curl_close($ch); } function copyDir($srcToken, $dstToken, $srcPath, $dstPath) { $data = apiGet("https://call2all.co.il/ym/api/GetIVR2Dir?path=ivr2:$srcPath/&token=$srcToken"); if (!isset($data['responseStatus']) || $data['responseStatus'] !== 'OK') return; foreach ($data['files'] as $file) { $content = file_get_contents("https://call2all.co.il/ym/api/DownloadFile?path={$file['what']}&token=$srcToken"); uploadFile($dstToken, "ivr2:$dstPath", $file['name'], $content); echo "הועתק קובץ: {$file['name']}<br>"; flush(); } foreach ($data['dirs'] as $dir) { copyDir( $srcToken, $dstToken, trim($srcPath . '/' . $dir['name'], '/'), trim($dstPath . '/' . $dir['name'], '/') ); } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $srcUser = $_POST['src_user']; $srcPass = $_POST['src_pass']; $srcPath = trim($_POST['src_path'], '/'); $dstUser = $_POST['dst_user']; $dstPass = $_POST['dst_pass']; $dstPath = trim($_POST['dst_path'], '/'); echo "<h3>מתחיל העתקה...</h3>"; $srcToken = login($srcUser, $srcPass); $dstToken = login($dstUser, $dstPass); copyDir($srcToken, $dstToken, $srcPath, $dstPath); apiGet("https://call2all.co.il/ym/api/Logout?token=$srcToken"); apiGet("https://call2all.co.il/ym/api/Logout?token=$dstToken"); echo "<h2>ההעתקה הושלמה בהצלחה</h2>"; exit; } ?> <!DOCTYPE html> <html lang="he"> <head> <meta charset="UTF-8"> <title>העתקת מערכת</title> </head> <body> <h2>העתקת מערכת</h2> <form method="post"> מערכת מקור:<br> <input type="text" name="src_user" required><br> <input type="password" name="src_pass" required><br> שלוחה להעתקה (ריק = הכל):<br> <input type="text" name="src_path"><br><br> מערכת יעד:<br> <input type="text" name="dst_user" required><br> <input type="password" name="dst_pass" required><br> שלוחה יעד:<br> <input type="text" name="dst_path" required><br><br> <button type="submit">התחל העתקה</button> </form> </body> </html>גם בפיטון
from flask import Flask, request import requests app = Flask(__name__) def api_get(url): r = requests.get(url, verify=False) return r.json() def login(user, password): r = api_get(f"https://call2all.co.il/ym/api/Login?path=ivr2:/&username={user}&password={password}") if r.get("responseStatus") != "OK": raise Exception("Login failed") return r["token"] def upload_file(token, path, name, content): requests.post( f"https://call2all.co.il/ym/api/UploadFile?path={path}/{name}&token={token}", data=content, verify=False ) def copy_dir(src_token, dst_token, src_path, dst_path): data = api_get(f"https://call2all.co.il/ym/api/GetIVR2Dir?path=ivr2:{src_path}/&token={src_token}") if data.get("responseStatus") != "OK": return "" out = "" for f in data["files"]: content = requests.get( f"https://call2all.co.il/ym/api/DownloadFile?path={f['what']}&token={src_token}", verify=False ).content upload_file(dst_token, f"ivr2:{dst_path}", f["name"], content) out += f"הועתק קובץ: {f['name']}<br>" for d in data["dirs"]: out += copy_dir( src_token, dst_token, f"{src_path}/{d['name']}".strip("/"), f"{dst_path}/{d['name']}".strip("/") ) return out @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "POST": src_user = request.form["src_user"] src_pass = request.form["src_pass"] src_path = request.form["src_path"].strip("/") dst_user = request.form["dst_user"] dst_pass = request.form["dst_pass"] dst_path = request.form["dst_path"].strip("/") try: src_token = login(src_user, src_pass) dst_token = login(dst_user, dst_pass) result = copy_dir(src_token, dst_token, src_path, dst_path) api_get(f"https://call2all.co.il/ym/api/Logout?token={src_token}") api_get(f"https://call2all.co.il/ym/api/Logout?token={dst_token}") return "<h2>העתקה הושלמה</h2>" + result except Exception as e: return "שגיאה" return """ <html><body> <h2>העתקת מערכת</h2> <form method="post"> <h3>מערכת מקור</h3> מספר מערכת:<br><input name="src_user"><br> סיסמה:<br><input type="password" name="src_pass"><br> שלוחה (ריק = הכל):<br><input name="src_path"><br><br> <h3>מערכת יעד</h3> מספר מערכת:<br><input name="dst_user"><br> סיסמה:<br><input type="password" name="dst_pass"><br> שלוחה יעד:<br><input name="dst_path"><br><br> <button type="submit">התחל העתקה</button> </form> </body></html> """ if __name__ == "__main__": app.run(host="0.0.0.0", port=5000) -
@טנטפון איך משתמשים בקוד, היכן מפעילים אותו, והיכן מקבלים את כל הגיבוי?