forked from egystory/Librekernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-configuration-script.sh
executable file
·7126 lines (6131 loc) · 223 KB
/
app-configuration-script.sh
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
# ---------------------------------------------------------
# This script aims to configure all the packages and
# services which have been installed by test.sh script.
# This script is functionally seperated into 4 parts
# 1. Detect system variables
# 2. Configuration of Network Interfaces
# 3. Configuration of Revers Proxy Services
# 4. Configuration of Applications
# ---------------------------------------------------------
# ---------------------------------------------------------
# Variables list
# ---------------------------------------------------------
PROCESSOR="Not Detected" # Processor type (ARM/Intel/AMD)
HARDWARE="Not Detected" # Hardware type (Board/Physical/Virtual)
PLATFORM="Not Detected" # Platform type (U12/U14/D7/D8/T7)
ARCH="Not Detected" # Architecture (i386/x86_64)
EXT_INTERFACE="Not Detected" # External Interface (Connected to Internet)
INT_INETRFACE="Not Detected" # Internal Interface (Connected to local network)
POSTFIX_PASS="null" # Password for postfixadmin admin account
# ---------------------------------------------------------
# This function checks user.
# Script must be executed by root user, otherwise it will
# output an error and terminate further execution.
# ---------------------------------------------------------
check_root ()
{
echo -ne "Checking user root ... " | tee /var/libre_config.log
if [ "$(whoami)" != "root" ]; then
echo "Fail"
echo "You need to be root to proceed. Exiting"
exit 1
else
echo "OK" | tee -a /var/libre_config.log
fi
}
# ---------------------------------------------------------
# Function to get varibales from /var/box_variables file
# Variables to be initialized are:
# PLATFORM
# HARDWARE
# PROCESSOR
# EXT_INTERFACE
# INT_INTERFACE
# ----------------------------------------------------------
get_variables()
{
echo "Initializing variables ..." | tee -a /var/libre_config.log
if [ -e /var/box_variables ]; then
PLATFORM=`cat /var/box_variables | grep "Platform" | awk {'print $2'}`
HARDWARE=`cat /var/box_variables | grep "Hardware" | awk {'print $2'}`
PROCESSOR=`cat /var/box_variables | grep "Processor" | awk {'print $2'}`
ARCH=`cat /var/box_variables | grep "Architecture" | awk {'print $2'}`
EXT_INTERFACE=`cat /var/box_variables | grep "Ext_int" | awk {'print $2'}`
INT_INTERFACE=`cat /var/box_variables | grep "Int_int" | awk {'print $2'}`
# touch "/tmp/variables.log"
if [ -z "$PLATFORM" -o -z "$HARDWARE" \
-o -z "$PROCESSOR" -o -z "$ARCH" \
-o -z "$EXT_INTERFACE" -o -z "$INT_INTERFACE" ]; then
echo "Error: Can not detect variables. Exiting"
exit 5
else
echo "Platform: $PLATFORM" | tee -a /var/libre_config.log
echo "Hardware: $HARDWARE" | tee -a /var/libre_config.log
echo "Processor: $PROCESSOR" | tee -a /var/libre_config.log
echo "Architecture: $ARCH" | tee -a /var/libre_config.log
echo "Ext Interface: $EXT_INTERFACE" | tee -a /var/libre_config.log
echo "Int Interface: $INT_INTERFACE" | tee -a /var/libre_config.log
fi
else
echo "Error: i cant find variables of the machine and operating system ,the installation script wasnt installed or failed, please check the Os requirements (at the moment only works in Debian 8 we are ongoing to ubuntu)" | tee -a /var/libre_config.log
exit 6
fi
}
# ----------------------------------------------
# This function detects platform.
#
# Suitable platform are:
#
# * Ubuntu 12.04
# * Ubuntu 14.04
# * Debian GNU/Linux 7
# * Debian GNU/Linux 8
# * Trisquel 7
# ----------------------------------------------
get_platform ()
{
echo "Detecting platform ..." | tee -a /var/libre_config.log
FILE=/etc/issue
if cat $FILE | grep "Ubuntu 12.04" > /dev/null; then
PLATFORM="U12"
elif cat $FILE | grep "Ubuntu 14.04" > /dev/null; then
PLATFORM="U14"
elif cat $FILE | grep "Debian GNU/Linux 7" > /dev/null; then
PLATFORM="D7"
elif cat $FILE | grep "Debian GNU/Linux 8" > /dev/null; then
PLATFORM="D8"
elif cat $FILE | grep "Trisquel GNU/Linux 7.0" > /dev/null; then
PLATFORM="T7"
else
echo "ERROR: UNKNOWN PLATFORM" | tee -a /var/libre_config.log
exit
fi
echo "Platform: $PLATFORM" | tee -a /var/libre_config.log
}
# ----------------------------------------------
# This function checks hardware
# Hardware can be.
# 1. Intel board pipo x10.
# 2. Intel Physical/Virtual machine.
# Function gets Processor, Hardware and
# Architecture types and saves them in
# PROCESSOR, HARDWARE and ARCH variables.
# ----------------------------------------------
get_hardware()
{
echo "Detecting hardware ..." | tee -a /var/libre_config.log
# Checking CPU for ARM and saving
# Processor and Hardware types in
# PROCESSOR and HARDWARE variables
if grep ARM /proc/cpuinfo > /dev/null 2>&1; then
PROCESSOR="ARM"
HARDWARE=`cat /proc/cpuinfo | grep Hardware | awk {'print $3'}`
# Checking CPU for Intel and saving
# Processor and Hardware types in
# PROCESSOR and HARDWARE variables
elif grep Intel /proc/cpuinfo > /dev/null 2>&1; then
PROCESSOR="Intel"
HARDWARE=`dmidecode -s system-product-name`
# Checking CPU for AMD and saving
# Processor and Hardware types in
# PROCESSOR and HARDWARE variables
elif grep AMD /proc/cpuinfo > /dev/null 2>&1; then
PROCESSOR="AMD"
HARDWARE=`dmidecode -s system-product-name`
fi
# Detecting Architecture
ARCH=`uname -m`
# Printing Processor Hardware and Architecture types
echo "Processor: $PROCESSOR" | tee -a /var/libre_config.log
echo "Hardware: $HARDWARE" | tee -a /var/libre_config.log
echo "Architecture: $ARCH" | tee -a /var/libre_config.log
}
# ----------------------------------------------
# This function enables DHCP client and checks
# for Internet on predefined network interface.
#
# Steps to define interface are:
#
# 1. Checking Internet access.
# *
# *
# ***** If success.
# *
# * 2. Get Interface name
# *
# ***** If no success.
# *
# * 2. Checking for DHCP server and Internet in
# * network connected to eth0.
# *
# ***** If success.
# * *
# * * 2. Enable DHCP client on eth0 and
# * default route to eth0
# *
# ***** If no success.
# *
# * 2. Checking for DHCP server and Internet
# * in network connected to eth1
# *
# ***** If success.
# * *
# * * 3. Enable DHCP client on eth1.
# *
# *
# ***** If no success.
# *
# * 3. Warn user and exit with error.
#
# ----------------------------------------------
get_interfaces()
{
# Removing firewall
iptables -F
iptables -t nat -F
iptables -t mangle -F
# Check internet Connection. If Connection exist then get
# and save Internet side network interface name in
# EXT_INTERFACE variable
if ping -c1 8.8.8.8 >/dev/null 2>/dev/null; then
EXT_INTERFACE=`route -n | awk {'print $1 " " $8'} | grep "0.0.0.0" | awk {'print $2'} | sed -n '1p'`
echo "Internet connection established on interface $EXT_INTERFACE" | tee -a /var/libre_config.log
else
# Checking eth0 for Internet connection
echo "Getting Internet access on eth0"
echo "# interfaces(5) file used by ifup(8) and ifdown(8) " > /etc/network/interfaces
echo -e "auto lo\niface lo inet loopback\n" >> /etc/network/interfaces
echo -e "auto eth0\niface eth0 inet dhcp" >> /etc/network/interfaces
/etc/init.d/networking restart
if ping -c1 8.8.8.8 >/dev/null 2>/dev/null; then
echo "Internet conection established on: eth0"
EXT_INTERFACE="eth0"
else
echo "Warning: Unable to get Internet access on eth0"
# Checking eth1 for Internet connection
echo "Getting Internet access on eth1"
echo "# interfaces(5) file used by ifup(8) and ifdown(8) " > /etc/network/interfaces
echo -e "auto lo\niface lo inet loopback\n" >> /etc/network/interfaces
echo -e "auto eth1\niface eth1 inet dhcp" >> /etc/network/interfaces
/etc/init.d/networking restart
if ping -c1 8.8.8.8 >/dev/null 2>/dev/null; then
echo "Internet conection established on: eth1"
EXT_INTERFACE="eth1"
else
echo "Warning: Unable to get Internet access on eth1"
echo "Please plugin Internet cable to eth0 or eth1 and enable DHCP on gateway"
echo "Error: Unable to get Internet access. Exiting"
exit 7
fi
fi
fi
echo "Checking DNS resolution ..." | tee -a /var/libre_config.log
if ! getent hosts github.com >> /var/libre_config.log; then
echo "You need DNS resolution to proceed... Exiting" | tee -a /var/libre_config.log
exit 1
fi
echo "Showing the interface configuration ..." | tee -a /var/libre_config.log
CLINKUP=$(ip link |grep UP |grep eth | cut -d: -f2 |sed -n 1p)
CWANIP=$(wget -qO- ipinfo.io/ip)
CLANIP=$(ifconfig $CLINKUP | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
CNETMASK=$(ifconfig $CLINKUP | grep 'Mask:' | cut -d: -f4 | awk '{ print $1}')
CGWIP=$(route -n | grep 'UG[ \t]' | awk '{print $2}')
CDNS=$(cat /etc/resolv.conf | cut -d: -f2 | awk '{ print $2}')
echo 'Wired interface:' $CLINKUP
echo 'Public IP:' $CWANIP
echo 'LAN IP:' $CLANIP
echo 'Netmask:' $CNETMASK
echo 'Gateway:' $CGWIP
echo 'DNS Servers:' $CDNS
# Getting internal interface name
INT_INTERFACE=`ls /sys/class/net/ | grep -w 'eth0\|eth1\|wlan0\|wlan1' | grep -v "$EXT_INTERFACE" | sed -n '1p'`
echo "Internal interface: $INT_INTERFACE" | tee -a /var/libre_config.log
}
# ---------------------------------------------------------
# Function to get info about available HDDs
# ---------------------------------------------------------
get_hdd(){
echo "Checking HDDs ..." | tee -a /var/libre_config.log
ALL_HDD=`lsblk -l | grep "disk" | awk '{print $1}' ORS=' '`
HDDS=`lsblk -l | grep "disk" | awk '{print $1}' | wc -l`
SYS_HDD=`lsblk -l | grep -w "/" | awk '{print $1}' | sed 's/[0-9]//g'`
if [ $HDDS -ge 2 ]; then
EXT_HDD=`echo $ALL_HDD | sed s/"$SYS_HDD "//g`
else
EXT_HDD="N/A"
fi
echo "
Detected: $ALL_HDD
System: $SYS_HDD
External: $EXT_HDD
" | tee -a /var/libre_config.log
}
# ---------------------------------------------------------
# This functions configures hostname and static lookup
# table
# ---------------------------------------------------------
configure_hosts()
{
echo "Configuring hosts ..." | tee -a /var/libre_config.log
echo "librerouter" > /etc/hostname
cat << EOF > /etc/hosts
#
# /etc/hosts: static lookup table for host names
#
#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.librenet librerouter localhost
10.0.0.1 librerouter.librenet
10.0.0.12 snorby.librenet
10.0.0.238 waffle.librerouter.net
10.0.0.239 kibana.librerouter.net
10.0.0.240 glype.librerouter.net
10.0.0.241 sogo.librerouter.net
10.0.0.242 postfix.librerouter.net
10.0.0.243 roundcube.librerouter.net
10.0.0.244 ntop.librerouter.net
10.0.0.245 webmin.librerouter.net
10.0.0.246 squidguard.librerouter.net
10.0.0.247 gitlab.librerouter.net
10.0.0.248 trac.librerouter.net
10.0.0.249 redmine.librerouter.net
10.0.0.250 conference.librerouter.net
10.0.0.251 search.librerouter.net
10.0.0.252 social.librerouter.net
10.0.0.253 storage.librerouter.net
10.0.0.254 email.librerouter.net
EOF
}
# ----------------------------------------------
# This script installs bridge-utils package and
# configures bridge interfaces.
#
# br0 = eth0 and wlan0
# br1 = eth1 and wlan1
# ----------------------------------------------
configure_bridges()
{
EXT_BR_INT=`echo $EXT_INTERFACE | tail -c 2`
INT_BR_INT=`echo $INT_INTERFACE | tail -c 2`
echo "Configuring bridge interfaces..."
echo "# interfaces(5) file used by ifup(8) and ifdown(8) " > /etc/network/interfaces
echo "auto lo" >> /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
# Configuring bridge interfaces
echo "#External network interface" >> /etc/network/interfaces
echo "auto $EXT_INTERFACE" >> /etc/network/interfaces
echo "allow-hotplug $EXT_INTERFACE" >> /etc/network/interfaces
echo "iface $EXT_INTERFACE inet dhcp" >> /etc/network/interfaces
echo "#External network interface" >> /etc/network/interfaces
echo "auto wlan$EXT_BR_INT" >> /etc/network/interfaces
echo "allow-hotplug wlan$EXT_BR_INT" >> /etc/network/interfaces
echo "iface wlan$EXT_BR_INT inet manual" >> /etc/network/interfaces
echo "##External Network Bridge " >> /etc/network/interfaces
echo "#auto br$EXT_BR_INT" >> /etc/network/interfaces
echo "#allow-hotplug br$EXT_BR_INT" >> /etc/network/interfaces
echo "#iface br$EXT_BR_INT inet dhcp" >> /etc/network/interfaces
echo "#bridge_ports eth$EXT_BR_INT wlan$EXT_BR_INT" >> /etc/network/interfaces
echo "#Internal network interface" >> /etc/network/interfaces
echo "auto $INT_INTERFACE" >> /etc/network/interfaces
echo "allow-hotplug $INT_INTERFACE" >> /etc/network/interfaces
echo "iface $INT_INTERFACE inet manual" >> /etc/network/interfaces
echo "#Internal network interface" >> /etc/network/interfaces
echo "auto wlan$INT_BR_INT" >> /etc/network/interfaces
echo "allow-hotplug wlan$INT_BR_INT" >> /etc/network/interfaces
echo "iface wlan$INT_BR_INT inet manual" >> /etc/network/interfaces
echo "# Internal network Bridge" >> /etc/network/interfaces
echo "auto br$INT_BR_INT" >> /etc/network/interfaces
echo "allow-hotplug br$INT_BR_INT" >> /etc/network/interfaces
echo "# Setup bridge" >> /etc/network/interfaces
echo "iface br$INT_BR_INT inet static" >> /etc/network/interfaces
echo " bridge_ports eth$INT_BR_INT wlan$INT_BR_INT" >> /etc/network/interfaces
echo " address 10.0.0.1" >> /etc/network/interfaces
echo " netmask 255.255.255.0" >> /etc/network/interfaces
echo " network 10.0.0.0" >> /etc/network/interfaces
}
# ---------------------------------------------------------
# This function configures internal and external interfaces
# ---------------------------------------------------------
configure_interfaces()
{
echo "Configuring Interfaces ..." | tee -a /var/libre_config.log
# Network interfaces configuration for
# Physical/Virtual machine
if [ "$PROCESSOR" = "Intel" -o "$PROCESSOR" = "AMD" -o "$PROCESSOR" = "ARM" ]; then
cat << EOF > /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
#External network interface
auto $EXT_INTERFACE
#allow-hotplug $EXT_INTERFACE
iface $EXT_INTERFACE inet dhcp
#Internal network interface
auto $INT_INTERFACE
#allow-hotplug $INT_INTERFACE
iface $INT_INTERFACE inet static
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
#Yacy
auto $INT_INTERFACE:1
#allow-hotplug $INT_INTERFACE:1
iface $INT_INTERFACE:1 inet static
address 10.0.0.251
netmask 255.255.255.0
#Friendica
auto $INT_INTERFACE:2
#allow-hotplug $INT_INTERFACE:2
iface $INT_INTERFACE:2 inet static
address 10.0.0.252
netmask 255.255.255.0
#OwnCloud
auto $INT_INTERFACE:3
#allow-hotplug $INT_INTERFACE:3
iface $INT_INTERFACE:3 inet static
address 10.0.0.253
netmask 255.255.255.0
#Mailpile
auto $INT_INTERFACE:4
#allow-hotplug $INT_INTERFACE:4
iface $INT_INTERFACE:4 inet static
address 10.0.0.254
netmask 255.255.255.0
#Webmin
auto $INT_INTERFACE:5
#allow-hotplug $INT_INTERFACE:5
iface $INT_INTERFACE:5 inet static
address 10.0.0.245
netmask 255.255.255.0
#EasyRTC
auto $INT_INTERFACE:6
#allow-hotplug $INT_INTERFACE:6
iface $INT_INTERFACE:6 inet static
address 10.0.0.250
netmask 255.255.255.0
#Kibana
auto $INT_INTERFACE:7
#allow-hotplug $INT_INTERFACE:7
iface $INT_INTERFACE:7 inet static
address 10.0.0.239
netmask 255.255.255.0
#Snorby
auto $INT_INTERFACE:8
#allow-hotplug $INT_INTERFACE:8
iface $INT_INTERFACE:8 inet static
address 10.0.0.12
netmask 255.255.255.0
#squidguard
auto $INT_INTERFACE:9
#allow-hotplug $INT_INTERFACE:9
iface $INT_INTERFACE:9 inet static
address 10.0.0.246
netmask 255.255.255.0
#gitlab
auto $INT_INTERFACE:10
#allow-hotplug $INT_INTERFACE:10
iface $INT_INTERFACE:10 inet static
address 10.0.0.247
netmask 255.255.255.0
#trac
auto $INT_INTERFACE:11
#allow-hotplug $INT_INTERFACE:11
iface $INT_INTERFACE:11 inet static
address 10.0.0.248
netmask 255.255.255.0
#redmine
auto $INT_INTERFACE:12
#allow-hotplug $INT_INTERFACE:12
iface $INT_INTERFACE:12 inet static
address 10.0.0.249
netmask 255.255.255.0
#Webmin
auto $INT_INTERFACE:13
#allow-hotplug $INT_INTERFACE:13
iface $INT_INTERFACE:13 inet static
address 10.0.0.244
netmask 255.255.255.0
#Roundcube
auto $INT_INTERFACE:14
#allow-hotplug $INT_INTERFACE:14
iface $INT_INTERFACE:14 inet static
address 10.0.0.243
netmask 255.255.255.0
#Postfix
auto $INT_INTERFACE:15
#allow-hotplug $INT_INTERFACE:15
iface $INT_INTERFACE:15 inet static
address 10.0.0.242
netmask 255.255.255.0
#Sogo
auto $INT_INTERFACE:16
#allow-hotplug $INT_INTERFACE:16
iface $INT_INTERFACE:16 inet static
address 10.0.0.241
netmask 255.255.255.0
#Glype
auto $INT_INTERFACE:17
#allow-hotplug $INT_INTERFACE:17
iface $INT_INTERFACE:17 inet static
address 10.0.0.240
netmask 255.255.255.0
#WAF-FLE
auto $INT_INTERFACE:18
#allow-hotplug $INT_INTERFACE:18
iface $INT_INTERFACE:18 inet static
address 10.0.0.238
netmask 255.255.255.0
EOF
# Network interfaces configuration for board
# elif [ "$PROCESSOR" = "ARM" ]; then
# cat << EOF > /etc/network/interfaces
# # interfaces(5) file used by ifup(8) and ifdown(8)
# auto lo
# iface lo inet loopback
#
# #External network interface
# auto eth0
# allow-hotplug eth0
# iface eth0 inet dhcp
#
# #External network interface
# # wireless wlan0
# auto wlan0
# allow-hotplug wlan0
# iface wlan0 inet dhcp
#
# ##External Network Bridge
# #auto br0
# allow-hotplug br0
# iface br0 inet dhcp
# bridge_ports eth0 wlan0
#
# #Internal network interface
# auto eth1
# allow-hotplug eth1
# iface eth1 inet manual
#
# #Internal network interface
# # wireless wlan1
# auto wlan1
# allow-hotplug wlan1
# iface wlan1 inet manual
#
# #Internal network Bridge
# auto br1
# allow-hotplug br1
# # Setup bridge
# iface br1 inet static
# bridge_ports eth1 wlan1
# address 10.0.0.1
# netmask 255.255.255.0
# network 10.0.0.0
#
# #Yacy
# auto eth1:1
# allow-hotplug eth1:1
# iface eth1:1 inet static
# address 10.0.0.251
# netmask 255.255.255.0
#
# #Friendica
# auto eth1:2
# allow-hotplug eth1:2
# iface eth1:2 inet static
# address 10.0.0.252
# netmask 255.255.255.0
#
# #OwnCloud
# auto eth1:3
# allow-hotplug eth1:3
# iface eth1:3 inet static
# address 10.0.0.253
# netmask 255.255.255.0
#
# #Mailpile
# auto eth1:4
# allow-hotplug eth1:4
# iface eth1:4 inet static
# address 10.0.0.254
# netmask 255.255.255.0
#
# #Webmin
# auto eth1:5
# allow-hotplug eth1:5
# iface eth1:5 inet static
# address 10.0.0.245
# netmask 255.255.255.0
#
# #EasyRTC
# auto eth1:6
# allow-hotplug eth1:6
# iface eth1:6 inet static
# address 10.0.0.250
# netmask 255.255.255.0
#
#EOF
fi
# Restarting network configuration
/etc/init.d/networking restart
}
# ---------------------------------------------------------
# Disable reboot (CTRL + ALT + DEL)
# ---------------------------------------------------------
configure_reboot()
{
systemctl mask ctrl-alt-del.target
systemctl daemon-reload
# Disable power button
sed -i 's/^/#/' /etc/acpi/powerbtn-acpi-support.sh
}
# ---------------------------------------------------------
# Function to configure DHCP server
# ---------------------------------------------------------
configure_dhcp()
{
echo "Configuring dhcp server ..." | tee -a /var/libre_config.log
echo "
ddns-update-style none;
option domain-name \"librerouter.librenet\";
option domain-name-servers 10.0.0.1;
default-lease-time 600;
max-lease-time 7200;
authoritative;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.100 10.0.0.200;
option routers 10.0.0.1;
}
" > /etc/dhcp/dhcpd.conf
# Configuring listen interface
sed "s~INTERFACES=\"\".*~INTERFACES=\"$INT_INTERFACE\"~g" -i /etc/default/isc-dhcp-server
# Restarting dhcp server
service isc-dhcp-server restart | tee -a /var/libre_config.log
}
# ---------------------------------------------------------
# Function to configure blacklists
# ---------------------------------------------------------
configre_blacklists()
{
#mkdir -p /etc/blacklists
#cd /etc/blacklists
#
#cat << EOF > /etc/blacklists/update-blacklists.sh
##!/bin/bash
#
##squidguard DB
#mkdir -p /etc/blacklists/shallalist/tmp
#cd /etc/blacklists/shallalist/tmp
#wget http://www.shallalist.de/Downloads/shallalist.tar.gz
#tar xvzf shallalist.tar.gz ; res=\$?
#rm -f shallalist.tar.gz
#if [ "\$res" = 0 ]; then
# rm -fr /etc/blacklists/shallalist/ok
# mv /etc/blacklists/shallalist/tmp /etc/blacklists/shallalist/ok
#else
# rm -fr /etc/blacklists/shallalist/tmp
#fi
#
#mkdir -p /etc/blacklists/urlblacklist/tmp
#cd /etc/blacklists/urlblacklist/tmp
#wget http://urlblacklist.com/cgi-bin/commercialdownload.pl?type=download\\&file=bigblacklist -O urlblacklist.tar.gz
#tar xvzf urlblacklist.tar.gz ; res=\$?
#rm -f urlblacklist.tar.gz
#if [ "\$res" = 0 ]; then
# rm -fr /etc/blacklists/urlblacklist/ok
# mv /etc/blacklists/urlblacklist/tmp /etc/blacklists/urlblacklist/ok
#else
# rm -fr /etc/blacklists/urlblacklist/tmp
#fi
#
#mkdir -p /etc/blacklists/mesdk12/tmp
#cd /etc/blacklists/mesdk12/tmp
#wget http://squidguard.mesd.k12.or.us/blacklists.tgz
#tar xvzf blacklists.tgz ; res=\$?
#rm -f blacklists.tgz
#if [ "\$res" = 0 ]; then
# rm -fr /etc/blacklists/mesdk12/ok
# mv /etc/blacklists/mesdk12/tmp /etc/blacklists/mesdk12/ok
#else
# rm -fr /etc/blacklists/mesdk12/tmp
#fi
#
#mkdir -p /etc/blacklists/capitole/tmp
#cd /etc/blacklists/capitole/tmp
#wget ftp://ftp.ut-capitole.fr/pub/reseau/cache/squidguard_contrib/publicite.tar.gz
#tar xvzf publicite.tar.gz ; res=\$?
#rm -f publicite.tar.gz
#if [ "\$res" = 0 ]; then
# rm -fr /etc/blacklists/capitole/ok
# mv /etc/blacklists/capitole/tmp /etc/blacklists/capitole/ok
#else
# rm -fr /etc/blacklists/capitole/tmp
#fi
#
#
## chown proxy:proxy -R /etc/blacklists/*
#
#EOF
#
#chmod +x /etc/blacklists/update-blacklists.sh
#/etc/blacklists/update-blacklists.sh
#
#cat << EOF > /etc/blacklists/blacklists-iptables.sh
##ipset implementation for nat
#for i in \$(grep -iv [A-Z] /etc/blacklists/shallalist/ok/BL/adv/domains)
#do
# iptables -t nat -I PREROUTING -i br1 -s 10.0.0.0/16 -p tcp -d \$i -j DNAT --to-destination 5.5.5.5
#done
#EOF
#
#chmod +x /etc/blacklists/blacklists-iptables.sh
cat /etc/unbound/block_domain.list.conf | awk -F '"' '{print $2}' | awk '{print $1}' > ads_domains
for i in `cat ads_domains`
do
iptables -t nat -I PREROUTING -p tcp -s 10.0.0.0/24 -d $i -j DNAT --to-destination 10.0.0.1
done
}
# ---------------------------------------------------------
# Function to configure mysql
# ---------------------------------------------------------
configure_mysql()
{
echo "Configuring MySQL ..." | tee -a /var/libre_config.log
# Getting MySQL password
if grep "DB_PASS" /var/box_variables > /dev/null 2>&1; then
MYSQL_PASS=`cat /var/box_variables | grep "DB_PASS" | awk {'print $2'}`
else
MYSQL_PASS=`pwgen 10 1`
echo "DB_PASS: $MYSQL_PASS" >> /var/box_variables
# Setting password
mysqladmin -u root password $MYSQL_PASS | tee -a /var/libre_config.log
fi
}
# ---------------------------------------------------------
# Function to configure banks direct access to Internet
# ---------------------------------------------------------
configure_banks_access()
{
echo "Configuring banks access ..." | tee -a /var/libre_config.log
touch /var/banks_ips.txt
echo "192.229.182.219
194.224.167.58
195.21.32.34
195.21.32.40
192.229.182.219
217.148.69.165
217.148.69.240
217.148.71.165
217.148.71.240
" > /var/banks_ips.txt
touch /var/banks_access.sh
cat << EOF > /var/banks_access.sh
#!/bin/bash
for i in \$(cat /var/banks_ips.txt)
do
iptables -t nat -I PREROUTING -i $INT_INTERFACE -p tcp -d \$i -j ACCEPT
done
EOF
chmod a+x /var/banks_access.sh
}
# ---------------------------------------------------------
# Function to configure iptables
# ---------------------------------------------------------
configure_iptables()
{
echo "Configuring iptables ..." | tee -a /var/libre_config.log
# Disabling ipv6 and enabling ipv4 forwarding
echo "
net.ipv4.ip_forward=1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
" > /etc/sysctl.conf
# Restarting sysctl
sysctl -p > /dev/null
cat << EOF > /etc/rc.local
#!/bin/sh
iptables -X
iptables -F
iptables -t nat -F
iptables -t filter -F
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.11 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.12 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.238 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.239 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.240 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.241 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.242 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.243 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.244 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.245 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.246 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.247 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.248 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.249 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.250 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.251 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.252 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.253 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.254 -j ACCEPT
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.1 --dport 22 -j REDIRECT --to-ports 22
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p udp -d 10.0.0.1 --dport 53 -j REDIRECT --to-ports 53
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.1 --dport 80 -j REDIRECT --to-ports 80
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.1 --dport 443 -j REDIRECT --to-ports 443
# to squid-i2p
iptables -t nat -A OUTPUT -d 10.191.0.1 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -d 10.191.0.1 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -m tcp --sport 80 -d 10.191.0.1 -j REDIRECT --to-ports 3128
# ssh to tor socks proxy
# iptables -t nat -A OUTPUT -p tcp -d 10.0.0.0/8 --dport 22 -j REDIRECT --to-ports 9051
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.0/8 --dport 22 -j REDIRECT --to-ports 9051
# to squid-tor
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -d 10.0.0.0/8 -j DNAT --to 10.0.0.1:3129
# to squid http
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp -m ndpi --http -j REDIRECT --to-ports 3130
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp --dport 80 -j DNAT --to 10.0.0.1:3130
# to squid https
iptables -t nat -A PREROUTING -i $INT_INTERFACE -p tcp --dport 443 -j REDIRECT --to-ports 3131
# iptables nat
iptables -t nat -A POSTROUTING -o $EXT_INTERFACE -j MASQUERADE
# ndpi protocole checking
#iptables -t mangle -I PREROUTING -m ndpi --dpi_check
#iptables -t mangle -I POSTROUTING -m ndpi --dpi_check
# Blocking ICMP from LAN_TO_WAN and from WAN_TO_LAN/ROUTER
iptables -A FORWARD -p ICMP -j DROP
iptables -A OUTPUT -p icmp -o $EXT_INTERFACE -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -s 0/0 -i $EXT_INTERFACE -j ACCEPT
iptables -A INPUT -p icmp --icmp-type destination-unreachable -s 0/0 -i $EXT_INTERFACE -j ACCEPT
iptables -A INPUT -p icmp --icmp-type time-exceeded -s 0/0 -i $EXT_INTERFACE -j ACCEPT
iptables -A INPUT -p icmp -i $EXT_INTERFACE -j DROP
iptables -A INPUT -p ICMP -i $INT_INTERFACE -j ACCEPT
iptables -A OUTPUT -p ICMP -o $INT_INTERFACE -j ACCEPT
iptables -A INPUT -p ICMP -j DROP
iptables -A OUTPUT -p ICMP -j DROP
iptables -A FORWARD -p ICMP -j DROP
# Blocking IPsec (All Directions)
iptables -A INPUT -m ndpi --ip_ipsec -j DROP
iptables -A OUTPUT -m ndpi --ip_ipsec -j DROP
iptables -A FORWARD -m ndpi --ip_ipsec -j DROP
# Blocking DNS request from client to any servers other than librerouter
iptables -A INPUT -i $INT_INTERFACE -m ndpi --dns ! -d 10.0.0.1 -j DROP
iptables -A FORWARD -m ndpi --dns ! -d 10.0.0.1 -j DROP
# Block any other TCP-UDP connections
iptables -P FORWARD DROP
## Enable Blacklist
#[ -e /etc/blacklists/blacklists-iptables.sh ] && /etc/blacklists/blacklists-iptables.sh &
# Configuring banks direct access
/var/banks_access.sh
# Stopping dnsmasq
kill -9 \`ps aux | grep dnsmasq | grep -v grep | awk {'print \$2'} | sed -n '1p'\` \
2> /dev/null
service unbound restart
# Starting easyrtc
nohup nodejs /opt/easyrtc/server_example/server.js &
# Starting Mailpile
/usr/bin/screen -dmS mailpile_init /opt/Mailpile/mp
# Restarting i2p
/etc/init.d/i2p restart
# Restarting tor
/etc/init.d/tor restart
# Running uwsgi
uwsgi --ini /etc/uwsgi/uwsgi.ini & > /dev/null 2>&1
# Time sync
ntpdate -s ntp.ubuntu.com
# Start nginx
/etc/init.d/nginx start > /dev/null 2>&1
# Start suricata
ethtool -K lo rx off tso off gso off sg off gro off lro off
ifconfig lo mtu 1400
suricata -D -c /etc/suricata/suricata.yaml -i lo &
# Start logstash
/opt/logstash/bin/logstash -f /etc/logstash/conf.d/logstash.conf & > /dev/null 2>&1
# Start Evebox
evebox -e http://localhost:9200 &
# Start elasticsearch
/etc/init.d/elasticsearch start
# Start Trac
tracd -s -b 127.0.0.1 --port 8000 /opt/trac/libretrac &
# Start Redmine
thin -c /opt/redmine/redmine-3.3.1 --servers 1 -e production -a 127.0.0.1 -p 8889 -d start > /dev/null 2>&1
# Start Redsocks
/opt/redsocks/redsocks -c /opt/redsocks/redsocks.conf
exit 0
EOF
chmod +x /etc/rc.local
#/etc/rc.local | tee -a /var/libre_config.log
}
# ---------------------------------------------------------
# Function to configure ssh
# ---------------------------------------------------------
configure_ssh()
{
echo "Configuring ssh ..."
# Allowing only V2 protocole
sed '/Protocol/c\Protocol 2' -i /etc/ssh/sshd_config
# Restarting ssh service
/etc/init.d/ssh restart
}
# ---------------------------------------------------------
# Function to configure TOR
# ---------------------------------------------------------
configure_tor()
{
echo "Configuring Tor server ..." | tee -a /var/libre_config.log
tordir=/var/lib/tor/hidden_service
for i in yacy owncloud friendica mailpile easyrtc ssh gitlab trac redmine roundcube
do
# Setting user and group to debian-tor
mkdir -p $tordir/$i