What's new

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

Martijnxd

New Around Here
I made a Nordvpn html/script for r7800 with voxel firmware

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


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:

/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:

kamoj

Very Senior Member
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!
 

kamoj

Very Senior Member
Thank you,
Yes nordvpn is slow for me as well in particular the us servers , but i already had an account there so havent really looked to other providers.
But it should be possible to get the list of servers ranked, or at least the recommended server using their web page
https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations
like here:
https://stackoverflow.com/questions/53114981/nordvpn-setup-on-linux
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.
 

Voxel

Very Senior Member
I made a Nordvpn html/script for r7800 with voxel firmware

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.
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.
 

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top