unmovable.fix

main
Satur@it-depot.ru 2025-03-11 11:08:59 +03:00
parent c3ad744421
commit f472d2a6ca
1 changed files with 244 additions and 374 deletions

618
app.py
View File

@ -1,396 +1,266 @@
from fastapi import FastAPI, HTTPException, File, UploadFile, Form, Query, WebSocket, WebSocketDisconnect $ErrorActionPreference = 'silentlycontinue'
from pydantic import BaseModel
import sqlite3
import datetime
import csv
import markdown
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse, StreamingResponse
import io
import os
from fastapi.middleware.cors import CORSMiddleware
from werkzeug.utils import secure_filename
import json
# Создаем два экземпляра FastAPI # Формируем пароль из зашифрованных частей
web_app = FastAPI(title="Web Interface") # Для веб-интерфейса (порт 8001) $p1 = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("cDk4"))
api_app = FastAPI(title="API Endpoints") # Для API (порт 8002) $p2 = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("Nng="))
$p3 = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("Yjc4"))
$rustdesk_pw = $p1 + $p2 + $p3
# Общий код для подключения к базе данных # Get your config string from your Web portal and Fill Below
conn = sqlite3.connect("/db/rustdesk.db", check_same_thread=False) $rustdesk_cfg = "0nI1JnL09GclRWL0lmL0NXdy9yL6MHc0RHaiojIpBXYiwiI9gjYwBjbXVERFRXZiNEVYBjRGdHUZhUUvBVRx52dWlmenlTY6t0U1IlMLhlI6ISeltmIsISdy5CdvBXZk1Cdp5CdzVnciojI5FGblJnIsISdy5CdvBXZk1Cdp5CdzVnciojI0N3boJye"
cursor = conn.cursor()
# Проверяем и обновляем структуру таблицы installs ################################### Please Do Not Edit Below This Line #########################################
cursor.execute("PRAGMA table_info(installs)")
columns = [row[1] for row in cursor.fetchall()]
if 'protocol' not in columns:
cursor.execute("ALTER TABLE installs ADD COLUMN protocol TEXT DEFAULT 'rustdesk'")
conn.commit()
if 'note' not in columns:
cursor.execute("ALTER TABLE installs ADD COLUMN note TEXT DEFAULT ''")
conn.commit()
if 'last_seen' not in columns:
cursor.execute("ALTER TABLE installs ADD COLUMN last_seen TEXT DEFAULT NULL")
conn.commit()
# Создаем таблицы # Run as administrator and stays in the current directory
cursor.execute(""" if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
CREATE TABLE IF NOT EXISTS folders ( if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
id INTEGER PRIMARY KEY AUTOINCREMENT, Start-Process PowerShell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
name TEXT NOT NULL, Exit;
parent_id INTEGER,
FOREIGN KEY (parent_id) REFERENCES folders(id)
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS installs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
rust_id TEXT,
computer_name TEXT,
install_time TEXT,
folder_id INTEGER,
protocol TEXT DEFAULT 'rustdesk',
note TEXT DEFAULT '',
last_seen TEXT DEFAULT NULL,
FOREIGN KEY (folder_id) REFERENCES folders(id)
)
""")
conn.commit()
# Проверяем/создаем папку "Несортированные" и получаем её ID
cursor.execute("SELECT id FROM folders WHERE name = 'Несортированные'")
unsorted_folder = cursor.fetchone()
if not unsorted_folder:
cursor.execute("INSERT INTO folders (name) VALUES ('Несортированные')")
conn.commit()
unsorted_folder_id = cursor.lastrowid
else:
unsorted_folder_id = unsorted_folder[0]
# Папка для загрузки изображений
UPLOAD_FOLDER = "/app/uploads"
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
# Монтируем папку uploads для доступа к изображениям
api_app.mount("/uploads", StaticFiles(directory=UPLOAD_FOLDER), name="uploads")
web_app.mount("/uploads", StaticFiles(directory=UPLOAD_FOLDER), name="uploads")
# Модели данных
class Folder(BaseModel):
name: str
parent_id: int | None = None
class FolderUpdate(BaseModel):
name: str
class InstallData(BaseModel):
rust_id: str | None = None
computer_name: str | None = None
install_time: str | None = None
folder_id: int | None = None
protocol: str | None = 'rustdesk'
note: str | None = ''
last_seen: str | None = None # Добавлено для поддержки обновлений статуса
# Функция форматирования времени
def format_time(time_str):
if not time_str:
return None
try:
dt = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S.%fZ")
return dt.strftime("%Y-%m-%d %H:%M:%S")
except ValueError:
try:
dt = datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S")
return dt.strftime("%Y-%m-%d %H:%M:%S")
except ValueError:
return time_str
# Монтируем папки templates и icons
web_app.mount("/templates", StaticFiles(directory="templates"), name="templates")
web_app.mount("/icons", StaticFiles(directory="templates/icons"), name="icons")
# Веб-интерфейс
@web_app.get("/")
async def root():
return FileResponse("templates/index.html")
# WebSocket для отправки обновлений статуса
class ConnectionManager:
def __init__(self):
self.active_connections: list[WebSocket] = []
self.max_connections = 100 # Ограничение числа подключений
async def connect(self, websocket: WebSocket):
if len(self.active_connections) >= self.max_connections:
await websocket.close(code=1008, reason="Too many connections")
return
await websocket.accept()
self.active_connections.append(websocket)
def disconnect(self, websocket: WebSocket):
self.active_connections.remove(websocket)
async def broadcast(self, message: str):
for connection in self.active_connections[:]: # Копируем список для безопасного удаления
await connection.send_text(message)
manager = ConnectionManager()
@api_app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await manager.connect(websocket)
try:
while True:
data = await websocket.receive_text()
except WebSocketDisconnect:
manager.disconnect(websocket)
# API-эндпоинты
@api_app.get("/api/folders")
def get_folders():
cursor.execute("SELECT * FROM folders")
rows = cursor.fetchall()
return [{"id": row[0], "name": row[1], "parent_id": row[2]} for row in rows]
@api_app.post("/api/folders")
def add_folder(folder: Folder):
cursor.execute("INSERT INTO folders (name, parent_id) VALUES (?, ?)",
(folder.name, folder.parent_id))
conn.commit()
return {"status": "success", "id": cursor.lastrowid}
@api_app.put("/api/folders/{folder_id}")
def update_folder(folder_id: int, folder: FolderUpdate):
cursor.execute("UPDATE folders SET name = ? WHERE id = ?", (folder.name, folder_id))
conn.commit()
if cursor.rowcount == 0:
raise HTTPException(status_code=404, detail="Папка не найдена")
return {"status": "success"}
@api_app.delete("/api/folders/{folder_id}")
def delete_folder(folder_id: int):
cursor.execute("SELECT name FROM folders WHERE id = ?", (folder_id,))
folder_name = cursor.fetchone()
if folder_name and folder_name[0] == 'Несортированные':
raise HTTPException(status_code=403, detail="Папка 'Несортированные' не может быть удалена")
cursor.execute("DELETE FROM folders WHERE id = ?", (folder_id,))
conn.commit()
if cursor.rowcount == 0:
raise HTTPException(status_code=404, detail="Папка не найдена")
return {"status": "success"}
@api_app.get("/api/installs")
def get_installs():
cursor.execute("""
SELECT i.id, i.rust_id, i.computer_name, i.install_time, i.folder_id, f.name as folder_name, i.protocol, i.note, i.last_seen
FROM installs i
LEFT JOIN folders f ON i.folder_id = f.id
""")
rows = cursor.fetchall()
return [{"id": row[0], "rust_id": row[1], "computer_name": row[2],
"install_time": format_time(row[3]),
"folder_id": row[4], "folder_name": row[5], "protocol": row[6], "note": row[7], "last_seen": row[8]}
for row in rows]
@api_app.post("/api/install")
async def add_install(data: InstallData):
rust_id = data.rust_id
computer_name = data.computer_name or f"PC_{rust_id}"
install_time = data.install_time or datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
folder_id = data.folder_id if data.folder_id is not None else unsorted_folder_id
protocol = data.protocol or 'rustdesk'
note = data.note or ''
last_seen = data.last_seen or datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
cursor.execute("SELECT id FROM installs WHERE rust_id = ?", (rust_id,))
existing = cursor.fetchone()
if existing:
cursor.execute("""
UPDATE installs
SET computer_name = ?, install_time = ?, folder_id = ?, protocol = ?, note = ?, last_seen = ?
WHERE rust_id = ?
""", (computer_name, install_time, folder_id, protocol, note, last_seen, rust_id))
else:
cursor.execute("""
INSERT INTO installs (rust_id, computer_name, install_time, folder_id, protocol, note, last_seen)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (rust_id, computer_name, install_time, folder_id, protocol, note, last_seen))
conn.commit()
# Получаем обновленную запись
cursor.execute("""
SELECT id, rust_id, computer_name, install_time, folder_id, protocol, note, last_seen
FROM installs WHERE rust_id = ?
""", (rust_id,))
updated_install = cursor.fetchone()
install_data = {
"id": updated_install[0],
"rust_id": updated_install[1],
"computer_name": updated_install[2],
"install_time": format_time(updated_install[3]),
"folder_id": updated_install[4],
"protocol": updated_install[5],
"note": updated_install[6],
"last_seen": updated_install[7]
} }
# Отправляем только обновленную запись через WebSocket }
await manager.broadcast(json.dumps({"type": "update", "data": install_data}))
return {"status": "success"} # Проверка наличия установленного RustDesk
$rustdeskInstalled = Test-Path "$env:ProgramFiles\RustDesk\rustdesk.exe"
$rdver = ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RustDesk\" -ErrorAction SilentlyContinue).Version)
@api_app.put("/api/install/{install_id}") if ($rustdeskInstalled -and $rdver) {
def update_install(install_id: int, data: InstallData): echo "RustDesk $rdver is already installed. Importing configuration..."
cursor.execute("SELECT rust_id, computer_name, install_time, folder_id, protocol, note FROM installs WHERE id = ?", (install_id,)) cd $env:ProgramFiles\RustDesk
current = cursor.fetchone() .\rustdesk.exe --config $rustdesk_cfg
if not current: .\rustdesk.exe --password $rustdesk_pw
raise HTTPException(status_code=404, detail="Запись не найдена") } else {
$localRustDesk = Join-Path $PSScriptRoot "rustdesk.exe"
new_rust_id = data.rust_id if data.rust_id is not None else current[0] $rustdeskExistsLocally = Test-Path $localRustDesk
new_computer_name = data.computer_name if data.computer_name is not None else current[1]
new_install_time = data.install_time if data.install_time is not None else current[2]
new_folder_id = data.folder_id if data.folder_id is not None else current[3]
new_protocol = data.protocol if data.protocol is not None else current[4]
new_note = data.note if data.note is not None else current[5]
if new_install_time: if (-not $rustdeskExistsLocally) {
try: $url = 'https://www.github.com//rustdesk/rustdesk/releases/latest'
datetime.datetime.strptime(new_install_time, "%Y-%m-%d %H:%M:%S") $request = [System.Net.WebRequest]::Create($url)
except ValueError: $response = $request.GetResponse()
raise HTTPException(status_code=400, detail="Неверный формат времени. Используйте YYYY-MM-DD HH:MM:SS") $realTagUrl = $response.ResponseUri.OriginalString
else: $RDLATEST = $realTagUrl.split('/')[-1].Trim('v')
new_install_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") echo "RustDesk $RDLATEST is the latest version."
} else {
cursor.execute(""" $RDLATEST = "local"
UPDATE installs
SET rust_id = ?, computer_name = ?, install_time = ?, folder_id = ?, protocol = ?, note = ?
WHERE id = ?
""", (new_rust_id, new_computer_name, new_install_time, new_folder_id, new_protocol, new_note, install_id))
conn.commit()
return {"status": "success"}
@api_app.delete("/api/install/{install_id}")
def delete_install(install_id: int):
cursor.execute("DELETE FROM installs WHERE id = ?", (install_id,))
conn.commit()
if cursor.rowcount == 0:
raise HTTPException(status_code=404, detail="Запись не найдена")
return {"status": "success"}
@api_app.get("/api/export/csv")
async def export_csv(folder_id: int | None = Query(None, description="ID папки для экспорта, если None - экспортировать все папки")):
if folder_id:
cursor.execute("""
SELECT i.rust_id, i.computer_name, i.install_time, f.name as folder_name, i.protocol, i.note, i.last_seen
FROM installs i
LEFT JOIN folders f ON i.folder_id = f.id
WHERE i.folder_id = ?
""", (folder_id,))
else:
cursor.execute("""
SELECT i.rust_id, i.computer_name, i.install_time, f.name as folder_name, i.protocol, i.note, i.last_seen
FROM installs i
LEFT JOIN folders f ON i.folder_id = f.id
""")
rows = cursor.fetchall()
output = io.StringIO()
writer = csv.writer(output, lineterminator='\n')
writer.writerow(['ID подключения', 'Имя компьютера', 'Время установки', 'Папка', 'Протокол', 'Заметка', 'Последнее подключение'])
for row in rows:
install_time = format_time(row[2]) if row[2] else ""
last_seen = format_time(row[6]) if row[6] else ""
writer.writerow([row[0], row[1], install_time, row[3], row[4], row[5], last_seen])
headers = {
'Content-Disposition': 'attachment; filename="rustdesk_data.csv"',
'Content-Type': 'text/csv'
} }
return StreamingResponse(iter([output.getvalue()]), headers=headers)
@api_app.post("/api/import/csv") if (!(Test-Path C:\ProgramData\RustDesk)) {
async def import_csv(file: UploadFile = File(...), folder_id: int | None = Query(None, description="ID папки для импорта, если None - использовать 'Несортированные'")): New-Item -ItemType Directory -Force -Path C:\ProgramData\RustDesk > null
try: }
contents = await file.read()
csv_data = io.StringIO(contents.decode('utf-8'))
reader = csv.DictReader(csv_data)
target_folder_id = folder_id if folder_id is not None else unsorted_folder_id cd C:\ProgramData\RustDesk
for row in reader: if ($rustdeskExistsLocally) {
rust_id = row['ID подключения'] echo "Found local rustdesk.exe, using it for installation."
computer_name = row['Имя компьютера'] Copy-Item -Path $localRustDesk -Destination ".\rustdesk.exe" -Force
install_time = row['Время установки'] } else {
folder_name = row.get('Папка', None) echo "Downloading RustDesk version $RDLATEST."
protocol = row.get('Протокол', 'rustdesk') powershell Invoke-WebRequest "https://github.com/rustdesk/rustdesk/releases/download/$RDLATEST/rustdesk-$RDLATEST-x86_64.exe" -Outfile "rustdesk.exe"
note = row.get('Заметка', '') }
cursor.execute("SELECT id FROM installs WHERE rust_id = ?", (rust_id,)) echo "Installing RustDesk."
if cursor.fetchone(): Start-Process .\rustdesk.exe --silent-install
continue Start-Sleep -Seconds 10
if install_time: $ServiceName = 'rustdesk'
try: $arrService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
dt = datetime.datetime.strptime(install_time, "%Y-%m-%d %H:%M:%S")
install_time = dt.strftime("%Y-%m-%d %H:%M:%S")
except ValueError:
try:
dt = datetime.datetime.strptime(install_time, "%Y-%m-%dT%H:%M:%S.%fZ")
install_time = dt.strftime("%Y-%m-%d %H:%M:%S")
except ValueError:
raise HTTPException(status_code=400, detail=f"Неверный формат времени для записи с ID {rust_id}. Используйте YYYY-MM-DD HH:MM:SS или ISO 8601")
if folder_name: if ($arrService -eq $null) {
cursor.execute("SELECT id FROM folders WHERE name = ?", (folder_name,)) echo "Installing service."
folder = cursor.fetchone() cd $env:ProgramFiles\RustDesk
folder_id = folder[0] if folder else unsorted_folder_id Start-Process .\rustdesk.exe --install-service -wait -Verbose
else: Start-Sleep -Seconds 20
folder_id = target_folder_id }
cursor.execute(""" while ($arrService.Status -ne 'Running') {
INSERT INTO installs (rust_id, computer_name, install_time, folder_id, protocol, note) Start-Service $ServiceName
VALUES (?, ?, ?, ?, ?, ?) Start-Sleep -seconds 5
""", (rust_id, computer_name, install_time, folder_id, protocol, note)) $arrService.Refresh()
}
conn.commit()
return {"status": "success", "message": "Данные успешно импортированы"}
except Exception as e:
raise HTTPException(status_code=400, detail=f"Ошибка импорта: {str(e)}")
@api_app.post("/api/upload-image") echo "Please wait a few seconds."
async def upload_image(install_id: int = Form(...), file: UploadFile = File(...)): Start-Sleep -Seconds 10
if not file.filename: Remove-Item -Path "C:\ProgramData\RustDesk\rustdesk.exe" -Force
raise HTTPException(status_code=400, detail="No file provided") echo "Temporary installation files have been cleaned up."
cd $env:ProgramFiles\RustDesk
allowed_extensions = {'png', 'jpg', 'jpeg', 'gif'} echo "Inputting configuration now."
if not secure_filename(file.filename).rsplit('.', 1)[1].lower() in allowed_extensions: .\rustdesk.exe --config $rustdesk_cfg
raise HTTPException(status_code=400, detail="Invalid file format. Use png, jpg, jpeg, or gif") .\rustdesk.exe --password $rustdesk_pw
}
filename = secure_filename(f"{install_id}_{file.filename}") # Добавляем папку RustDesk в исключения Windows Defender
file_path = os.path.join(UPLOAD_FOLDER, filename) $defenderPath = "C:\Program Files\RustDesk"
try {
Add-MpPreference -ExclusionPath $defenderPath -ErrorAction Stop
echo "Added $defenderPath to Windows Defender exclusions."
} catch {
echo "Failed to add $defenderPath to Windows Defender exclusions: $_"
}
with open(file_path, "wb") as buffer: # Удаляем ярлык с общего рабочего стола
buffer.write(await file.read()) $publicDesktop = "C:\Users\Public\Desktop\RustDesk.lnk"
if (Test-Path $publicDesktop) {
Remove-Item -Path $publicDesktop -Force
echo "Removed RustDesk shortcut from Public Desktop."
}
url = f"/uploads/{filename}" # Создаем папку RustDesk в меню Пуск под Critical Fixes
return {"url": url} $startMenuPath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Critical Fixes\RustDesk"
if (!(Test-Path $startMenuPath)) {
New-Item -ItemType Directory -Force -Path $startMenuPath
}
# CORS для API $shortcutPath = "$startMenuPath\RustDesk.lnk"
api_app.add_middleware( $shell = New-Object -ComObject WScript.Shell
CORSMiddleware, $shortcut = $shell.CreateShortcut($shortcutPath)
allow_origins=["https://rd.it-depot.ru"], # Обновлено для HTTPS $shortcut.TargetPath = "$env:ProgramFiles\RustDesk\rustdesk.exe"
allow_credentials=True, $shortcut.Save()
allow_methods=["*"], echo "Created RustDesk shortcut in Start Menu under Critical Fixes\RustDesk."
allow_headers=["*"],
)
# CORS для веб-интерфейса # Удаляем папку RustDesk из корня Programs
web_app.add_middleware( $rustDeskStartMenu = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\RustDesk"
CORSMiddleware, if (Test-Path $rustDeskStartMenu) {
allow_origins=["https://rd.it-depot.ru"], # Обновлено для HTTPS Remove-Item -Path $rustDeskStartMenu -Recurse -Force
allow_credentials=True, echo "Removed RustDesk folder from Start Menu Programs."
allow_methods=["*"], }
allow_headers=["*"],
) # Добавляем параметры в конфигурационные файлы
$configPath = "$env:USERPROFILE\AppData\Roaming\RustDesk\config"
$config2Path = "$configPath\RustDesk2.toml"
$configLocalPath = "$configPath\RustDesk_local.toml"
if (!(Test-Path $configPath)) {
New-Item -ItemType Directory -Force -Path $configPath
}
if (!(Test-Path $config2Path)) {
"[options]`nallow-remote-config-modification = 'Y'" | Out-File -FilePath $config2Path -Encoding utf8
} else {
$content = Get-Content $config2Path
if (!($content -match "allow-remote-config-modification")) {
if ($content -match "\[options\]") {
$content = $content -replace "\[options\]", "[options]`nallow-remote-config-modification = 'Y'"
} else {
$content += "`n[options]`nallow-remote-config-modification = 'Y'"
}
$content | Out-File -FilePath $config2Path -Encoding utf8
}
}
if (!(Test-Path $configLocalPath)) {
"[options]`ntheme = 'dark'" | Out-File -FilePath $configLocalPath -Encoding utf8
} else {
$content = Get-Content $configLocalPath
if (!($content -match "theme")) {
if ($content -match "\[options\]") {
$content = $content -replace "\[options\]", "[options]`ntheme = 'dark'"
} else {
$content += "`n[options]`ntheme = 'dark'"
}
$content | Out-File -FilePath $configLocalPath -Encoding utf8
}
}
# Создание BAT-файла для удаления
$uninstallBatPath = "$env:ProgramFiles\RustDesk\Uninstall RustDesk.bat"
$uninstallBatContent = @"
@echo off
echo Stopping RustDeskOnlineCheck task...
schtasks /End /TN "RustDeskOnlineCheck"
timeout /t 2 >nul
echo Deleting RustDeskOnlineCheck task...
schtasks /Delete /TN "RustDeskOnlineCheck" /F
echo Stopping RustDesk service...
sc stop rustdesk
timeout /t 2 >nul
echo Uninstalling RustDesk...
"C:\Program Files\RustDesk\rustdesk.exe" --uninstall
echo Cleaning up files...
rd /s /q "C:\ProgramData\RustDesk"
rd /s /q "%appdata%\RustDesk"
rd /s /q "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Critical Fixes\RustDesk"
echo Removing Windows Defender exclusion...
powershell -Command "Remove-MpPreference -ExclusionPath 'C:\Program Files\RustDesk'" 2>nul
echo RustDesk has been completely removed.
pause
"@
# Удаляем существующий ярлык Uninstall RustDesk, если он есть
$uninstallLnkPath = "$env:ProgramFiles\RustDesk\Uninstall RustDesk.lnk"
if (Test-Path $uninstallLnkPath) {
Remove-Item -Path $uninstallLnkPath -Force
echo "Removed original Uninstall RustDesk shortcut."
}
# Создаем BAT-файл в папке RustDesk
$uninstallBatContent | Out-File -FilePath $uninstallBatPath -Encoding ASCII
echo "Created Uninstall RustDesk.bat in $env:ProgramFiles\RustDesk"
# Копируем BAT-файл в Critical Fixes\RustDesk
Copy-Item -Path $uninstallBatPath -Destination "$startMenuPath\Uninstall RustDesk.bat" -Force
echo "Copied Uninstall RustDesk.bat to $startMenuPath"
$rustdesk_id = .\rustdesk.exe --get-id | Write-Output -OutVariable rustdesk_id
echo "All done! Please double check the Network settings tab in RustDesk."
echo ""
echo "..............................................."
echo "RustDesk ID: $rustdesk_id"
$RustID = $rustdesk_id
$ComputerName = $env:COMPUTERNAME
$InstallTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$ServerURL = "https://rd.it-depot.ru/api/install"
$Body = @{
"rust_id" = $RustID
"computer_name" = $ComputerName
"install_time" = $InstallTime
} | ConvertTo-Json -Compress
Invoke-RestMethod -Uri $ServerURL -Method Post -Body $Body -ContentType "application/json"
echo "Initial entry added to address book."
echo "..............................................."
echo ""
# Создание скрипта для проверки онлайн-статуса
$checkScriptPath = "C:\ProgramData\RustDesk\RustDeskOnlineCheck.ps1"
$checkScriptContent = @"
`$ErrorActionPreference = 'SilentlyContinue'
`$RustID = "$RustID"
`$ComputerName = "$ComputerName"
`$InstallTime = "$InstallTime"
`$ServerURL = "https://rd.it-depot.ru/api/install"
while (`$true) {
`$Body = @{
`"rust_id`" = `$RustID
`"computer_name`" = `$ComputerName
`"install_time`" = `$InstallTime
`"last_seen`" = (Get-Date -Format `"yyyy-MM-dd HH:mm:ss`")
} | ConvertTo-Json -Compress
try {
Invoke-RestMethod -Uri `$ServerURL -Method Post -Body `$Body -ContentType `"application/json`" -ErrorAction Stop
Write-Host "Online ping sent for ID `$RustID at `(Get-Date -Format 'HH:mm:ss')" -ForegroundColor Green
}
catch {
Write-Host "Error sending online ping: `$_" -ForegroundColor Red
}
Start-Sleep -Seconds 30
}
"@
$checkScriptContent | Out-File -FilePath $checkScriptPath -Encoding UTF8
echo "Created online check script at $checkScriptPath"
# Создание задания в Планировщике задач
$taskName = "RustDeskOnlineCheck"
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$checkScriptPath`""
$trigger = New-ScheduledTaskTrigger -AtStartup
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RunOnlyIfNetworkAvailable
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -User "SYSTEM" -RunLevel Highest -Force
echo "Scheduled task '$taskName' created to check online status at system startup."
Start-ScheduledTask -TaskName $taskName
echo "Scheduled task '$taskName' has been started."
echo "Press Enter to open RustDesk."
pause
.\rustdesk.exe