From: Sebastien D. <sde...@us...> - 2005-03-14 16:58:20
|
Update of /cvsroot/tslogparser/web/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6308 Modified Files: index.php tar.inc.php Log Message: Update demo to 0.6 Index: tar.inc.php =================================================================== RCS file: /cvsroot/tslogparser/web/admin/tar.inc.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- tar.inc.php 27 Jan 2005 10:37:52 -0000 1.1 +++ tar.inc.php 14 Mar 2005 16:58:01 -0000 1.2 @@ -1005,16 +1005,17 @@ // | obtain it through the world-wide-web, please send a note to | // | li...@ph... so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ -// | Author: Vincent Blavet <vi...@bl...> | +// | Author: Vincent Blavet <vi...@ph...> | // +----------------------------------------------------------------------+ // // $Id$ +define ('ARCHIVE_TAR_ATT_SEPARATOR', 90001); /** * Creates a (compressed) Tar archive * -* @author Vincent Blavet <vi...@bl...> +* @author Vincent Blavet <vi...@ph...> * @version $Revision$ * @package Archive */ @@ -1036,6 +1037,11 @@ var $_compress_type='none'; /** + * @var string Explode separator + */ + var $_separator=' '; + + /** * @var file descriptor */ var $_file=0; @@ -1093,12 +1099,16 @@ } } } else { - if (($p_compress == true) || ($p_compress == 'gz')) { + if (($p_compress === true) || ($p_compress == 'gz')) { $this->_compress = true; $this->_compress_type = 'gz'; } else if ($p_compress == 'bz2') { $this->_compress = true; $this->_compress_type = 'bz2'; + } else { + die("Unsupported compression type '$p_compress'\n". + "Supported types are 'gz' and 'bz2'.\n"); + return false; } } $this->_tarname = $p_tarname; @@ -1147,8 +1157,9 @@ * sub-directories are also added. * See also createModify() method for more details. * - * @param array $p_filelist An array of filenames and directory names, or a single - * string with names separated by a single blank space. + * @param array $p_filelist An array of filenames and directory names, or a + * single string with names separated by a single + * blank space. * @return true on success, false on error. * @see createModify() * @access public @@ -1168,8 +1179,9 @@ * even if a file with the same name is already archived. * See also createModify() method for more details. * - * @param array $p_filelist An array of filenames and directory names, or a single - * string with names separated by a single blank space. + * @param array $p_filelist An array of filenames and directory names, or a + * single string with names separated by a single + * blank space. * @return true on success, false on error. * @see createModify() * @access public @@ -1227,13 +1239,15 @@ * for extraction in a different path than the origin files are. * See also addModify() method for file adding properties. * - * @param array $p_filelist An array of filenames and directory names, or a single - * string with names separated by a single blank space. - * @param string $p_add_dir A string which contains a path to be added to the - * memorized path of each element in the list. - * @param string $p_remove_dir A string which contains a path to be removed from - * the memorized path of each element in the list, when - * relevant. + * @param array $p_filelist An array of filenames and directory names, + * or a single string with names separated by + * a single blank space. + * @param string $p_add_dir A string which contains a path to be added + * to the memorized path of each element in + * the list. + * @param string $p_remove_dir A string which contains a path to be + * removed from the memorized path of each + * element in the list, when relevant. * @return boolean true on success, false on error. * @access public * @see addModify() @@ -1249,7 +1263,7 @@ if (is_array($p_filelist)) $v_list = $p_filelist; elseif (is_string($p_filelist)) - $v_list = explode(" ", $p_filelist); + $v_list = explode($this->_separator, $p_filelist); else { $this->_cleanFile(); $this->_error('Invalid file list'); @@ -1297,12 +1311,15 @@ * If a file/dir is not readable the file/dir is ignored. However an * error text is send to PEAR error. * - * @param array $p_filelist An array of filenames and directory names, or a single - * string with names separated by a single blank space. - * @param string $p_add_dir A string which contains a path to be added to the - * memorized path of each element in the list. - * @param string $p_remove_dir A string which contains a path to be removed from - * the memorized path of each element in the list, when + * @param array $p_filelist An array of filenames and directory + * names, or a single string with names + * separated by a single blank space. + * @param string $p_add_dir A string which contains a path to be + * added to the memorized path of each + * element in the list. + * @param string $p_remove_dir A string which contains a path to be + * removed from the memorized path of + * each element in the list, when * relevant. * @return true on success, false on error. * @access public @@ -1311,13 +1328,14 @@ { $v_result = true; - if (!@is_file($this->_tarname)) - $v_result = $this->createModify($p_filelist, $p_add_dir, $p_remove_dir); + if (!$this->_isArchive()) + $v_result = $this->createModify($p_filelist, $p_add_dir, + $p_remove_dir); else { if (is_array($p_filelist)) $v_list = $p_filelist; elseif (is_string($p_filelist)) - $v_list = explode(" ", $p_filelist); + $v_list = explode($this->_separator, $p_filelist); else { $this->_error('Invalid file list'); return false; @@ -1336,17 +1354,19 @@ * end of the existing archive. If the archive does not yet exists it * is created. * - * @param string $p_filename A string which contains the full filename path - * that will be associated with the string. - * @param string $p_string The content of the file added in the archive. + * @param string $p_filename A string which contains the full + * filename path that will be associated + * with the string. + * @param string $p_string The content of the file added in + * the archive. * @return true on success, false on error. * @access public */ function addString($p_filename, $p_string) { $v_result = true; - - if (!@is_file($this->_tarname)) { + + if (!$this->_isArchive()) { if (!$this->_openWrite()) { return false; } @@ -1392,10 +1412,11 @@ * is returned. However the result can be a partial extraction that may * need to be manually cleaned. * - * @param string $p_path The path of the directory where the files/dir need to by - * extracted. - * @param string $p_remove_path Part of the memorized path that can be removed if - * present at the beginning of the file/dir path. + * @param string $p_path The path of the directory where the + * files/dir need to by extracted. + * @param string $p_remove_path Part of the memorized path that can be + * removed if present at the beginning of + * the file/dir path. * @return boolean true on success, false on error. * @access public * @see extractList() @@ -1406,7 +1427,8 @@ $v_list_detail = array(); if ($v_result = $this->_openRead()) { - $v_result = $this->_extractList($p_path, $v_list_detail, "complete", 0, $p_remove_path); + $v_result = $this->_extractList($p_path, $v_list_detail, + "complete", 0, $p_remove_path); $this->_close(); } @@ -1442,12 +1464,14 @@ * in the directory indicated by the optional $p_path parameter. * If indicated the $p_remove_path can be used in the same way as it is * used in extractModify() method. - * @param array $p_filelist An array of filenames and directory names, or a single - * string with names separated by a single blank space. - * @param string $p_path The path of the directory where the files/dir need to by - * extracted. - * @param string $p_remove_path Part of the memorized path that can be removed if - * present at the beginning of the file/dir path. + * @param array $p_filelist An array of filenames and directory names, + * or a single string with names separated + * by a single blank space. + * @param string $p_path The path of the directory where the + * files/dir need to by extracted. + * @param string $p_remove_path Part of the memorized path that can be + * removed if present at the beginning of + * the file/dir path. * @return true on success, false on error. * @access public * @see extractModify() @@ -1460,14 +1484,15 @@ if (is_array($p_filelist)) $v_list = $p_filelist; elseif (is_string($p_filelist)) - $v_list = explode(" ", $p_filelist); + $v_list = explode($this->_separator, $p_filelist); else { $this->_error('Invalid string list'); return false; } if ($v_result = $this->_openRead()) { - $v_result = $this->_extractList($p_path, $v_list_detail, "partial", $v_list, $p_remove_path); + $v_result = $this->_extractList($p_path, $v_list_detail, "partial", + $v_list, $p_remove_path); $this->_close(); } @@ -1475,6 +1500,60 @@ } // }}} + // {{{ setAttribute() + /** + * This method set specific attributes of the archive. It uses a variable + * list of parameters, in the format attribute code + attribute values : + * $arch->setAttribute(ARCHIVE_TAR_ATT_SEPARATOR, ','); + * @param mixed $argv variable list of attributes and values + * @return true on success, false on error. + * @access public + */ + function setAttribute() + { + $v_result = true; + + // ----- Get the number of variable list of arguments + if (($v_size = func_num_args()) == 0) { + return true; + } + + // ----- Get the arguments + $v_att_list = &func_get_args(); + + // ----- Read the attributes + $i=0; + while ($i<$v_size) { + + // ----- Look for next option + switch ($v_att_list[$i]) { + // ----- Look for options that request a string value + case ARCHIVE_TAR_ATT_SEPARATOR : + // ----- Check the number of parameters + if (($i+1) >= $v_size) { + $this->_error('Invalid number of parameters for ' + .'attribute ARCHIVE_TAR_ATT_SEPARATOR'); + return false; + } + + // ----- Get the value + $this->_separator = $v_att_list[$i+1]; + $i++; + break; + + default : + $this->_error('Unknow attribute code '.$v_att_list[$i].''); + return false; + } + + // ----- Next attribute + $i++; + } + + return $v_result; + } + // }}} + // {{{ _error() function _error($p_message) { @@ -1491,20 +1570,33 @@ } // }}} + // {{{ _isArchive() + function _isArchive($p_filename=NULL) + { + if ($p_filename == NULL) { + $p_filename = $this->_tarname; + } + clearstatcache(); + return @is_file($p_filename); + } + // }}} + // {{{ _openWrite() function _openWrite() { if ($this->_compress_type == 'gz') - $this->_file = @gzopen($this->_tarname, "wb"); + $this->_file = @gzopen($this->_tarname, "wb9"); else if ($this->_compress_type == 'bz2') $this->_file = @bzopen($this->_tarname, "wb"); else if ($this->_compress_type == 'none') $this->_file = @fopen($this->_tarname, "wb"); else - $this->_error('Unknown or missing compression type ('.$this->_compress_type.')'); + $this->_error('Unknown or missing compression type (' + .$this->_compress_type.')'); if ($this->_file == 0) { - $this->_error('Unable to open in write mode \''.$this->_tarname.'\''); + $this->_error('Unable to open in write mode \'' + .$this->_tarname.'\''); return false; } @@ -1521,12 +1613,14 @@ if ($this->_temp_tarname == '') { $this->_temp_tarname = uniqid('tar').'.tmp'; if (!$v_file_from = @fopen($this->_tarname, 'rb')) { - $this->_error('Unable to open in read mode \''.$this->_tarname.'\''); + $this->_error('Unable to open in read mode \'' + .$this->_tarname.'\''); $this->_temp_tarname = ''; return false; } if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { - $this->_error('Unable to open in write mode \''.$this->_temp_tarname.'\''); + $this->_error('Unable to open in write mode \'' + .$this->_temp_tarname.'\''); $this->_temp_tarname = ''; return false; } @@ -1550,7 +1644,8 @@ else if ($this->_compress_type == 'none') $this->_file = @fopen($v_filename, "rb"); else - $this->_error('Unknown or missing compression type ('.$this->_compress_type.')'); + $this->_error('Unknown or missing compression type (' + .$this->_compress_type.')'); if ($this->_file == 0) { $this->_error('Unable to open in read mode \''.$v_filename.'\''); @@ -1571,10 +1666,12 @@ else if ($this->_compress_type == 'none') $this->_file = @fopen($this->_tarname, "r+b"); else - $this->_error('Unknown or missing compression type ('.$this->_compress_type.')'); + $this->_error('Unknown or missing compression type (' + .$this->_compress_type.')'); if ($this->_file == 0) { - $this->_error('Unable to open in read/write mode \''.$this->_tarname.'\''); + $this->_error('Unable to open in read/write mode \'' + .$this->_tarname.'\''); return false; } @@ -1585,7 +1682,8 @@ // {{{ _close() function _close() { - if (isset($this->_file)) { + //if (isset($this->_file)) { + if (is_resource($this->_file)) { if ($this->_compress_type == 'gz') @gzclose($this->_file); else if ($this->_compress_type == 'bz2') @@ -1593,7 +1691,8 @@ else if ($this->_compress_type == 'none') @fclose($this->_file); else - $this->_error('Unknown or missing compression type ('.$this->_compress_type.')'); + $this->_error('Unknown or missing compression type (' + .$this->_compress_type.')'); $this->_file = 0; } @@ -1632,7 +1731,7 @@ // {{{ _writeBlock() function _writeBlock($p_binary_data, $p_len=null) { - if ($this->_file) { + if (is_resource($this->_file)) { if ($p_len === null) { if ($this->_compress_type == 'gz') @gzputs($this->_file, $p_binary_data); @@ -1641,7 +1740,8 @@ else if ($this->_compress_type == 'none') @fputs($this->_file, $p_binary_data); else - $this->_error('Unknown or missing compression type ('.$this->_compress_type.')'); + $this->_error('Unknown or missing compression type (' + .$this->_compress_type.')'); } else { if ($this->_compress_type == 'gz') @gzputs($this->_file, $p_binary_data, $p_len); @@ -1650,7 +1750,8 @@ else if ($this->_compress_type == 'none') @fputs($this->_file, $p_binary_data, $p_len); else - $this->_error('Unknown or missing compression type ('.$this->_compress_type.')'); + $this->_error('Unknown or missing compression type (' + .$this->_compress_type.')'); } } @@ -1659,13 +1760,10 @@ // }}} // {{{ _readBlock() - function _readBlock($p_len=null) + function _readBlock() { $v_block = null; - if ($this->_file) { - if ($p_len === null) - $p_len = 512; - + if (is_resource($this->_file)) { if ($this->_compress_type == 'gz') $v_block = @gzread($this->_file, 512); else if ($this->_compress_type == 'bz2') @@ -1673,8 +1771,8 @@ else if ($this->_compress_type == 'none') $v_block = @fread($this->_file, 512); else - $this->_error('Unknown or missing compression type ('.$this->_compress_type.')'); - + $this->_error('Unknown or missing compression type (' + .$this->_compress_type.')'); } return $v_block; } @@ -1683,12 +1781,13 @@ // {{{ _jumpBlock() function _jumpBlock($p_len=null) { - if ($this->_file) { + if (is_resource($this->_file)) { if ($p_len === null) $p_len = 1; - if ($this->_compress_type == 'gz') + if ($this->_compress_type == 'gz') { @gzseek($this->_file, @gztell($this->_file)+($p_len*512)); + } else if ($this->_compress_type == 'bz2') { // ----- Replace missing bztell() and bzseek() for ($i=0; $i<$p_len; $i++) @@ -1696,7 +1795,8 @@ } else if ($this->_compress_type == 'none') @fseek($this->_file, @ftell($this->_file)+($p_len*512)); else - $this->_error('Unknown or missing compression type ('.$this->_compress_type.')'); + $this->_error('Unknown or missing compression type (' + .$this->_compress_type.')'); } return true; @@ -1706,7 +1806,7 @@ // {{{ _writeFooter() function _writeFooter() { - if ($this->_file) { + if (is_resource($this->_file)) { // ----- Write the last 0 filled block for end of archive $v_binary_data = pack("a512", ''); $this->_writeBlock($v_binary_data); @@ -1733,8 +1833,10 @@ if (sizeof($p_list) == 0) return true; - for ($j=0; ($j<count($p_list)) && ($v_result); $j++) { - $v_filename = $p_list[$j]; + foreach ($p_list as $v_filename) { + if (!$v_result) { + break; + } // ----- Skip the current tar name if ($v_filename == $this->_tarname) @@ -1757,15 +1859,17 @@ $this->_warning("Directory '$v_filename' can not be read"); continue; } - $p_hitem = readdir($p_hdir); // '.' directory - $p_hitem = readdir($p_hdir); // '..' directory while (false !== ($p_hitem = readdir($p_hdir))) { - if ($v_filename != ".") - $p_temp_list[0] = $v_filename.'/'.$p_hitem; - else - $p_temp_list[0] = $p_hitem; + if (($p_hitem != '.') && ($p_hitem != '..')) { + if ($v_filename != ".") + $p_temp_list[0] = $v_filename.'/'.$p_hitem; + else + $p_temp_list[0] = $p_hitem; - $v_result = $this->_addList($p_temp_list, $p_add_dir, $p_remove_dir); + $v_result = $this->_addList($p_temp_list, + $p_add_dir, + $p_remove_dir); + } } unset($p_temp_list); @@ -1814,9 +1918,10 @@ $v_stored_filename = $this->_pathReduction($v_stored_filename); - if (is_file($p_filename)) { + if ($this->_isArchive($p_filename)) { if (($v_file = @fopen($p_filename, "rb")) == 0) { - $this->_warning("Unable to open file '$p_filename' in binary read mode"); + $this->_warning("Unable to open file '".$p_filename + ."' in binary read mode"); return true; } @@ -1856,7 +1961,8 @@ // ----- Calculate the stored filename $p_filename = $this->_translateWinPath($p_filename, false);; - if (!$this->_writeHeaderBlock($p_filename, strlen($p_string), 0, 0, "", 0, 0)) + if (!$this->_writeHeaderBlock($p_filename, strlen($p_string), + 0, 0, "", 0, 0)) return false; $i=0; @@ -1913,8 +2019,13 @@ $v_prefix = ''; - $v_binary_data_first = pack("a100a8a8a8a12A12", $v_reduce_filename, $v_perms, $v_uid, $v_gid, $v_size, $v_mtime); - $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", $v_typeflag, $v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix, ''); + $v_binary_data_first = pack("a100a8a8a8a12A12", + $v_reduce_filename, $v_perms, $v_uid, + $v_gid, $v_size, $v_mtime); + $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", + $v_typeflag, $v_linkname, $v_magic, + $v_version, $v_uname, $v_gname, + $v_devmajor, $v_devminor, $v_prefix, ''); // ----- Calculate the checksum $v_checksum = 0; @@ -1944,7 +2055,8 @@ // }}} // {{{ _writeHeaderBlock() - function _writeHeaderBlock($p_filename, $p_size, $p_mtime=0, $p_perms=0, $p_type='', $p_uid=0, $p_gid=0) + function _writeHeaderBlock($p_filename, $p_size, $p_mtime=0, $p_perms=0, + $p_type='', $p_uid=0, $p_gid=0) { $p_filename = $this->_pathReduction($p_filename); @@ -1981,8 +2093,13 @@ $v_prefix = ''; - $v_binary_data_first = pack("a100a8a8a8a12A12", $p_filename, $v_perms, $v_uid, $v_gid, $v_size, $v_mtime); - $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", $p_type, $v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix, ''); + $v_binary_data_first = pack("a100a8a8a8a12A12", + $p_filename, $v_perms, $v_uid, $v_gid, + $v_size, $v_mtime); + $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", + $p_type, $v_linkname, $v_magic, + $v_version, $v_uname, $v_gname, + $v_devmajor, $v_devminor, $v_prefix, ''); // ----- Calculate the checksum $v_checksum = 0; @@ -2034,8 +2151,12 @@ $v_prefix = ''; - $v_binary_data_first = pack("a100a8a8a8a12A12", '././@LongLink', 0, 0, 0, $v_size, 0); - $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", $v_typeflag, $v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix, ''); + $v_binary_data_first = pack("a100a8a8a8a12A12", + '././@LongLink', 0, 0, 0, $v_size, 0); + $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", + $v_typeflag, $v_linkname, $v_magic, + $v_version, $v_uname, $v_gname, + $v_devmajor, $v_devminor, $v_prefix, ''); // ----- Calculate the checksum $v_checksum = 0; @@ -2097,7 +2218,10 @@ for ($i=156; $i<512; $i++) $v_checksum+=ord(substr($v_binary_data,$i,1)); - $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $v_binary_data); + $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" + ."a8checksum/a1typeflag/a100link/a6magic/a2version/" + ."a32uname/a32gname/a8devmajor/a8devminor", + $v_binary_data); // ----- Extract the checksum $v_header['checksum'] = OctDec(trim($v_data['checksum'])); @@ -2108,7 +2232,9 @@ if (($v_checksum == 256) && ($v_header['checksum'] == 0)) return true; - $this->_error('Invalid checksum for file "'.$v_data['filename'].'" : '.$v_checksum.' calculated, '.$v_header['checksum'].' expected'); + $this->_error('Invalid checksum for file "'.$v_data['filename'] + .'" : '.$v_checksum.' calculated, ' + .$v_header['checksum'].' expected'); return false; } @@ -2122,7 +2248,8 @@ if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { $v_header['size'] = 0; } - /* ----- All these fields are removed form the header because they do not carry interesting info + /* ----- All these fields are removed form the header because + they do not carry interesting info $v_header[link] = trim($v_data[link]); $v_header[magic] = trim($v_data[magic]); $v_header[version] = trim($v_data[version]); @@ -2190,7 +2317,8 @@ if ($v_header['filename'] == $p_filename) { if ($v_header['typeflag'] == "5") { - $this->_error('Unable to extract in string a directory entry {'.$v_header['filename'].'}'); + $this->_error('Unable to extract in string a directory ' + .'entry {'.$v_header['filename'].'}'); return NULL; } else { $n = floor($v_header['size']/512); @@ -2199,7 +2327,8 @@ } if (($v_header['size'] % 512) != 0) { $v_content = $this->_readBlock(); - $v_result_str .= substr($v_content, 0, ($v_header['size'] % 512)); + $v_result_str .= substr($v_content, 0, + ($v_header['size'] % 512)); } return $v_result_str; } @@ -2213,7 +2342,8 @@ // }}} // {{{ _extractList() - function _extractList($p_path, &$p_list_detail, $p_mode, $p_file_list, $p_remove_path) + function _extractList($p_path, &$p_list_detail, $p_mode, + $p_file_list, $p_remove_path) { $v_result=true; $v_nb = 0; @@ -2221,7 +2351,8 @@ $v_listing = false; $p_path = $this->_translateWinPath($p_path, false); - if ($p_path == '' || (substr($p_path, 0, 1) != '/' && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { + if ($p_path == '' || (substr($p_path, 0, 1) != '/' + && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { $p_path = "./".$p_path; } $p_remove_path = $this->_translateWinPath($p_remove_path); @@ -2251,7 +2382,7 @@ clearstatcache(); - While (strlen($v_binary_data = $this->_readBlock()) != 0) + while (strlen($v_binary_data = $this->_readBlock()) != 0) { $v_extract_file = FALSE; $v_extraction_stopped = 0; @@ -2259,8 +2390,9 @@ if (!$this->_readHeader($v_binary_data, $v_header)) return false; - if ($v_header['filename'] == '') + if ($v_header['filename'] == '') { continue; + } // ----- Look for long filename if ($v_header['typeflag'] == 'L') { @@ -2276,7 +2408,9 @@ // ----- Look if it is a directory if (substr($p_file_list[$i], -1) == '/') { // ----- Look if the directory is in the filename path - if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) == $p_file_list[$i])) { + if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) + && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) + == $p_file_list[$i])) { $v_extract_file = TRUE; break; } @@ -2296,8 +2430,10 @@ if (($v_extract_file) && (!$v_listing)) { if (($p_remove_path != '') - && (substr($v_header['filename'], 0, $p_remove_path_size) == $p_remove_path)) - $v_header['filename'] = substr($v_header['filename'], $p_remove_path_size); + && (substr($v_header['filename'], 0, $p_remove_path_size) + == $p_remove_path)) + $v_header['filename'] = substr($v_header['filename'], + $p_remove_path_size); if (($p_path != './') && ($p_path != '/')) { while (substr($p_path, -1) == '/') $p_path = substr($p_path, 0, strlen($p_path)-1); @@ -2308,16 +2444,21 @@ $v_header['filename'] = $p_path.'/'.$v_header['filename']; } if (file_exists($v_header['filename'])) { - if ((@is_dir($v_header['filename'])) && ($v_header['typeflag'] == '')) { - $this->_error('File '.$v_header['filename'].' already exists as a directory'); + if ( (@is_dir($v_header['filename'])) + && ($v_header['typeflag'] == '')) { + $this->_error('File '.$v_header['filename'] + .' already exists as a directory'); return false; } - if ((is_file($v_header['filename'])) && ($v_header['typeflag'] == "5")) { - $this->_error('Directory '.$v_header['filename'].' already exists as a file'); + if ( ($this->_isArchive($v_header['filename'])) + && ($v_header['typeflag'] == "5")) { + $this->_error('Directory '.$v_header['filename'] + .' already exists as a file'); return false; } if (!is_writeable($v_header['filename'])) { - $this->_error('File '.$v_header['filename'].' already exists and is write protected'); + $this->_error('File '.$v_header['filename'] + .' already exists and is write protected'); return false; } if (filemtime($v_header['filename']) > $v_header['mtime']) { @@ -2326,7 +2467,10 @@ } // ----- Check the directory availability and create it if necessary - elseif (($v_result = $this->_dirCheck(($v_header['typeflag'] == "5"?$v_header['filename']:dirname($v_header['filename'])))) != 1) { + elseif (($v_result + = $this->_dirCheck(($v_header['typeflag'] == "5" + ?$v_header['filename'] + :dirname($v_header['filename'])))) != 1) { $this->_error('Unable to create path for '.$v_header['filename']); return false; } @@ -2335,13 +2479,15 @@ if ($v_header['typeflag'] == "5") { if (!@file_exists($v_header['filename'])) { if (!@mkdir($v_header['filename'], 0777)) { - $this->_error('Unable to create directory {'.$v_header['filename'].'}'); + $this->_error('Unable to create directory {' + .$v_header['filename'].'}'); return false; } } } else { if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { - $this->_error('Error while opening {'.$v_header['filename'].'} in write binary mode'); + $this->_error('Error while opening {'.$v_header['filename'] + .'} in write binary mode'); return false; } else { $n = floor($v_header['size']/512); @@ -2358,17 +2504,18 @@ // ----- Change the file mode, mtime @touch($v_header['filename'], $v_header['mtime']); - if ($v_header['mode'] & 0111) { - // make file executable, obey umask - $mode = fileperms($v_header['filename']) | (~umask() & 0111); - @chmod($v_header['filename'], $mode); - } + // To be completed + //chmod($v_header[filename], DecOct($v_header[mode])); } // ----- Check the file size clearstatcache(); if (filesize($v_header['filename']) != $v_header['size']) { - $this->_error('Extracted file '.$v_header['filename'].' does not have the correct file size \''.filesize($v_filename).'\' ('.$v_header['size'].' expected). Archive may be corrupted.'); + $this->_error('Extracted file '.$v_header['filename'] + .' does not have the correct file size \'' + .filesize($v_header['filename']) + .'\' ('.$v_header['size'] + .' expected). Archive may be corrupted.'); return false; } } @@ -2388,7 +2535,8 @@ if ($v_listing || $v_extract_file || $v_extraction_stopped) { // ----- Log extracted files - if (($v_file_dir = dirname($v_header['filename'])) == $v_header['filename']) + if (($v_file_dir = dirname($v_header['filename'])) + == $v_header['filename']) $v_file_dir = ''; if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) $v_file_dir = '/'; @@ -2411,7 +2559,9 @@ $this->_close(); if (!@rename($this->_tarname, $this->_tarname.".tmp")) { - $this->_error('Error while renaming \''.$this->_tarname.'\' to temporary file \''.$this->_tarname.'.tmp\''); + $this->_error('Error while renaming \''.$this->_tarname + .'\' to temporary file \''.$this->_tarname + .'.tmp\''); return false; } @@ -2421,7 +2571,8 @@ $v_temp_tar = @bzopen($this->_tarname.".tmp", "rb"); if ($v_temp_tar == 0) { - $this->_error('Unable to open file \''.$this->_tarname.'.tmp\' in binary read mode'); + $this->_error('Unable to open file \''.$this->_tarname + .'.tmp\' in binary read mode'); @rename($this->_tarname.".tmp", $this->_tarname); return false; } @@ -2451,8 +2602,10 @@ $v_buffered_lines[] = @bzread($v_temp_tar, 512); // ----- Read the following blocks but not the last one - while (strlen($v_buffered_lines[] = @bzread($v_temp_tar, 512)) > 0) { - $v_binary_data = pack("a512", array_shift($v_buffered_lines)); + while (strlen($v_buffered_lines[] + = @bzread($v_temp_tar, 512)) > 0) { + $v_binary_data = pack("a512", + array_shift($v_buffered_lines)); $this->_writeBlock($v_binary_data); } @@ -2460,11 +2613,13 @@ } if (!@unlink($this->_tarname.".tmp")) { - $this->_error('Error while deleting temporary file \''.$this->_tarname.'.tmp\''); + $this->_error('Error while deleting temporary file \'' + .$this->_tarname.'.tmp\''); } } else { - // ----- For not compressed tar, just add files before the last 512 bytes block + // ----- For not compressed tar, just add files before the last + // 512 bytes block if (!$this->_openReadWrite()) return false; @@ -2527,8 +2682,8 @@ // {{{ _pathReduction() /** - * Compress path by changing for example "/dir/foo/../bar" to "/dir/bar", and - * remove double slashes. + * Compress path by changing for example "/dir/foo/../bar" to "/dir/bar", + * rand emove double slashes. * * @param string $p_dir path to reduce * @@ -2557,11 +2712,14 @@ // ----- Ignore it and ignore the $i-1 $i--; } - else if (($v_list[$i] == '') && ($i!=(sizeof($v_list)-1)) && ($i!=0)) { + else if ( ($v_list[$i] == '') + && ($i!=(sizeof($v_list)-1)) + && ($i!=0)) { // ----- Ignore only the double '//' in path, // but not the first and last / } else { - $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?'/'.$v_result:''); + $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?'/' + .$v_result:''); } } } @@ -2576,7 +2734,8 @@ { if (OS_WINDOWS) { // ----- Look for potential disk letter - if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { + if ( ($p_remove_disk_letter) + && (($v_position = strpos($p_path, ':')) != false)) { $p_path = substr($p_path, $v_position+1); } // ----- Change potential windows directory separator Index: index.php =================================================================== RCS file: /cvsroot/tslogparser/web/admin/index.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- index.php 27 Jan 2005 10:47:56 -0000 1.3 +++ index.php 14 Mar 2005 16:58:01 -0000 1.4 @@ -182,7 +182,7 @@ && ($_FILES['tsarchive']['type'] != "application/x-tar") && ($_FILES['tsarchive']['type'] != "application/x-gzip")) { - echo "<b>You have to supply the testsuite in a tar gzip'd format.</b>\n"; + echo "<b>You have to supply the testsuite in a tar gzip'd format (got '".htmlentities($_FILES['tsarchive']['type'])."').</b>\n"; db_fini(); require($root."footer.inc.php"); die(); @@ -194,7 +194,7 @@ $tmpdir = $root."ts/".time(); - if (!$tar->extractModify($tmpdir, "ts")) + if (!$tar->extractModify($tmpdir, "")) { echo "<b>Archive extraction failed.</b>\n"; @@ -203,6 +203,40 @@ die(); } + /* Find directory name from inside archive, if any */ + /* 1 - check the files are inside a subdirectory */ + if (!is_dir($tmpdir."/conformance/interface")) + { + /* 2 - open the directory where files were extracted */ + if ($dh = opendir($tmpdir)) + { + /* 3 - list the files. We assume there is only 1 directory here */ + while (($file = readdir($dh)) !== false) + { + if (($file == ".") || ($file == "..")) + continue; + if (is_dir($tmpdir."/".$file)) + { + $tmpdir .= "/".$file; + break; + } + echo "<b>Unexpected entry in archive: $file</b>"; + db_fini(); + require($root."footer.inc.php"); + die(); + } + /* 4 - close the directory */ + closedir($dh); + } + else + { + echo "<b>Unable to open temporary directory $tmpdir</b>"; + db_fini(); + require($root."footer.inc.php"); + die(); + } + } + /* Here we're in step 2 in process: ready to proceed */ echo "<pre>\n"; @@ -264,7 +298,7 @@ <td><textarea name="ts_descr" rows="3" cols="79"><?php echo $_GET["ts_descr"]; ?></textarea></td> </tr> <tr> - <td>New release archive (tar.gz expanding in 'ts' directory):</td> + <td>New release archive (tar.gz format):</td> <td><input name="tsarchive" type="file"></td> </tr> <tr> |