4 $ewiki_plugins["page"]["MiniDump"] = "ewiki_page_wiki_mini_tarball_dump";
9 function ewiki_page_wiki_mini_tarball_dump($id, $data, $action) {
11 global $ewiki_config, $ewiki_plugins;
14 #-- get all pages / binary files
15 $result = ewiki_db::GETALL(array("id", "version", "flags"));
19 header("Content-Type: application/x-tar");
20 header("Content-Disposition: attachment; filename=\"InitPages.tar.gz\"");
23 $tarball = new ewiki_virtual_tarball();
27 while ($row=$result->get(0, 0x1037)) {
30 $row = ewiki_db::GET($id);
31 $content = &$row["content"];
34 if (!$row || !$row["id"] || !$row["content"]) {
40 "mtime" => $row["lastmodified"],
42 "mode" => 0664 | (($row["flags"]&EWIKI_DB_F_WRITEABLE)?0002:0000),
64 ############################################################################
68 if (!class_exists("ewiki_virtual_tarball")) {
70 #-- allows to generate a tarball from virtual files
71 # (supports no directories or symlinks and other stuff)
72 class ewiki_virtual_tarball {
76 function open($fn="/dev/stdout") {
82 if ($fn && ($fn != "-")) {
83 $this->f = gzopen("$fn", "wb9");
86 $_ENV["HTTP_ACCEPT_ENCODING"] = "gzip, deflate";
87 $_SERVER["HTTP_ACCEPT_ENCODING"] = "gzip, deflate";
88 ob_start("ob_gzhandler");
96 $this->write(str_repeat("\000", 9*1024));
105 function write($str) {
107 gzwrite($this->f, $str);
117 function oct($int, $len) {
120 $o = ($int & 0x07) . $o;
128 function add($filename, $content, $args=array()) {
130 $args = array_merge($args, array(
134 "uid" => 65534, #-- common for user "nobody"
140 $args["mode"] |= 0100000;
141 $args["size"] = strlen($content);
143 $magic = "ustar \000";
144 $filename = substr($filename, 0, 99);
147 $header = str_pad($filename, 100, "\000") # 0x0000
148 . $this->oct($args["mode"], 8) # 0x0064
149 . $this->oct($args["uid"], 8) # 0x006C
150 . $this->oct($args["gid"], 8) # 0x0074
151 . $this->oct($args["size"], 12) # 0x007C
152 . $this->oct($args["mtime"], 12) # 0x0088
153 . ($checksum) # 0x0094
154 . ($args["type"]) # 0x009C
155 . str_repeat("\000", 100) # 0x009D
157 . str_pad($args["uname"], 32, "\000") # 0x0109
158 . str_pad($args["gname"], 32, "\000") # 0x0129
160 $header = str_pad($header, 512, "\000");
162 #-- calculate and add header checksum
164 for ($n=0; $n<512; $n++) {
165 $cksum += ord($header[$n]);
167 $header = substr($header, 0, 0x0094)
168 . $this->oct($cksum, 7) . " "
169 . substr($header, 0x009C);
172 if ($fill = (512 - (strlen($content) % 512))) {
173 $content .= str_repeat("\000", $fill);
175 $this->write($header . $content);