-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall_kippo_graph.sh
111 lines (94 loc) · 3.74 KB
/
install_kippo_graph.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
#!/bin/bash
set -e
set -x
# Install MySQL and matplotlib dependencies
sudo apt-get update
sudo apt-get install -y python-dev mysql-server libpng12-dev libfreetype6-dev libxft-dev
# Modifying Mysql configuration to allow connection from everywhere
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
sudo service mysql restart
# Getting MHN directory
MHN_HOME=`dirname $0`/../..
cd $MHN_HOME
MHN_HOME=`pwd`
# Installing pymysql numpy matplotlib and PILLOW
. env/bin/activate
pip install pymysql numpy matplotlib>=1.4.3 PILLOW
# Downloading the sql file to create tables on the databases
cd scripts/
sudo wget https://github.com/threatstream/kippo/raw/master/doc/sql/mysql.sql -O kippo_mysql.sql
# Creating the directory inside mhn server app
mkdir -p $MHN_HOME/server/mhn/static/img/kippo_graphs
sudo chown www-data:www-data $MHN_HOME/server/mhn/static/img/kippo_graphs
# Adding the kippo with mysql support to mhn app
cd mhn_kippo_graphs/
sudo python insert_deploy_kippo.py $MHN_HOME/server/mhn.db
# Creating CronTab to run the generating graph script every 5 minutes
crontab -l | grep -v kippo_generate_graphs.py | crontab -
crontab -l | { cat; echo "*/5 * * * * $MHN_HOME/env/bin/python $MHN_HOME/scripts/mhn_kippo_graphs/kippo_generate_graphs.py"; } | crontab -
# Modifying Web Application
# Modifying configuration file to add channel kippo-mysql
if [ -f $MHN_HOME/server/config.py~ ];
then
echo "Config.py File exists, replacing it"
sudo mv $MHN_HOME/server/config.py~ $MHN_HOME/server/config.py
sed -i~ '$i\ '\''kippo-mysql'\'' : ['\''kippo.sessions'\'']' $MHN_HOME/server/config.py
sudo chown www-data:www-data $MHN_HOME/server/config.py
else
sed -i~ '$i\ '\''kippo-mysql'\'' : ['\''kippo.sessions'\'']' $MHN_HOME/server/config.py
fi
# Removing blank lines in base.html
sed -i "/^\s*$/d" $MHN_HOME/server/mhn/templates/base.html
# Adding menu item
if [ -f $MHN_HOME/server/mhn/templates/base.html~ ];
then
echo "Base.html File exists, replacing it"
sudo mv $MHN_HOME/server/mhn/templates/base.html~ $MHN_HOME/server/mhn/templates/base.html
sed -i~ '
/\s*<\/ul>/ {
N
/\n.*Right Nav Section.*/ i\
\ <li><a href="{{ url_for('\''kg.kippo_graph'\'') }}">Kippo-Graph</a></li>
}' $MHN_HOME/server/mhn/templates/base.html
sudo chown www-data:www-data $MHN_HOME/server/mhn/templates/base.html
else
sed -i~ '
/\s*<\/ul>/ {
N
/\n.*Right Nav Section.*/ i\
\ <li><a href="{{ url_for('\''kg.kippo_graph'\'') }}">Kippo-Graph</a></li>
}' $MHN_HOME/server/mhn/templates/base.html
fi
# Registering Blueprint with Flask app
if [ -f $MHN_HOME/server/mhn/__init__.py~ ];
then
echo "_init__.py File exists, replacing it"
sudo mv $MHN_HOME/server/mhn/__init__.py~ $MHN_HOME/server/mhn/__init__.py
sed -i~ '
/mhn.register_blueprint(auth)/ a\
\
from mhn.kg.views import kg\
mhn.register_blueprint(kg)
' $MHN_HOME/server/mhn/__init__.py
sudo chown www-data:www-data $MHN_HOME/server/mhn/__init__.py
else
sed -i~ '
/mhn.register_blueprint(auth)/ a\
\
from mhn.kg.views import kg\
mhn.register_blueprint(kg)
' $MHN_HOME/server/mhn/__init__.py
fi
#Copying blueprint and templates and changing the ownerships
cd $MHN_HOME/scripts/mhn_kippo_graphs
mkdir -p $MHN_HOME/server/mhn/kg/
sudo cp mhn/kg/* $MHN_HOME/server/mhn/kg/
mkdir -p $MHN_HOME/server/mhn/templates/kg/
sudo cp mhn/templates/kg/* $MHN_HOME/server/mhn/templates/kg/
sudo chown -R www-data:www-data $MHN_HOME/server/mhn/kg/
sudo chown -R www-data:www-data $MHN_HOME/server/mhn/templates/kg/
#Restart uwsgi
sudo supervisorctl restart mhn-uwsgi
# Remember to run this script
echo "Remember, each time a kippo sensor with MySQL support is installed you should run the following command:"
echo "sudo /opt/mhn/env/bin/python /opt/mhn/scripts/mhn_kippo_graphs/kippo_update_mysql.py"