Blame
Date:
Sat Aug 13 04:00:24 2022 UTC
Message:
Daily backup
001
2021-12-17
jrmu
<?php if (!defined('PmWiki')) exit();
002
2021-12-17
jrmu
/* Copyright 2003-2015 Patrick R. Michaud (pmichaud@pobox.com)
003
2021-12-17
jrmu
This file is part of PmWiki; you can redistribute it and/or modify
004
2021-12-17
jrmu
it under the terms of the GNU General Public License as published
005
2021-12-17
jrmu
by the Free Software Foundation; either version 2 of the License, or
006
2021-12-17
jrmu
(at your option) any later version. See pmwiki.php for full details.
007
2021-12-17
jrmu
008
2021-12-17
jrmu
This file adds "?action=diag" and "?action=phpinfo" actions to PmWiki.
009
2021-12-17
jrmu
This produces lots of diagnostic output that may be helpful to the
010
2021-12-17
jrmu
software authors when debugging PmWiki or other scripts.
011
2021-12-17
jrmu
012
2021-12-17
jrmu
Script maintained by Petko YOTOV www.pmwiki.org/petko
013
2021-12-17
jrmu
*/
014
2021-12-17
jrmu
015
2021-12-17
jrmu
016
2021-12-17
jrmu
if ($action=='diag') {
017
2021-12-17
jrmu
@ini_set('track_errors','1');
018
2021-12-17
jrmu
@ini_set('display_errors', '1');
019
2021-12-17
jrmu
@session_start();
020
2021-12-17
jrmu
header('Content-type: text/plain');
021
2021-12-17
jrmu
print_r($GLOBALS);
022
2021-12-17
jrmu
exit();
023
2021-12-17
jrmu
}
024
2021-12-17
jrmu
025
2021-12-17
jrmu
if ($action=='phpinfo') { phpinfo(); exit(); }
026
2021-12-17
jrmu
027
2021-12-17
jrmu
function Ruleset() {
028
2021-12-17
jrmu
global $MarkupTable;
029
2021-12-17
jrmu
$out = '';
030
2021-12-17
jrmu
$dbg = 0;
031
2021-12-17
jrmu
BuildMarkupRules();
032
2021-12-17
jrmu
foreach($MarkupTable as $id=>$m) {
033
2021-12-17
jrmu
$out .= sprintf("%-16s %-16s %-16s %s\n",$id,@$m['cmd'],@$m['seq'], @$m['dbg']);
034
2021-12-17
jrmu
if (@$m['dbg']) $dbg++;
035
2021-12-17
jrmu
}
036
2021-12-17
jrmu
if ($dbg) $out .= "
037
2021-12-17
jrmu
[!] Markup rules possibly incompatible with PHP 5.5 or newer.
038
2021-12-17
jrmu
Please contact the recipe maintainer for update
039
2021-12-17
jrmu
or see www.pmwiki.org/wiki/PmWiki/CustomMarkup";
040
2021-12-17
jrmu
return $out;
041
2021-12-17
jrmu
}
042
2021-12-17
jrmu
043
2021-12-17
jrmu
$HandleActions['ruleset'] = 'HandleRuleset';
044
2021-12-17
jrmu
045
2021-12-17
jrmu
function HandleRuleset($pagename) {
046
2021-12-17
jrmu
header("Content-type: text/plain");
047
2021-12-17
jrmu
print Ruleset();
048
2021-12-17
jrmu
}
049
2021-12-17
jrmu
050
2021-12-17
jrmu
function StopWatchHTML($pagename, $print = 0) {
051
2021-12-17
jrmu
global $StopWatch;
052
2021-12-17
jrmu
StopWatch('now');
053
2021-12-17
jrmu
$l = strlen(count($StopWatch));
054
2021-12-17
jrmu
$out = '<pre>';
055
2021-12-17
jrmu
foreach((array)$StopWatch as $i => $x)
056
2021-12-17
jrmu
$out .= sprintf("%{$l}d: %s\n", $i, $x);
057
2021-12-17
jrmu
$out .= '</pre>';
058
2021-12-17
jrmu
if (is_array($StopWatch)) array_pop($StopWatch);
059
2021-12-17
jrmu
if ($print) print $out;
060
2021-12-17
jrmu
return $out;
061
2021-12-17
jrmu
}
062
2021-12-17
jrmu
063
2021-12-17
jrmu
### From Cookbook:RecipeCheck
064
2021-12-17
jrmu
/* Copyright 2007-2019 Patrick R. Michaud (pmichaud@pobox.com)
065
2021-12-17
jrmu
066
2021-12-17
jrmu
This recipe adds ?action=recipecheck to a site. When activated,
067
2021-12-17
jrmu
?action=recipecheck fetches the current list of Cookbook recipes
068
2021-12-17
jrmu
and their versions from pmwiki.org. It then compares this list
069
2021-12-17
jrmu
with the versions of any installed recipes on the local site
070
2021-12-17
jrmu
and reports any differences.
071
2021-12-17
jrmu
072
2021-12-17
jrmu
By default the recipe restricts ?action=recipecheck to admins.
073
2021-12-17
jrmu
074
2021-12-17
jrmu
Note that not all recipes currently follow PmWiki's
075
2021-12-17
jrmu
recipecheck standard (feel free to report these to the pmwiki-users
076
2021-12-17
jrmu
mailing list).
077
2021-12-17
jrmu
078
2021-12-17
jrmu
* 2007-04-17: Added suggestions by Feral
079
2021-12-17
jrmu
- explicit black text
080
2021-12-17
jrmu
- skip non-php files and directories
081
2021-12-17
jrmu
* 2019-11-28: Added to scripts/diag.php by Petko
082
2021-12-17
jrmu
*/
083
2021-12-17
jrmu
SDV($HandleActions['recipecheck'], 'HandleRecipeCheckCore');
084
2021-12-17
jrmu
SDV($HandleAuth['recipecheck'], 'admin');
085
2021-12-17
jrmu
SDV($ActionTitleFmt['recipecheck'], '| $[Recipe Check]');
086
2021-12-17
jrmu
087
2021-12-17
jrmu
SDV($WikiStyleApply['tr'], 'tr');
088
2021-12-17
jrmu
SDV($HTMLStylesFmt['recipecheck'], '
089
2021-12-17
jrmu
table.recipecheck tr.ok { color:black; background-color:#ccffcc; }
090
2021-12-17
jrmu
table.recipecheck tr.check { color:black; background-color:#ffffcc; }
091
2021-12-17
jrmu
table.recipecheck { border:1px solid #cccccc; padding:4px; }
092
2021-12-17
jrmu
');
093
2021-12-17
jrmu
094
2021-12-17
jrmu
SDV($RecipeListUrl, 'http://www.pmwiki.org/pmwiki/recipelist');
095
2021-12-17
jrmu
096
2021-12-17
jrmu
function HandleRecipeCheckCore($pagename, $auth = 'admin') {
097
2021-12-17
jrmu
global $RecipeListUrl, $Version, $RecipeInfo,
098
2021-12-17
jrmu
$RecipeCheckFmt, $PageStartFmt, $PageEndFmt;
099
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
100
2021-12-17
jrmu
if (!$page) Abort('?admin access required');
101
2021-12-17
jrmu
$cvinfo = GetRecipeListCore($RecipeListUrl);
102
2021-12-17
jrmu
if (!$cvinfo) {
103
2021-12-17
jrmu
$msg = "Unable to retrieve cookbook data from $RecipeListUrl\n";
104
2021-12-17
jrmu
$allow_url_fopen = ini_get('allow_url_fopen');
105
2021-12-17
jrmu
if (!$allow_url_fopen) $msg .= "
106
2021-12-17
jrmu
<br /><br />It appears that your PHP environment isn't allowing
107
2021-12-17
jrmu
the recipelist to be downloaded from pmwiki.org
108
2021-12-17
jrmu
(allow_url_fopen&nbsp;=&nbsp;$allow_url_fopen).";
109
2021-12-17
jrmu
Abort($msg);
110
2021-12-17
jrmu
}
111
2021-12-17
jrmu
$rinfo['PmWiki:Upgrades'] = $Version;
112
2021-12-17
jrmu
ScanRecipeInfoCore('cookbook', $cvinfo);
113
2021-12-17
jrmu
foreach((array)$RecipeInfo as $r => $v) {
114
2021-12-17
jrmu
if (!@$v['Version']) continue;
115
2021-12-17
jrmu
$r = preg_replace('/^(?!PmWiki:)(Cookbook[.:])?/', 'Cookbook:', $r);
116
2021-12-17
jrmu
$rinfo[$r] = $v['Version'];
117
2021-12-17
jrmu
}
118
2021-12-17
jrmu
$markup = "!!Recipe status for {\$PageUrl}\n".RecipeTableCore($rinfo, $cvinfo);
119
2021-12-17
jrmu
$html = MarkupToHTML($pagename, $markup);
120
2021-12-17
jrmu
SDV($RecipeCheckFmt, array(&$PageStartFmt, $html, &$PageEndFmt));
121
2021-12-17
jrmu
PrintFmt($pagename, $RecipeCheckFmt);
122
2021-12-17
jrmu
}
123
2021-12-17
jrmu
124
2021-12-17
jrmu
125
2021-12-17
jrmu
function GetRecipeListCore($list) {
126
2021-12-17
jrmu
$cvinfo = array();
127
2021-12-17
jrmu
$fp = fopen($list, 'r');
128
2021-12-17
jrmu
while ($fp && !feof($fp)) {
129
2021-12-17
jrmu
$line = fgets($fp, 1024);
130
2021-12-17
jrmu
if ($line[0] == '#') continue;
131
2021-12-17
jrmu
if (preg_match('/(\\S+) +(.*)/', $line, $match))
132
2021-12-17
jrmu
$cvinfo[$match[1]] = trim($match[2]);
133
2021-12-17
jrmu
}
134
2021-12-17
jrmu
fclose($fp);
135
2021-12-17
jrmu
return $cvinfo;
136
2021-12-17
jrmu
}
137
2021-12-17
jrmu
138
2021-12-17
jrmu
139
2021-12-17
jrmu
function ScanRecipeInfoCore($dlistfmt, $cvinfo = NULL) {
140
2021-12-17
jrmu
global $RecipeInfo;
141
2021-12-17
jrmu
foreach((array)$dlistfmt as $dir) {
142
2021-12-17
jrmu
$dfp = @opendir($dir); if (!$dfp) continue;
143
2021-12-17
jrmu
while ( ($name = readdir($dfp)) !== false) {
144
2021-12-17
jrmu
if ($name[0] == '.') continue;
145
2021-12-17
jrmu
if (!preg_match('/\\.php/i', $name)) continue;
146
2021-12-17
jrmu
$text = implode('', @file("$dir/$name"));
147
2021-12-17
jrmu
if (preg_match("/^\\s*\\\$RecipeInfo\\['(.*?)'\\]\\['Version'\\]\\s*=\\s*'(.*?)'\\s*;/m", $text, $match))
148
2021-12-17
jrmu
SDV($RecipeInfo[$match[1]]['Version'], $match[2]);
149
2021-12-17
jrmu
if (preg_match("/^\\s*SDV\\(\\s*\\\$RecipeInfo\\['(.*?)'\\]\\['Version'\\]\\s*,\\s*'(.*?)'\\s*\\)\\s*\\;/m", $text, $match))
150
2021-12-17
jrmu
SDV($RecipeInfo[$match[1]]['Version'], $match[2]);
151
2021-12-17
jrmu
if (@$cvinfo[$name]) {
152
2021-12-17
jrmu
$r = preg_replace('/^.*:/', '', $cvinfo[$name]);
153
2021-12-17
jrmu
SDV($RecipeInfo[$r]['Version'], "unknown ($name)");
154
2021-12-17
jrmu
}
155
2021-12-17
jrmu
}
156
2021-12-17
jrmu
closedir($dfp);
157
2021-12-17
jrmu
}
158
2021-12-17
jrmu
}
159
2021-12-17
jrmu
160
2021-12-17
jrmu
161
2021-12-17
jrmu
function RecipeTableCore($rinfo, $cvinfo) {
162
2021-12-17
jrmu
$fmt = "||%-40s ||%-20s ||%-20s ||\n";
163
2021-12-17
jrmu
$out = "||class=recipecheck cellpadding=0 cellspacing=0 width=600\n";
164
2021-12-17
jrmu
$out .= sprintf($fmt, '!Recipe', '!local', '!pmwiki.org');
165
2021-12-17
jrmu
foreach($rinfo as $r => $lv) {
166
2021-12-17
jrmu
$cv = @$cvinfo[$r];
167
2021-12-17
jrmu
$style = ($lv == $cv) ? 'ok' : 'check';
168
2021-12-17
jrmu
$out .= sprintf($fmt, "%apply=tr $style%[[$r]]", $lv, $cv);
169
2021-12-17
jrmu
}
170
2021-12-17
jrmu
return $out;
171
2021-12-17
jrmu
}
172
2021-12-17
jrmu
IRCNow