@@ -17,15 +17,12 @@ return view.extend({
1717 L . resolveDefault ( fs . exec ( "/usr/sbin/fleth" , [ "get_area" ] ) , { stdout : "" } ) ,
1818 L . resolveDefault ( fs . exec ( "/usr/sbin/fleth" , [ "mape_status" ] ) , { stdout : "" } ) ,
1919 L . resolveDefault ( fs . exec ( "/usr/sbin/fleth" , [ "get_prefix_length" ] ) , { stdout : "" } ) ,
20- L . resolveDefault ( fs . stat ( "/lib/netifd/proto/map.sh.flethbak" ) , null ) ,
21- L . resolveDefault ( fs . exec ( "sh" , [ "-c" , "cmp -s /lib/netifd/proto/map.sh /lib/netifd/proto/map.sh.flethbak && echo 'same' || echo 'different'" ] ) , { stdout : "" } ) ,
20+ L . resolveDefault ( fs . exec ( "/usr/sbin/fleth" , [ "mapsh_status" ] ) , { stdout : "" } ) ,
2221 ] ) . then ( function ( results ) {
2322 const area = ( results [ 0 ] . stdout || "" ) . trim ( ) ;
2423 const mape_status = ( results [ 1 ] . stdout || "" ) . split ( "\n" ) ;
2524 const prefix_length = ( results [ 2 ] . stdout || "" ) . trim ( ) ;
26- const mapBackupExists = results [ 3 ] !== null ;
27- const filesAreSame = ( results [ 4 ] . stdout || "" ) . trim ( ) === 'same' ;
28-
25+ const mapsh_status = ( results [ 3 ] . stdout || "" ) . trim ( ) ;
2926 let areaValue = area || "UNKNOWN" ;
3027 const mapeIsUnknown = mape_status . length <= 1 || mape_status [ 0 ] === "UNKNOWN" ;
3128
@@ -47,8 +44,7 @@ return view.extend({
4744 mape_status : mape_status ,
4845 prefix_length : prefix_length || "UNKNOWN" ,
4946 isPending : true ,
50- mapBackupExists : mapBackupExists ,
51- mapIsPatched : mapBackupExists && ! filesAreSame ,
47+ mapIsPatched : mapsh_status === "patched" ,
5248 } ;
5349 }
5450 // No pending status, check DS-Lite provider
@@ -61,8 +57,7 @@ return view.extend({
6157 mape_status : mape_status ,
6258 prefix_length : prefix_length || "UNKNOWN" ,
6359 isPending : false ,
64- mapBackupExists : mapBackupExists ,
65- mapIsPatched : mapBackupExists && ! filesAreSame ,
60+ mapIsPatched : mapsh_status === "patched" ,
6661 } ;
6762 } ) ;
6863 } ) ;
@@ -74,8 +69,7 @@ return view.extend({
7469 mape_status : mape_status ,
7570 prefix_length : prefix_length || "UNKNOWN" ,
7671 isPending : false ,
77- mapBackupExists : mapBackupExists ,
78- mapIsPatched : mapBackupExists && ! filesAreSame ,
72+ mapIsPatched : mapsh_status === "patched" ,
7973 } ;
8074 }
8175 } ) ;
@@ -378,32 +372,36 @@ return view.extend({
378372 return this . setupIPv6Config ( mapObj , 'pd' ) ;
379373 } ,
380374
381- replaceMapSh : function ( mapObj ) {
375+ manageMapSh : function ( mapObj , action ) {
376+ const actionConfig = {
377+ replace : { verb : _ ( 'Replacing' ) , gerund : _ ( 'Downloading...' ) } ,
378+ restore : { verb : _ ( 'Restoring' ) , gerund : _ ( 'Restoring...' ) }
379+ } ;
380+
381+ const config = actionConfig [ action ] ;
382+ const actionLower = action . toLowerCase ( ) ;
383+
382384 return new Promise ( function ( resolve , reject ) {
383- // First save current configuration
384385 mapObj . save ( )
385386 . then ( function ( ) {
386- // Show loading message
387- ui . showModal ( _ ( 'Replacing' ) , [
388- E ( 'p' , { 'class' : 'spinning' } , _ ( 'Downloading...' ) )
387+ ui . showModal ( config . verb , [
388+ E ( 'p' , { 'class' : 'spinning' } , config . gerund )
389389 ] ) ;
390390
391- // Execute the replace operation via fleth script
392- return fs . exec ( '/usr/sbin/fleth' , [ 'replace_mapsh' ] ) ;
391+ return fs . exec ( '/usr/sbin/fleth' , [ action + '_mapsh' ] ) ;
393392 } )
394393 . then ( function ( result ) {
395394 ui . hideModal ( ) ;
396395
397396 if ( result . code === 0 && result . stdout . trim ( ) === 'SUCCESS' ) {
398- ui . addNotification ( null , E ( 'p' , _ ( 'Replaced successfully! Please restart the network interface manually.' ) ) , 'info' ) ;
397+ ui . addNotification ( null , E ( 'p' , _ ( 'Operation completed successfully! Please restart the network interface manually.' ) ) , 'info' ) ;
399398
400- // Reload page to update backup status
401399 setTimeout ( function ( ) {
402400 window . location . reload ( ) ;
403- } , 2000 ) ;
401+ } , 5000 ) ;
404402 } else {
405403 ui . addNotification ( null , E ( 'div' , [
406- E ( 'p' , _ ( 'Failed to replace :' ) ) ,
404+ E ( 'p' , _ ( 'Failed to ' + actionLower + ' :') ) ,
407405 E ( 'pre' , result . stdout || result . stderr || 'Unknown error' )
408406 ] ) , 'error' ) ;
409407 }
@@ -413,54 +411,19 @@ return view.extend({
413411 . catch ( function ( error ) {
414412 ui . hideModal ( ) ;
415413 ui . addNotification ( null , E ( 'div' , [
416- E ( 'p' , _ ( 'Error replacing :' ) ) ,
414+ E ( 'p' , _ ( 'Error ' + config . gerund . toLowerCase ( ) + ' :') ) ,
417415 E ( 'pre' , error . message || error )
418416 ] ) , 'error' ) ;
419417 reject ( error ) ;
420418 } ) ;
421419 } ) ;
422420 } ,
423421
424- restoreMapSh : function ( mapObj ) {
425- return new Promise ( function ( resolve , reject ) {
426- // First save current configuration
427- mapObj . save ( )
428- . then ( function ( ) {
429- // Show loading message
430- ui . showModal ( _ ( 'Restoring' ) , [
431- E ( 'p' , { 'class' : 'spinning' } , _ ( 'Restoring...' ) )
432- ] ) ;
433-
434- // Execute the restore operation via fleth script
435- return fs . exec ( '/usr/sbin/fleth' , [ 'restore_mapsh' ] ) ;
436- } )
437- . then ( function ( result ) {
438- ui . hideModal ( ) ;
439-
440- if ( result . code === 0 && result . stdout . trim ( ) === 'SUCCESS' ) {
441- ui . addNotification ( null , E ( 'p' , _ ( 'Restored successfully! Please restart the network interface manually.' ) ) , 'info' ) ;
442-
443- // Reload page to update backup status
444- setTimeout ( function ( ) {
445- window . location . reload ( ) ;
446- } , 2000 ) ;
447- } else {
448- ui . addNotification ( null , E ( 'div' , [
449- E ( 'p' , _ ( 'Failed to restore:' ) ) ,
450- E ( 'pre' , result . stdout || result . stderr || 'Unknown error' )
451- ] ) , 'error' ) ;
452- }
422+ replaceMapSh : function ( mapObj ) {
423+ return this . manageMapSh ( mapObj , 'replace' ) ;
424+ } ,
453425
454- resolve ( ) ;
455- } )
456- . catch ( function ( error ) {
457- ui . hideModal ( ) ;
458- ui . addNotification ( null , E ( 'div' , [
459- E ( 'p' , _ ( 'Error restoring:' ) ) ,
460- E ( 'pre' , error . message || error )
461- ] ) , 'error' ) ;
462- reject ( error ) ;
463- } ) ;
464- } ) ;
426+ restoreMapSh : function ( mapObj ) {
427+ return this . manageMapSh ( mapObj , 'restore' ) ;
465428 } ,
466429} ) ;
0 commit comments