Openwrt/etc/rc.button/reset Saving Configuration security scripts

Source: Internet
Author: User

Write a/etc/rc.button/reset script to deal with the feedback of security, status and configuration change.

Remote operations Press the reset button and store the configuration, script file:

#!/bin/sh path= "$PATH:/usr/local/sbin/:/usr/local/bin/" # Only run on button release. [["${action}" = "released"]] | | Exit 0 # Logger "$BUTTON pressed for $SEEN seconds" # env >>/tmp/reset-button if [["$SEEN"-le 1]]; Then message= "RESET button:retain current overlay, restore safebackup, and reboot" echo "$MESSAGE" >/dev/cons OLE logger "$MESSAGE" safebackup restore && reboot & Elif [["$SEEN"-ge 3-a "$SEEN"-le 5]]; Then message= "RESET button:wipe overlay, restore safebackup, and reboot" echo "$MESSAGE" >/dev/console lo Gger "$MESSAGE" Safebackup fullrestore elif [["$SEEN"-ge 9-a "$SEEN"-le 12]]; Then message= "Reset Button:wipe overlay (factory reset) and reboot" echo "$MESSAGE" >/dev/console Logger "$MESSAGE" jffs2reset-y && reboot & Else message= "RESET button:error. Pressed for $SEEN seconds.
    Do nothing. " echo "$MESSAGE" >/dev/console logger "$MESSAGE" fi

Another secure backup script:

#!/bin/sh # This script is written to run under the BusyBox ash shell.

# # Save and restore a safe configuration backup state for the host.
Export bakdir= "/safebackups" Export savefile= "/safebackups/safebackup-$ (hostname)-$ (date +%y%m%d%h%m%s)-$$.tar.gz" Export restorefile=$ (find/safebackups/-maxdepth 1-mindepth 1-type f-name ' safebackup-*.tar.gz ' | head-n 1 2>/dev /null) Export sysupgrade_conf_tar= "/tmp/sysupgrade.tgz" pidfile= "/tmp/$ (basename $0.pid)" myname=$ (basename $) #--EC
    Hoerr () {# Print errors to stderr.
echo "$@" 1>&2;
    } f_validate_restore () {# Validate before a restoration.
    # If There is no restore file, there are nothing we can do. if! [-F "$RESTOREFILE"];
        Then Echoerr "Echoerr" error:no the restore file could be found. "
    Echoerr "" Exit 1 Fi} f_save () {# Save a backup. echo "# Make sure the Bakdir exists.
    If not, create it. if! [-D "$BAKDIR"]; Then echo "$BAKDIR does not exist, so creating it. " mkdir "$BAKDIR" chmod o-rwx "$BAKDIR" Fi # Remove old backups prior to the new save.
    We only have keep one backup at a time.
    Echo-n "Removing old backups ..." rm-rf/safebackups/safebackup-*.tar.gz echo "Done" # Save the new backup. Sysupgrade-b "$SAVEFILE" echo "Sysupgrade backup saved to $SAVEFILE" echo ""} F_restore () {# restore T
    He backup. F_validate_restore echo "echo" Restoring sysupgrade backup from File: $RESTOREFILE "Sysupgrade-r" $RESTOREF
    ILE "echo" Done "echo" "} F_fullrestore () {# Wipe the overlay flash, and restore from backup. # This is a complicated and dangerous process.
    This was mostly based on the Sysupgrade script does. # fixme:ext-root Problems?
    Reference notes. F_validate_restore echo "echo" Wiping overlay and restoring Sysupgrade backup from File: $RESTOREFILE "Echoe RR "Warning:network access would be lOST during this process and the host would be rebooted. " echo "" # Copy the safe backup to/tmp cp "$RESTOREFILE" "$SYSUPGRADE _conf_tar" | |
    {ECHOERR "error:unable cp restore File To/tmp"; exit 1;}
    # # Source required functions. source/lib/functions.sh for each in/lib/upgrade/*.sh; Do source "$EACH";
    Done # Run_hooks'll disable the process watchdog and does other important tasks.
    Run_hooks "" $sysupgrade _pre_upgrade # No idea about what the this does, and is not being needed at all.
    Ubus Call System Upgrade # # Kill off all non-critical processes. kill_remaining term; Sleep 3; Kill_remaining KILL # # important part.
    This runs the Ramfs, pivots root, erases the overlay, and restores the config backup. 
    # Warning:remember If we do Run_ramfs, we lose access to the old filesystem, possibly functions, envrionment, etc. Run_ramfs ' mtd-e rootfs_data jffs2write $SYSUPGRADE _conf_tar rootfs_data ; Reboot-f ' # # Nothing from here on our matters.
    We ' ve already rebooted. # Sysupgrade_conf_tar is restored on reboot by/lib/preinit/80_mount_root and erased By/etc/init.d/done # echo "
    Done "echo" "} #--Case" $ "in Save) F_save;;
    restore) F_restore;;
    Fullrestore) F_fullrestore;; *) echo "echo" Usage: $MYNAME Save|restore|fullrestore "echo" Warning:fullrestore implies a O
Verlay wipe and reboot "echo" "Exit 1;; Esac

Before resetting the reset, a secure backup is performed, without a backup, and no reset is performed:
Button pressed for 0-1 seconds, save configuration and reboot, overlay no erase
Button pressed for 3-5 seconds, overly erased, storage configuration, reboot
Button pressed for 9-12 seconds, factory reset, overlay with erase, no Configuration Storage

Warning: This script is not a openwrt generic script, only for reference, you need to make corresponding changes based on the unused router

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.