@echo off setlocal EnableExtensions chcp 65001 >nul title PICKAXE - INSTALADOR DE AGENTE net session >nul 2>&1 if not "%errorlevel%"=="0" ( echo Solicitando permisos de administrador... set "PICKAXE_INSTALLER_PATH=%~f0" powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath $env:ComSpec -ArgumentList '/d','/c',([char]34 + $env:PICKAXE_INSTALLER_PATH + [char]34) -Verb RunAs" if errorlevel 1 ( echo No se pudo abrir el instalador como administrador. echo Haz clic derecho sobre el archivo y selecciona Ejecutar como administrador. pause ) exit /b ) echo. echo ============================================================ echo INSTALADOR DEL AGENTE PICKAXE echo ============================================================ echo. set "PICKAXE_HOME=%ProgramData%\PickaxeAgent" if not exist "%PICKAXE_HOME%" mkdir "%PICKAXE_HOME%" if exist "%PICKAXE_HOME%\config_agente.json" goto ACTUALIZAR set /p "PICKAXE_KEY=Clave de activacion: " set /p "PICKAXE_SITE=Nombre de la mina o sitio: " set /p "PICKAXE_NETWORKS=Redes separadas por coma [192.168.0.0/24]: " if "%PICKAXE_NETWORKS%"=="" set "PICKAXE_NETWORKS=192.168.0.0/24" echo. echo Descargando agente... powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$ErrorActionPreference='Stop';" ^ "$homePath=$env:PICKAXE_HOME;" ^ "Invoke-WebRequest -UseBasicParsing 'https://control.morflo.com.mx/downloads/AGENTE_PICKAXE.exe' -OutFile (Join-Path $homePath 'AGENTE_PICKAXE.exe');" ^ "if(-not (Test-Path (Join-Path $homePath 'cloudflared.exe'))){Invoke-WebRequest -UseBasicParsing 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe' -OutFile (Join-Path $homePath 'cloudflared.exe')};" ^ "$machine=(Get-CimInstance Win32_ComputerSystemProduct).UUID; if(-not $machine){$machine=[guid]::NewGuid().ToString()};" ^ "$agentId=($env:PICKAXE_SITE.ToUpperInvariant() -replace '[^A-Z0-9-]','-')+'-'+$machine.Substring(0,8);" ^ "$body=@{clave=$env:PICKAXE_KEY;agente_id=$agentId;nombre_sitio=$env:PICKAXE_SITE;hostname=$env:COMPUTERNAME}|ConvertTo-Json;" ^ "$activation=Invoke-RestMethod -Method Post -Uri 'https://control.morflo.com.mx/api/agentes/activar' -ContentType 'application/json' -Body $body;" ^ "$networks=@($env:PICKAXE_NETWORKS.Split(',')|ForEach-Object{$_.Trim()}|Where-Object{$_});" ^ "$config=[ordered]@{agente_id=$agentId;nombre_sitio=$env:PICKAXE_SITE;servidor_url='https://control.morflo.com.mx';api_key=$activation.token;redes=$networks;intervalo_segundos=60;timeout_segundos=2;timeout_envio_segundos=20;hilos=254};" ^ "$configJson=$config|ConvertTo-Json -Depth 5;" ^ "[IO.File]::WriteAllText((Join-Path $homePath 'config_agente.json'),$configJson,[Text.UTF8Encoding]::new($false));" ^ "$action=New-ScheduledTaskAction -Execute (Join-Path $homePath 'AGENTE_PICKAXE.exe') -WorkingDirectory $homePath;" ^ "$trigger=New-ScheduledTaskTrigger -AtStartup;" ^ "$settings=New-ScheduledTaskSettingsSet -RestartCount 10 -RestartInterval (New-TimeSpan -Minutes 1) -ExecutionTimeLimit ([TimeSpan]::Zero);" ^ "& netsh.exe advfirewall firewall delete rule name='PICKAXE IP Reporter'|Out-Null; & netsh.exe advfirewall firewall add rule name='PICKAXE IP Reporter' dir=in action=allow protocol=UDP localport=14235,11503,8888,1314,18650,9999,12345,54321,42069 program=(Join-Path $homePath 'AGENTE_PICKAXE.exe') profile=any|Out-Null;" ^ "Register-ScheduledTask -TaskName 'PickaxeAgent' -Action $action -Trigger $trigger -Settings $settings -User 'SYSTEM' -RunLevel Highest -Force|Out-Null;" ^ "Start-ScheduledTask -TaskName 'PickaxeAgent';" ^ "Write-Host 'Agente instalado correctamente:' $agentId -ForegroundColor Green" if errorlevel 1 ( echo. echo ERROR: no se pudo activar o instalar el agente. echo Verifica la clave, la conexion a Internet y vuelve a ejecutar. pause exit /b 1 ) echo. echo PICKAXE ya trabaja en segundo plano y arrancara con Windows. pause exit /b 0 :ACTUALIZAR echo Instalacion existente detectada. Actualizando Agente y Gateway... powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$ErrorActionPreference='Stop';" ^ "$homePath=$env:PICKAXE_HOME;" ^ "$newFile=Join-Path $homePath 'AGENTE_PICKAXE.nuevo.exe';" ^ "$currentFile=Join-Path $homePath 'AGENTE_PICKAXE.exe';" ^ "$backupFile=Join-Path $homePath 'AGENTE_PICKAXE.anterior.exe';" ^ "Invoke-WebRequest -UseBasicParsing 'https://control.morflo.com.mx/downloads/AGENTE_PICKAXE.exe' -OutFile $newFile;" ^ "if(-not (Test-Path (Join-Path $homePath 'cloudflared.exe'))){Invoke-WebRequest -UseBasicParsing 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe' -OutFile (Join-Path $homePath 'cloudflared.exe')};" ^ "Stop-ScheduledTask -TaskName 'PickaxeAgent' -ErrorAction SilentlyContinue;" ^ "Get-Process -Name 'AGENTE_PICKAXE' -ErrorAction SilentlyContinue|Stop-Process -Force;" ^ "Start-Sleep -Seconds 2;" ^ "if(Test-Path $currentFile){Copy-Item -Force $currentFile $backupFile};" ^ "Move-Item -Force $newFile $currentFile;" ^ "$action=New-ScheduledTaskAction -Execute $currentFile -WorkingDirectory $homePath;" ^ "$trigger=New-ScheduledTaskTrigger -AtStartup;" ^ "$settings=New-ScheduledTaskSettingsSet -RestartCount 10 -RestartInterval (New-TimeSpan -Minutes 1) -ExecutionTimeLimit ([TimeSpan]::Zero);" ^ "& netsh.exe advfirewall firewall delete rule name='PICKAXE IP Reporter'|Out-Null; & netsh.exe advfirewall firewall add rule name='PICKAXE IP Reporter' dir=in action=allow protocol=UDP localport=14235,11503,8888,1314,18650,9999,12345,54321,42069 program=$currentFile profile=any|Out-Null;" ^ "Register-ScheduledTask -TaskName 'PickaxeAgent' -Action $action -Trigger $trigger -Settings $settings -User 'SYSTEM' -RunLevel Highest -Force|Out-Null;" ^ "Start-ScheduledTask -TaskName 'PickaxeAgent';" ^ "Write-Host 'Agente PICKAXE y Gateway actualizados correctamente.' -ForegroundColor Green" if errorlevel 1 ( echo ERROR: no se pudo actualizar el Agente PICKAXE. pause exit /b 1 ) echo. echo Gateway actualizado y ejecutandose en segundo plano. pause