Highdude

Untitled

Sep 23rd, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. class admin_upgrade extends Model {
  2. public function __construct()
  3. {
  4.  
  5. }
  6. public function run()
  7. {
  8. $doUpgradeFlag=false;
  9. $error="";
  10. if( isset($_POST['Upgrade']) ){
  11. if( isset($_FILES['AP_FIRMWARE']) ){
  12. $f = $_FILES['AP_FIRMWARE'];
  13. if( $f['error'] ){
  14. $msg = codeToMessage($f['error']);
  15. $error = $msg;
  16. }
  17. if( preg_match("|\.lxl$|",$f['name']) == false ){
  18. $error = "Extension error";
  19. }
  20. $ret = move_uploaded_file( $f['tmp_name'], TEMP_FILE_UPLOAD );
  21. if( $ret ){
  22. file_put_contents(FIRMWARE_NAME_FILE,TEMP_FILE_UPLOAD);
  23. //$output = exec($this->verifyCmd);
  24.  
  25.  
  26. //verify model number
  27. if($error==""){
  28. $fw_model=exec('echo $(dd if='. TEMP_FILE_UPLOAD .' bs=2 skip=24 count=6 2>/dev/null)');
  29. $my_model=Uci::get(sprintf(constants::LUXUL_HARDWARE_MODEL,0));
  30. if($fw_model!=$my_model){
  31. $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.';
  32. }
  33. }
  34. //validate checksum
  35. if($error==""){
  36. $md5_img=exec('echo $(dd if='. TEMP_FILE_UPLOAD. ' bs=16 count=2 2>/dev/null)');
  37. $md5_gen=preg_split("/\s+/",exec('echo $(dd if='. TEMP_FILE_UPLOAD .' bs=16 skip=4 2>/dev/null | md5sum)'));
  38. if($md5_gen[0]!=$md5_img){
  39. $error = "Firmware update failed: The firmware file is corrupted. Please download the firmware and try again.";
  40. }
  41. }
  42. if( $error!="" ){
  43. $this->_unlinkTmpFiles();
  44. }else{
  45. $doUpgradeFlag=true;
  46. }
  47. }else{
  48. $error = "Could not process this file";
  49. }
  50. }
  51.  
  52. }
  53. include_once $doUpgradeFlag==true ? CFG_VIEW_DIRECTORY . "admin/sub/upgrade/progressbar.html" : CFG_VIEW_DIRECTORY . "admin/sub/upgrade/upgrade.html";
  54. }
  55.  
  56. public function run_api(){
  57. //clip off the header
  58. exec('dd if='. TEMP_FILE_UPLOAD .' bs=16 skip=4 of='. TEMP_FILE_UPLOAD .' conv=notrunc 2>/dev/null', $o, $ret);
  59. //do the upgrade
  60. exec('/sbin/sysupgrade '. TEMP_FILE_UPLOAD .' >/dev/null &');
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment