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 pathGrav.java
129 lines (107 loc) · 4.84 KB
/
Grav.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
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.pkg.InstalledUnit;
public class Grav extends AStructuredProfile {
private Nginx webserver;
private PHP php;
public Grav(ServerModel me, NetworkModel networkModel) {
super("grav", me, networkModel);
this.webserver = new Nginx(me, networkModel);
this.php = new PHP(me, networkModel);
}
protected Vector<IUnit> getInstalled() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getInstalled());
units.addAll(php.getInstalled());
units.addElement(new InstalledUnit("php_cli", "php_fpm_installed", "php-cli"));
units.addElement(new InstalledUnit("php_common", "php_fpm_installed", "php-common"));
units.addElement(new InstalledUnit("php_curl", "php_fpm_installed", "php-curl"));
units.addElement(new InstalledUnit("php_gd", "php_fpm_installed", "php-gd"));
units.addElement(new InstalledUnit("php_json", "php_fpm_installed", "php-json"));
units.addElement(new InstalledUnit("php_readline", "php_fpm_installed", "php-readline"));
units.addElement(new InstalledUnit("php_mbstring", "php_fpm_installed", "php-mbstring"));
units.addElement(new InstalledUnit("php_xml", "php_fpm_installed", "php-xml"));
units.addElement(new InstalledUnit("php_zip", "php_fpm_installed", "php-zip"));
return units;
}
protected Vector<IUnit> getPersistentConfig() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getPersistentConfig());
units.addAll(php.getPersistentConfig());
return units;
}
protected Vector<IUnit> getLiveConfig() {
Vector<IUnit> units = new Vector<IUnit>();
String nginxConf = "";
nginxConf += "server {\n";
nginxConf += " listen 80;\n";
nginxConf += " server_name _;\n";
nginxConf += "\n";
nginxConf += " root /media/data/www/grav/;\n";
nginxConf += " index index.php;\n";
nginxConf += " try_files \\$uri \\$uri/ =404;\n";
nginxConf += "\n";
nginxConf += " location / {\n";
nginxConf += " if (!-e \\$request_filename){ rewrite ^(.*)\\$ /index.php last; }\n";
nginxConf += " }\n";
nginxConf += "\n";
nginxConf += " location /images/ {\n";
nginxConf += " #Serve images statically\n";
nginxConf += " }\n";
nginxConf += "\n";
nginxConf += " location /user {\n";
nginxConf += " rewrite ^/user/accounts/(.*)\\$ /error redirect;\n";
nginxConf += " rewrite ^/user/config/(.*)\\$ /error redirect;\n";
nginxConf += " rewrite ^/user/(.*)\\.(txt|md|html|php|yaml|json|twig|sh|bat)\\$ /error redirect;\n";
nginxConf += " }\n";
nginxConf += "\n";
nginxConf += " location /cache {\n";
nginxConf += " rewrite ^/cache/(.*) /error redirect;\n";
nginxConf += " }\n";
nginxConf += "\n";
nginxConf += " location /bin {\n";
nginxConf += " rewrite ^/bin/(.*)\\$ /error redirect;\n";
nginxConf += " }\n";
nginxConf += "\n";
nginxConf += " location /backup {\n";
nginxConf += " rewrite ^/backup/(.*) /error redirect;\n";
nginxConf += " }\n";
nginxConf += "\n";
nginxConf += " location /system {\n";
nginxConf += " rewrite ^/system/(.*)\\.(txt|md|html|php|yaml|json|twig|sh|bat)\\$ /error redirect;\n";
nginxConf += " }\n";
nginxConf += "\n";
nginxConf += " location /vendor {\n";
nginxConf += " rewrite ^/vendor/(.*)\\.(txt|md|html|php|yaml|json|twig|sh|bat)\\$ /error redirect;\n";
nginxConf += " }\n";
nginxConf += "\n";
nginxConf += " location ~ \\.php\\$ {\n";
nginxConf += " try_files \\$uri =404;\n";
nginxConf += " fastcgi_split_path_info ^(.+\\.php)(/.+)\\$;\n";
nginxConf += " fastcgi_pass unix:" + php.getSockPath() + ";\n";
nginxConf += " fastcgi_index index.php;\n";
nginxConf += " fastcgi_param SCRIPT_FILENAME \\$document_root\\$fastcgi_script_name;\n";
nginxConf += " include fastcgi_params;\n";
nginxConf += " }\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());
return units;
}
public Vector<IUnit> getNetworking() {
Vector<IUnit> units = new Vector<IUnit>();
me.addRequiredEgress("getgrav.com");
units.addAll(webserver.getNetworking());
return units;
}
}