To enable OpenWrt to automatically restore a previous backup during the first reboot after flashing

To enable OpenWrt to automatically restore a previous backup during the first reboot after flashing, you can integrate the backup file and the restore script into the firmware during the build process. Here’s how to do it:

1. Create the files Directory

In the root directory of your OpenWrt source tree, create a directory named files. Any files placed in this directory will be directly copied into the final firmware with the same directory structure.

mkdir -p ~/openwrt/files

2. Add the Backup File and Script

2.1 Place the Backup File

Copy the backup file you’ve prepared (e.g., backup.tar.gz) into the files/etc/backup/ directory:

mkdir -p ~/openwrt/files/etc/backup
cp /path/to/your/backup.tar.gz ~/openwrt/files/etc/backup/

Replace /path/to/your/backup.tar.gz with the actual path to your backup file.

2.2 Add the Auto-Restore Script

Create an auto-restore script and place it in the files/etc/init.d/ directory, for example, named restore_backup:

mkdir -p ~/openwrt/files/etc/init.d
nano ~/openwrt/files/etc/init.d/restore_backup

In the editor, add the following script content:

#!/bin/sh

# Define the backup file path
BACKUP_FILE="/etc/backup/backup.tar.gz"

# Check if the backup file exists
if [ -f "$BACKUP_FILE" ]; then
    # Restore the backup
    sysupgrade -r $BACKUP_FILE
    echo "Backup successfully restored"

    # Delete the backup file and the script itself
    rm -f $BACKUP_FILE
    rm -f /etc/init.d/restore_backup
    echo "Backup file and restore script deleted"
else
    echo "Backup file not found"
fi

Save and exit the editor.

3. Set Script Permissions and Startup

To ensure the restore script runs on system startup, create a 99_restore_backup script in the files/etc/uci-defaults/ directory:

mkdir -p ~/openwrt/files/etc/uci-defaults
nano ~/openwrt/files/etc/uci-defaults/99_restore_backup

In this file, add the following:

#!/bin/sh

# Ensure the restore script is executable
chmod +x /etc/init.d/restore_backup

# Enable the restore script to run on startup
/etc/init.d/restore_backup enable

# Delete this initialization script
rm -f /etc/uci-defaults/99_restore_backup

Save and exit the editor.

4. Compile the OpenWrt Firmware

After completing the above steps, compile the OpenWrt firmware. This will generate a firmware image that includes your backup file and the auto-restore script.

5. Flash and Test the Firmware

Flash the generated firmware to your device and verify that the device automatically restores the backup upon the first boot and deletes the script and backup file afterward.

These steps will help you integrate an automatic backup restore feature into your OpenWrt firmware.

Only to one directory on an internal server

the Nginx configuration and explanation for allowing external access only to the /report directory on an internal server, while blocking access to other directories:

Configuration Example

server {
    listen 80;
    server_name your-domain.com;

    # Allow access only to the /report directory
    location /report {
        proxy_pass http://192.168.1.1;  # Replace with the actual internal server address
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Optional: Handle path rewriting if needed
        rewrite ^/report(/.*)?$ $1 break;
    }

    # Deny access to other paths
    location / {
        deny all;
    }

    # Handle other path requests if necessary
    # You can add additional location blocks for specific path requests
}

Explanation

  1. Allowing Access to /report:
  • The location /report block forwards requests to the internal server http://192.168.1.1.
  • The rewrite directive (optional) handles path rewriting to ensure that the /report prefix is not added to the internal server’s request path.
  1. Denying Access to Other Paths:
  • The location / block with the deny all; directive blocks access to all other paths. This means that external users will receive a 403 Forbidden error when trying to access other paths.

Considerations

  • Access Control:
    If your Nginx server is exposed to the public internet and needs to control access to multiple directories or services, make sure to implement appropriate security measures, such as IP whitelisting and authentication mechanisms.
  • Logging:
    You can configure Nginx’s access and error logs to monitor and troubleshoot access issues. Log configuration is typically done within the server block.
  • SSL/TLS:
    If your site is exposed on the public internet, it’s recommended to use SSL/TLS to encrypt traffic and protect data transmission.
  • Nginx Configuration Testing:
    Before applying any changes, run nginx -t to test the syntax of the configuration file. Make sure there are no errors before reloading the Nginx configuration.

With this configuration, external users will only be able to access the /report directory, while access to other paths will be blocked.

About frontend and backend web development

both frontend and backend web development utilize a variety of open platforms and technologies. These platforms and tools provide a range of functionalities for building, testing, deploying, and maintaining web applications. Here are some commonly used open platforms and technology stacks in frontend and backend development:

Frontend Development

  1. Frameworks and Libraries
  • React: A JavaScript library developed by Facebook for building user interfaces, particularly suitable for single-page applications (SPA) and complex user interfaces.
  • Angular: An open-source frontend framework maintained by Google for building dynamic web applications.
  • Vue.js: A progressive JavaScript framework that is easy to learn and suitable for building single-page applications and complex user interfaces.
  1. Build Tools and Package Managers
  • Webpack: A module bundler for packaging JavaScript and other assets, supporting code splitting and hot module replacement.
  • Parcel: A zero-configuration web application bundler designed to provide a fast build and development experience.
  • npm: A package manager for Node.js used to manage JavaScript libraries and tools.
  • Yarn: Another popular package manager developed by Facebook, known for its fast installation speed and reliable dependency management.
  1. Styling Tools
  • Sass: A CSS preprocessor that provides variables, nesting, and mixins to enhance CSS writing.
  • Less: Another CSS preprocessor that offers similar functionality to improve CSS authoring efficiency.
  • Tailwind CSS: A utility-first CSS framework that allows rapid construction of custom designs through predefined classes.
  1. UI Component Libraries
  • Bootstrap: A popular frontend framework providing responsive layout and a variety of pre-built UI components.
  • Material-UI: A React component library based on Google’s Material Design guidelines.
  • Ant Design: A React UI library based on Ant Design, suitable for enterprise-level application development.

Backend Development

  1. Server Frameworks and Platforms
  • Node.js: An event-driven JavaScript runtime that enables running JavaScript code on the server side.
  • Express.js: A lightweight Node.js framework for building web applications and APIs.
  • Django: A high-level Python web framework that encourages rapid development and clean, pragmatic design.
  • Flask: A Python microframework that is simple and flexible, ideal for building lightweight web applications.
  • Ruby on Rails: A comprehensive Ruby framework that emphasizes convention over configuration for rapidly building database-driven web applications.
  1. API Development
  • GraphQL: A query language that allows clients to specify the data they need, reducing the amount of data transferred.
  • RESTful APIs: Based on HTTP methods and standards, widely used for building web services and APIs.
  1. Databases
  • MongoDB: A NoSQL database based on document storage, suitable for handling large-scale, unstructured data.
  • PostgreSQL: A powerful open-source relational database that supports complex queries and transaction processing.
  • MySQL: A widely used open-source relational database, suitable for various web applications.
  1. Cloud Platforms and Deployment
  • AWS (Amazon Web Services): Provides a broad range of cloud computing services, including compute, storage, databases, and machine learning.
  • Google Cloud Platform (GCP): Google’s cloud service platform, covering computing, storage, and data analytics.
  • Microsoft Azure: Microsoft’s cloud platform offering services for computing, storage, AI, and data analytics.
  • Heroku: A platform-as-a-service (PaaS) that simplifies application deployment and management.
  • Netlify: A frontend-focused deployment platform providing static site hosting and automated build features.
  1. Containerization and Orchestration
  • Docker: An open-source platform for automating application deployment, scaling, and management through containerization, improving development and operations efficiency.
  • Kubernetes: An open-source container orchestration platform for automating deployment, scaling, and management of containerized applications.

These open platforms and technology stacks are widely used in modern web development, helping developers enhance productivity, improve application performance, and streamline development processes. Choosing the right tools and technologies based on project needs and team skills can significantly impact development efficiency and the quality of the final product.

A good day

Today, something that made me quite happy happened—I finally finished building my own website. It might not seem like a big deal, but for me, it feels like a small adventure and achievement. The most interesting part was the learning and exploration throughout the process. Seeing the site evolve from nothing to what it is now has made me genuinely happy.

Next, I plan to continue optimizing the site and learning more. Although this project is now complete, I know there are still many exciting things to explore in the future.

I’d also like to extend my gratitude to serv00.com for providing such an excellent platform.

So, I’m recording my feelings for today. It might not be a groundbreaking success, but this little joy is enough to keep me smiling all day.