forked from roxy-wi/roxy-wi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
328 lines (285 loc) · 7.91 KB
/
install.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
#!/bin/bash
PORT=8080
HOME_HAPROXY_WI=haproxy-wi
echo "Choose DB: (1)Sqlite or (2)Mysql? Default: Sqlite"
read DB
if [[ $DB == 2 ]];then
echo "Mysql server is (1)remote or (2)local?"
read REMOTE
if [[ $REMOTE == 1 ]];then
echo "Enter IP remote Mysql server"
read IP
else
MINSTALL=1
fi
fi
echo "Choose Haproxy-WI port. Default: [$PORT]"
read CHPORT
echo "Enter Haproxy-wi home dir. Default: /var/www/[$HOME_HAPROXY_WI]"
read CHHOME_HAPROXY
if [[ -z $HAPROXY ]];then
HAPROXY="no"
fi
if [[ -n $CHPORT ]];then
PORT=$CHPORT
fi
if [[ -n "$CHHOME_HAPROXY" ]];then
HOME_HAPROXY_WI=$CHHOME_HAPROXY
fi
echo "################################"
echo ""
echo ""
echo -e "Installing Required Software"
echo ""
echo ""
echo "################################"
if hash apt-get 2>/dev/null; then
apt-get install git net-tools lshw dos2unix apache2 gcc netcat python3-pip -y
HTTPD_CONFIG="/etc/apache2/apache2.conf"
HAPROXY_WI_VHOST_CONF="/etc/apache2/sites-enabled/haproxy-wi.conf"
HTTPD_NAME="apache2"
HTTPD_PORTS="/etc/apache2/ports.conf"
if [[ $MINSTALL == 1 ]];then
apt-get install software-properties-common -y
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
add-apt-repository 'deb [arch=amd64,i386,ppc64el] https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu xenial main' -y
apt-get install mariadb-server -y
fi
else
if [[ $(cat /etc/*-rele* |grep NAME |head -1) == 'NAME="CentOS Linux"' ]];then
yum -y install epel-release
fi
yum -y install git nmap-ncat net-tools lshw python34 dos2unix python34-pip httpd mod_ssl gcc python34-devel
HTTPD_CONFIG="/etc/httpd/conf/httpd.conf"
HAPROXY_WI_VHOST_CONF="/etc/httpd/conf.d/haproxy-wi.conf"
HTTPD_NAME="httpd"
HTTPD_PORTS=$HTTPD_CONFIG
echo "Edit firewalld"
firewall-cmd --zone=public --add-port=$PORT/tcp --permanent
firewall-cmd --reload
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
if [[ $MINSTALL == 1 ]];then
yum -y install mariadb mariadb-server mysql-devel
fi
fi
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Unable to install Required Packages Please check Yum config"
echo ""
echo ""
echo "################################"
exit 1
fi
echo "################################"
echo ""
echo ""
echo -e "Updating Apache config and Configuring Virtual Host"
echo ""
echo ""
echo "################################"
sudo sed -i "0,/^Listen .*/s//Listen $PORT/" $HTTPD_PORTS
echo "################################"
echo ""
echo ""
echo -e "Checking for Apache Vhost config"
echo ""
echo ""
echo "################################"
sudo touch $HAPROXY_WI_VHOST_CONF
/bin/cat $HAPROXY_WI_VHOST_CONF
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Didnt Sense exisitng installation Proceeding ...."
echo ""
echo ""
echo "################################"
exit 1
else
echo "################################"
echo ""
echo ""
echo -e "Creating VirtulHost for Apache"
echo ""
echo ""
echo "################################"
cat << EOF > $HAPROXY_WI_VHOST_CONF
<VirtualHost *:$PORT>
ServerName haprox-wi.example.com
ErrorLog /var/log/httpd/haproxy-wi.error.log
CustomLog /var/log/httpd/haproxy-wi.access.log combined
DocumentRoot /var/www/$HOME_HAPROXY_WI
ScriptAlias /cgi-bin/ "/var/www/$HOME_HAPROXY_WI/app/"
<Directory /var/www/$HOME_HAPROXY_WI/app>
Options +ExecCGI
AddHandler cgi-script .py
Order deny,allow
Allow from all
</Directory>
<FilesMatch "\.config$">
Order Deny,Allow
Deny from all
</FilesMatch>
</VirtualHost>
EOF
fi
if hash apt-get 2>/dev/null; then
sed -i 's|/var/log/httpd/|/var/log/apache2/|g' $HAPROXY_WI_VHOST_CONF
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/cgi.load
fi
echo "################################"
echo ""
echo ""
echo -e " Testing config"
echo ""
echo ""
echo "################################"
/usr/sbin/apachectl configtest
if [ $? -eq 1 ]
then
echo "apache Configuration Has failed, Please verify Apache Config"
echo ""
echo ""
echo "################################"
exit 1
fi
echo "################################"
echo ""
echo ""
echo -e "Getting Latest software from The repository"
echo ""
echo ""
echo "################################"
/usr/bin/git clone https://github.com/Aidaho12/haproxy-wi.git /var/www/$HOME_HAPROXY_WI
if [ $? -eq 1 ]
then
echo "Unable to clone The repository Please check connetivity to Github"
exit 1
fi
echo "################################"
echo ""
echo ""
echo -e "Installing required Python Packages"
echo ""
echo ""
echo "################################"
/usr/bin/pip3 install -r /var/www/$HOME_HAPROXY_WI/requirements.txt
if [ $? -eq 1 ]
then
echo "Unable to install Required Packages, Please check Pip error log and Fix the errors and Rerun the script"
exit 1
else
echo "################################"
echo ""
echo ""
echo -e "Installation Succesful"
echo ""
echo ""
echo "################################"
fi
if [[ $MINSTALL = 1 ]];then
echo "################################"
echo ""
echo ""
echo -e "starting databse and applying config"
echo ""
echo ""
echo "################################"
systemctl enable mariadb
systemctl start mariadb
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Can't start Mariadb"
echo ""
echo ""
echo "################################"
exit 1
fi
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Unable to start Mariadb Service Please check logs"
echo ""
echo ""
echo "################################"
exit 1
else
mysql -u root -e "create database haproxywi";
mysql -u root -e "grant all on haproxywi.* to 'haproxy-wi'@'%' IDENTIFIED BY 'haproxy-wi';"
mysql -u root -e "grant all on haproxywi.* to 'haproxy-wi'@'localhost' IDENTIFIED BY 'haproxy-wi';"
mysql -u root -e "flush privileges;"
echo "################################"
echo ""
echo ""
echo -e "Databse has been created Succesfully and User permissions added"
echo ""
echo ""
echo "################################"
fi
fi
if [[ $DB == 2 ]];then
echo "################################"
echo ""
echo ""
echo -e "Setting Application to use Mysql As a backend"
echo ""
echo ""
echo "################################"
sed -i '0,/enable = 0/s//enable = 1/' /var/www/$HOME_HAPROXY_WI/app/haproxy-webintarface.config
fi
if [[ -n $IP ]];then
sed -i "0,/mysql_host = 127.0.0.1/s//mysql_host = $IP/" /var/www/$HOME_HAPROXY_WI/app/haproxy-webintarface.config
fi
echo "################################"
echo ""
echo ""
echo -e " Starting Services"
echo ""
echo ""
echo "################################"
systemctl enable $HTTPD_NAME; systemctl restart $HTTPD_NAME
if [ $? -eq 1 ]
then
echo "################################"
echo ""
echo ""
echo "Services Has Not been started, Please check error logs"
echo ""
echo ""
echo "################################"
else
echo "################################"
echo ""
echo ""
echo -e "Services have been started, Please Evaluate the tool by adding a host / DNS ectry for /etc/hosts file. \n This can be done by adding an entry like this \n 192.168.1.100 haprox-wi.example.com"
echo ""
echo ""
echo "################################"
fi
sed -i "s|^fullpath = .*|fullpath = /var/www/$HOME_HAPROXY_WI|g" /var/www/$HOME_HAPROXY_WI/app/haproxy-webintarface.config
echo "################################"
echo ""
echo ""
echo -e " Thank You for Evaluating Haproxy-wi"
echo ""
echo ""
echo "################################"
mkdir /var/www/$HOME_HAPROXY_WI/app/certs
chmod +x /var/www/$HOME_HAPROXY_WI/app/*.py
rm -f /var/www/$HOME_HAPROXY_WI/log/config_edit.log
cd /var/www/$HOME_HAPROXY_WI/app
./update_db.py
chown -R apache:apache /var/www/$HOME_HAPROXY_WI/
exit 0