Multi-broadband networking (3) Use the cURL method to write Shell scripts in OpenWrt to automatically complete the webpage broadband authentication login (campus network authentication login solution) Use the awk command

  For non-PPPoE authentication, broadband users (such as campus network) who use web authentication to log in. It is too cumbersome to use the method in "Multiple Broadband Networking (2)" to authenticate and log in one by one. In this section, the Shell script and cURL method will be used to simulate the manual authentication steps, automatically enable a single interface and complete the authentication login process.

Table of contents

1. cURL installation

 Two, cURL authentication request capture

1. Capture browser authentication request

2. Edit browser authentication request

3. Write Shell script

1. Preparatory work (grep filter IP, awk modify configuration file)

2. Write shell script

3. Save the shell script

4. Execute Shell script

4. Automatically execute Shell script when booting

Appendix, Complete Shell Authentication Login Script Code


1. cURL installation

  Log in to OpenWrt's web management background, select the "System -> Software" menu, enter cURL in "Filter", and in the software list, select the application named "curl" to install (Figure 14 ) . Note: If you can’t find any software, please click “Update lists” in “Operation” to update the software list. When updating, you need to ensure that OpenWrt can correctly access the WAN, that is: in "Network->Interface", at least one interface must be able to successfully connect to the WAN.

Figure 14 cURL software installation

 Two, cURL authentication request capture

  Through cURL, the browser can be simulated to send a request to the server to complete the process of broadband account authentication and login. First, you need to capture the request sent by the browser to the server, and then use the cURL method to simulate sending it.

1. Capture browser authentication request

  1) Enable only one virtual macvlan interface: In the OpenWrt web panel, enter the "Network -> Load Balancing (load balancing)" menu, select the "Interface" tab, in the interface list, edit each interface, and only keep one interface For the subsequent capture of authentication login data packets, disable other interfaces to prevent OpenWrt from switching to other outlets through load balancing after broadband login, which will affect debugging.

  2) Open a browser (Chrome is recommended) and visit the broadband authentication login page.

  3) Press the F12 key on the keyboard to open the developer debugging tool.

  4) Select the "Network" tab (Figure 15), here, you can see the interaction request between the browser and the server. First, click the Clear button in the upper left corner (the red box in the upper left corner of the developer debugging tool in Figure 15) to clear the existing request (if it is already empty, you do not need to clear it).

Figure 15 Debugging tools for browser developers

   5) After completing the preparation, enter the user name and password, and click the login button to complete all the login processes. At this point, you can see the login request data in the developer debugging tool. Right-click the piece of data and select "Copy -> Copy as cURL (bash)", as shown in Figure 16. Note: cURL in bash form can be executed in a Linux (such as OpenWrt) terminal or Shell script, and cURL in cmd form can be executed in the command prompt (cmd) of Windows system.

Figure 16 capture browser login authentication request

   6) Paste the copied cURL request into a text file. For example, the authentication data captured in this experiment is as follows.

curl 'http://10.255.255.34/api/v1/login' \
  -H 'Connection: keep-alive' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -H 'Origin: http://10.255.255.34' \
  -H 'Referer: http://10.255.255.34/authentication/login' \
  -H 'Accept-Language: zh-CN,zh;q=0.9' \
  --data-raw '{"username":"**********5","password":"******","channel":"3","ifautologin":"0","pagesign":"secondauth","usripadd":"10.12.57.76"}' \
  --compressed \
  --insecure

2. Edit browser authentication request

  1) For the captured browser authentication request, remove the following two lines at the end, and remove the newline character "\" at the end of the previous line of these two lines.

--compressed \
--insecure

  The complete request after removal looks like this:

curl 'http://10.255.255.34/api/v1/login' \
  -H 'Connection: keep-alive' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -H 'Origin: http://10.255.255.34' \
  -H 'Referer: http://10.255.255.34/authentication/login' \
  -H 'Accept-Language: zh-CN,zh;q=0.9' \
  --data-raw '{"username":"**********5","password":"******","channel":"3","ifautologin":"0","pagesign":"secondauth","usripadd":"10.12.57.76"}'

  2) Log in to the OpenWrt terminal as the root account (you can log in directly to the machine, or use SSH to log in). Copy the above-edited cURL request text, paste it into the OpenWrt terminal, and press Enter to run. After running, you can see the successful login data returned by the server, such as the data of this experiment (Figure 17).

Figure 17 Terminal execution results

3. Write Shell script

  The shell script will simulate the behavior of manually enabling/disabling the interface and authentication login, enable each MWAN3 interface in turn, and close the remaining interfaces to complete the authentication login of the macvlan virtual network card corresponding to the interface. After completing all macvlan virtual network card authentication and login, and then open all MWAN3 interfaces, you can perform load balancing through each interface.

1. Preparatory work (grep filter IP, awk modify configuration file)

  From the captured cURL authentication request, we can see that the request parameter also needs the IP address of the network card (different authentication pages require different parameters, some may also need the MAC address of the network card, and some only need the account password), so The IP address of each virtual macvlan NIC needs to be prepared. The IP address of the network card can be checked through the OpenWrt Web management page, and the "Network->Interface" menu is selected, and the IPv4 address of the network card can be viewed at the corresponding interface (such as wan0). Here, we need to obtain the IP of the network card through commands in the terminal.

  1) View network card information

  In the OpenWrt terminal, enter the ifconfig command to view all network card information.

  Enter the ifconfig vth0 command to view the information of a single network card (such as vth0), and the result is as shown in Figure 18. The first red box is the MAC address of vth0, and the second red box is the IPv4 address of vth0.

Figure 18 View network card information

   2) Filter out IPv4 addresses

  With the command grep "text" , you can filter out the lines with the text "text".

  Through the cut -d 'separator' -f display field command, you can display the content of the specified field in the text. Such as executing the command:

echo "a/b/c" | cut -d '/' -f 2

  echo  means to output the result after the output, cut -d '/'  means to use the symbol / as a separator to split the string a/b/c into three fields a, b, and c, -f 2 means to display the second field, That is the character b. So the return result is b.

  To sum up, combined with the network card information format queried by ipconfig (Figure 18), the following command can be used to obtain the IPv4 address of the specified network card (Figure 19).

ifconfig vth0 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2
Figure 19 Filtering IPv4 addresses

  If the authentication information also requires the MAC address, you can write a command to obtain it.

  3) Prepare enable/stop commands for MWAN3 interface

  The MWAN3 configuration file is located at: /etc/config/mwan3, use the following command in the terminal to view the MWAN3 configuration file.

vim /etc/config/mwan3

  After opening the MWAN3 configuration file, you can view the configuration file (Figure 20). Wherein, config interface  is an interface configuration chapter, and each interface corresponds to a  config interface . The next option ... is the configuration options corresponding to the interface chapter, focusing on the option enabled option. By modifying the value of this option to "1" or "0", the MWAN3 interface can be enabled or disabled.

Figure 20 Interpretation of the MWAN3 configuration file

  Use the awk function to write a Shell script to automatically locate each interface, then enable the interface, and disable the function of other interfaces. When a certain interface is uniquely opened, the cURL method can be used to log in to the web page authentication account for this interface.

       Use the following commands to automatically find the chapter location of wan0, and find the enabled configuration option under this chapter, automatically replace 0 with 1, and save it to the file. For other interfaces, just replace ' wan0' in the first line of the command  with the name of the corresponding mwan3 interface. The fourth line gsub(0,1)  is used to replace 0 with 1. If you need to close the interface, just change it to gsub(1,0).

awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' /etc/config/mwan3 1<>/etc/config/mwan3

  After changing the configuration file, the service needs to be restarted using the following command.

/etc/init.d/mwan3 restart

[Detailed explanation] awk function instructions

  • In the awk statement, the single quote part is the command part to be executed, the front part is the parameter setting, and the back part is the file operation.
  • -F parameter: delimiter parameter. The default delimiter is space. Specify single quotes here.

  For example, a file contains a string: option enabled '1'

  After using  the awk -F "'" '{print $0;print $1;print $2}' file name  command, the above string can be separated by single quotes. In awk, the variable $0 is a complete string, $1 is the first part, namely option enabled; $2 is the second part, namely 1.

  • -v parameter: You can specify a custom variable. Such as -v section="config interface 'wan0'" , the section  variable can be used to express  config interface 'wan0' in the executed command part  .
  • Instruction part: The single quote part after the -v parameter is the executed instruction part. There are four instructions here. awk will execute each instruction line by line on the file. In the instruction, the inside of {} is the operation to be executed, and the condition before the {} is the condition of the operation.

  Among them, next  means to jump to the next line immediately. That is: ignore the remaining instructions and immediately jump to the next line. In this example, when the $0==section match is satisfied, the section of the wan0 interface is found, and after setting the flag to 1, the next line is executed immediately. This can avoid using the regular expression /config/ command in the next paragraph to match the line where config interface 'wan0' is located again, and set the flag to 0 immediately. The correct operation should be to set the flag to 0 when /config/ matches to the beginning of the next chapter.

  The range where the flag is 1 is the range of configuration options where wan0 is located. Just continue to match the option enabled option within this range . After matching flag is 1 and option enabled , use gsub() to replace 0 with 1. Then output the modified results to a file.


2. Write shell script

  1) Write a shell script for a virtual macvlan network card (such as vth0).

FILEDIR=/etc/config/mwan3
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth0 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
NStat=$(curl 'http://10.255.255.34/api/v1/login' \
  -H 'Connection: keep-alive' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -H 'Origin: http://10.255.255.34' \
  -H 'Referer: http://10.255.255.34/authentication/login' \
  -H 'Accept-Language: zh-CN,zh;q=0.9' \
  --data-raw '{"username":"**********5","password":"******","channel":"3","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')

# Judge whether the login is successful.
echo "${NStat}"
NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
if [ $NCode != 200 ]; then
    # Login failed.
    vth0ISP=0
else
    vth0ISP=1
fi

  Line 1~Line 43: enable vth0 interface, disable vth1~vth7 interface.

  Lines 45-46, get the IP address of the vth0 NIC and save it to the CUIP variable.

  Lines 48-57 execute the cURL request and store the result returned by the server into the NStat variable. Note: $() needs to be added outside the captured cURL to get the returned string result. It is also necessary to replace the IP address in the request with the CUIP variable, and the variable reading method is $CUIP.

  Lines 59~67, according to Figure 17, write the return result screening code by yourself, here filter the status parameter code returned, after testing, when the code in this experiment is 200, it indicates that the login is successful.


  After the login is successful, the vth0ISP variable is set to 1. After all the interfaces are enabled, the vth*ISP variable will be judged one by one. If it is 1, the corresponding interface will be enabled, otherwise the corresponding interface will be disabled. After the script is executed, log in to the OpenWrt background, go to the "Network->Load Balance" page, select the "Interface" tab, and check the enabled status of each interface to know which interfaces fail to authenticate and log in.


  2) Write a complete shell script

  Copy the above Shell script, and modify the enabled interface and disabled interface in line 1~line 43, modify the network card name in line 46, modify the broadband account and password in line 48~57, and modify the flag variable name in line 64 and 66. .

  The full reference script is at the end of the article.

  At the end, add the following code to open all interfaces for successful authentication and login.

# Start all mwan interface.
if [ $vth0ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan0'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan0'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth1ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan1'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan1'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth2ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan2'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan2'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth3ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan3'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan3'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth4ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan4'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan4'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth5ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan5'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan5'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth6ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan6'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan6'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth7ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan7'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan7'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
/etc/init.d/mwan3 restart

3. Save the shell script

  1) Script file creation

  In the OpenWrt terminal, run the following command to create the script file in the /etc/config folder (you can also choose the save path yourself).

vim /etc/config/nw_log.bash

  Press the keyboard key "i" to enter the editing state, and input or paste the above complete Shell script into the script file. Note: You need to insert a line at the top of the script as the first line, and enter the following script interpreter declaration code.

#!/bin/bash

  After editing, press the keyboard key "ESC" to exit the editing state. And enter the following code and press the Enter button to save and close the file.

:wq

  2) Give execution permission to Shell script

  In the OpenWrt terminal, run the following command.

chmod +x /etc/config/nw_log.bash

4. Execute Shell script

  In the OpenWrt terminal, run the following command.

sh /etc/config/nw_log.bash

4. Automatically execute Shell script when booting

  Log in to the OpenWrt web management panel, select the "System -> Startup Items" menu, and switch to the "Local Startup Script" tab. Above exit 0, enter the following code and click the save button in the lower right corner.

sleep 10

# Log in to the network.
sh /etc/config/nw_log.bash

  Sleep 10  is executed after a delay of 10s. After booting, each interface will be registered and enabled. The delay here can wait for each interface to successfully obtain an IP address from the server, which is very important for requests that require an IP address to authenticate and log in to a broadband account.

  Restart the server, under the "Interface" tab of "Network->Load Balance", you can see that the interface for successful authentication and login is enabled.

Appendix, Complete Shell Authentication Login Script Code

   [Tips] The use of structures such as arrays can realize the reuse of some codes and simplify the code structure. However, the shell script of the system itself does not have a structure such as an array, and you need to find information to install and configure it separately.

  [Note] Different webpages log in to the authentication page, and the login requests sent are also different. The code is for reference only , you need to at least understand the code and modify the operator identification NClass , awk command , and cURL request code  to use it normally.

#!/bin/bash

# Essential information.
# China Mobile. ISP=1
N1Class="2"
N1User="**********2"
N1Pass="******"

# China Telecom. ISP=2
N2Class="3"
N2User="**********5"
N2Pass="******"

# China Unicom ISP=3
N3Class="4"
N3User="**********1"
N3Pass="******"

# ISP selection and Enablement. ISP 1~3: CMob,CTel,CUni. ISP0: Disabled.
vth0ISP=2
vth1ISP=2
vth2ISP=1
vth3ISP=1
vth4ISP=1
vth5ISP=0
vth6ISP=0
vth7ISP=0

FILEDIR=/etc/config/mwan3
# Log in to the network in turn.
# ============ vth0 ============
ISP=$vth0ISP
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth0 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
if [ $ISP == 1 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N1User'","password":"'$N1Pass'","channel":"'$N1Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 2 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N2User'","password":"'$N2Pass'","channel":"'$N2Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 3 ]; then
   NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N3User'","password":"'$N3Pass'","channel":"'$N3Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
fi

# Judge whether the login is successful.
if [ $ISP != 0 ]; then
    echo "${NStat}"
    NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
    if [ $NCode != 200 ]; then
        # Login failed.
    	vth0ISP=0
    fi
fi

# ============ vth1 ============
ISP=$vth1ISP
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth1 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
if [ $ISP == 1 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N1User'","password":"'$N1Pass'","channel":"'$N1Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 2 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N2User'","password":"'$N2Pass'","channel":"'$N2Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 3 ]; then
   NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N3User'","password":"'$N3Pass'","channel":"'$N3Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
fi

# Judge whether the login is successful.
if [ $ISP != 0 ]; then
    echo "${NStat}"
    NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
    if [ $NCode != 200 ]; then
        # Login failed.
    	vth1ISP=0
    fi
fi

# ============ vth2 ============
ISP=$vth2ISP
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth2 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
if [ $ISP == 1 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N1User'","password":"'$N1Pass'","channel":"'$N1Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 2 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N2User'","password":"'$N2Pass'","channel":"'$N2Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 3 ]; then
   NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N3User'","password":"'$N3Pass'","channel":"'$N3Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
fi

# Judge whether the login is successful.
if [ $ISP != 0 ]; then
    echo "${NStat}"
    NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
    if [ $NCode != 200 ]; then
        # Login failed.
    	vth2ISP=0
    fi
fi

# ============ vth3 ============
ISP=$vth3ISP
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth3 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
if [ $ISP == 1 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N1User'","password":"'$N1Pass'","channel":"'$N1Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 2 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N2User'","password":"'$N2Pass'","channel":"'$N2Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 3 ]; then
   NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N3User'","password":"'$N3Pass'","channel":"'$N3Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
fi

# Judge whether the login is successful.
if [ $ISP != 0 ]; then
    echo "${NStat}"
    NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
    if [ $NCode != 200 ]; then
        # Login failed.
    	vth3ISP=0
    fi
fi

# ============ vth4 ============
ISP=$vth4ISP
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth4 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
if [ $ISP == 1 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N1User'","password":"'$N1Pass'","channel":"'$N1Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 2 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N2User'","password":"'$N2Pass'","channel":"'$N2Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 3 ]; then
   NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N3User'","password":"'$N3Pass'","channel":"'$N3Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
fi

# Judge whether the login is successful.
if [ $ISP != 0 ]; then
    echo "${NStat}"
    NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
    if [ $NCode != 200 ]; then
        # Login failed.
    	vth4ISP=0
    fi
fi

# ============ vth5 ============
ISP=$vth5ISP
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth5 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
if [ $ISP == 1 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N1User'","password":"'$N1Pass'","channel":"'$N1Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 2 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N2User'","password":"'$N2Pass'","channel":"'$N2Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 3 ]; then
   NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N3User'","password":"'$N3Pass'","channel":"'$N3Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
fi

# Judge whether the login is successful.
if [ $ISP != 0 ]; then
    echo "${NStat}"
    NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
    if [ $NCode != 200 ]; then
        # Login failed.
    	vth5ISP=0
    fi
fi

# ============ vth6 ============
ISP=$vth6ISP
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth6 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
if [ $ISP == 1 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N1User'","password":"'$N1Pass'","channel":"'$N1Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 2 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N2User'","password":"'$N2Pass'","channel":"'$N2Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 3 ]; then
   NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N3User'","password":"'$N3Pass'","channel":"'$N3Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
fi

# Judge whether the login is successful.
if [ $ISP != 0 ]; then
    echo "${NStat}"
    NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
    if [ $NCode != 200 ]; then
        # Login failed.
    	vth6ISP=0
    fi
fi

# ============ vth7 ============
ISP=$vth7ISP
# Open only one mwan interface.
awk -F "'" -v section="config interface 'wan0'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan1'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan2'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan3'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan4'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan5'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan6'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(1,0)}
    {print}' $FILEDIR 1<>$FILEDIR
awk -F "'" -v section="config interface 'wan7'" '
    $0==section{flag=1;print;next}
    /config/{flag=0}
    flag==1&&/option enabled/{gsub(0,1)}
    {print}' $FILEDIR 1<>$FILEDIR
/etc/init.d/mwan3 restart

# Get the IP address of the current network card.
CUIP=$(ifconfig vth7 |grep 'inet addr:'|cut -d ' ' -f 12|cut -d ':' -f 2)

# Log in through curl. This part is the general code of vth0 ~ vth7.
if [ $ISP == 1 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N1User'","password":"'$N1Pass'","channel":"'$N1Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 2 ]; then
    NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N2User'","password":"'$N2Pass'","channel":"'$N2Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
elif [ $ISP == 3 ]; then
   NStat=$(curl 'http://10.255.255.34/api/v1/login' \
      -H 'Connection: keep-alive' \
      -H 'Accept: application/json, text/plain, */*' \
      -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36' \
      -H 'Content-Type: application/json;charset=UTF-8' \
      -H 'Origin: http://10.255.255.34' \
      -H 'Referer: http://10.255.255.34/authentication/login' \
      -H 'Accept-Language: zh-CN,zh;q=0.9' \
      --data-raw '{"username":"'$N3User'","password":"'$N3Pass'","channel":"'$N3Class'","ifautologin":"0","pagesign":"secondauth","usripadd":"'$CUIP'"}')
fi

# Judge whether the login is successful.
if [ $ISP != 0 ]; then
    echo "${NStat}"
    NCode=$(echo "${NStat}" | grep "code" | cut -d " " -f 2 | cut -d "," -f 1)
    if [ $NCode != 200 ]; then
        # Login failed.
    	vth7ISP=0
    fi
fi


# Start all mwan interface.
if [ $vth0ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan0'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan0'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth1ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan1'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan1'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth2ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan2'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan2'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth3ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan3'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan3'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth4ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan4'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan4'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth5ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan5'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan5'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth6ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan6'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan6'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
if [ $vth7ISP != 0 ]; then
    awk -F "'" -v section="config interface 'wan7'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(0,1)}
		{print}' $FILEDIR 1<>$FILEDIR
else
	awk -F "'" -v section="config interface 'wan7'" '
	    $0==section{flag=1;print;next}
		/config/{flag=0}
		flag==1&&/option enabled/{gsub(1,0)}
		{print}' $FILEDIR 1<>$FILEDIR
fi
/etc/init.d/mwan3 restart

Guess you like

Origin blog.csdn.net/Cx2008Lxl/article/details/123116995