forked from privacyint/thornsec-profiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYourls.java
147 lines (118 loc) · 5.59 KB
/
Yourls.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
135
136
137
138
139
140
141
142
143
144
145
146
147
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.GitCloneUnit;
public class Yourls extends AStructuredProfile {
private Nginx webserver;
private PHP php;
private MariaDB db;
public Yourls(ServerModel me, NetworkModel networkModel) {
super("yourls", me, networkModel);
this.webserver = new Nginx(me, networkModel);
this.php = new PHP(me, networkModel);
this.db = new MariaDB(me, networkModel);
this.db.setUsername("yourls");
this.db.setUserPrivileges("ALL");
this.db.setUserPassword("${YOURLS_PASSWORD}");
this.db.setDb("yourls");
}
protected Vector<IUnit> getInstalled() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getInstalled());
units.addAll(php.getInstalled());
units.addAll(db.getInstalled());
return units;
}
protected Vector<IUnit> getPersistentConfig() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getPersistentConfig());
units.addAll(db.getPersistentConfig());
units.addAll(php.getPersistentConfig());
units.addElement(new GitCloneUnit("yourls", "proceed", "https://github.com/YOURLS/YOURLS.git", "/media/data/www", "Could not download Yourls. This is fatal."));
return units;
}
protected Vector<IUnit> getLiveConfig() {
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 += "\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());
units.addElement(new SimpleUnit("yourls_mysql_password", "proceed",
"YOURLS_PASSWORD=`grep 'YOURLS_DB_PASS' /media/data/www/user/config.php 2>/dev/null | awk '{ print $2 }' | tr -d \"',);\");` [[ -z $YOURLS_PASSWORD ]] && YOURLS_PASSWORD=`openssl rand -hex 32`",
"echo $YOURLS_PASSWORD", "", "fail",
"Couldn't set a password for Yourl's database user. The installation will fail."));
units.addElement(new SimpleUnit("yourl_cookie_salt", "proceed",
"YOURLS_COOKIEKEY=`sudo grep 'YOURLS_COOKIEKEY' /media/data/www/user/config.php 2>/dev/null | grep -v \"[*#]\" | awk '{ print $3 }' | tr -d \"',;\"`; [[ -z $YOURLS_COOKIEKEY ]] && YOURLS_COOKIEKEY=`openssl rand -hex 75`",
"echo $YOURLS_COOKIEKEY", "", "fail",
"Couldn't set a cookie hash salt for Yourls. Your installation may not function correctly."));
//Set up our database
units.addAll(db.checkUserExists());
units.addAll(db.checkDbExists());
String yourlsConfig = "";
yourlsConfig += "<?php\n";
yourlsConfig += " define('YOURLS_DB_USER', 'yourls');\n";
yourlsConfig += " define('YOURLS_DB_PASS', '$YOURLS_DB_PASS');\n";
yourlsConfig += " define('YOURLS_DB_NAME', 'yourls');\n";
yourlsConfig += " define('YOURLS_DB_HOST', 'localhost');\n";
yourlsConfig += " define('YOURLS_DB_PREFIX', 'yourls_');\n";
yourlsConfig += " define('YOURLS_SITE', '" + networkModel.getData().getDomain(me.getLabel()) + "');\n";
yourlsConfig += " define('YOURLS_HOURS_OFFSET', 0);\n";
yourlsConfig += " define('YOURLS_LANG', '');\n";
yourlsConfig += " define('YOURLS_UNIQUE_URLS', false);\n";
yourlsConfig += " define('YOURLS_PRIVATE', true);\n";
yourlsConfig += " define('YOURLS_COOKIEKEY', '$YOURLS_COOKIEKEY');\n";
yourlsConfig += " $yourls_user_passwords = array(\n";
yourlsConfig += " 'admin' => 'password',\n";
yourlsConfig += " );\n";
yourlsConfig += " define('YOURLS_DEBUG', false);\n";
yourlsConfig += " define('YOURLS_URL_CONVERT', 36);\n";
yourlsConfig += " $yourls_reserved_URL = array(\n";
//The below line was fun to write, as we are children...
yourlsConfig += " 'porn', 'fag', 'trannie', 'tranny', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', 'shit', 'spic', 'twat', 'pussy',\n";
yourlsConfig += " );";
units.addElement(((ServerModel)me).getConfigsModel().addConfigFile("opensocial", "opensocial_installed", yourlsConfig, "/media/data/www/user/config.php"));
return units;
}
public Vector<IUnit> getNetworking() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getNetworking());
me.addRequiredEgress("github.com");
return units;
}
}