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
|
<?php if (!defined('PmWiki')) exit();
/* Copyright 2003-2024 Patrick R. Michaud (pmichaud@pobox.com)
This file is part of PmWiki; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. See pmwiki.php for full details.
This file adds "?action=diag" and "?action=phpinfo" actions to PmWiki.
This produces lots of diagnostic output that may be helpful to the
software authors when debugging PmWiki or other scripts.
Script maintained by Petko YOTOV www.pmwiki.org/petko
*/
if ($action=='diag') {
@ini_set('track_errors','1');
@ini_set('display_errors', '1');
pm_session_start();
header('Content-type: text/plain');
print_r($GLOBALS);
exit();
}
if ($action=='phpinfo') { phpinfo(); exit(); }
function Ruleset() {
global $MarkupTable;
$out = '';
$dbg = 0;
BuildMarkupRules();
foreach($MarkupTable as $id=>$m) {
$out .= sprintf("%-16s %-16s %-16s %s\n",$id,@$m['cmd'],@$m['seq'], @$m['dbg']);
if (@$m['dbg']) $dbg++;
}
if ($dbg) $out .= "
[!] Markup rules possibly incompatible with PHP 5.5 or newer.
Please contact the recipe maintainer for update
or see www.pmwiki.org/wiki/PmWiki/CustomMarkup";
return $out;
}
$HandleActions['ruleset'] = 'HandleRuleset';
function HandleRuleset($pagename) {
header("Content-type: text/plain");
print Ruleset();
}
function StopWatchHTML($pagename, $print = 0) {
global $StopWatch;
StopWatch('now');
$l = strlen(count($StopWatch));
$out = '<pre>';
foreach((array)$StopWatch as $i => $x)
$out .= sprintf("%{$l}d: %s\n", $i, $x);
$out .= '</pre>';
if (is_array($StopWatch)) array_pop($StopWatch);
if ($print) print $out;
return $out;
}
### From Cookbook:RecipeCheck
/* Copyright 2007-2023 Patrick R. Michaud (pmichaud@pobox.com)
This recipe adds ?action=recipecheck to a site. When activated,
?action=recipecheck fetches the current list of Cookbook recipes
and their versions from pmwiki.org. It then compares this list
with the versions of any installed recipes on the local site
and reports any differences.
By default the recipe restricts ?action=recipecheck to admins.
Note that not all recipes currently follow PmWiki's
recipecheck standard (feel free to report these to the pmwiki-users
mailing list).
* 2007-04-17: Added suggestions by Feral
- explicit black text
- skip non-php files and directories
* 2019-11-28: Added to scripts/diag.php by Petko
* Subsequent changes listed at PmWiki:ChangeLog
*/
if($action=='recipecheck') {
SDV($HandleActions['recipecheck'], 'HandleRecipeCheckCore');
SDV($HandleAuth['recipecheck'], 'admin');
SDV($ActionTitleFmt['recipecheck'], '| $[Recipe Check]');
SDV($WikiStyleApply['tr'], 'tr');
SDV($HTMLStylesFmt['recipecheck'], '
table.recipecheck tr.ok { color:black; background-color:#ccffcc; }
table.recipecheck tr.check { color:black; background-color:#ffffcc; }
table.recipecheck { border:1px solid #cccccc; padding:4px; }
');
SDV($RecipeListUrl, 'https://www.pmwiki.org/pmwiki/recipelist');
}
function HandleRecipeCheckCore($pagename, $auth = 'admin') {
global $RecipeListUrl, $Version, $RecipeInfo,
$RecipeCheckFmt, $PageStartFmt, $PageEndFmt;
$page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
if (!$page) Abort('?admin access required');
$cvinfo = GetRecipeListCore($RecipeListUrl);
if (!$cvinfo) {
$msg = "Unable to retrieve cookbook data from $RecipeListUrl\n";
$allow_url_fopen = ini_get('allow_url_fopen');
if (!$allow_url_fopen) $msg .= "
<br /><br />It appears that your PHP environment isn't allowing
the recipelist to be downloaded from pmwiki.org
(allow_url_fopen = $allow_url_fopen).";
Abort($msg);
}
$rinfo['PmWiki:Upgrades'] = $Version;
ScanRecipeInfoCore('cookbook', $cvinfo, 'Cookbook:');
$skindirs = glob("pub/skins/*");
if($skindirs) foreach($skindirs as $skindir) {
if($skindir[0] == '.') continue;
if(is_dir($skindir)) ScanRecipeInfoCore($skindir, $cvinfo, 'Skins:');
}
foreach((array)$RecipeInfo as $r => $v) {
if (!@$v['Version']) continue;
if (!preg_match('/:/', $r)) {
$imap = isset($v['InterMap']) ? $v['InterMap'] : 'Cookbook:';
$r = $imap.$r;
}
$rinfo[$r] = $v['Version'];
}
$markup = "!!Recipe status for {\$PageUrl}\n".RecipeTableCore($rinfo, $cvinfo);
$html = MarkupToHTML($pagename, $markup);
SDV($RecipeCheckFmt, array(&$PageStartFmt, $html, &$PageEndFmt));
PrintFmt($pagename, $RecipeCheckFmt);
}
function GetRecipeListCore($list) {
$cvinfo = array();
$fp = fopen($list, 'r');
while ($fp && !feof($fp)) {
$line = fgets($fp, 1024);
if ($line[0] == '#') continue;
if (preg_match('/(\\S+) +(.*)/', $line, $match))
$cvinfo[$match[1]] = trim($match[2]);
}
fclose($fp);
return $cvinfo;
}
function ScanRecipeInfoCore($dlistfmt, $cvinfo = NULL, $imap = 'Cookbook:') {
global $RecipeInfo;
foreach((array)$dlistfmt as $dir) {
$dfp = @opendir($dir); if (!$dfp) continue;
while ( ($name = readdir($dfp)) !== false) {
if ($name[0] == '.') continue;
if (!preg_match('/\\.php/i', $name)) continue;
$text = implode('', (array)@file("$dir/$name"));
if (preg_match("/^\\s*\\\$RecipeInfo\\['(.*?)'\\]\\['Version'\\]\\s*=\\s*'(.*?)'\\s*;/m", $text, $match)) {
SDV($RecipeInfo[$match[1]]['Version'], $match[2]);
SDV($RecipeInfo[$match[1]]['InterMap'], $imap);
}
if (preg_match("/^\\s*SDV\\(\\s*\\\$RecipeInfo\\['(.*?)'\\]\\['Version'\\]\\s*,\\s*'(.*?)'\\s*\\)\\s*\\;/m", $text, $match)) {
SDV($RecipeInfo[$match[1]]['Version'], $match[2]);
SDV($RecipeInfo[$match[1]]['InterMap'], $imap);
}
if (@$cvinfo[$name]) {
$r = preg_replace('/^.*:/', '', $cvinfo[$name]);
SDV($RecipeInfo[$r]['Version'], "unknown ($name)");
SDV($RecipeInfo[$r]['InterMap'], $imap);
}
}
closedir($dfp);
}
}
function RecipeTableCore($rinfo, $cvinfo) {
$fmt = "||%-40s ||%-20s ||%-20s ||\n";
$out = "||class='recipecheck sortable filterable' "
. "cellpadding=0 cellspacing=0\n";
$out .= sprintf($fmt, '!Recipe', '!local', '!pmwiki.org');
foreach($rinfo as $r => $lv) {
$cv = @$cvinfo[$r];
$style = ($lv == $cv) ? 'ok' : 'check';
$out .= sprintf($fmt, "%apply=tr $style%[[$r]]", $lv, $cv);
}
return $out;
}
|