diff --git a/app/Services/SyncService.php b/app/Services/SyncService.php index 1451440..f7eda5d 100644 --- a/app/Services/SyncService.php +++ b/app/Services/SyncService.php @@ -30,7 +30,7 @@ public static function fromConfig(): static token: OsurgInitial::val('sync_token', config('sync.token', '')), ftpUser: OsurgInitial::val('ftp_user', config('sync.ftp_user', '')), ftpPass: OsurgInitial::val('ftp_pass', config('sync.ftp_pass', '')), - ftpPort: (int) OsurgInitial::val('ftp_port', config('sync.ftp_port', 21)), + ftpPort: (int) OsurgInitial::val('ftp_port', config('sync.ftp_port', 2121)), ftpRemotePath: OsurgInitial::val('ftp_remote_path', config('sync.ftp_remote_path', '')), ); } @@ -133,6 +133,9 @@ public function applyChanges(array $changes): array private function transferFilesViaFtp(array $changes, string $side, array &$report): void { + if (empty($changes)) { + return; + } $ftp = $this->connectFtp(); if (! $ftp) { $report[] = 'خطا در اتصال FTP به سیستم مقابل'; diff --git a/config/sync.php b/config/sync.php index c92f909..60d1b54 100644 --- a/config/sync.php +++ b/config/sync.php @@ -1,7 +1,11 @@ env('SYNC_PEER_IP', ''), - 'peer_port' => env('SYNC_PEER_PORT', 80), - 'token' => env('SYNC_TOKEN', ''), + + 'peer_ip' => env('SYNC_PEER_IP', ''), + 'peer_port' => env('SYNC_PEER_PORT', 80), + 'token' => env('SYNC_TOKEN', ''), + 'ftp_user' => env('FTP_USER', 'root'), + 'ftp_pass' => env('FTP_PASS', ''), + 'ftp_port' => env('FTP_PORT', 2121), + 'ftp_remote_path'=> env('FTP_REMOTE_PATH', ''), ]; diff --git a/scripts/setup-autostart.bat b/scripts/setup-autostart.bat index b69f0ba..202f94c 100644 --- a/scripts/setup-autostart.bat +++ b/scripts/setup-autostart.bat @@ -7,17 +7,25 @@ for %%F in ("%SCRIPTS_DIR%\..") do set "PROJECT_DIR=%%~fF" echo === MatabPanel Autostart Setup === echo. -echo [1/3] Registering web server autostart... +echo [1/4] Opening firewall ports... +netsh advfirewall firewall delete rule name="Matab Web 8000" >nul 2>&1 +netsh advfirewall firewall delete rule name="Matab FTP 2121" >nul 2>&1 +netsh advfirewall firewall add rule name="Matab Web 8000" dir=in action=allow protocol=TCP localport=8000 >nul +netsh advfirewall firewall add rule name="Matab FTP 2121" dir=in action=allow protocol=TCP localport=2121 >nul +echo Firewall rules added for ports 8000 and 2121. +echo. + +echo [2/4] Registering web server autostart... set "VBS_PATH=%SCRIPTS_DIR%\start-server.vbs" powershell -NoProfile -Command "$vbs='%VBS_PATH%'; $startup=[Environment]::GetFolderPath('Startup'); $s=(New-Object -COM WScript.Shell).CreateShortcut($startup+'\MatabPanel.lnk'); $s.TargetPath='wscript.exe'; $s.Arguments=[char]34+$vbs+[char]34; $s.WindowStyle=7; $s.Save(); Write-Host ('Registered: '+$startup+'\MatabPanel.lnk')" echo. -echo [2/3] Registering FTP server autostart... +echo [3/4] Registering FTP server autostart... set "FTP_VBS=%SCRIPTS_DIR%\start-ftp-server.vbs" powershell -NoProfile -Command "$vbs='%FTP_VBS%'; $startup=[Environment]::GetFolderPath('Startup'); $s=(New-Object -COM WScript.Shell).CreateShortcut($startup+'\MatabPanelFTP.lnk'); $s.TargetPath='wscript.exe'; $s.Arguments=[char]34+$vbs+[char]34; $s.WindowStyle=7; $s.Save(); Write-Host ('Registered: '+$startup+'\MatabPanelFTP.lnk')" echo. -echo [3/3] Starting servers now... +echo [4/4] Starting servers now... wscript.exe "%SCRIPTS_DIR%\start-ftp-server.vbs" wscript.exe "%SCRIPTS_DIR%\start-server.vbs" echo Waiting for server to be ready... diff --git a/scripts/start-ftp-server.vbs b/scripts/start-ftp-server.vbs index 91e5e9d..849e092 100644 --- a/scripts/start-ftp-server.vbs +++ b/scripts/start-ftp-server.vbs @@ -61,5 +61,21 @@ ts2.WriteLine Now & " - Starting FTP server with: " & phpExe ts2.Close On Error GoTo 0 -' --- Start FTP server silently in background --- -shell.Run "cmd /c """ & phpExe & """ -d display_errors=0 """ & scriptsDir & "\ftp-server.php"" >> """ & logFile & """ 2>&1", 0, False +' --- Start FTP server - run from PHP's own directory so extension_dir="ext" resolves correctly --- +Dim phpDir +phpDir = fso.GetParentFolderName(phpExe) +Dim ftpCmd +ftpCmd = "cmd /c """ & "cd /d """ & phpDir & """ && """ & phpExe & """ -d display_errors=1 -d error_reporting=0 """ & scriptsDir & "\ftp-server.php"" >> """ & logFile & """ 2>&1""" +shell.Run ftpCmd, 0, False + +' --- Wait a moment and check it actually started --- +WScript.Sleep 3000 +portInUse = shell.Run("cmd /c netstat -ano | find "":2121 "" >nul 2>&1", 0, True) +If portInUse <> 0 Then + ' Failed to start - log and try once more + Dim ts3 + Set ts3 = fso.OpenTextFile(logFile, 8, True) + ts3.WriteLine Now & " - WARN: FTP did not start, retrying..." + ts3.Close + shell.Run ftpCmd, 0, False +End If