Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class admin_upgrade extends Model {
- public function __construct()
- {
- }
- public function run()
- {
- $doUpgradeFlag=false;
- $error="";
- if( isset($_POST['Upgrade']) ){
- if( isset($_FILES['AP_FIRMWARE']) ){
- $f = $_FILES['AP_FIRMWARE'];
- if( $f['error'] ){
- $msg = codeToMessage($f['error']);
- $error = $msg;
- }
- if( preg_match("|\.lxl$|",$f['name']) == false ){
- $error = "Extension error";
- }
- $ret = move_uploaded_file( $f['tmp_name'], TEMP_FILE_UPLOAD );
- if( $ret ){
- file_put_contents(FIRMWARE_NAME_FILE,TEMP_FILE_UPLOAD);
- //$output = exec($this->verifyCmd);
- //verify model number
- if($error==""){
- $fw_model=exec('echo $(dd if='. TEMP_FILE_UPLOAD .' bs=2 skip=24 count=6 2>/dev/null)');
- $my_model=Uci::get(sprintf(constants::LUXUL_HARDWARE_MODEL,0));
- if($fw_model!=$my_model){
- $error = 'Firmware update failed: The firmware file is for a different AP model. Please download the firmware for the '. Uci::get(sprintf(constants::LUXUL_HARDWARE_MODEL,0)) . ' and try again.';
- }
- }
- //validate checksum
- if($error==""){
- $md5_img=exec('echo $(dd if='. TEMP_FILE_UPLOAD. ' bs=16 count=2 2>/dev/null)');
- $md5_gen=preg_split("/\s+/",exec('echo $(dd if='. TEMP_FILE_UPLOAD .' bs=16 skip=4 2>/dev/null | md5sum)'));
- if($md5_gen[0]!=$md5_img){
- $error = "Firmware update failed: The firmware file is corrupted. Please download the firmware and try again.";
- }
- }
- if( $error!="" ){
- $this->_unlinkTmpFiles();
- }else{
- $doUpgradeFlag=true;
- }
- }else{
- $error = "Could not process this file";
- }
- }
- }
- include_once $doUpgradeFlag==true ? CFG_VIEW_DIRECTORY . "admin/sub/upgrade/progressbar.html" : CFG_VIEW_DIRECTORY . "admin/sub/upgrade/upgrade.html";
- }
- public function run_api(){
- //clip off the header
- exec('dd if='. TEMP_FILE_UPLOAD .' bs=16 skip=4 of='. TEMP_FILE_UPLOAD .' conv=notrunc 2>/dev/null', $o, $ret);
- //do the upgrade
- exec('/sbin/sysupgrade '. TEMP_FILE_UPLOAD .' >/dev/null &');
- }
Advertisement
Add Comment
Please, Sign In to add comment