This repository has been archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Piwik.java
132 lines (106 loc) · 5.18 KB
/
Piwik.java
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
package profile;
import java.util.Vector;
import core.iface.IUnit;
import core.model.NetworkModel;
import core.model.ServerModel;
import core.profile.AStructuredProfile;
import core.unit.SimpleUnit;
import core.unit.fs.FileChecksumUnit;
import core.unit.fs.FileDownloadUnit;
import core.unit.pkg.InstalledUnit;
public class Piwik extends AStructuredProfile {
private Nginx webserver;
private PHP php;
private MariaDB db;
public Piwik(ServerModel me, NetworkModel networkModel) {
super("piwik", me, networkModel);
this.webserver = new Nginx(me, networkModel);
this.php = new PHP(me, networkModel);
this.db = new MariaDB(me, networkModel);
this.db.setUsername("piwik");
this.db.setUserPrivileges("SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES");
this.db.setUserPassword("${PIWIK_PASSWORD}");
this.db.setDb("piwik");
}
protected Vector<IUnit> getInstalled() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getInstalled());
units.addAll(php.getInstalled());
units.addAll(db.getInstalled());
units.addElement(new InstalledUnit("unzip", "proceed", "unzip"));
units.addElement(new InstalledUnit("ca_certificates", "proceed", "ca-certificates"));
units.addElement(new InstalledUnit("php_mysql", "php_fpm_installed", "php-mysql"));
units.addElement(new InstalledUnit("php_mbstring", "php_fpm_installed", "php-mbstring"));
units.addElement(new InstalledUnit("php_gd", "php_fpm_installed", "php-gd"));
units.addElement(new InstalledUnit("php_xml", "php_fpm_installed", "php-xml"));
units.addElement(new FileDownloadUnit("piwik", "proceed", "https://builds.matomo.org/piwik.zip", "/root/piwik.zip",
"Couldn't download Piwik. This could mean you ave no network connection, or that the specified download is no longer available."));
units.addElement(new FileChecksumUnit("piwik", "piwik_downloaded", "/root/piwik.zip", "449a91225b0f942f454bbccd5fba1ff9ea9d0459b37f69004d43060c24e3626b6303373c66711b316314ec72ed96fda3c76b4a4f6a930c1569a2a72ed6ff6a1f",
"Piwik's checksum doesn't match. This could indicate a failed download, MITM attack, or a newer version than our code supports. Piwik's installation will fail."));
units.addElement(new SimpleUnit("piwik_installed", "piwik_checksum",
"sudo unzip /root/piwik.zip -d /media/data/www",
"[ -d /media/data/www/piwik ] && echo pass || echo fail", "pass", "pass",
"Piwik couldn't be extracted to the required directory."));
return units;
}
protected Vector<IUnit> getPersistentConfig() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getPersistentConfig());
units.addAll(php.getPersistentConfig());
units.addAll(db.getPersistentConfig());
return units;
}
protected Vector<IUnit> getLiveConfig() {
Vector<IUnit> units = new Vector<IUnit>();
units.addElement(new SimpleUnit("piwik_mysql_password", "piwik_installed",
"PIWIK_PASSWORD=`sudo grep \"password\" /media/data/www/piwik/config/config.ini.php | head -1 | awk '{ print $3 }' | tr -d \"\\\",\"`; [[ -z $PIWIK_PASSWORD ]] && PIWIK_PASSWORD=`openssl rand -hex 32`;"
+ "echo \"Your database password is ${PIWIK_PASSWORD}\"",
"echo $PIWIK_PASSWORD", "", "fail",
"Couldn't set the Piwik database user's password. Piwik will be left in a broken state."));
//Set up our database
units.addAll(db.checkUserExists());
units.addAll(db.checkDbExists());
String nginxConf = "";
nginxConf += "server {\n";
nginxConf += " listen *:80 default;\n";
nginxConf += " server_name _;\n";
nginxConf += " root /media/data/www/piwik;\n";
nginxConf += " index index.php;\n";
nginxConf += " sendfile off;\n";
nginxConf += " default_type text/plain;\n";
nginxConf += " server_tokens off;\n";
nginxConf += " location / {\n";
nginxConf += " try_files \\$uri @rewrite;\n";
nginxConf += " }\n";
nginxConf += " location @rewrite {\n";
nginxConf += " rewrite ^ /index.php;\n";
nginxConf += " }\n";
nginxConf += " error_page 500 502 503 504 /50x.html;\n";
nginxConf += " location = /50x.html {\n";
nginxConf += " root /usr/share/nginx/html;\n";
nginxConf += " }\n";
nginxConf += " location ~ \\.php\\$ {\n";
nginxConf += " fastcgi_split_path_info ^(.+\\.php)(/.+)\\$;\n";
nginxConf += " fastcgi_pass unix:" + php.getSockPath() + ";\n";
nginxConf += " fastcgi_param SCRIPT_FILENAME \\$document_root\\$fastcgi_script_name;\n";
nginxConf += " fastcgi_index index.php;\n";
nginxConf += " include fastcgi_params;\n";
nginxConf += " }\n";
nginxConf += " location ~ /\\.ht {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " include /media/data/nginx_custom_conf_d/default.conf;\n";
nginxConf += "}";
webserver.addLiveConfig("default", nginxConf);
units.addAll(webserver.getLiveConfig());
units.addAll(php.getLiveConfig());
units.addAll(db.getLiveConfig());
return units;
}
public Vector<IUnit> getNetworking() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getNetworking());
me.addRequiredEgress("builds.matomo.org", new Integer[]{443});
return units;
}
}