changed git call from https to git readonly
[atutor.git] / mods / wiki / tools / t_ewikictl.php
1 <?php
2
3   include("t_config.php");
4
5 ?>
6 <html>
7 <head>
8  <title>ewikictl (www-only interface)</title>
9  <link rel="stylesheet" type="text/css" href="t_config.css">
10 </head>
11 <body bgcolor="#ffffff" text="#000000">
12 <h1>ewikictl<sup><small>/web</small></sup></h1>
13
14 <?php
15
16   if (empty($_REQUEST["action"])) {
17
18     ?>
19
20     <tt>ewikictl</tt> is a commandline tool, ought to be used from within
21     a shell account on your Web server. If your provider doesn't give you
22     that you have to stick to the features that can be provided through
23     this www-only interface.
24     <br>
25     <br>
26     You often need to prepare a www-deamon writeable directory, into
27     which you upload files before or download from after execution of one
28     of the actions. Inconvinient as it is, this is the only way to work
29     with this tool.
30     <br>
31
32
33     <br>
34     <table border="0" width="85%">
35     <tr>
36     <td width="50%" valign="top" class="add-border-right">
37       <h4>--backup</h4>
38       <?php
39          aform(
40            "backup",
41            array(
42              "dest" => array("", "", "directory", "(must exist on web server and be world-writeable)"),
43              "format" => array(array(
44                   "fast" => "fast files (recommended)",
45                   "flat" => "flat files (rfc822 format)",
46                   "plain" => "plain text pages",
47                   "meta" => "plain text companion .meta",
48                   "xmlmeta" => "plain with .meta in xml",
49                   "xml" => "XML-like format",
50                   "sql" => "MySQL INSERT (backup only)",
51                 ), "select", "file format", "(not all can be imported again!)<br>"),
52              "all" => array("1", "x", "all versions", "backs up database fully"),
53              "enc" => array("1", "x", "urlencode", "makes filenames DOS/Win-compatible"),
54              "force" => array("1", "checkbox", "force", "don't stop on errors"),
55            )
56          );
57       ?>
58     </td>
59     <td width="50%" valign="top">
60       <h4>--insert</h4>
61       <?php
62          aform(
63            "insert",
64            array(
65              "source" => array("", "", "directory", "(you must upload the backed up files there beforehand)"),
66              "format" => array(array(
67                   "fast" => "fast files (serialized)",
68                   "flat" => "flat files (message/http)",
69                   "plain" => "plain text pages",
70                 ), "select", "file format", "<br>"),
71              "all" => array("1", "x", "versioned files", "if they have .NNN extensions"),
72              "keep" => array("1", "x", "keep", "don't overwrite existing page versions"),
73              "dec" => array("1", "x", "urldecode filenames", "from Win-sys"),
74              "force" => array("1", "checkbox", "force", "don't stop on errors"),
75            )
76          );
77       ?>
78     </td>
79     </tr></table>
80
81
82     <br>
83     <table border="0" width="80%">
84     <tr>
85     <td width="60%" valign="top" class="add-border-right">
86       <h4>--holes</h4>
87       Removes older revisions (in given range) from all pages. It can
88       automatically make a backup of the killed data.
89       <br><br>
90       <?php
91          aform(
92            "holes",
93            array(
94              "holes_start" => array("2", "", "keep versions", "how many of the first few versions to keep (no 1 must remain for flat file databases!)"),
95              "holes_end" => array("-10", "", "kill from end", "that many versions shall remain at the end (minimum is 1 here of course!)<br>"),
96              "dest" => array("", "", "backup dir", "(must exist on web server and be world-writeable)"),
97              "format" => array(array(
98                   "fast" => "fast files",
99                   "flat" => "flat files",
100                   "plain" => "plain text",
101                 ), "select", "backup format", "<br>"),
102              "all" => array("1", "x", "backup all", "(implicit)"),
103              "enc" => array("1", "x", "backup filnames encode", ""),
104              "force" => array("1", "checkbox", "force", "don't stop on errors"),
105            )
106          );
107       ?>
108     </td>
109     <td width="40%" valign="top">
110       <h4>--help</h4>
111       to learn about new features in the commandline version ;)
112       <br><br>
113       <?php
114          aform(
115             "help",
116             array()
117          );
118       ?>
119     </td>
120     </tr></table>
121
122
123
124     <br>
125     <table border="0" width="99%">
126     <tr>
127     <td width="25%" valign="top" class="add-border-right">
128       <h4>--list</h4>
129       shows a wide list of all existing pages, including flags, size
130       author name and timestamp (like 'ls -l' under Unix)
131       <?php
132          aform(
133            "ls",
134            array()
135          );
136       ?>
137     </td>
138     <td width="40%" valign="top" class="add-border-right">
139       <h4>--rename</h4>
140       <?php
141          aform(
142             "rename",
143             array(
144               "0" => array("", "", "from", "(pagenames)"),
145               "1" => array("", "", "to"),
146             )
147          );
148       ?>
149     </td>
150     <td width="40%" valign="top" class="add-border-right">
151       <h4>--chmod</h4>
152       <?php
153          aform(
154             "chmod",
155             array(
156               "file" => array("SandBox", "", "page", ""),
157               "0" => array("+TEXT,-OFF", "", "flags", "can be either decimal (54), octal (0377) or hex (0x137f) - or a combination of <a href=\"t_commander/info.php\">flag abbreviations</a> separated by comma, + or a - sign<br> &nbsp; like <tt>+HTM,WRITE,-OFF</tt>"),
158             )
159          );
160       ?>
161     </td>
162     <td width="40%" valign="top">
163       <h4>--unlink</h4>
164       deletes a page completely (with all its versions)<br><br>
165       <?php
166          aform(
167             "unlink",
168             array(
169               "0" => array("SandBox", "", "page", ""),
170             )
171          );
172       ?>
173     </td>
174     </tr></table>
175
176
177     <br>
178     <br>
179     
180     There are equations for some of the above commands in the collection
181     of <a href=".">database tools</a>, that sometimes provide more options
182     or are easier to use.
183     
184     <br>
185     <br>
186
187     <?php
188
189   }
190
191
192
193   else {
194
195      #-- build request
196      $argv = array();
197      $action = $_REQUEST["action"];
198      
199      // action
200      $argv[0] = "t_ewikictl";
201      $argv[1] = "--$action";
202      
203      // special treatment to
204      if ($action == "holes") {
205         $argv[] = $_REQUEST["holes_start"] . ".." . $_REQUEST["holes_end"];
206      }
207      if (($action == "holes") && ($dir = $_REQUEST["dir"])) {
208         $argv[] = "--backup";
209      }
210
211      // numeric args
212      foreach ($_REQUEST as $field=>$str) {
213         if (is_int($field) && $str) {
214            $argv[] = $str;
215         }
216      }
217
218      // take common --args asis
219      foreach (array("force", "dest", "source", "dir", "all",
220         "urlencode", "urldecode", "keep", "db", "file")
221      as $field)
222      {
223         if ($str = $_REQUEST[$field]) {
224            $argv[] = "--$field";
225            if ($str !== "1") {
226               $argv[] = $str;
227            }
228         }
229      }
230      
231
232      #-- perform
233      echo "<h3>--$action</h3>\n<br>\n";
234
235      ob_start();
236      $GLOBALS["argv"] = $_SERVER["argv"] = $argv;
237      $GLOBALS["argv"] = $_SERVER["argc"] = count($argv);
238      $_SERVER["SERVER_SOFTWARE"] = 0;
239      include("ewikictl");
240      
241      #-- output
242      $text = ob_get_contents();
243      ob_end_clean();
244      #-- transform
245      $text = htmlentities($text);
246      $text = preg_replace('/\033\[([\d;]+)m/e', 'ansiesc2font("$1")', $text);
247      echo '<pre style="background:#111611;color:white;font:monospace;display:block;padding:5px;">'
248         . "\n\n$text\n\n"
249         . "</pre>";
250
251
252
253   }// end of everything here
254      
255   
256
257
258 #-- output form for one action
259 function aform($action, $args) {
260    static $xn=0;
261    echo '<form action="t_ewikictl.php">';
262    echo "\n<input type=\"hidden\" name=\"action\" value=\"$action\">\n";
263    foreach ($args as $i=>$l) {
264       echo "<label for=\"$i$xn\">$l[2]</label> ";
265       if (is_array($l[0])) {
266          echo "<select name=\"$i\" id=\"$i\">";
267          foreach ($l[0] as $v=>$vd) {
268             echo "<option value=\"$v\">$vd</option>";
269          }
270          echo "</select>\n";
271       }
272       else {
273          if (!strlen($l[1])) {
274             $l[1] = "text";
275          }
276          elseif ($l[1]=="x") {
277             $l[1] = 'checkbox" checked="checked';
278          }
279          echo "<input type=\"$l[1]\" name=\"$i\" id=\"$i$xn\" value=\"$l[0]\">\n";
280       }
281       echo "<small>$l[3]</small>\n<br>\n";
282    }
283    echo '<input type="submit" value="do">';
284    echo "</form>\n";
285    $xn++;
286 }
287
288
289
290 function ansiesc2font($str) {
291    $cols = array(
292       "black", "red", "green", "magenta", "blue", "yellow", "grey", "white",
293    );
294    foreach (explode(";", $str) as $n) {
295       $col = $cols[0 + ((0+$n) % 10)];
296       if (($n == "37") or ($n == "0") or ($n == "27")) {
297          return "</b>";
298       }
299       elseif ($n >= 40) {
300          return "<b style=\"background:$col\">";
301       }
302       elseif ($n >= 30) {
303          return "<b style=\"color:$col\">";
304       }
305    }
306 }
307   
308 ?>
309
310 </body>
311 </html>