-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsinstaller
executable file
·1433 lines (1389 loc) · 46.5 KB
/
rsinstaller
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#License:
#"Remote Syslog" is a free application what can be used to view syslog messages.
#Copyright (C) 2021 Tom Slenter
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#For more information contact the author:
#Name author: Tom Slenter
#E-mail: info@remotesyslog.com
#Variables
RSCONF=/opt/remotesyslog
RSPATH=$(pwd)
RSDEST=/opt/RS
SYSLOGCONF=/etc/syslog-ng/conf.d
APACHCONF=/var/www/html
APACONFIG=/etc/apache2/sites-available
VLOG=/var/log
RSBIN=/usr/bin
RSTMP=/tmp
APACHPHP=/etc/php/7.[0-9]/apache2
bid=00000070
#Banner
function banner() {
echo ""
echo "##################################################"
echo "#Remote Syslog (redirect enabled) #"
echo "#More information: https://www.remotesyslog.com #"
echo "#Remote Syslog installation #"
echo "#Version: RSX 0.1 #"
echo "#Donations: https://github.com/tslenter/RSX-RSC #"
echo "##################################################"
echo ""
}
#Check if user is root
if ! [ $(id -u) = 0 ]; then
clear
banner
echo "This installation must be run as root!"
echo ""
exit 1
fi
#Check build
function version() {
if [ -e "$RSBIN/rsinstaller" ]; then
fbid="$(sed -n -e '/bid/ s/.*\= *//p' $RSDEST/rsinstaller | head -n 1)"
if [ -z ${fbid} ];
then
echo "Upgrade variable not found ..."
echo "${fbid}"
else
echo "Build ${fbid} found ..."
if [ ${fbid} -le $bid ];
then
echo "This upgrade is not allowed ..."
exit
else
echo "Upgrade detected ..."
fi
fi
else
echo "File: rsinstaller not found, is rsx/rsc installed ..."
exit
fi
}
#Functions to check files, packages ...
function check_package() {
echo "Check package $1"
dpkg-query -l $1 > /dev/null 2>&1
if [ $? = 0 ]
then
echo "Installation found ..."
else
echo "Installation failed, abort (Hint: Did you install the core? ..."
exit
fi
}
#Check if file exist
function check_file() {
file=$1
if [ -e "$file" ]; then
echo "File: $1 exists, continue installation ..."
else
echo "File: $1 does not exist, exit ..."
exit
fi
}
#Check if debug module is activated
function mod_activ() {
file=$1
if [ -e "$file" ]; then
echo "Module activated ..."
else
echo "Module not activated ..."
fi
}
#Check files in reverse
function check_file_reverse() {
file=$1
if [ -e "$file" ]; then
echo "File: $1 exists, module already installed? Exiting ..."
exit
else
echo "File: $1 does not exist, continue installation ..."
fi
}
#Check file for GUI based functions
function check_file_gui() {
file=$1
if [ -e "$file" ]; then
echo "File: $1 exists, other GUI installed? Exiting ..."
exit
else
echo "File: $1 does not exist, continue installation ..."
fi
}
#Enroll functions
function rscinstall() {
#Check installation conflics ...
echo "Check if RSX is installed ..."
check_file_gui $SYSLOGCONF/99RSX-rs.conf
echo "Check if RSC is installed ..."
check_file_reverse $APACHCONF/rsc/index.php
#Install packages
echo "Starting RSC installation ..."
apt -y install apache2 apache2-utils php libapache2-mod-php libapache2-mod-authnz-external php apache2 libapache2-mod-authz-unixgroup php-cli libpam0g-dev php-pear php-dev libapache2-mod-php build-essential
check_package "apache2"
check_package "apache2-utils"
check_package "php"
check_package "libapache2-mod-php"
check_package "libapache2-mod-authnz-external"
check_package "libapache2-mod-authz-unixgroup"
check_package "php-cli"
check_package "libapache2-mod-php"
check_package "libpam0g-dev"
check_package "php-pear"
check_package "php-dev"
check_package "build-essential"
#Checks for php-pam build
echo "Check packages ..."
check_package "apache2"
check_package "build-essential"
#Load PHP authentication module
echo "Activate PHP PAM ..."
echo "Compile ..."
currentpath=$(pwd)
cd $RSDEST/php-pam
phpize
./configure --prefix=/usr
make
make install
cd $currentpath
ldconfig
#Setup php login experimental
echo "Write php config ..."
cp -rf $RSDEST/rsc/20-pam.ini $APACHPHP/conf.d/
check_file $APACHPHP/conf.d/20-pam.ini
#Setup permissions on shadow file (Dangerous)
echo "!Setup permissions /etc/shadow ...!"
chmod o+r /etc/shadow
#Remove default webpage
echo "Remove default GUI website ..."
if [ -e "$APACHCONF/index.html" ]; then
echo "File: $APACHCONF/index.html exists, remove file ..."
rm -rf $APACHCONF/index.html
else
echo "File: $APACHCONF/index.html does not exist, continue installation ..."
fi
#Create RSC directory
echo "Add RSC website ..."
echo "Create directory ..."
mkdir $APACHCONF/rsc
#Copy RSC files
echo "Copy files ..."
cp -rf $RSDEST/rsc/favicon.ico $APACHCONF/rsc/
cp -rf $RSDEST/rsc/index.php $APACHCONF/rsc/
cp -rf $RSDEST/rsc/bootstrap.min.css $APACHCONF/rsc/
cp -rf $RSDEST/rsc/bootstrap.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/bootstrap-theme.min.css $APACHCONF/rsc/
cp -rf $RSDEST/rsc/html5shiv.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/jquery.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/jquery-ui.css $APACHCONF/rsc/
cp -rf $RSDEST/rsc/jquery-ui.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/logo_black.png $APACHCONF/rsc/
cp -rf $RSDEST/rsc/PHPTail.php $APACHCONF/rsc/
cp -rf $RSDEST/rsc/respond.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/rsc.php $APACHCONF/rsc/
cp -rf $RSDEST/rsc/logout.php $APACHCONF/rsc/
cp -rf $RSDEST/rsc/login.php $APACHCONF/login.php
cp -rf $RSDEST/rsc/rscforwarder.php $APACHCONF/index.php
cp -rf $RSDEST/rsc/logo.png $APACHCONF/logo.png
cp -rf $RSDEST/rsc/favicon.ico $APACHCONF/favicon.ico
cp -rf $RSDEST/fontawesome $APACHCONF/fontawesome
cp -rf $RSDEST/rsc/style.css $APACHCONF/style.css
check_file_reverse $APACHCONF/index.html
check_file $APACHCONF/login.php
check_file $APACHCONF/index.php
check_file $APACHCONF/logo.png
check_file $APACHCONF/favicon.ico
check_file $APACHCONF/style.css
check_file $APACHCONF/fontawesome/css/all.css
check_file $APACHCONF/rsc/favicon.ico
check_file $APACHCONF/rsc/index.php
check_file $APACHCONF/rsc/bootstrap.min.css
check_file $APACHCONF/rsc/bootstrap.min.js
check_file $APACHCONF/rsc/bootstrap-theme.min.css
check_file $APACHCONF/rsc/html5shiv.min.js
check_file $APACHCONF/rsc/jquery.min.js
check_file $APACHCONF/rsc/jquery-ui.css
check_file $APACHCONF/rsc/jquery-ui.min.js
check_file $APACHCONF/rsc/logo_black.png
check_file $APACHCONF/rsc/PHPTail.php
check_file $APACHCONF/rsc/respond.min.js
check_file $APACHCONF/rsc/rsc.php
check_file $APACHCONF/rsc/logout.php
echo "Set archive symlink ..."
ln -s $VLOG/remote_syslog $APACHCONF/rsc/
#Load apache2 configuration and create SSL with authentication
echo "Load apache2 configuration with SSL ..."
#Activate SSL
echo "Activate SSL ..."
#Setup variables:
varfullservername=$(host -TtA $(hostname -s)|grep "has address"|awk '{print $1}')
certpath=/etc/cert
echo "Create .rnd file ..."
touch $HOME/.rnd
echo "Certificate auto request for linux webservers!"
echo "Powered by RSX ..."
echo "Generate Certificate ..."
if [ -f $HOME/.rnd ]; then
echo "File $HOME/.rnd exists ..."
openssl req -new -x509 -days 3650 -sha256 -newkey rsa:2048 -subj "/C=NL/ST=Limburg/L=Maastricht/O=IT/CN=$varfullservername" -nodes -keyout $HOME/$varfullservername.key -out $HOME/$varfullservername.crt
echo "Copy SSL certificates ..."
if [ -d $certpath ]; then
echo "Directory already exist ..."
else
mkdir $certpath
echo "Directory created ..."
fi
cp $HOME/$varfullservername.key $certpath/rs.key
cp $HOME/$varfullservername.crt $certpath/rs.crt
echo "Setup permissions ..."
chmod 600 $certpath/rs.key
echo "Clean up ..."
rm -rf $HOME/$varfullservername.key
rm -rf $HOME/$varfullservername.crt
echo "Generated key file: $certpath/rs.key"
echo "Generated cert file: $certpath/rs.crt"
check_file $certpath/rs.key
check_file $certpath/rs.crt
else
echo "No .rnd found ..."
fi
#Webserver configuration
echo "Activate website ..."
cp -rf $RSDEST/rsc/rsc-apache.conf $APACONFIG/rsc-apache.conf
check_file $APACONFIG/rsc-apache.conf
a2ensite rsc-apache
echo "Disable default config ..."
a2dissite 000-default
#Load apache modules
echo "Load modules ..."
a2enmod rewrite
a2enmod ssl
service apache2 restart
echo "Done ..."
}
function rscremove() {
#Check removal steps ...
echo "Check if RSX is installed ..."
check_file_gui $SYSLOGCONF/99RSX-rs.conf
echo "Check if RSC is installed"
check_file $APACHCONF/rsc/index.php
#Remove Apache files
echo "Removing RSC website ..."
rm -rf $APACHCONF/rsc/
#Check core install
echo "Removing installation RSC ..."
if [ -e "$RSBIN/rsinstaller" ]; then
echo "Core still installed ..."
apt -y purge apache2 apache2-utils php libapache2-mod-php libapache2-mod-authnz-external php apache2 libapache2-mod-authz-unixgroup php-cli libpam0g-dev php-pear php-dev libapache2-mod-php build-essential
apt -y install syslog-ng
apt -y autoremove
else
echo "No core found ..."
apt -y purge apache2 apache2-utils php libapache2-mod-php libapache2-mod-authnz-external php apache2 libapache2-mod-authz-unixgroup php-cli libpam0g-dev php-pear php-dev libapache2-mod-php build-essential
apt -y install rsyslog
apt -y autoremove
fi
#Remove Apache config and cleanup mess
rm -rf $certpath/rs.key
rm -rf $certpath/rs.crt
rm -rf $APACONFIG/rsx-apache.conf
rm -rf $APACHPHP/conf.d/20-pam.ini
rm -rf $APACHCONF/*
#Remove PHP Authentication
echo "Remove PHP authentication modules ..."
chmod o-r /etc/shadow
rm -rf $APACHPHP/conf.d/20-pam.ini
echo "Done ..."
}
#Setup environment for installation
function debpackage() {
echo "Check if Remote Syslog is installed ..."
check_file_reverse $RSBIN/rsinstaller
echo "Notice: This installation is tested for Ubuntu Server 18.04 LTS and Debian 10.x ..."
echo "Starting installation ..."
echo "Update installer cache ..."
if apt-add-repository multiverse > /dev/null 2>&1 ; then
printf 'Multiverse command succeeded\n'
apt-add-repository multiverse
else
printf 'Multiverse not found ...\n'
fi
apt update
#Install syslog-ng
echo "Checking dependencies ..."
apt -y purge rsyslog
apt -y install syslog-ng colortail wget logrotate grep tar
}
#Check if core is correctly installed
function checkinstallationcore() {
echo "Check CLI application 1X ..."
check_file $RSBIN/rsview
echo "Check user management 1X ..."
check_file $RSBIN/rsuser
echo "Check installer 1X ..."
check_file $RSBIN/rsinstaller
echo "Check logrotate 1X ..."
check_file /etc/logrotate.d/remotelog
echo "Check colortail 1X ..."
check_file /etc/colortail/conf.colortail
echo "Check syslog-ng 1X ..."
check_file $SYSLOGCONF/99-remote.conf
echo "Check remote_log dummy file 1X ..."
check_file $VLOG/remote_syslog/remote_syslog.log
echo "Check reconfiguration files 7X ..."
check_file $RSCONF/syslog-ng
check_file $RSCONF/logrotate
check_file $RSCONF/colortail
check_file $RSCONF/syslog-ngdefault
check_file $RSCONF/logrotatedefault
check_file $RSCONF/colortaildefault
check_file $RSCONF/syslog-ng-localdefault
echo "Optional: check if debug module is activated:"
mod_activ $SYSLOGCONF/99-remote-local.conf
exit
}
#Check minimum requirements
function pre_install() {
echo "Check packages installations ..."
check_package "syslog-ng"
check_package "colortail"
check_package "wget"
check_package "logrotate"
check_package "grep"
check_package "tar"
}
#Setup core install with textbased viewer
function coreinstall() {
echo "Starting core installation ..."
echo "Creating dummy remote_syslog file ..."
mkdir $VLOG/remote_syslog/
touch $VLOG/remote_syslog/remote_syslog.log
echo "Set dummy remote_syslog file permissions ..."
chown www-data:www-data $VLOG/remote_syslog/
chown www-data:www-data $VLOG/remote_syslog/remote_syslog.log
echo "Configuring syslog-ng ..."
cp -rf $RSDEST/core/syslog-ng $SYSLOGCONF/99-remote.conf
echo "Restart syslog-ng ..."
service syslog-ng restart
echo "Set logrotation ..."
cp -rf $RSDEST/core/logrotate /etc/logrotate.d/remotelog
echo "Activate colortail regex ..."
cp -rf $RSDEST/core/colortail /etc/colortail/conf.colortail
echo "Deploying application for CLI logging ..."
cp -rf $RSDEST/rsview $RSBIN/rsview
echo "Set permissions for CLI application ..."
chmod +x $RSBIN/rsview
echo "Deploying installer ..."
cp -rf $RSDEST/rsinstaller $RSBIN/rsinstaller
echo "User Management ..."
cp -rf $RSDEST/rsuser $RSBIN/rsuser
echo "Set permissions user Management ..."
chmod +x $RSBIN/rsuser
echo "Deploy config to $RSCONF/ ..."
mkdir $RSCONF/
cp -rf $RSDEST/core/syslog-ng $RSCONF/
cp -rf $RSDEST/core/syslog-ng $RSCONF/syslog-ngdefault
cp -rf $RSDEST/core/logrotate $RSCONF/
cp -rf $RSDEST/core/logrotate $RSCONF/logrotatedefault
cp -rf $RSDEST/core/colortail $RSCONF/
cp -rf $RSDEST/core/colortail $RSCONF/colortaildefault
cp -rf $RSDEST/core/syslog-ng-local $RSCONF/syslog-ng-localdefault
}
#Remove core and RSX or RSC (Complete deinstall)
function coreremove() {
echo "Check if Remote Syslog is installed ..."
check_file "$RSBIN/rsinstaller"
echo "Starting core removal ..."
echo "Configuring syslog-ng ..."
rm -rf $SYSLOGCONF/99-remote.conf
if [ -e "$SYSLOGCONF/99-remote-local.conf" ]; then
rm -rf $SYSLOGCONF/99-remote-local.conf
else
echo "No local debug found ..."
fi
echo "Removing packages syslog-ng ..."
apt -y purge syslog-ng colortail
apt -y autoremove
apt -y install rsyslog
echo "Set logrotation ..."
rm -rf /etc/logrotate.d/remotelog
echo "Remove colortail regex ..."
rm -rf /etc/colortail/conf.colortail
echo "Remove application for CLI logging ..."
rm -rf $RSBIN/rsview
echo "Remove config to $RSCONF/ ..."
rm -rf $RSCONF
echo "Remove $RSDEST"
rm -rf $RSDEST
echo "Remove installer ..."
rm -rf $RSBIN/rsinstaller
echo "Remove user management ..."
rm -rf $RSBIN/rsuser
echo "Remove REPO file ..."
rm -rf /etc/apt/sources.list.d/91-debian-unstable.list
echo "Move log files ..."
cp -rf $VLOG/remote_syslog $VLOG/remote_syslog_uninstall && rm -rf $VLOG/remote_syslog
echo "Moved files to $VLOG/remote_syslog_uninstall .."
if [ -e "$APACHCONF/rsc/index.php" ]; then
rscremove
elif [ -e $SYSLOGCONF/99RSX-rs.conf ]; then
rsxremove
else
echo "No GUI found, remove done ..."
fi
}
#Upgrade function
function guiupgrade() {
echo "Check if Remote Syslog is installed ..."
check_file "$RSBIN/rsinstaller"
#Check packages
if [ -e "$APACHCONF/rsc/index.php" ]; then
check_file $APACHCONF/rsc/index.php
echo "Starting installation legacy GUI ..."
check_package "apache2"
check_package "apache2-utils"
check_package "php"
check_package "libapache2-mod-php"
check_package "apache2"
check_package "apache2-utils"
check_package "php"
check_package "libapache2-mod-php"
check_package "libapache2-mod-authnz-external"
check_package "libapache2-mod-authz-unixgroup"
check_package "php-cli"
check_package "libapache2-mod-php"
check_package "libpam0g-dev"
check_package "php-pear"
check_package "php-dev"
check_package "build-essential"
#Update Webpage
echo "Update webpage code ..."
cp -rf $RSDEST/rsc/favicon.ico $APACHCONF/rsc/
cp -rf $RSDEST/rsc/index.php $APACHCONF/rsc/
cp -rf $RSDEST/rsc/bootstrap.min.css $APACHCONF/rsc/
cp -rf $RSDEST/rsc/bootstrap.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/bootstrap-theme.min.css $APACHCONF/rsc/
cp -rf $RSDEST/rsc/html5shiv.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/jquery.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/jquery-ui.css $APACHCONF/rsc/
cp -rf $RSDEST/rsc/jquery-ui.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/logo_black.png $APACHCONF/rsc/
cp -rf $RSDEST/rsc/PHPTail.php $APACHCONF/rsc/
cp -rf $RSDEST/rsc/respond.min.js $APACHCONF/rsc/
cp -rf $RSDEST/rsc/rsc.php $APACHCONF/rsc/
cp -rf $RSDEST/rsc/logout.php $APACHCONF/rsc/
cp -rf $RSDEST/rsc/login.php $APACHCONF/login.php
cp -rf $RSDEST/rsc/rscforwarder.php $APACHCONF/index.php
cp -rf $RSDEST/rsc/logo.png $APACHCONF/logo.png
cp -rf $RSDEST/rsc/favicon.ico $APACHCONF/favicon.ico
cp -rf $RSDEST/fontawesome $APACHCONF/fontawesome
cp -rf $RSDEST/rsc/style.css $APACHCONF/style.css
check_file_reverse $APACHCONF/index.html
check_file $APACHCONF/login.php
check_file $APACHCONF/index.php
check_file $APACHCONF/logo.png
check_file $APACHCONF/favicon.ico
check_file $APACHCONF/style.css
check_file $APACHCONF/fontawesome/css/all.css
check_file $APACHCONF/rsc/favicon.ico
check_file $APACHCONF/rsc/index.php
check_file $APACHCONF/rsc/bootstrap.min.css
check_file $APACHCONF/rsc/bootstrap.min.js
check_file $APACHCONF/rsc/bootstrap-theme.min.css
check_file $APACHCONF/rsc/html5shiv.min.js
check_file $APACHCONF/rsc/jquery.min.js
check_file $APACHCONF/rsc/jquery-ui.css
check_file $APACHCONF/rsc/jquery-ui.min.js
check_file $APACHCONF/rsc/logo_black.png
check_file $APACHCONF/rsc/PHPTail.php
check_file $APACHCONF/rsc/respond.min.js
check_file $APACHCONF/rsc/rsc.php
check_file $APACHCONF/rsc/logout.php
echo "Done ..."
echo "Restarting Apache ..."
service apache2 restart
echo "Restarting Syslog-NG ..."
service syslog-ng restart
echo "Upgrade GUI done ..."
elif [ -e $SYSLOGCONF/99RSX-rs.conf ]; then
echo "Check packages ..."
check_package "apache2"
check_package "apache2-utils"
check_package "php"
check_package "libapache2-mod-php"
check_package "apache2"
check_package "apache2-utils"
check_package "php"
check_package "libapache2-mod-php"
check_package "libapache2-mod-authnz-external"
check_package "libapache2-mod-authz-unixgroup"
check_package "php-cli"
check_package "libapache2-mod-php"
check_package "libpam0g-dev"
check_package "php-pear"
check_package "php-dev"
check_package "build-essential"
#Enable if required, but any custom apache2 config will be lost
#echo "Copy new apache config ..."
#cp -rf $RSDEST/rsx/rsx-apache.conf $APACONFIG/rsx-apache.conf
#check_file $APACONFIG/rsx-apache.conf
#echo "Update syslog-ng with RSX config ..."
#cp $RSDEST/rsx/99RSX-rs.conf $SYSLOGCONF/99RSX-rs.conf
check_file $SYSLOGCONF/99RSX-rs.conf
cp -rf $RSDEST/rsx/login.php $APACHCONF/login.php
cp -rf $RSDEST/rsx/rsxforwarder.php $APACHCONF/index.php
cp -rf $RSDEST/rsx/logo.png $APACHCONF/logo.png
cp -rf $RSDEST/rsx/favicon.ico $APACHCONF/favicon.ico
cp -rf $RSDEST/fontawesome $APACHCONF/fontawesome
cp -rf $RSDEST/rsx/style.css $APACHCONF/style.css
check_file_reverse $APACHCONF/index.html
check_file $APACHCONF/login.php
check_file $APACHCONF/index.php
check_file $APACHCONF/logo.png
check_file $APACHCONF/favicon.ico
check_file $APACHCONF/fontawesome/css/all.css
check_file $APACHCONF/style.css
echo "Restarting Apache ..."
service apache2 restart
echo "Restarting Syslog-NG ..."
service syslog-ng restart
echo "To upgrade the default config run the 'Restore default core configuration' option ..."
echo "Warning this will override the plugin and custom configuration files ..."
echo "Upgrade GUI done ..."
else
echo "No GUI found, upgrade done ..."
fi
}
#Upgrade online
function upgrade() {
echo "Check if Remote Syslog is installed ..."
check_file $RSBIN/rsinstaller
echo "Starting upgrade ..."
echo "Download installation ..."
git clone --branch master https://github.com/tslenter/RSX-RSC.git $RSTMP/rs
echo "Check if download is successfull"
if [ -d "$RSTMP/rs" ]; then
echo "Continue installation ..."
else
echo "Clone not successfull ..."
exit
fi
cp -rf $RSTMP/rs/* $RSDEST
rm -rf $RSTMP/rs
version
echo "Start update ..."
echo "Deploying application for CLI logging ..."
cp -rf $RSDEST/rsview $RSBIN/rsview
echo "Set permissions for CLI application ..."
chmod +x $RSBIN/rsview
echo "Deploying user management ..."
cp -rf $RSDEST/rsuser $RSBIN/rsuser
echo "Set permissions for user management ..."
chmod +x $RSBIN/rsuser
echo "Deploying installer ..."
cp -rf $RSDEST/rsinstaller $RSBIN/rsinstaller
echo "Set permissions for installer ..."
chmod +x $RSBIN/rsinstaller
echo "Set new default core configuration in $RSCONF/ ..."
cp -rf $RSDEST/core/syslog-ng $RSCONF/syslog-ngdefault
cp -rf $RSDEST/core/logrotate $RSCONF/logrotatedefault
cp -rf $RSDEST/core/colortail $RSCONF/colortaildefault
echo "Copy upgrade file to $RSTMP/ ..."
cp -rf $RSDEST/extraupgrade $RSTMP/extraupgrade
chmod +x $RSTMP/extraupgrade
$RSTMP/extraupgrade
echo "Remove update file ..."
rm -rf $RSTMP/extraupgrade
echo "Remove upgrade folder ..."
rm -rf $RSTMP/rs
echo "Restart syslog-ng ..."
service syslog-ng restart
guiupgrade
}
#Upgrade platform
function osupdate() {
echo "Start OS update ..."
echo "WARNING: This will upgrade all Elasticsearch products ..."
read -p "Are you sure? Press y/Y: " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
apt update && apt upgrade -y
if [ -e /etc/kibana/kibana.yml ]; then
echo "RSX Kibana found ..."
echo "Restart services ..."
service kibana stop
service kibana start
else
echo "Nothing to do"
fi
else
echo "Nothing to do"
fi
#Disabled apt autoremove may break something. Run apt autoremove -y if you like to remove unused packages.
#apt autoremove -y
}
function changedefault() {
echo "Reconfigure default values ..."
cp -rf $RSCONF/syslog-ng $SYSLOGCONF/99-remote.conf
echo "Restart syslog-ng ..."
service syslog-ng restart
echo "Set logrotation ..."
cp -rf $RSCONF/logrotate /etc/logrotate.d/remotelog
echo "Activate colortail regex ..."
cp -rf $RSCONF/colortail /etc/colortail/conf.colortail
}
function restoredefault() {
echo "Restore default syslog-ng values..."
cp -rf $RSCONF/syslog-ngdefault $SYSLOGCONF/99-remote.conf
echo "Restart syslog-ng ..."
service syslog-ng restart
echo "Restore default logrotation ..."
cp -rf $RSCONF/logrotatedefault /etc/logrotate.d/remotelog
echo "Restore default colortail regex ..."
cp -rf $RSCONF/colortaildefault /etc/colortail/conf.colortail
read -p "Do you want to reset RSX configuration? y/n " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Restore default RSX configuration ..."
cp -rf $RSDEST/rsx/rsx-apache.conf $APACONFIG/rsx-apache.conf
cp $RSDEST/rsx/99RSX-rs.conf $SYSLOGCONF/99RSX-rs.conf
else
echo "Done ..."
fi
}
#Activate debug for rsview
function startdebug() {
echo "Activate local syslog for debug ..."
cp -rf $RSCONF/syslog-ng-localdefault $SYSLOGCONF/99-remote-local.conf
echo "Restart syslog-ng ..."
service syslog-ng restart
}
#Stop debug for rsview
function stopdebug() {
echo "Deactivate local syslog for debug ..."
rm -rf $SYSLOGCONF/99-remote-local.conf
echo "Restart syslog-ng ..."
service syslog-ng restart
}
#FIX for larger RSC searches
function extentphplimit() {
echo "Extent PHP limit to 512M ..."
check_file $APACHPHP/php.ini
echo "Setting PHP limit to 512M ..."
sed -i '/memory_limit/c\\memory_limit = 512M' $APACHPHP/php.ini
echo "Restarting webservices ..."
service apache2 restart
}
#Restore FIX for larger RSC searches
function restorephplimit() {
echo "Restoring PHP limit to default values 128M ..."
check_file $APACHPHP/php.ini
echo "Setting PHP limit to 128M ..."
sed -i '/memory_limit/c\\memory_limit = 128M' $APACHPHP/php.ini
echo "Restarting webservices ..."
service apache2 restart
}
#Installation RSX
function rsxinstall() {
#Check installation
echo "Check if Raspberry Pi ..."
drel="$(lsb_release -a | egrep 'Description:')"
echo "$drel found ..."
if [[ $drel =~ "Raspbian" ]]; then
echo "Raspberry Pi detected, RSX unsupported ..."
echo "It is to slow and is missing some packages ..."
echo "Abort ..."
exit
else
echo "Continue ..."
fi
echo "Check GUI ..."
check_file_gui $APACHCONF/rsc/index.php
check_file_reverse $SYSLOGCONF/99RSX-rs.conf
echo "Check if Remote Syslog is installed ..."
check_file "$RSBIN/rsinstaller"
#Install packages
echo "Install required packages ..."
apt install libapache2-mod-authnz-external php apache2 libapache2-mod-authz-unixgroup php-cli libpam0g-dev php-pear php-dev libapache2-mod-php build-essential -y
check_package "libapache2-mod-authnz-external"
check_package "apache2"
check_package "php"
check_package "libapache2-mod-authz-unixgroup"
check_package "php-cli"
check_package "libapache2-mod-php"
check_package "libpam0g-dev"
check_package "php-pear"
check_package "php-dev"
check_package "build-essential"
#Load apache modules
echo "Load modules ..."
a2enmod proxy
a2enmod proxy_http
a2enmod headers
a2enmod authnz_external
a2enmod authz_unixgroup
a2enmod rewrite
a2enmod ssl
a2enmod session
a2enmod auth_form
a2enmod request
a2enmod session_cookie
a2enmod session_crypto
#Elastic
echo "Load Elastic ..."
if [ -e "/etc/apt/sources.list.d/elastic-7.x.list" ]; then
echo "Nothing to do ..."
else
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
apt-get install apt-transport-https -y
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list
echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list
fi
apt update && apt install elasticsearch liblog4j2-java -y
check_package "elasticsearch"
check_package "liblog4j2-java"
#Install Kibana
echo "Install Kibana ..."
apt update && apt install kibana -y
#Writing config
#RSX Syslog-ng config
echo "Update syslog-ng with RSX config ..."
cp $RSDEST/rsx/99RSX-rs.conf $SYSLOGCONF/99RSX-rs.conf
#RSX elastic config
elc="$(cat /etc/elasticsearch/elasticsearch.yml | grep cluster.name:.rsx | head -n 1)"
if [[ $elc == *"cluster.name: rsx"* ]]; then
echo "Config already written ..."
else
echo "Write elastic config ..."
echo "cluster.name: rsx" >> /etc/elasticsearch/elasticsearch.yml
echo "node.name: ${HOSTNAME}" >> /etc/elasticsearch/elasticsearch.yml
fi
#RSX kibana config
kic="$(cat /etc/kibana/kibana.yml | grep server.rewriteBasePath:.true | head -n 1)"
if [[ $kic == *"server.rewriteBasePath: true"* ]]; then
echo "Config already written ..."
else
echo "Write kibana config ..."
echo 'server.rewriteBasePath: true' >> /etc/kibana/kibana.yml
echo 'server.basePath: "/kibana"' >> /etc/kibana/kibana.yml
fi
#Activate service on boot
echo "Activate startup log configuration ..."
systemctl enable kibana
systemctl enable elasticsearch
#Reload services
echo "Activate start/reload configuration ..."
service elasticsearch start
service kibana start
service syslog-ng restart
#Activate SSL
echo "Activate SSL ..."
#Setup variables:
varfullservername=$(host -TtA $(hostname -s)|grep "has address"|awk '{print $1}')
certpath=/etc/cert/
echo "Create .rnd file ..."
touch $HOME/.rnd
echo "Certificate auto request for linux webservers!"
echo "Powered by RSX ..."
echo "Generate Certificate ..."
if [ -f $HOME/.rnd ]; then
echo "File $HOME/.rnd exists ..."
openssl req -new -x509 -days 3650 -sha256 -newkey rsa:2048 -subj "/C=NL/ST=Limburg/L=Maastricht/O=IT/CN=$varfullservername" -nodes -keyout $HOME/$varfullservername.key -out $HOME/$varfullservername.crt
echo "Copy SSL certificates ..."
if [ -d $certpath ]; then
echo "Directory already exist ..."
else
mkdir $certpath
echo "Directory created ..."
fi
cp $HOME/$varfullservername.key $certpath/rs.key
cp $HOME/$varfullservername.crt $certpath/rs.crt
echo "Setup permissions ..."
chmod 600 $certpath/rs.key
echo "Clean up ..."
rm -rf $HOME/$varfullservername.key
rm -rf $HOME/$varfullservername.crt
echo "Generated key file: $certpath/rs.key"
echo "Generated cert file: $certpath/rs.crt"
check_file $certpath/rs.key
check_file $certpath/rs.crt
else
echo "No .rnd found ..."
fi
#Proxy setup
echo "Activate proxy ..."
echo "Disable default config ..."
cp -rf $RSDEST/rsx/rsx-apache.conf $APACONFIG/rsx-apache.conf
check_file $APACONFIG/rsx-apache.conf
a2ensite rsx-apache
a2dissite 000-default
#Remove default webpage
echo "Remove default GUI website ..."
if [ -e "$APACHCONF/index.html" ]; then
echo "File: $APACHCONF/index.html exists, remove file ..."
rm -rf $APACHCONF/index.html
else
echo "File: $APACHCONF/index.html does not exist, continue installation ..."
fi
#Create login website
echo "Create login for webpages ..."
cp -rf $RSDEST/rsx/login.php $APACHCONF/login.php
cp -rf $RSDEST/rsx/rsxforwarder.php $APACHCONF/index.php
cp -rf $RSDEST/rsx/logo.png $APACHCONF/logo.png
cp -rf $RSDEST/rsx/favicon.ico $APACHCONF/favicon.ico
cp -rf $RSDEST/fontawesome $APACHCONF/fontawesome
cp -rf $RSDEST/rsx/style.css $APACHCONF/style.css
check_file_reverse $APACHCONF/index.html
check_file $APACHCONF/login.php
check_file $APACHCONF/index.php
check_file $APACHCONF/logo.png
check_file $APACHCONF/favicon.ico
check_file $APACHCONF/style.css
check_file $APACHCONF/fontawesome/css/all.css
echo "Reload apache services ..."
service apache2 restart
#Final message
echo "RSX installation done ..."
}
#RSX removal
function rsxremove() {
#Basic check
check_file_gui $APACHCONF/rsc/index.php
check_file $SYSLOGCONF/99RSX-rs.conf
#Remove Syslog-NG RSX config
rm -rf $SYSLOGCONF/99RSX-rs.conf
echo "Restart Syslog-NG ..."
service syslog-ng restart
#Remove Apache config
rm -rf $certpath/rs.key
rm -rf $certpath/rs.crt
rm -rf $APACONFIG/rsx-apache.conf
rm -rf $APACHPHP/conf.d/20-pam.ini
rm -rf $APACHCONF/*
#Remove packages
echo "Remove config ..."
rm -rf /etc/apt/sources.list.d/elastic-7.x.list
rm -rf /etc/elasticsearch/elasticsearch.yml
rm -rf /etc/kibana/kibana.yml
echo "Remove packages ..."
apt -y purge kibana elasticsearch liblog4j2-java libapache2-mod-authnz-external php apache2 libapache2-mod-authz-unixgroup php-cli libpam0g-dev php-pear php-dev libapache2-mod-php build-essential -y
apt -y install syslog-ng
apt -y autoremove
echo "RSX removed ..."
}
#Thank you message
function quit() {
echo "Thank you for using Remote Syslog ..."
}
function fwenable() {
echo "Install package ufw ..."
apt install -y ufw
echo "Activation of ufw rules ..."
check_package "ufw"
echo "Setting firewall rules ..."
ufw allow 22/tcp
ufw allow 8080/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 514/tcp
ufw allow 514/udp
ufw --force enable
ufw status
echo "Done ..."
}
function fwdisable() {
check_package "ufw"
echo "Disable firewall rules ..."
ufw disable
ufw status
echo "Done ..."
}
function status() {
dpkg-query -l syslog-ng > /dev/null 2>&1
if [ $? = 0 ]
then
echo "Installation found ..."
service syslog-ng status | cat
else
echo "Installation not found, skipped ..."
fi
dpkg-query -l apache2 > /dev/null 2>&1
if [ $? = 0 ]
then
echo "Installation found ..."
service apache2 status | cat
else
echo "Installation not found, skipped ..."
fi
dpkg-query -l elasticsearch > /dev/null 2>&1
if [ $? = 0 ]
then
echo "Installation found ..."
service elasticsearch status | cat
else
echo "Installation not found, skipped ..."
fi
dpkg-query -l kibana > /dev/null 2>&1
if [ $? = 0 ]
then
echo "Installation found ..."
service kibana status | cat
else
echo "Installation not found, skipped ..."
fi
dpkg-query -l ufw > /dev/null 2>&1
if [ $? = 0 ]
then
ufwcheck2="$(dpkg-query -l ufw | egrep '<none>')"
if [[ $ufwcheck2 =~ "<none>" ]]; then
echo "ufw missing ..."
else
echo "Installation found ..."
ufw status
fi
else
echo "Installation not found, skipped ..."
fi
echo "Done ..."
}
function ubntrepofix() {
#Syslog-ng
echo "Update repository's ..."