#!/usr/local/bin/php -f "; $url = chop(fgets($fp)); if(!$url) die; $status = does_url_exist($url); if($status) { echo "\nFetching file...\n"; exec("fetch -w15 -a -v -o /tmp/firmware.tgz \"$url\""); $status = does_url_exist("$url.md5"); if($status) { echo "\nFetching MD5...\n"; exec("fetch -w15 -a -v -o /tmp/firmware.tgz.md5 \"$url.md5\""); } else { echo "\n\nWARNING.\n"; echo "\nCould not locate a MD5 file. We cannot verify the download once its done.\n\n"; sleep(15); } if(file_exists("/tmp/firmware.tgz.md5")) { $source_md5 = trim(`cat /tmp/firmware.tgz.md5 | awk '{ print \$4 }'`,"\r"); $file_md5 = trim(`md5 /tmp/firmware.tgz | awk '{ print \$4 }'`,"\r"); if($source_md5 <> $file_md5) { echo "\nURL MD5: $source_md5"; echo "\nDownloaded file MD5: $file_md5"; echo "\n\nMD5 checksum does not match. Cancelling upgrade.\n\n"; die -1; } echo "\nMD5 checksum matches.\n"; } if(file_exists("/tmp/firmware.tgz")) do_upgrade("/tmp/firmware.tgz"); } else { echo "\nCould not download update.\n\n"; die -1; } case "2": echo "\nEnter the complete path to the .tgz update file: "; $path = chop(fgets($fp)); if(!$path) die; if(file_exists($path)) { do_upgrade($path); } else { echo "\nCould not find file.\n\n"; die -1; } } function do_upgrade($path) { echo "\nOne moment please... Invoking firmware upgrade...\n"; exec("/etc/rc.firmware pfSenseupgrade $path"); } ?>