fix : change and fix SyncService

This commit is contained in:
SajjadMahmoody 2026-04-18 00:53:44 +03:30
parent 7e8aa185ab
commit ea82f5968e
3 changed files with 38 additions and 26 deletions

View File

@ -172,7 +172,7 @@ private function transferFilesViaFtp(array $changes, string $side, array &$repor
continue; continue;
} }
@ftp_mkdir($ftp, $remoteFolder); @ftp_mkdir($ftp, $remoteFolder);
if (ftp_put($ftp, $remoteFile, $localFile, FTP_BINARY)) { if (@ftp_put($ftp, $remoteFile, $localFile, FTP_BINARY)) {
$report[] = "فایل [{$filePath}] ارسال شد (FTP) ✓"; $report[] = "فایل [{$filePath}] ارسال شد (FTP) ✓";
} else { } else {
$report[] = "فایل [{$filePath}] ارسال نشد (FTP) ✗"; $report[] = "فایل [{$filePath}] ارسال نشد (FTP) ✗";
@ -185,7 +185,7 @@ private function transferFilesViaFtp(array $changes, string $side, array &$repor
if (! is_dir($localFolder)) { if (! is_dir($localFolder)) {
mkdir($localFolder, 0755, true); mkdir($localFolder, 0755, true);
} }
if (ftp_get($ftp, $localFile, $remoteFile, FTP_BINARY)) { if (@ftp_get($ftp, $localFile, $remoteFile, FTP_BINARY)) {
$report[] = "فایل [{$filePath}] دریافت شد (FTP) ✓"; $report[] = "فایل [{$filePath}] دریافت شد (FTP) ✓";
} else { } else {
$report[] = "فایل [{$filePath}] دریافت نشد (FTP) ✗"; $report[] = "فایل [{$filePath}] دریافت نشد (FTP) ✗";

View File

@ -182,7 +182,7 @@ function ftpSession($ctrl, string $user, string $pass, string $root): void
case 'PASV': case 'PASV':
if (!$authed) { ftpSend($ctrl, '530 Not logged in'); break; } if (!$authed) { ftpSend($ctrl, '530 Not logged in'); break; }
if ($pasvSock) fclose($pasvSock); if ($pasvSock) fclose($pasvSock);
$pasvPort = rand(49152, 65534); $pasvPort = rand(60000, 60020); // fixed range — must match firewall rule
$pasvSock = @stream_socket_server("tcp://0.0.0.0:{$pasvPort}", $e1, $e2); $pasvSock = @stream_socket_server("tcp://0.0.0.0:{$pasvPort}", $e1, $e2);
if (!$pasvSock) { ftpSend($ctrl, '425 Cannot open passive connection'); break; } if (!$pasvSock) { ftpSend($ctrl, '425 Cannot open passive connection'); break; }
$localAddr = stream_socket_get_name($ctrl, false); $localAddr = stream_socket_get_name($ctrl, false);
@ -220,15 +220,13 @@ function ftpSession($ctrl, string $user, string $pass, string $root): void
$full = $root . $p; $full = $root . $p;
$dir = dirname($full); $dir = dirname($full);
if (!is_dir($dir)) mkdir($dir, 0755, true); if (!is_dir($dir)) mkdir($dir, 0755, true);
$fp = @fopen($full, 'wb');
if (!$fp) { ftpSend($ctrl, '550 Cannot write file'); break; }
$data = ftpOpenData($pasvSock); $data = ftpOpenData($pasvSock);
if (!$data) { ftpSend($ctrl, '425 No data connection'); break; } if (!$data) { fclose($fp); ftpSend($ctrl, '425 No data connection'); break; }
ftpSend($ctrl, '150 Ready to receive'); ftpSend($ctrl, '150 Ready to receive');
$fp = fopen($full, 'wb'); stream_set_timeout($data, 30);
if (!$fp) { fclose($data); ftpSend($ctrl, '550 Cannot write file'); break; } stream_copy_to_stream($data, $fp);
while (!feof($data)) {
$buf = fread($data, 65536);
if ($buf !== false && $buf !== '') fwrite($fp, $buf);
}
fclose($fp); fclose($fp);
fclose($data); fclose($data);
echo " STOR: {$p} (" . number_format(filesize($full)) . " bytes)\n"; echo " STOR: {$p} (" . number_format(filesize($full)) . " bytes)\n";

View File

@ -34,22 +34,34 @@ if not exist "!SCRIPTS!\php\php-cgi.exe" (
pause & exit /b 1 pause & exit /b 1
) )
REM --- [1/6] storage:link --- REM --- [1/7] Clear bootstrap cache ---
echo [1/6] Creating storage link... echo [1/7] Clearing bootstrap cache...
cd /d "!PROJECT_DIR!" cd /d "!PROJECT_DIR!"
if exist "bootstrap\cache\config.php" del /F /Q "bootstrap\cache\config.php" >nul 2>&1
if exist "bootstrap\cache\routes-v7.php" del /F /Q "bootstrap\cache\routes-v7.php" >nul 2>&1
if exist "bootstrap\cache\services.php" del /F /Q "bootstrap\cache\services.php" >nul 2>&1
if exist "bootstrap\cache\packages.php" del /F /Q "bootstrap\cache\packages.php" >nul 2>&1
if exist "bootstrap\cache\events.php" del /F /Q "bootstrap\cache\events.php" >nul 2>&1
if exist "bootstrap\cache\blade-icons.php" del /F /Q "bootstrap\cache\blade-icons.php" >nul 2>&1
if exist "bootstrap\cache\filament" rmdir /S /Q "bootstrap\cache\filament" >nul 2>&1
echo [OK] Done.
echo.
REM --- [2/7] storage:link ---
echo [2/7] Creating storage link...
"!SCRIPTS!\php\php.exe" artisan storage:link >nul 2>&1 "!SCRIPTS!\php\php.exe" artisan storage:link >nul 2>&1
echo [OK] Done. echo [OK] Done.
echo. echo.
REM --- [2/6] Optimize Laravel --- REM --- [3/7] Optimize Laravel ---
echo [2/6] Optimizing Laravel... echo [3/7] Optimizing Laravel...
"!SCRIPTS!\php\php.exe" artisan optimize --quiet 2>nul "!SCRIPTS!\php\php.exe" artisan optimize --quiet 2>nul
"!SCRIPTS!\php\php.exe" artisan filament:optimize --quiet 2>nul "!SCRIPTS!\php\php.exe" artisan filament:optimize --quiet 2>nul
echo [OK] Done. echo [OK] Done.
echo. echo.
REM --- [3/6] Configure OPcache --- REM --- [4/7] Configure OPcache ---
echo [3/6] Configuring OPcache... echo [4/7] Configuring OPcache...
if not exist "C:\tmp\php-opcache" mkdir "C:\tmp\php-opcache" if not exist "C:\tmp\php-opcache" mkdir "C:\tmp\php-opcache"
set "SCRIPTS_BAK=!SCRIPTS!" set "SCRIPTS_BAK=!SCRIPTS!"
powershell -NoProfile -Command ^ powershell -NoProfile -Command ^
@ -57,8 +69,8 @@ powershell -NoProfile -Command ^
echo [OK] Done. echo [OK] Done.
echo. echo.
REM --- [4/6] Generate nginx.conf from template --- REM --- [5/7] Generate nginx.conf from template ---
echo [4/6] Writing nginx.conf... echo [5/7] Writing nginx.conf...
set "PUBLIC_DIR=!PROJECT_DIR:\=/!/public" set "PUBLIC_DIR=!PROJECT_DIR:\=/!/public"
if not exist "!SCRIPTS!\nginx\conf\nginx.conf.template" ( if not exist "!SCRIPTS!\nginx\conf\nginx.conf.template" (
echo [ERROR] nginx.conf.template not found in scripts\nginx\conf\ echo [ERROR] nginx.conf.template not found in scripts\nginx\conf\
@ -69,17 +81,19 @@ powershell -NoProfile -Command ^
echo [OK] nginx.conf written. echo [OK] nginx.conf written.
echo. echo.
REM --- [5/6] Firewall --- REM --- [6/7] Firewall ---
echo [5/6] Firewall rules... echo [6/7] Firewall rules...
netsh advfirewall firewall delete rule name="Matab Web 8000" >nul 2>&1 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 delete rule name="Matab FTP 2121" >nul 2>&1
netsh advfirewall firewall delete rule name="Matab FTP Passive" >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 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 netsh advfirewall firewall add rule name="Matab FTP 2121" dir=in action=allow protocol=TCP localport=2121 >nul
netsh advfirewall firewall add rule name="Matab FTP Passive" dir=in action=allow protocol=TCP localport=60000-60020 >nul
echo [OK] Done. echo [OK] Done.
echo. echo.
REM --- [6/6] Windows Services --- REM --- [7/7] Windows Services ---
echo [6/6] Installing Windows services... echo [7/7] Installing Windows services...
echo Stopping old services... echo Stopping old services...
"!WINSW!" stop "!SCRIPTS!\matab-autostart.xml" >nul 2>&1 "!WINSW!" stop "!SCRIPTS!\matab-autostart.xml" >nul 2>&1