-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·332 lines (280 loc) · 14.2 KB
/
functions.php
File metadata and controls
executable file
·332 lines (280 loc) · 14.2 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<?php
function init_wp_variables($config = "wp-config.php") {
if (file_exists($config)) {
require_once($config);
$values['state'] = 1;
@$values['bdd_host'] = DB_HOST;
@$values['bdd_user'] = DB_USER;
@$values['bdd_pass'] = DB_PASSWORD;
@$values['bdd_name'] = DB_NAME;
@$values['bdd_prefix'] = $table_prefix;
@$values['wp_lang'] = WPLANG;
@$values['wp_debug'] = WP_DEBUG;
@$values['wp_multisite'] = WP_ALLOW_MULTISITE;
} else {
$values['state'] = 0;
}
return($values);
}
function rm_backslash_n($pattern = "\n") {
$result = str_replace("\n", "", $pattern);
return $result;
}
// Display informations returned by "infos" option.
function wrush_infos($bdd, $prefix = "wp_") {
$resultat = $bdd->query("SELECT option_name, option_value FROM ".$prefix."options WHERE option_name IN ('siteurl','blogname','admin_email')");
$resultat->setFetchMode(PDO::FETCH_OBJ);
echo "Wordpress main informations\n";
echo "---------------------------\n";
while( $ligne = $resultat->fetch() )
{
echo "- ".$ligne->option_name." : ".$ligne->option_value."\n";
}
echo " --- \n";
# Test versions
$version_file = rm_backslash_n(shell_exec('pwd')."/wp-includes/version.php");
if(file_exists($version_file)) {
require_once($version_file);
# PHP
$system_php = rm_backslash_n(shell_exec("php -v | grep -i cli | awk {'print $2'}"));
echo "- PHP Version installed : $system_php (Required : $required_php_version)\n";
echo "- Wordpress version : $wp_version\n";
}
}
// Display informations returned by "blogs" option.
function wrush_blogs($bdd, $prefix = "wp_", $multisite = "false") {
echo "Wordpress blogs list\n";
echo "---------------------------\n";
if($multisite == "true")
{
$resultat = $bdd->query("SELECT domain, path, deleted, public FROM ".$prefix."blogs");
$resultat->setFetchMode(PDO::FETCH_OBJ);
while( $ligne = $resultat->fetch() )
{
echo "- http://".$ligne->domain.$ligne->path." : ";
echo "Public=".$ligne->public.", Deleted=".$ligne->deleted;
echo "\n";
}
} else {
$resultat = $bdd->query("SELECT option_value FROM ".$prefix."options WHERE option_name = 'siteurl'");
$resultat->setFetchMode(PDO::FETCH_OBJ);
while( $ligne = $resultat->fetch() )
{
echo "- ".$ligne->option_value;
echo "\n";
}
}
}
// Display informations returned by "cron-posts" option.
function wrush_cron_posts($bdd, $prefix = "wp_", $multisite = "false") {
echo "Wordpress scheduled posts\n";
echo "---------------------------\n";
if($multisite == "true")
{
$resultat = $bdd->query("SELECT blog_id, domain, path FROM ".$prefix."blogs");
$resultat->setFetchMode(PDO::FETCH_OBJ);
while( $ligne = $resultat->fetch() )
{
echo "- http://".$ligne->domain.$ligne->path." : ";
if($ligne->path == '/') {
$table_msql = $prefix."posts";
} else {
$table_msql = $prefix.$ligne->blog_id."_posts";
}
$resultat_sub = $bdd->query("SELECT ID, post_title, post_date_gmt FROM $table_msql WHERE post_status = 'future'");
$resultat_sub->setFetchMode(PDO::FETCH_OBJ);
echo $resultat_sub->rowCount()." found\n";
while( $ligne_sub = $resultat_sub->fetch() )
{
if(posts_date_test($ligne_sub->post_date_gmt) == 2) {
$bdd->query("UPDATE $table_msql SET post_status='publish' WHERE ID = ".$ligne_sub->ID);
$state = "[done]";
} elseif(posts_date_test($ligne_sub->post_date_gmt) == 1) {
$state = "[scheduled]";
} else {
$state = "[too late dude!]";
}
echo "--> $state ".$ligne_sub->post_date_gmt." GMT : ".$ligne_sub->post_title."\n";
}
}
} else {
$resultat = $bdd->query("SELECT option_value FROM ".$prefix."options WHERE option_name = 'siteurl'");
$resultat->setFetchMode(PDO::FETCH_OBJ);
while( $ligne = $resultat->fetch() )
{
echo "- ".$ligne->option_value." : ";
$table_msql = $prefix."posts";
$resultat_sub = $bdd->query("SELECT ID, post_title, post_date_gmt FROM $table_msql WHERE post_status = 'future'");
$resultat_sub->setFetchMode(PDO::FETCH_OBJ);
echo $resultat_sub->rowCount()." found\n";
while( $ligne_sub = $resultat_sub->fetch() )
{
if(posts_date_test($ligne_sub->post_date_gmt) == 2) {
$bdd->query("UPDATE $table_msql SET post_status='publish' WHERE ID = ".$ligne_sub->ID);
$state = "[done]";
} elseif(posts_date_test($ligne_sub->post_date_gmt) == 1) {
$state = "[scheduled]";
} else {
$state = "[too late dude!]";
}
echo "--> $state ".$ligne_sub->post_date_gmt." GMT : ".$ligne_sub->post_title."\n";
}
}
}
}
// Display informations returned by "plugins" option.
function wrush_plugins($bdd, $prefix = "wp_", $multisite = "false") {
if($multisite == "false") {
$resultat = $bdd->query("SELECT blog_id, domain, path FROM ".$prefix."blogs WHERE deleted = 0 AND public = 1");
echo "Wordpress plugins enabled on each blogs\n";
$resultat->setFetchMode(PDO::FETCH_OBJ);
echo "---------------------------\n";
while( $ligne = $resultat->fetch() )
{
echo "- http://".$ligne->domain.$ligne->path." : ";
echo "\n";
if($ligne->path == "/") {
$resultat_sub = $bdd->query("SELECT option_value FROM ".$prefix."options WHERE option_name = 'active_plugins'");
} else {
$resultat_sub = $bdd->query("SELECT option_value FROM ".$prefix.$ligne->blog_id."_options WHERE option_name = 'active_plugins'");
}
$resultat_sub->setFetchMode(PDO::FETCH_OBJ);
while( $ligne_sub = $resultat_sub->fetch() )
{
preg_match_all('/s:[0-9]{2}:"(.*?)"\;/',$ligne_sub->option_value,$match);
foreach($match[1] as $plugin)
{
$exploded = explode("/", $plugin);
echo "___ ".$exploded[0]."\n";
}
}
echo "\n";
}
} else {
$resultat = $bdd->query("SELECT option_value FROM ".$prefix."options WHERE option_name = 'siteurl'");
echo "Wordpress plugins enabled on your blog\n";
$resultat->setFetchMode(PDO::FETCH_OBJ);
echo "---------------------------\n";
while( $ligne = $resultat->fetch() )
{
echo "- ".$ligne->option_value." : ";
echo "\n";
$resultat_sub = $bdd->query("SELECT option_value FROM ".$prefix."options WHERE option_name = 'active_plugins'");
$resultat_sub->setFetchMode(PDO::FETCH_OBJ);
while( $ligne_sub = $resultat_sub->fetch() )
{
preg_match_all('/s:[0-9]{2}:"(.*?)"\;/',$ligne_sub->option_value,$match);
foreach($match[1] as $plugin)
{
$exploded = explode("/", $plugin);
echo "___ ".$exploded[0]."\n";
}
}
echo "\n";
}
}
}
// Display informations returned by "blogs" option.
function wrush_crons($bdd, $prefix = "wp_", $multisite = "false", $action = "all", $auth = 0) {
echo "Wordpress blogs WP-Cron launcher\n";
echo "---------------------------\n";
if($multisite == "true")
{
if ($action != "all") {
$action = str_replace("http://", "", $action);
$exploded_url = explode("/", $action);
if(!isset($exploded_url[1]) || $exploded_url[1] == "")
{
$resultat = $bdd->query("SELECT domain, path FROM ".$prefix."blogs WHERE deleted = 0 AND public = 1 AND domain LIKE \"%".$exploded_url[0]."%\" AND path = \"/\"");
} else {
$resultat = $bdd->query("SELECT domain, path FROM ".$prefix."blogs WHERE deleted = 0 AND public = 1 AND domain LIKE \"%".$exploded_url[0]."%\" AND path LIKE \"%".$exploded_url[1]."%\"");
}
} else {
$resultat = $bdd->query("SELECT domain, path FROM ".$prefix."blogs WHERE deleted = 0 AND public = 1");
}
$resultat->setFetchMode(PDO::FETCH_OBJ);
if($resultat->rowCount())
{
while( $ligne = $resultat->fetch() )
{
echo "- http://".$ligne->domain.$ligne->path." : ";
$result = curl_request($ligne->domain, $ligne->path, $auth);
if ($result['http_code'] == '200') {
echo "OK \n";
} else {
echo "Error (".$result['http_code'].")\n";
}
#if ($result['curl_error']) throw new Exception($result['curl_error']);
#if ($result['http_code']!='200') throw new Exception("HTTP Code = ".$result['http_code']);
#if (!$result['body']) throw new Exception("Body of file is empty");
}
} else {
echo "Wrush : Sorry, requested blog doesn't exist.";
}
} else {
$resultat = $bdd->query("SELECT option_name, option_value FROM ".$prefix."options WHERE option_name = 'siteurl'");
$resultat->setFetchMode(PDO::FETCH_OBJ);
while( $ligne = $resultat->fetch() )
{
echo "- ".$ligne->option_value." : ";
$cut = str_replace("http://", "", $ligne->option_value);
$explode_url = explode("/", $cut);
if(!isset($exploded_url[1]) || $exploded_url[1] == "")
{
$path_blog = "";
} else {
$path_blog = $explode_url[1];
}
$result = curl_request($explode_url[0], $path_blog, $auth);
if ($result['http_code'] == '200') {
echo "OK \n";
} else {
echo "Error (".$result['http_code'].")\n";
}
#if ($result['curl_error']) throw new Exception($result['curl_error']);
#if ($result['http_code']!='200') throw new Exception("HTTP Code = ".$result['http_code']);
#if (!$result['body']) throw new Exception("Body of file is empty");
}
}
}
function curl_request ($host, $path, $auth) {
$host_header= gethostname();
$ip = gethostbyname($host_header);
$params = array('url' => 'http://'.$ip.'/'.$path.'/wp-cron.php?doing_wp_cron',
'host' => $host,
'header' => '',
'method' => 'GET',
'referer' => '',
'cookie' => '',
'post_fields' => '',
'timeout' => 30
);
if ($auth) {
$explode_auth = explode(":", $auth);
if(isset($explode_auth[0]) && isset($explode_auth[1]))
{
$params['login'] = $explode_auth[0];
$params['password'] = $explode_auth[1];
}
}
$curl = new CurlRequest;
$curl->init($params);
$result = $curl->exec();
return $result;
}
function posts_date_test($date) {
$current_date = strtotime("now");
$minlate_date = $current_date + 60;
$defined_date = strtotime($date);
# 2 : Done
# 1 : Scheduled
# 0 : Too Late
if($defined_date >= $current_date && $defined_date <= $minlate_date) {
return 2;
} elseif($defined_date > $current_date) {
return 1;
} else {
return 0;
}
}
?>