3 * File checking functions
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2010 (c) Franck Villaume
7 * http://fusionforge.org/
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * filechecks_islegalname() - Make sure a filename is legal
28 * @param string The name of the file to check
30 function filechecks_islegalname($filename) {
31 if (strstr($filename,' ') || strstr($filename,'\\')
32 || strstr($filename,"'") || strstr($filename,'"')
33 || strstr($filename,';') || strstr($filename,'`')
34 || strstr($filename,'|') || strstr($filename,'$')
35 || strstr($filename,',') || strstr($filename,':')
36 || strstr($filename,'@') || strstr($filename,'*')
37 || strstr($filename,'%') || strstr($filename,'^')
38 || strstr($filename,'&')
39 || strstr($filename,'(') || strstr($filename,')')
40 || strstr($filename,'>') || strstr($filename,'<')) {
44 if (preg_match('/^\./',$filename)) {
52 * filechecks_targz() - Verify the integrity of a .tar.gz file.
54 * @param string The name of the targz file to check
56 function filechecks_targz($filename) {
57 exec("tar -ztvf $GLOBALS[FTPINCOMING_DIR]/" . EscapeShellCmd($filename),$output,$ret);
59 for ($i=0;$i<count($output);$i++) {
60 $exitout .= "<br />" . $output[$i] . "\n";
62 exit_error(sprintf(_('Failed tar/gz integrity check. Output follows: <p>$s</p>'),$exitout),'');
67 * filechecks_gz(0 - Verify the integrity of a .gz file.
69 * @param string The name of the gz file to check.
71 function filechecks_gz($filename) {
72 exec("gunzip -t $GLOBALS[FTPINCOMING_DIR]/" . EscapeShellCmd($filename),$output,$ret);
74 for ($i=0;$i<count($output);$i++) {
75 $exitout .= "<br />" . $output[$i] . "\n";
77 exit_error(sprintf(_('Failed gzip integrity check. Output follows: <p>$s</p>'),$exitout),'');
82 * filechecks_getfiletype() - Resolve the filetype of a file.
84 * @param string The name of the file to resolve.
86 function filechecks_getfiletype($filename) {
88 $filename = chop($filename);
90 if (preg_match("/\.diff$/",$filename)) {
93 elseif (preg_match("/\.diff.gz$/",$filename)) {
94 $filetype = "diff/gz";
95 filechecks_gz($filename);
97 elseif (preg_match("/\.asc$/",$filename)) {
100 elseif (preg_match("/\.bin$/",$filename)) {
103 elseif (preg_match("/\.exe$/",$filename)) {
106 elseif (preg_match("/\.jar$/",$filename)) {
109 elseif (preg_match("/\.lsm$/",$filename)) {
112 elseif (preg_match("/\.pdb$/",$filename)) {
115 elseif (preg_match("/\.pl$/",$filename)) {
118 elseif (preg_match("/\.py$/",$filename)) {
119 $filetype = "python";
121 elseif (preg_match("/\.prc$/",$filename)) {
124 elseif (preg_match("/\.sig$/",$filename)) {
127 elseif (preg_match("/\.tar.bz2$/",$filename)) {
128 $filetype = "tar/bz2";
130 elseif (preg_match("/\.tar.gz$/",$filename)) {
131 $filetype = "tar/gz";
132 filechecks_targz($filename);
134 elseif (preg_match("/\.tgz$/",$filename)) {
137 elseif (preg_match("/\.zip$/",$filename)) {
140 elseif (preg_match("/\.shar.gz$/",$filename)) {
141 $filetype = "shar/gz";
143 elseif (preg_match("/\.bz2$/",$filename)) {
146 elseif (preg_match("/\.gz$/",$filename)) {
148 filechecks_gz($filename);
150 elseif (preg_match("/\.i386.rpm$/",$filename)) {
151 $filetype = "i386 rpm";
153 elseif (preg_match("/\.alpha.rpm$/",$filename)) {
154 $filetype = "alpha rpm";
156 elseif (preg_match("/\.src.rpm$/",$filename)) {
157 $filetype = "src rpm";
159 elseif (preg_match("/\.rpm$/",$filename)) {
162 elseif (preg_match("/\.deb$/",$filename)) {
165 elseif (preg_match("/\.([a-zA-Z]+)$/",$filename,$regs)) {
166 $filetype = $regs[1];
170 exit_error (_('This file does not have a system-recognized filename type.'),'');
174 exit_error (_('File does not exist. You must supply a filename.'),'');
177 if (!file_exists("$GLOBALS[FTPINCOMING_DIR]/$filename")) {
178 exit_error (sprintf(_('File does not exist. File %s is not in incoming FTP directory.'),$filename),'');