00001 <?php 00002 // ftp_publish.php - 00003 // 00004 // SiT (Support Incident Tracker) - Support call tracking system 00005 // Copyright (C) 2010-2011 The Support Incident Tracker Project 00006 // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors 00007 // 00008 // This software may be used and distributed according to the terms 00009 // of the GNU General Public License, incorporated herein by reference. 00010 // 00011 00012 // Author: Ivan Lucas <ivanlucas[at]users.sourceforge.net> 00013 00014 00015 $permission = 44; // Publish Files to FTP site 00016 00017 require ('core.php'); 00018 require (APPLICATION_LIBPATH . 'functions.inc.php'); 00019 00020 // This page requires authentication 00021 require (APPLICATION_LIBPATH . 'auth.inc.php'); 00022 00023 // seed with microseconds since last "whole" second 00024 mt_srand((double)microtime()*1000000); 00025 $maxVal = 1000000; 00026 $minVal = 1; 00027 $randvala = (mt_rand() % ($maxVal-$minVal)) + $minVal; 00028 // seed with current time 00029 mt_srand($now); 00030 $maxVal = 1000000; 00031 $minVal = 1; 00032 $randvalb = (mt_rand() % ($maxVal-$minVal)) + $minVal; 00033 $randomdir = dechex(crc32($randvala.$randvalb)); 00034 00035 $filesize = filesize($source_file); 00036 00037 $pretty_file_size = readable_file_size($filesize); 00038 00039 // FIXME This temp variable name can't be right can it? INL 00040 if (!isset($temp_directory)) 00041 { 00042 // show form 00043 include (APPLICATION_INCPATH . 'htmlheader.inc.php'); 00044 echo "<h2>{$strFTPPublish}</h2>"; 00045 echo "<form name='publishform' action='{$_SERVER['PHP_SELF']}' method='post'>"; 00046 echo "<input type='hidden' name='source_file' value='{$source_file}' />"; 00047 echo "<input type='hidden' name='destination_file' value='{$destination_file}' />"; 00048 echo "<input type='hidden' name='temp_directory' value='{$randomdir}' />"; 00049 echo "<input type='hidden' name='ftp_url' value=\"ftp://{$CONFIG['ftp_hostname']}{$CONFIG['ftp_path']}{$randomdir}/{$destination_file}\" />"; 00050 echo "<table summary='ftp-publish' align='center' width='60%' class='vertical'>"; 00051 echo "<tr><th>{$strPublish}:</th><td><img src='".getattachmenticon($filename)."' alt='{$filename} ({$pretty_file_size})' border='0' />"; 00052 echo "<strong>{$destination_file}</strong> ({$pretty_file_size})</td></tr>"; 00053 echo "<tr><th>{$strTo}:</th><td><code>'ftp://{$CONFIG['ftp_hostname']}{$CONFIG['ftp_path']}{$randomdir}/{$destination_file}</code></td></tr>"; 00054 echo "<tr><th>{$strTitle}:</th><td><input type='text' name='shortdescription' maxlength='255' size='40'' /></td></tr>"; 00055 echo "<tr><th>{$strDescription}:</th><td><textarea name='longdescription' cols='40' rows='3'></textarea></td></tr>"; 00056 echo "<tr><th>{$strFileVersion}:</th><td><input type='text' name='fileversion' maxlength='50' size='10' /></td></tr>"; 00057 echo "<tr><th>{$strValid}:</th><td>"; 00058 echo "<input type='radio' name='expiry_none' value='time'> {$strForXDaysHoursMinutes}<br /> "; 00059 echo "<input maxlength='3' name='expiry_days' value='{$na_days}' onclick=\"window.document.publishform.expiry_none[0].checked = true;\" size='3' /> {$strDays} "; 00060 echo "<input maxlength='2' name='expiry_hours' value='{$na_hours}' onclick=\"window.document.publishform.expiry_none[0].checked = true;\" size='3' /> {$strHours} "; 00061 echo "<input maxlength='2' name='expiry_minutes' value='{$na_minutes}' onclick=\"window.document.publishform.expiry_none[0].checked = true;\" size='3' /> {$strMinutes}<br />"; 00062 echo "<input type='radio' name='expiry_none' value='date'>{$strUntilSpecificDateAndTime}<br /> "; 00063 00064 // Print Listboxes for a date selection 00065 echo "<select name='day' onclick=\"window.document.publishform.expiry_none[1].checked = true;\">"; 00066 00067 for ($t_day = 1; $t_day <= 31; $t_day++) 00068 { 00069 echo "<option value=\"$t_day\" "; 00070 if ($t_day == date("j")) 00071 { 00072 echo "selected='selected'"; 00073 } 00074 echo ">$t_day</option>\n"; 00075 } 00076 00077 echo "</select><select name='month' onclick=\"window.document.publishform.expiry_none[1].checked = true;\">"; 00078 00079 for ($t_month = 1; $t_month <= 12; $t_month++) 00080 { 00081 echo "<option value=\"$t_month\""; 00082 if ($t_month == date("n")) 00083 { 00084 echo " selected='selected'"; 00085 } 00086 echo ">". date ("F", mktime(0,0,0,$t_month,1,2000)) ."</option>\n"; 00087 } 00088 00089 echo "</select><select name='year' onclick=\"window.document.publishform.expiry_none[1].checked = true;\">"; 00090 00091 for ($t_year=(date("Y")-1); $t_year <= (date("Y")+5); $t_year++) 00092 { 00093 echo "<option value=\"$t_year\" "; 00094 if ($t_year == date("Y")) 00095 { 00096 echo "selected='selected'"; 00097 } 00098 echo ">$t_year\n"; 00099 } 00100 00101 echo "</select>"; 00102 echo "</td></tr>"; 00103 echo "</table>"; 00104 echo "<p align='center'><input type='submit' value='{$strPublish}' /></p>"; 00105 echo "</form>"; 00106 00107 include (APPLICATION_INCPATH . 'htmlfooter.inc.php'); 00108 } 00109 else 00110 { 00111 // publish file 00112 include (APPLICATION_INCPATH . 'htmlheader.inc.php'); 00113 echo "<h2>{$strFTPPublish}</h2>"; 00114 // set up basic connection 00115 $conn_id = create_ftp_connection(); 00116 00117 $destination_filepath = $CONFIG['ftp_path'] . $temp_directory . '/' . $destination_file; 00118 00119 // make the temporary directory 00120 $mk = @ftp_mkdir($conn_id, $CONFIG['ftp_path'] . $temp_directory); 00121 if (!mk) trigger_error(sprintf($strFTPFailedCreatingDirectoryX , $temp_directory), E_USER_WARNING); 00122 00123 // check the source file exists 00124 if (!file_exists($source_file)) trigger_error(sprintf($strSourceFailCannotBeFoundX, $source_file), E_USER_WARNING); 00125 00126 // set passive mode 00127 if (!ftp_pasv($conn_id, TRUE)) trigger_error($strProblemSettingPassiveFTPMode, E_USER_WARNING); 00128 00129 // upload the file 00130 $upload = ftp_put($conn_id, "$destination_filepath", "$source_file", FTP_BINARY); 00131 00132 // check upload status 00133 if (!$upload) 00134 { 00135 echo "{$strUploadFailed}<br />"; 00136 } 00137 else 00138 { 00139 echo sprintf($strUpdatedXToYAsZ, $source_file, $CONFIG['ftp_hostname'], $destination_filepath)."<br />"; 00140 echo "<code>{$ftp_url}</code>"; 00141 00142 journal(CFG_LOGGING_NORMAL, 'FTP File Published', "File $destination_file_file was published to {$CONFIG['ftp_hostname']}", CFG_JOURNAL_OTHER, 0); 00143 00144 switch ($expiry_none) 00145 { 00146 case 'none': $expirydate = 0; break; 00147 case 'time': 00148 if ($expiry_days < 1 && $expiry_hours < 1 && $expiry_minutes < 1) $expirydate = 0; 00149 else 00150 { 00151 // uses calculate_time_of_next_action() because the function suits our purpose 00152 $expirydate = calculate_time_of_next_action($expiry_days, $expiry_hours, $expiry_minutes); 00153 } 00154 break; 00155 00156 case 'date': 00157 // $now + ($days * 86400) + ($hours * 3600) + ($minutes * 60); 00158 $unixdate = mktime(9,0,0,$month,$day,$year); 00159 $expirydate = $unixdate; 00160 if ($expirydate < 0) $expirydate = 0; 00161 break; 00162 00163 default: 00164 $expirydate = 0; 00165 break; 00166 } 00167 00168 // store file details in database 00169 $sql = "INSERT INTO `{$dbFiles}` ('category', filename, size, userid, shortdescription, longdescription, path, date, expiry, fileversion) "; 00170 $sql .= "VALUES ('ftp', '$destination_file', '$filesize', '".$sit[2]."', '$shortdescription', '$longdescription', '".$temp_directory.'/'."', '$now', FROM_UNIXTIME($expirydate) ,'$fileversion')"; 00171 mysql_query($sql); 00172 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 00173 } 00174 // close the FTP stream 00175 ftp_close($conn_id); 00176 include (APPLICATION_INCPATH . 'htmlfooter.inc.php'); 00177 } 00178 ?>
For more help developing with SiT! see http://sitracker.org/wiki/DevelopmentHowTo