-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgo.sh
More file actions
322 lines (271 loc) · 8.5 KB
/
Copy pathgo.sh
File metadata and controls
322 lines (271 loc) · 8.5 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/sh
RED="\033[1;31m"
BLUE="\033[1;34m"
GREEN="\033[1;32m"
Color_Off='\033[0m' # Text Reset
Yellow='\033[0;33m' # Yellow
Cyan='\033[0;36m' # Cyan
NC=""
DIRFILE=`readlink -e "$0"`
CURFILE=`basename "$DIRFILE"`
CURDIR=`dirname "$DIRFILE"`
echo "\n"
echo "${RED} Devoleped by ExRecod${NC}"
echo "${BLUE} Forum http://xxxreal.ru/{NC}"
echo "${RED} MULTI SERVERS RCM ADMIN MOD v.9.x ${NC}"
sleep 1
# check if nohup is installed
command php --version >/dev/null 2>&1 || (
echo "\n"
echo "${Red} PHP install ${NC}"
sleep 1
update() {
echo "\n ${Cyan} Updating package repositories.. ${Color_Off}"
sudo apt -qq update
}
installPHP() {
echo "\n ${Cyan} Installing PHP and common Modules.. ${Color_Off}"
# PHP7 (latest)
sudo apt -qy install php php-fpm php-pear php-dev php-common php-fpm php-gd php-cli php-mbstring php-curl php-gd php-gettext php-intl php-mbstring php-sqlite3 php-mysql php-pear php-pspell php-recode php-xml php-zip
}
# RUN
update
installPHP
echo "${Yellow} PHP install finished ${NC}"
echo "\n"
echo "\n"
sudo php -v
echo "\n"
)
# check if nohup is installed
command nohup --version >/dev/null 2>&1 || (echo "install nohup if you want to use this script"; exit 1)
#if [ -d $CURDIR/cache_ms/ ]; then
#rm $CURDIR/cache_ms/
#fi
if ! [ -d $CURDIR/cache_ms/ ]; then
mkdir -m 777 $CURDIR/cache_ms/
mkdir -m 777 $CURDIR/cache_ms/functions/
fi
while read line ; do
IFS=";"
set -- $line
ip=$1
port=$2
rcon=$3
log=$4
IPPORT=$1
IPPORT=$(echo $ip | sed -e "s/\.//g")
IPPORTW=$IPPORT$port
echo "$IPPORTW \n"
if (echo "$IPPORTW" | grep -E -q "^?[0-9]+$"); then
echo "$port->$rcon->$log => \n"
pkill -f go_$IPPORTW.sh
pkill -f go_$IPPORTW.php
echo "Killed go_$IPPORTW \n"
fi
done < $CURDIR/cfg/servers.cfg
# ESLI EST, PROVERKU NADO
#echo $(ps aux | grep 'php -q -f');
while read line ; do
IFS=";"
set -- $line
ip=$1
port=$2
rcon=$3
log=$4
IPPORT=$1
IPPORT=$(echo $ip | sed -e "s/\.//g")
IPPORTW=$IPPORT$port
echo "$IPPORTW \n"
if (echo "$IPPORTW" | grep -E -q "^?[0-9]+$"); then
##########RESET /////////////////////RESET ON START fopen($mplogfile, "w");
### php -q -f $CURDIR/cache_ms/functions/cleaner_'$IPPORTW'.php '$port' '$rcon' '$log'
### sleep 1
if [ -f $CURDIR/go_$IPPORTW.sh ]; then
echo ""
else
echo '#!/bin/sh
DIRFILE=`readlink -e "$0"`
CURFILE=`basename "$DIRFILE"`
CURDIR=`dirname "$DIRFILE"`
setterm -term linux -back black
while (true)
do
php -q -f $CURDIR/cache_ms/go_'$IPPORTW'.php '$port' '$rcon' '$log'
done;
' > $CURDIR/go_$IPPORTW.sh
fi
if [ -f $CURDIR/cache_ms/go_$IPPORTW.php ]; then
echo ""
else
echo '#!/bin/php
<?php
header("Content-Type: text/html; charset=UTF-8");
function hxh($sc)
{
$sc = str_replace(array(
"cache_ms/go_'$IPPORTW'.php","cache_ms\go_'$IPPORTW'.php","cache_ms\\go_'$IPPORTW'.php"
), "", $sc);
return $sc . "";
}
$cpath = hxh(__FILE__);
error_reporting(E_ALL); // Error engine - always TRUE!
ini_set("ignore_repeated_errors", TRUE); // always TRUE
ini_set("display_errors", TRUE); // Error display - FALSE only in production environment or real server
ini_set("log_errors", TRUE); // Error logging engine
ini_set("error_log", $cpath."ReCodMod/php-all-errors.log");
$server_ip = "'$ip'";
$server_port = "'$port'";
$server_rconpass = "'$rcon'";
$mplogfile = "'$log'";
$server_port = trim($server_port);
$nullLogFiles = 1;
if (empty($_SERVER["OS"])) $_SERVER["OS"] = "";
if (strpos($_SERVER["OS"], "Win") !== false) {
function hxlog2($scwin) {
$scwin = str_replace(array(
"//////"
) , "\\", $scwin);
$scwin = str_replace(array(
"/////"
) , "\\", $scwin);
$scwin = str_replace(array(
"////"
) , "\\", $scwin);
$scwin = str_replace(array(
"///"
) , "\\", $scwin);
$scwin = str_replace(array(
"//"
) , "\\", $scwin);
$scwin = str_replace(array(
"/"
) , "\\", $scwin);
$scwin = str_replace(array(
"\\\\"
) , "\\", $scwin);
$scwin = str_replace(array(
"\\\"
) , "\\", $scwin);
$scwin = str_replace(array(
"\\"
) , "\\", $scwin);
return $scwin . "";
}
}
else {
function hxlog2($scwin) {
$scwin = str_replace(array(
"//////"
) , "/", $scwin);
$scwin = str_replace(array(
"/////"
) , "/", $scwin);
$scwin = str_replace(array(
"////"
) , "/", $scwin);
$scwin = str_replace(array(
"///"
) , "/", $scwin);
$scwin = str_replace(array(
"//"
) , "/", $scwin);
$scwin = str_replace(array(
"\\\\"
) , "/", $scwin);
$scwin = str_replace(array(
"'\\\'"
) , "/", $scwin);
$scwin = str_replace(array(
"\\"
) , "/", $scwin);
$scwin = str_replace(array(
"\\"
) , "/", $scwin);
return $scwin . "";
}
}
function debuglog2($s) {
global $cpath;
$s = str_replace(array("\r","\n"), "", $s);
$fp = fopen($cpath . "ReCodMod/cache/x_errors/debug.log", "a");
fwrite($fp, " [".date('Y.m.d H:i:s')."] Debug : ".$s . "\n");
fclose($fp);
}
function ftp_to_upload_ftp2($conn_idqnew, $ftp_q_url, $filei, $file){
global $cpath,$server_ip,$server_port;
if (@ftp_put($conn_idqnew, $ftp_q_url, $filei, FTP_BINARY)) {
if (is_resource($conn_idqnew))
ftp_quit($conn_idqnew);
$fpa = fopen($file, "w+");
fputs($fpa, "---");
fclose($fpa);
$fpb = fopen($cpath . "ReCodMod/cache/x_cache/" . $server_ip . "_" . $server_port . "_pos.txt", "w+");
fputs($fpb, "0");
fclose($fpb);
$hu = fopen($cpath . "ReCodMod/cache/x_cache/" . $server_ip . "_" . $server_port . "_pos_ftp.txt", "w+");
fwrite($hub, "1");
fclose($hub);
return true;
}else{
if (is_resource($conn_idqnew))
ftp_quit($conn_idqnew);
return false;
}}
function ftp2locallog2($gmlobame) {
global $mplogfile;
$mplogfilei = str_replace(array(
"ftp://"
) , '', $mplogfile);
$ftp_user_explode = explode(':', $mplogfilei);
$ftp_exp_user = $ftp_user_explode[0];
$ftp_pass_explode = explode('@', $ftp_user_explode[1]);
$ftp_exp_password = $ftp_pass_explode[0];
$mssf = explode('@', $ftp_user_explode[1]);
$mssy = explode('/', $mssf[1]);
$ftp_exp_ip = $mssy[0];
$mssy = explode($mssy[0], $mssf[1]);
$ftp_exp_url = $mssy[1];
$gmlobame = basename($ftp_exp_url);
return $ftp_exp_user . "%" . $ftp_exp_password . "%" . $ftp_exp_ip . "%" . $ftp_exp_url . "%" . $gmlobame;
}
if (strpos($mplogfile, "ftp:") !== false) {
list($ftp_exp_user, $ftp_exp_password, $ftp_exp_ip, $ftp_exp_url, $gmlobame) = explode("%", ftp2locallog2($mplogfile));
$filei = $cpath."ReCodMod/cache/server_empty_ftp_log.log";
$file = hxlog2($cpath."ReCodMod/cache/".$server_ip."_".$server_port."_".$gmlobame);
$posftpe = ftp_to_upload_ftp2($conn_idqnew, $ftp_q_url, $filei, $file);
if($posftpe != false)
{
debuglog2((__FILE__)."\n * RCM DEBUG: ".$server_ip."_".$server_port." Обнуление фтп лога. УСПЕХ! ");
$ftp_fatal_error = 1;
$fileh = hxlog2($cpath."ReCodMod/cache/".$server_ip."_".$server_port."_".$gmlobame);
$fp = fopen($fileh, "w");
fputs($fp, " ---\n");
$fpb = fopen($cpath . "ReCodMod/cache/x_cache/" . $server_ip . "_" . $server_port . "_pos.txt", "w+");
fputs($fpb, "0");
fclose($fpb);
$hu = fopen($cpath . "ReCodMod/cache/x_cache/" . $server_ip . "_" . $server_port . "_pos_ftp.txt", "w+");
fwrite($hub, "1");
fclose($hub);
}
else
{
debuglog2((__FILE__)."\n * ФАТАЛЬНАЯ ОШИБКА: НЕ МОЖЕТ ЗАГРУЗИТЬ НУЛЕВОЙ ФАЙЛ $filei НА ЗАМЕНУ и НЕ ОБНУЛИЛО $file !!! ПРОШЛО $xftp_time СЕКУНД! ".$server_ip."_".$server_port.".");
}
}
require $cpath . "w.php";
'> $CURDIR/cache_ms/go_$IPPORTW.php
fi
if [ ! -x $CURDIR"/go_$IPPORTW.sh" ]; then
#chown root:root $CURDIR"/go_$port.sh" && echo "The go_$port.sh is now chmod root"
#chmod 700 $CURDIR"/go_$port.sh" && echo "The go_$port.sh is now chmod 700"
chmod +x $CURDIR"/go_$IPPORTW.sh" && echo "The file is now chmod X"
else
echo "The file is already for chmod X"
fi
#gnome-terminal -e $CURDIR"/go_$port.sh" &> /dev/null
nohup $CURDIR"/go_$IPPORTW.sh" >/dev/null 2>&1 & # runs in background, still doesn't create nohup.out
else
echo '';
fi
done < $CURDIR/cfg/servers.cfg