-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkitty_execute.bat
More file actions
270 lines (218 loc) · 9.53 KB
/
kitty_execute.bat
File metadata and controls
270 lines (218 loc) · 9.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
REM MIT License
REM Copyright (c) 2025 Mikhael Lerman checkthisresume.com
REM Permission is hereby granted, free of charge, to any person obtaining a copy
REM of this software and associated documentation files (the "Software"), to deal
REM in the Software without restriction, including without limitation the rights
REM to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
REM copies of the Software, and to permit persons to whom the Software is
REM furnished to do so, subject to the following conditions:
REM The above copyright notice and this permission notice shall be included in all
REM copies or substantial portions of the Software.
REM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
REM IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
REM FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
REM AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
REM LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
REM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
REM SOFTWARE.
rem limitations no filename with spaces
rem no concurent execution of the interpreter, only one instance
rem @echo off
rem n'affiche rien dans la console web
call C:\UniServer\www\doc\files\ThisPC\nircmd\move_me_top_right.bat
rem set PYTHON_CMD=C:\Python27\python.exe
set PYTHON_CMD=python.exe
call C:\UniServer\www\doc\files\common\global_settings\PSEXEC_EXE.sh.bat
rem set PSEXEC_EXE=PsExec.exe
rem set PSEXEC_EXE=paexec.exe
:LOOP
tasklist | C:\Windows\System32\find.exe /i "kitty_portable.exe" >nul 2>&1
IF ERRORLEVEL 1 (
GOTO CONTINUE
) ELSE (
ECHO kitty is still running
rem Timeout /T 5
set CHOICE=W
CHOICE /M "Press [K] to kill the SSH session or [W] to wait..." /T 5 /C KW /D W
IF ERRORLEVEL 1 SET CHOICE=K
IF ERRORLEVEL 2 SET CHOICE=W
if "%CHOICE%" == "W" GOTO LOOP
if "%CHOICE%" == "K" GOTO KILL_SSH
rem no choice
goto LOOP
echo CHOICE is %CHOICE%
)
:KILL_SSH
echo killing kitty_portable.exe
tasklist /FI "IMAGENAME eq kitty_portable.exe" 2>NUL | C:\Windows\System32\find.exe /I /N "kitty_portable.exe">NUL
if "%ERRORLEVEL%"=="0" taskkill /IM kitty_portable.exe /F
:CONTINUE
if not exist %1.escaped goto escaped_is_outdated
if not exist C:\UniServer\www\doc\files\ThisPC\install_wasfile\WasFile.exe echo NO WasFile.exe
C:\UniServer\www\doc\files\ThisPC\install_wasfile\WasFile.exe %1.escaped before %1
if %errorlevel% EQU 1 goto escaped_is_uptodate
:escaped_is_outdated
rem the escaped is before the kitty = true
set YES_UPTODATE=no
goto end_wasfile
:escaped_is_uptodate
rem the escaped is after kitty = false
set YES_UPTODATE=yes
:end_wasfile
if "%YES_UPTODATE%" == "no" %PYTHON_CMD% C:\UniServer\www\doc\files\Engineering\ENVIRONMENT\PYTHON\curly_brace_to_goto\run.py --file "%1"
rem this generates .curlyout
%PYTHON_CMD% C:\UniServer\www\doc\files\Engineering\ENVIRONMENT\PYTHON\kitty_preprocessor\run.py --file "%1.curlyout" --old "%YES_UPTODATE%"
call YES_CONTAINS_LINUX_CMD.sh.bat
call YES_CONTAINS_PSEXEC_CMD.sh.bat
if "%YES_CONTAINS_PSEXEC_CMD%" == "no" goto no_psexec_cmd
rem testing psexec console
call C:\UniServer\www\doc\files\common\global_settings\PEXIP.sh.bat
call C:\UniServer\www\doc\files\common\global_settings\PEXPW.sh.bat
call C:\UniServer\www\doc\files\common\global_settings\PEXUS.sh.bat
call C:\UniServer\www\doc\files\common\global_settings\YES_PSEXEC_LONG_WAIT.sh.bat
if "%2" == "" goto use_global_pexip
rem force the ip from param %2
set PEXIP=%2
:use_global_pexip
if "%3" == "" goto use_global_pexpw
set PEXPW=%3
:use_global_pexpw
if "%4" == "" goto use_global_pexuser
set PEXUS=%4
:use_global_pexuser
rem echo 4: ==%4== SSDUS is %SSDUS%
rem TODO lancer en child process de autoit et attendre le message "Started with psexec" et sortir
start C:\UniServer\www\doc\files\ThisPC\install_pstools\%PSEXEC_EXE% \\%PEXIP% -u %PEXUS% -p %PEXPW% -s cmd.exe /k "@echo Started with psexec"
rem sometimes if the firewall is enabled on the target we need to wait 30 sec
if "%PSEXEC_EXE%" == "PsExec.exe" goto psexec
if "%PSEXEC_EXE%" == "paexec.exe" goto paexec
goto end_ps
:psexec
if "%YES_PSEXEC_LONG_WAIT%" == "no" goto paexec
echo wait 30 sec until it starts then
C:\cygwin64\bin\sleep.exe 30
goto end_ps
:paexec
echo wait 2 sec until it starts then
C:\cygwin64\bin\sleep.exe 2
:end_ps
rem OK mais inutil
for /F "tokens=2" %%K in ('
tasklist /FI "IMAGENAME eq %PSEXEC_EXE%" /FI "Status eq Running" /FO LIST ^| findstr /B "PID:"
') do (
set PSEXEC_PID=%%K
)
echo %PSEXEC_EXE% is %PSEXEC_PID%
:no_psexec_cmd
if "%YES_CONTAINS_LINUX_CMD%" == "no" goto no_linux_cmd
call C:\UniServer\www\doc\files\common\global_settings\CONN.sh.bat
if "%2" == "" goto use_global_ssdip
rem force the ip from param %2
set CONN[1]=%2
:use_global_ssdip
if "%3" == "" goto use_global_ssdpw
set CONN[3]=%3
:use_global_ssdpw
if "%4" == "" goto use_global_ssduser
set CONN[2]=%4
:use_global_ssduser
rem check if the remote is living
ping -n 1 %CONN[1]% > out.txt
C:\Windows\System32\find.exe /c "Lost = 1" out.txt >nul
if %errorlevel% equ 1 goto found_remote
echo IP %CONN[1]% is OFF, exiting
exit /b
goto done_remote_is_live
:found_remote
:done_remote_is_live
if exist putty.log del putty.log /Q
call C:\UniServer\www\doc\files\common\global_settings\SYNC.sh.bat
if "%SYNC%" == "no" goto no_sync_1
call C:\UniServer\www\doc\files\Engineering\ENVIRONMENT\WINDOWS_BATCH\kitty_interpreter\create_sync_file.bat
call UUID.sh.bat
C:\UniServer\www\doc\files\ThisPC\putty\PSCP.EXE -scp -pw %CONN[3]% SYNC_%UUID%.sh.bat %CONN[2]%@%CONN[1]%: >nul
:no_sync_1
rem stty -echo\n
rem clear\n
call C:\UniServer\www\doc\files\common\global_settings\KITTY_STTY_ECHO.sh.bat
set STTY_ECHO_PARAM=
if "%KITTY_STTY_ECHO%" NEQ "no" goto normal_stty
set STTY_ECHO_PARAM=stty -echo\nPS1=\\\\\x6e${PS1}\n
:normal_stty
if "%YES_CONTAINS_LINUX_CMD%" == "no" goto no_linux_cmd
rem ne lance kitty_portable.exe que si on peut se connecter
if exist curlout_ssh_abl.txt del curlout_ssh_abl.txt /Q
echo ^] | curl telnet://%CONN[1]%:%CONN[4]% --max-time 2 -s >curlout_ssh_abl.txt 2>&1
rem echo curlout_ssh_abl.txt and size:
rem type curlout_ssh_abl.txt
echo set FSIZE=^^>FSIZE.sh.bat
FOR %%I in (curlout_ssh_abl.txt) do @ECHO %%~zI >>FSIZE.sh.bat
call FSIZE.sh.bat
rem echo FSIZE [%FSIZE%]
if "%FSIZE%" NEQ "0 " goto ok_to_ssh_or_telnet
rem previous code encore ok pour ssh
set FIND_THIS="SSH"
C:\WINDOWS\system32\find.exe /c %FIND_THIS% curlout_ssh_abl.txt >nul
if %errorlevel% equ 0 goto ok_to_ssh_or_telnet
goto not_ok_to_ssh
goto end_run_ssh
:ok_to_ssh_or_telnet
if "%CONN[0]%" == "telnet" goto ok_to_telnet
call C:\UniServer\www\doc\files\common\global_settings\CLEAR_CMD.sh.bat
rem was -ssh
start c:\UniServer\www\doc\files\ThisPC\install_kitty\kitty_portable.exe -%CONN[0]% %CONN[2]%@%CONN[1]% -pw %CONN[3]% -P %CONN[4]% -cmd "%STTY_ECHO_PARAM%%CLEAR_CMD%\n" -xpos 50 -ypos 0
goto end_ssh_or_telnet
:ok_to_telnet
start c:\UniServer\www\doc\files\ThisPC\install_kitty\kitty_portable.exe -%CONN[0]% %CONN[1]% -P %CONN[4]% -xpos 50 -ypos 0
C:\cygwin64\bin\sleep.exe 4
start c:\UniServer\www\doc\files\ThisPC\install_kitty\kitty_portable.exe -sendcmd "\n\n"
C:\cygwin64\bin\sleep.exe 4
start c:\UniServer\www\doc\files\ThisPC\install_kitty\kitty_portable.exe -sendcmd "%CONN[2]%\n"
C:\cygwin64\bin\sleep.exe 1
start c:\UniServer\www\doc\files\ThisPC\install_kitty\kitty_portable.exe -sendcmd "%CONN[3]%\n"
C:\cygwin64\bin\sleep.exe 1
start c:\UniServer\www\doc\files\ThisPC\install_kitty\kitty_portable.exe -sendcmd "%STTY_ECHO_PARAM%%CLEAR_CMD%\n"
:end_ssh_or_telnet
C:\cygwin64\bin\sleep.exe 3
goto end_run_ssh
:not_ok_to_ssh
echo Error not_ok_to_ssh: Cannot connect to target
echo protocol [%CONN[0]%]
echo IP [%CONN[1]%]
echo User [%CONN[2]%]
echo Pw [%CONN[3]%]
echo Port [%CONN[4]%]
echo prefix [%CONN[5]%]
pause
goto end_run_ssh
:end_run_ssh
:no_linux_cmd
rem les ':' dans :kitty_execute_line.bat font la difference entre la subroutine et le fichier extern
%PYTHON_CMD% C:\UniServer\www\doc\files\Engineering\ENVIRONMENT\PYTHON\explode_bat_lib\run.py --file "%1"
echo. >flow.txt
echo echo set GOTO_LINE=%%1 ^>GOTO_LINE.sh.bat>kittygotoline.bat
rem we calculate the total number of lines in the file to execute
for /f %%a in (%1.escaped) do (set /a total_lines+=1)
echo set THE_END=no>THE_END.sh.bat
set /a COUNT=0
:line_loop
set /a lineNr=%COUNT% -1
set /a COUNT+=1
rem echo set COUNT=%COUNT% >COUNT.sh.bat
rem make sure lineNR line number is pointing to a real line in the file
if %lineNr% LSS 1 goto line_loop
rem for every count index, we point to a line in the file
rem LineNr c'est la position dans le fichier ou on commence a envoyer a for_bat
for /f "usebackq delims=" %%a in (`more +%lineNr% %1.escaped`) DO call C:\UniServer\www\doc\files\Engineering\ENVIRONMENT\WINDOWS_BATCH\kitty_interpreter\for_bat.bat %%a
:leave_for
if not exist GOTO_LINE.sh.bat goto done_file
goto line_loop
:done_file
if "%YES_CONTAINS_LINUX_CMD%" == "no" goto no_linux_cmd_2
call C:\UniServer\www\doc\files\common\global_settings\LAST_EXIT_CMD.sh.bat
if "%SYNC%" == "no" goto no_sync
c:\UniServer\www\doc\files\ThisPC\install_kitty\kitty_portable.exe -sendcmd "rm SYNC_%UUID%.sh.bat\n%LAST_EXIT_CMD%\n"
if exist SYNC_%UUID%.sh.bat del SYNC_%UUID%.sh.bat /Q
:no_sync
:no_linux_cmd_2
exit /b