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.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * filechecks_islegalname() - Make sure a filename is legal
29 * @param string The name of the file to check
31 function filechecks_islegalname($filename) {
32 if (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,'%') || strstr($filename,'^')
39 || strstr($filename,'&')
40 || strstr($filename,'(') || strstr($filename,')')
41 || strstr($filename,'>') || strstr($filename,'<')) {
45 if (preg_match('/^\./',$filename)) {
53 * filechecks_targz() - Verify the integrity of a .tar.gz file.
55 * @param string The name of the targz file to check
57 function filechecks_targz($filename) {
58 exec("tar -ztvf $GLOBALS[FTPINCOMING_DIR]/" . EscapeShellCmd($filename),$output,$ret);
60 for ($i=0;$i<count($output);$i++) {
61 $exitout .= "<br />" . $output[$i] . "\n";
63 exit_error(sprintf(_('Failed tar/gz integrity check. Output follows: <p>$s</p>'),$exitout),'');
68 * filechecks_gz(0 - Verify the integrity of a .gz file.
70 * @param string The name of the gz file to check.
72 function filechecks_gz($filename) {
73 exec("gunzip -t $GLOBALS[FTPINCOMING_DIR]/" . EscapeShellCmd($filename),$output,$ret);
75 for ($i=0;$i<count($output);$i++) {
76 $exitout .= "<br />" . $output[$i] . "\n";
78 exit_error(sprintf(_('Failed gzip integrity check. Output follows: <p>$s</p>'),$exitout),'');
83 * filechecks_getfiletype() - Resolve the filetype of a file.
85 * @param string The name of the file to resolve.
87 function filechecks_getfiletype($filename) {
89 $filename = chop($filename);
91 if (preg_match("/\.diff$/",$filename)) {
94 elseif (preg_match("/\.diff.gz$/",$filename)) {
95 $filetype = "diff/gz";
96 filechecks_gz($filename);
98 elseif (preg_match("/\.asc$/",$filename)) {
101 elseif (preg_match("/\.bin$/",$filename)) {
104 elseif (preg_match("/\.exe$/",$filename)) {
107 elseif (preg_match("/\.jar$/",$filename)) {
110 elseif (preg_match("/\.lsm$/",$filename)) {
113 elseif (preg_match("/\.pdb$/",$filename)) {
116 elseif (preg_match("/\.pl$/",$filename)) {
119 elseif (preg_match("/\.py$/",$filename)) {
120 $filetype = "python";
122 elseif (preg_match("/\.prc$/",$filename)) {
125 elseif (preg_match("/\.sig$/",$filename)) {
128 elseif (preg_match("/\.tar.bz2$/",$filename)) {
129 $filetype = "tar/bz2";
131 elseif (preg_match("/\.tar.gz$/",$filename)) {
132 $filetype = "tar/gz";
133 filechecks_targz($filename);
135 elseif (preg_match("/\.tgz$/",$filename)) {
138 elseif (preg_match("/\.zip$/",$filename)) {
141 elseif (preg_match("/\.shar.gz$/",$filename)) {
142 $filetype = "shar/gz";
144 elseif (preg_match("/\.bz2$/",$filename)) {
147 elseif (preg_match("/\.gz$/",$filename)) {
149 filechecks_gz($filename);
151 elseif (preg_match("/\.i386.rpm$/",$filename)) {
152 $filetype = "i386 rpm";
154 elseif (preg_match("/\.alpha.rpm$/",$filename)) {
155 $filetype = "alpha rpm";
157 elseif (preg_match("/\.src.rpm$/",$filename)) {
158 $filetype = "src rpm";
160 elseif (preg_match("/\.rpm$/",$filename)) {
163 elseif (preg_match("/\.deb$/",$filename)) {
166 elseif (preg_match("/\.([a-zA-Z]+)$/",$filename,$regs)) {
167 $filetype = $regs[1];
171 exit_error (_('This file does not have a system-recognized filename type.'),'');
175 exit_error (_('File does not exist. You must supply a filename.'),'');
178 if (!file_exists("$GLOBALS[FTPINCOMING_DIR]/$filename")) {
179 exit_error (sprintf(_('File does not exist. File %s is not in incoming FTP directory.'),$filename),'');