#!/usr/local/bin/php "") { $file_size = intval($regs[2]); } ob_flush(); return $length; } function read_body2($ch, $string) { global $fout, $file_size, $downloaded, $sendto, $static_status, $static_output, $lastseen; global $pkg_interface; $length = strlen($string); $downloaded += intval($length); if($file_size > 0) { $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); $downloadProgress = 100 - $downloadProgress; } else $downloadProgress = 0; if($lastseen <> $downloadProgress and $downloadProgress < 101) { if($sendto == "status") { if($pkg_interface == "console") { if(substr($downloadProgress,2,1) == "0" || count($downloadProgress) < 2) { $tostatus = $static_status . $downloadProgress . "%"; update_status($tostatus); } } else { $tostatus = $static_status . $downloadProgress . "%"; update_status($tostatus); } } else { if($pkg_interface == "console") { if(substr($downloadProgress,2,1) == "0" || count($downloadProgress) < 2) { $tooutput = $static_output . $downloadProgress . "%"; update_output_window($tooutput); } } else { $tooutput = $static_output . $downloadProgress . "%"; update_output_window($tooutput); } } update_progress_bar($downloadProgress); $lastseen = $downloadProgress; } if($fout) fwrite($fout, $string); ob_flush(); return $length; } /* * update_progress_bar($percent): updates the javascript driven progress bar. */ function update_progress_bar2($percent, $file_size, $downloaded) { if($percent > 100) $percent = 1; if ($GLOBALS['tmp']['snort']['downloadupdate']['console'] != 'on') { snortSql_updateRuleSetList('percent2', $percent, $file_size, $downloaded, $GLOBALS['tmp']['snort']['downloadupdate']['workingfile']); // write out percent to db }else{ echo "\n" . 'percent: ' . $percent . ' filesize: ' . $file_size . ' downloaded: ' . $downloaded; } } function read_body_firmware($ch, $string) { global $fout, $file_size, $downloaded, $counter; $length = strlen($string); $downloaded += intval($length); $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); $downloadProgress = 100 - $downloadProgress; $counter++; if($counter > 150) { update_progress_bar2($downloadProgress, $file_size, $downloaded); flush(); $counter = 0; } fwrite($fout, $string); return $length; } function download_file_with_progress_bar2($url_file, $destination, $workingfile, $readbody = 'read_body2') { global $ch, $fout, $file_size, $downloaded; $file_size = 1; $downloaded = 1; $destination_file = $destination . '/' . $workingfile; /* open destination file */ $fout = fopen($destination_file, "wb"); /* * Originally by Author: Keyvan Minoukadeh * Modified by Scott Ullrich to return Content-Length size */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url_file); curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header2'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_WRITEFUNCTION, $readbody); curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '5'); curl_setopt($ch, CURLOPT_TIMEOUT, 0); curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if($fout) fclose($fout); curl_close($ch); return ($http_code == 200) ? true : $http_code; } // ----------------------------------------------------- Begin Code -------------------------------------------- /* if (!file_exists("{$tmpfname}/{$snort_filename}")) { $GLOBALS['tmp']['snort']['downloadupdate']['workingfile'] = $snort_filename; snortSql_updateRuleSetList('working', 'on', '', '', $snort_filename); // finish downloading //download_file_with_progress_bar2("http://www.snort.org/pub-bin/oinkmaster.cgi/{$oinkid}/{$snort_filename}", $tmpfname . "/{$snort_filename}", "read_body_firmware"); download_file_with_progress_bar2("http://theseusnetworking.com/pub-bin/oinkmaster.cgi/{$oinkid}/{$snort_filename}", $tmpfname, $snort_filename, "read_body_firmware"); snortSql_updateRuleSetList('percent', '100', '', '', $snort_filename); // finsh percent snortSql_updateRuleSetList('working', 'off', '', '', $snort_filename); // finish downloading } */ // rm all tmp filea exec("/bin/rm -r $tmpfname/\*"); // Set all downloads to be true so NO download by default $snort_md5_check_ok = true; $emerg_md5_check_ok = true; $pfsense_md5_check_ok = true; /* define checks */ $snortdownload = $generalSettings['snortdownload']; //$oinkid = $generalSettings['oinkmastercode']; $oinkid = '55a1b7a1291b55ac3c157124133744cfc386bb83'; // remove when finished testing $emergingthreats = $generalSettings['emergingthreatsdownload']; $emergingthreatscode = $generalSettings['emergingthreatscode']; if ($oinkid == '' && $snortdownload == 'on') { update_output_window2('ms1', 'You must obtain an oinkid from snort.org and set its value in the Snort settings tab.'); exec("/usr/bin/logger -p daemon.info -i -t SnortStartup 'You must obtain an oinkid from snort.org and set its value in the Snort settings tab.'"); exit; } if ($snortdownload != "on" && $emergingthreats != "on") { update_output_window2('ms1', 'SnortStartup: No rules have been selected to download.'); exec("/usr/bin/logger -p daemon.info -i -t SnortStartup 'No rules have been selected to download.'"); exit; } /* * Check MD5s and MARK * */ update_output_window2('ms1', 'Starting MD5 checks.....'); // download snort.org md5 and compare snort_file_get_contents($tmpfname, $snort_filename_md5, 'http://www.snort.org/pub-bin/oinkmaster.cgi/' . $oinkid); // if snort.org md5 do not match if(!snortCmpareMD5('string', $tmpfname, $snortdir, $snort_filename_md5)) { $snort_md5_check_ok = false; } // download emergingthreats.net md5 and compare snort_file_get_contents($tmpfname, $emergingthreats_filename_md5, 'http://rules.emergingthreats.net/open/snort-2.9.0'); // if emergingthreats.net md5 do not match if(!snortCmpareMD5('string', $tmpfname, $snortdir, $emergingthreats_filename_md5)) { $emerg_md5_check_ok = false; } // download pfsense.org md5 and compare snort_file_get_contents($tmpfname, $pfsense_rules_filename_md5, 'http://www.pfsense.com/packages/config/snort/pfsense_rules'); // if pfsense.org md5 do not match if(!snortCmpareMD5('string', $tmpfname, $snortdir, $pfsense_rules_filename_md5)) { $pfsense_md5_check_ok = false; } // ----------------------------------------------------- End Code -------------------------------------------- } // -------------------- END Main function ------------ $argv[1] = 'console'; sendUpdateSnortLogDownload($argv[1]); // start main function ?>