1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

NordVPN script change/start vpn server from gui on r7800 voxel

Discussion in 'NETGEAR AC Wireless' started by Martijnxd, Mar 30, 2019.

  1. Martijnxd

    Martijnxd New Around Here

    Joined:
    Mar 30, 2019
    Messages:
    4
    I made a Nordvpn html/script for r7800 with voxel firmware
    [​IMG]
    This is a really basic script to change the nordvpn server from the web gui of the router
    After the change it restarts the vpn client .
    maybe someone can use it.

    //
    V2.2
    added a stop vpn function
    [​IMG]
    [​IMG]
    the 4 files that are needed:
    https://github.com/martijnxd/nordvpn-r7800/archive/master.zip
    https://github.com/martijnxd/nordvpn-r7800

    /etc/openvpn/config/client/Nordvpn.auth
    /www/nvpn-addon.htm
    /www/cgi-bin/nvpn-addon.cgi
    /www/cgi-bin/nvpn-addon.sh

    I have replaced /www/license.html, with nvpn-addon.html, so i can now use the license info link in the gui of the router to access this page

    enable telnet at http://routerip/debug.htm
    login and
    create the following file with your user name and password for nordvpn

    /etc/openvpn/config/client/nordvpn.auth
    Code:
    [email protected]
    password

    /www/nvpn-addon.htm
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <style>
    * {
      box-sizing: border-box;
    }
    input[type=text], select, textarea {
      width: 100%;
      padding: 12px;
      border: 1px solid #ccc;
      border-radius: 4px;
      resize: vertical;
    }
    label {
      padding: 12px 12px 12px 0;
      display: inline-block;
    }
    input[type=submit] {
      background-color: blue;
      color: white;
      padding: 12px 20px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      float: right;
    }
    input[type=submit]:hover {
      background-color: lightblue;
    }
    .container {
      border-radius: 5px;
      background-color: #f2f2f2;
      padding: 20px;
    }
    .col-25 {
      float: left;
      width: 25%;
      margin-top: 6px;
    }
    .col-75 {
      float: left;
      width: 75%;
      margin-top: 6px;
    }
    /* Clear floats after the columns */
    .row:after {
      content: "";
      display: table;
      clear: both;
    }
    /* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
    @media screen and (max-width: 600px) {
      .col-25, .col-75, input[type=submit] {
        width: 100%;
        margin-top: 0;
      }
    }
    </style>
    </head>
    <body>
    <h2>Nordvpn add-on</h2>
    <p>Select country</p>
    <div class="container">
    <form id ="country" action="cgi-bin/nvpn-addon.cgi" method="get">
      <div class="row">
        <div class="col-25">
          <label for="country">Country</label>
        </div>
        <div class="col-75">
          <select id="countrypd" name="country">
            </select>
    <script>
    let dropdown = document.getElementById('countrypd');
    dropdown.length = 0;
    let defaultOption = document.createElement('option');
    defaultOption.text = 'Choose Country';
    dropdown.add(defaultOption);
    dropdown.selectedIndex = 0;
    const request = new XMLHttpRequest();
    request.open('GET','./cgi-bin/nvpn-addon.cgi',true);
    request.onload = function() {
      if (request.status === 200) {
          const data = JSON.parse(request.responseText);
              let option;
        for (let i = 0; i < data.length; i++) {
          option = document.createElement('option');
          option.text = data[i].name;
          option.value = data[i].id;
          dropdown.add(option);
        }
       } else {
      }
    }
    request.onerror = function() {
      console.error('An error occurred fetching the JSON from ' + url);
    };
    request.send();
    </script>
       </div>
      </div>
      <div class="row">
        <input type="submit" value="Submit">
      </div>
        <div class="row">
        <div class="col-25">
          <label for="country">Stop vpn server</label>
        </div>
        <div class="row">
        <input type="Submit" name="country"value="stop">
      </div>
      </form>
    </div>
    </body>
    </html>
    
    
    /www/cgi-bin/nvpn-addon.cgi

    Code:
    #!/bin/sh
    echo "Content-type: text/html"
    echo ""
    COUNTRY=$(echo ${QUERY_STRING##*=})
    if  [ ! -n "$COUNTRY"  ]
    then
    echo $(cgi-bin/nvpn-addon.sh)
    else
    echo Changed server to recommended server
    echo restarting...
    echo $(cgi-bin/nvpn-addon.sh $COUNTRY)
    fi
    
    and create the shell script file
    /www/cgi-bin/nvpn-addon.sh

    Code:
    if [ ! -n "$1" ]
    then
    curl --silent https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_countries
    else
    /etc/init.d/openvpn-client stop
    /etc/init.d/dnscrypt-proxy-2 stop
    fi
    if [ $1 != "stop" ]
    then
    server="$(curl --silent 'https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\{%22country_id%22:'$1'\}' | jq --raw-output 'limit(1;.[])|.hostname')"
    wget -O /etc/openvpn/config/client/nordvpn.ovpn https://downloads.nordcdn.com/configs/files/ovpn_legacy/servers/$server.udp1194.ovpn
    sed -i 's/auth-user-pass/auth-user-pass nordvpn.auth/g' /etc/openvpn/config/client/nordvpn.ovpn
    echo "nice -20" >> /etc/openvpn/config/client/nordvpn.ovpn
    echo "sndbuf 393216" >> /etc/openvpn/config/client/nordvpn.ovpn
    echo "rcvbuf 393216" >> /etc/openvpn/config/client/nordvpn.ovpn
    echo push \"rcvbuf 393216\" >> /etc/openvpn/config/client/nordvpn.ovpn
    echo push \"sndbuf 393216\" >> /etc/openvpn/config/client/nordvpn.ovpn
    sed -i 's/mssfix 1450/mssfix 1460/g' /etc/openvpn/config/client/nordvpn.ovpn
    /etc/init.d/openvpn-client start
    /etc/init.d/dnscrypt-proxy-2 start
    fi
    
    make the cgi and sh files executuble:
    Code:
    chmod +x /www/cgi-bin/nvpn-addon.sh
    chmod +x /www/cgi-bin/nvpn-addon.cgi
    and you can test the script with to http://routerip/nvpn-addon.htm
     
    Last edited: May 11, 2019
  2. kamoj

    kamoj Senior Member

    Joined:
    May 12, 2017
    Messages:
    409
    This is a very nice initiative!
    I have done similar code for other add-on purposes that is not released.
    I eg tried NordVPN a few days but the huge difference in speed between their servers made me pessimistic.
    But there might be a way to rank the servers and combine it with your ideas!
    I'll have look at it once home again.
    Thank you again for sharing with the community there!
     
    Martijnxd likes this.
  3. Martijnxd

    Martijnxd New Around Here

    Joined:
    Mar 30, 2019
    Messages:
    4
    kamoj likes this.
  4. kamoj

    kamoj Senior Member

    Joined:
    May 12, 2017
    Messages:
    409
    Thank you, but unfortunately the recommended server is not the fastest one... I have tested and talked to their support. They dont have or dont want to help with a solution.
    https://www.snbforums.com/threads/h...lient-using-voxel-firmware.55646/#post-473243
    But if i get a free trial I can have another try after I come back home.
     
  5. Martijnxd

    Martijnxd New Around Here

    Joined:
    Mar 30, 2019
    Messages:
    4
  6. Voxel

    Voxel Very Senior Member

    Joined:
    Dec 9, 2014
    Messages:
    1,315
    If you have an interest we can perform your nice job as an add-on for my version of fw (installation package). Please let me know if you are interested. Minuses for you are that you have to handle and maintain it yourself ;).

    Voxel.
     
    rk8531 likes this.
  7. Martijnxd

    Martijnxd New Around Here

    Joined:
    Mar 30, 2019
    Messages:
    4
    Sure you are free to use it , and let me know if you need help.
    I updated the script , forgot a bit in de cgi file, it should now work
     
    rk8531, L&LD and kamoj like this.