-
Notifications
You must be signed in to change notification settings - Fork 10
/
create_fudforum_archive
100 lines (86 loc) · 3.28 KB
/
create_fudforum_archive
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
#!/usr/bin/php -q
<?php
/***************************************************************************
* copyright : (C) 2001-2021 Advanced Internet Designs Inc.
* email : forum@prohost.org
* $Id$
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License, or
* (at your option) any later version.
***************************************************************************/
/** Create an archive of all files requred to install or upgrade a forum. */
function create_file_archive($dir)
{
$dirs = array(realpath($dir));
$base = dirname($dirs[0]);
$data = '';
foreach($dirs as &$v) { // Note the &$v, we're going to change the array.
if (!($d = opendir($v))) {
seterr('Cannot access ['. $path .'].');
}
$dd = str_replace($base, '', $v);
if ($dd && ($dd[0] == '/' || $dd[0] == '\\')) {
$dd = substr($dd, 1);
}
while (($f = readdir($d))) {
if ($f == '.' || $f == '..' || $f == 'CVS' || $f == '.svn') continue;
if (is_file($v .'/'. $f)) {
$fdata = file_get_contents($v .'/'. $f);
if ($f == 'lib.js') {
// Crude JavaScript compression.
$multiline_comment = '/\/\*(?!-)[\x00-\xff]*?\*\//';
$fdata = preg_replace($multiline_comment, '', $fdata);
$singleline_comment = '/[^:]\/\/.*/';
$fdata = preg_replace($singleline_comment, '', $fdata);
$extra_space = '/\s+/';
// $fdata = preg_replace($extra_space, ' ', $fdata);
$removable_space = '/\s?([\{\};\=\(\)\/\+\*-])\s?/';
$fdata = preg_replace($removable_space, "\\1", $fdata);
$empty_lines = '/^\n+|^[\t\s]*\n+/m';
$fdata = str_replace($empty_lines, '', $fdata);
}
$data .= '//'. $f .'//0600//'. $dd .'//'. md5($fdata) .'//'. strlen($fdata) ."//\n". $fdata ."\n";
} else {
$data .= '//'. $f .'//0700//'. $dd ."//\n";
$dirs[] = $v .'/'. $f;
}
}
closedir($d);
}
return $data;
}
/** Print error message and exit. */
function seterr($msg)
{
fwrite(STDERR, $msg ."\n");
exit;
}
/* main */
error_reporting(E_ALL);
@ini_set('display_errors', 1);
@ini_set('memory_limit', '128M'); // PHP 5.3's default, old defaults too small.
if (!defined('STDERR')) {
define('STDERR', fopen('php://stderr', 'wb'));
}
if (!isset($_SERVER['argv'][1]) ) {
seterr("No arguments.\n\tSyntax: create_file_archive directory_name [use compression]");
} else if (!@is_dir($_SERVER['argv'][1])) {
seterr('ERROR: ['. $_SERVER['argv'][1] ."] is not a valid valid directory.\nPlease specify a valid directory to package.");
}
if (isset($_SERVER['argv'][2]) && !extension_loaded('zlib')) {
seterr('The zlib extension that is required to compress the archive is not installed. Please install it or restart without compression.');
}
$_SERVER['argv'][1] = preg_replace('!/+$!', '', $_SERVER['argv'][1]);
$archive = create_file_archive($_SERVER['argv'][1]);
$check_sum = md5($archive);
$clean = array('<?' => 'PHP_OPEN_TAG', '<%' => 'PHP_OPEN_ASP_TAG');
if (isset($_SERVER['argv'][2])) {
$a_len = str_pad(strlen($archive), 10, '0', STR_PAD_LEFT);
echo $check_sum . $a_len . strtr(gzcompress($archive, 9), $clean);
} else {
$clean['<?'] = 'RAW_PHP_OPEN_TAG';
echo $check_sum . strtr($archive, $clean);
}
?>