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
/
Copy pathHorde.java
134 lines (108 loc) · 4.61 KB
/
Horde.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
133
134
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.FileEditUnit;
import core.unit.pkg.InstalledUnit;
public class Horde extends AStructuredProfile {
private Nginx webserver;
private PHP php;
private MariaDB db;
public Horde(ServerModel me, NetworkModel networkModel) {
super("horde", me, networkModel);
this.webserver = new Nginx(me, networkModel);
this.php = new PHP(me, networkModel);
this.db = new MariaDB(me, networkModel);
this.db.setUsername("horde");
this.db.setUserPrivileges("ALL");
this.db.setUserPassword("${HORDE_PASSWORD}");
this.db.setDb("horde");
}
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("php_pear", "proceed", "php-pear"));
units.addElement(new SimpleUnit("horde_channel_discover", "php_pear_installed",
"sudo pear channel-discover per.horde.org",
"sudo pear channel-info pear.horde.org", "Unknown channel \"pear.horde.org\"", "fail"));
units.addElement(new FileEditUnit("pear_base_dir", "horde_channel_discover", "/usr/share/php/htdocs", "/media/data/www", "/etc/pear/pear.conf"));
units.addElement(new SimpleUnit("horde_installed", "pear_base_dir_edited",
"sudo pear install horde/horde_role",
"sudo pear list-all | grep horde", "", "fail"));
return units;
}
protected Vector<IUnit> getPersistentConfig() {
Vector<IUnit> units = new Vector<IUnit>();
String nginxConf = "";
nginxConf += "server {\n";
nginxConf += " listen *:80 default;\n";
nginxConf += " server_name _;\n";
nginxConf += " root /media/data/www;\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:/var/run/php5-fpm.sock;\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 ~/sites/default/files/civicrm/ConfigAndLog {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " location ~/sites/default/files/civicrm/custom/ {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " location ~/sites/default/files/civicrm/templates_c {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " location ~/sites/default/files/civicrm/upload {\n";
nginxConf += " deny all;\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.getPersistentConfig());
units.addAll(db.getPersistentConfig());
units.addAll(php.getPersistentConfig());
return units;
}
protected Vector<IUnit> getLiveConfig() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getLiveConfig());
units.addAll(php.getLiveConfig());
units.addAll(db.getLiveConfig());
units.addElement(new SimpleUnit("horde_mysql_password", "proceed",
"HORDE_PASSWORD=`grep \"password\" /media/data/www/sites/default/settings.php 2>/dev/null | grep -v \"[*#]\" | awk '{ print $3 }' | tr -d \"',\"`; [[ -z $HORDE_PASSWORD ]] && HORDE_PASSWORD=`openssl rand -hex 32`",
"echo $HORDE_PASSWORD", "", "fail"));
//Set up our database
units.addAll(db.checkUserExists());
units.addAll(db.checkDbExists());
return units;
}
public Vector<IUnit> getNetworking() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getNetworking());
return units;
}
}