Connect to OpenVPN server through Node.js - javascript

I’m trying to create a GUI client for connecting to OpenVPN servers using electron and node but I’m struggling to figure out how to actually connect to the servers using the .ovpn files.
My question is what is the best way to connect to an OpenVPN server using node? Would it be best to Tun terminal commands like
“openvpn—config path to config”
Or is there another way applications like tunnelblick do it that might be easier or more efficient?

Hello I have been working with electron and ovpn on my last project, so here are a few tips.
VPNs require admin/root privilege in order to get setup, so running child_process.spawn on openvpn --config <path> will fail unless your electron app is being ran via sudo/admin privilege.
You can also use electron-sudo package, link here. This is basically a child process spawn with sudo/admin. Aka, app runs normally, but vpn command runs with sudo.
However, if your client is sketchy about giving you sudo/admin, the VPN must be ran separately prior to launching your app.
All in all its a admin/sudo thing.
Hope this helps.

Related

How to restart a Node.js project?

I'm not a Node.js developer. So I have no idea how it works. I've been a PHP developer for over 8 years.
Because of some reason, I need to make a small change in a Node.js project which is live. All I have to do is changing a payment gateway token. I did it like this:
After pulling it on the server, users still go to the old payment gateway. So I guess I need to do a restart. (I'm saying so because, for PHP projects, when you change a config-related thing, you need to restart PHP).
Not sure should I restart what thing? Noted that, the server is Ubuntu 20.04 and uses Nginx to talk to Node.js. In other word, how can I see Node is running as what service on Linux?
Also, there are two files that I think I need to run the project again after restarting Node through one of them: index.js, server.js. Am I right?
And
Your Node.js script likely runs under a process that restarts the script in case it dies. There are several "run forever" wrappers, the most popular one is pm2. Find out which one is used in your project. Try pm2 list as the user your project executes under. If pm2 type pm2 restart app_name to restart your project.
Please check if it is a node.js project so you can write the command node index.js or node server.js with this command you can start your node server.

Angular 4 SEO Friendly solution in prod

I'm trying to create a website in Angular 4. It is a base of my personal study.
My website is up and running but I'm trying to improve it. I checked and apparently my website is not SEO Friendly. I make some changes and I discovered this sample https://oliverveits.wordpress.com/2017/07/05/server-side-rendering-in-angular-4-with-universal/ That show an Angular 4 app with Page Source code.
I make the changes, I started to use Webpack and other features sugared by in the link. When I run the command "npm run start" and I access http://localhost:8000 I can see the Page Source. But when I copy the dist to my server on Godaddy domain I can't.
I'm not sure about what I have to do. If I need put my website in a node.js server or if I'm not compiling it correctly to have what I'm expecting.
I'm open to different approachs.
Well, I found the what causes this issue.
I think many of new Angular devs possible have the same problem.
When you run "npm start" or "ng s" what are you doing is put the node to listen a specific port. In other words, you are running a node server.
In another approach, copy the files to an IIS server or Apache Server. This doesn't make the Node Server run. In this scenario, the pages are download to the client browser and run as HTML/javascript page. And because of this when I try to see the Page source I saw the Angular files.
Took me a while to understand it. My background is .Net development.
Now a day my website is running in one of the many node.js servers. evennode.com, on this server instead of to have an IIS or Apache, they set up a Node Server to listing a specific port and then you are able to run all your development on the server side.
I found easier use a node js server like evennode them set tup node js run on my Goddady account.

How to use a browser on a remote server for an automated tests

I inherited a project where the person wrote tools to test our site's UI using JQuery and JS.
I don't know too much about it other than it requires a browser to be spawned and I think the tool uses JS to interact with iframes to see if it's the expected values.
My job is to get this tool to run on a remote server and post the results to Jenkins.
The remote test server and staging server is linux. From our staging server, I want to write a script to spawn a browser and run cmds from the tool to test our UI. I ran the following manually:
ssh -X user#remote_test_server /usr/bin/firefox
However, the remote server says:
Error: no display specified
Is there a way to spawn a browser for automated testing from one headless server to another? Thanks in advance for your help.
I faced a similar problem when I tried to automate a GUI installation program. While there are quite some different possibilities to choose from (e.g. Xnest, Xephyr?), I ended up using vncserver, because it's relatively easy to debug the GUI session this way.
You need to create a vncpassword file, I think:
mkdir -p $HOME/.vnc
chmod 0700 $HOME/.vnc
echo MyLittlePassword | vncpasswd -f > $HOME/.vnc/passwd
chmod 0600 $HOME/.vnc/passwd
Starting the server is then quite straightforward
vncserver
export DISPLAY=:1
/usr/bin/firefox&
...
Now it is possible to connect to the VNC server with a VNC viewer of your choice. But beware there may be no window manager, depending on the X startup scripts of your environment.
Shutting the server down
vncserver -kill :1
In the configuration of Jenkins project , specify the
Build Environment
Start Xvfb before the build, and shut it down after.
#

Installing NodeJS and SocketIO in a Remote Server

My project is a Real Time Two-Player Facebook Game, and what I need is a tool that will help me build the game with quick responses to enable the "Real Time" function of the game. I have just found out about the Node JS and Socket IO. I have some knowledge in JavaScript so I stepped up and watched a few tutorials that discuss the functions of Node JS and Socket IO.
Here's the link to the videos that I have watched:
http://www.youtube.com/watch?v=mSE6xHkcX0w
I understand the basic of the Node JS and Socket IO and successfully installed it in my localhost. The problem is when I uploaded the files from my localhost to my remote server, some functions of the program are not working well. I don't know how to node my JavaScript file when it is on the server, because if it's in my localhost, I am using command prompt to run it.
node app.js
Node is not a web framework.
Chances are, you're using a web host that's generalized for web frameworks like PHP and Ruby on Rails. You're going to need virtual private server hosting, or Node-specific hosting, because Node requires a virtual machine to run. You otherwise won't be able to run Node Package Manager or Node itself.
Joyent has provided a list of hosts here.
If you chose to use a VPS or dedicated machine, an installation guide would be found here. This is how you would install Node on CentOS.
wget http://nodejs.org/dist/v<version>/node-v<version>.tar.gz
tar -zxf node-v<version>.tar.gz
cd node-v<version>
./configure
make -j <number of cores>
make install

Installing/setting up Socket.IO on my server

Ok so I have read through the Socket.IO docs and I am still a little unsure of a couple of points:
The documentation says...
To run the demo, execute the following:
git clone git://github.com/LearnBoost/Socket.IO-node.git socket.io
cd socket.io/example/
sudo node server.js
Now I don't know what this means at all! I think it may be command line interface. I of course have access to this on my localhost, but my online hosting package is a shared LAMP setup. Meaning I don't have access to the root command line (i think).
How do I actually setup socket.IO, is it impossible on my shared server package?
Appreciate any help...
W.
If you aren't familiar with node.js or with basic command line usage then I would suggest that you use a hosted WebSockets solution like pusherapp. Trying to learn WebSockets, and Node.js, and the Linux command line all at once is going to lead to a lot of frustration. Take a look a pusherapp's quick start guide, it's very easy to get started. You can have 5 simultaneous connections with a single application for free (I'm not affiliated with pusherapp).
Updated (with inline answers to questions):
If you are going to go the direction of running a Socket.IO application:
You don't technically need git since you can download node.js and Socket.IO from their respective download links on github.
You don't actually need a LAMP server to use Socket.IO. By default Socket.IO functions as a simple webserver in addition to a WebSockets server. If you want server side scripting then you might want Apache with mod_php, mod_python, etc.
You don't technically need a dedicated server or even root access. You do need a system where you can have long running process. And if you want the service to start automatically when the system is rebooted, you probably want to add a startup file to /etc/init.d, /etc/rc.d which will require root access. Both node.js and Socket.IO can be installed and run from a normal home directory. If you want to run Socket.IO on a standard port like 80 or 443 then you will need to run it with root privilege.
Node.JS scales quite well so Socket.IO will probably scale pretty well too.
It's not a simple matter to get everything setup and working, but if your goal is a free solution for web serving+WebSockets then Socket.IO is probably is good route to at least explore if you are brave.
First you'll have to determine if your host supports SSH. Sometimes they don't by default on shared hosting, but if you ask they can turn it on. If it does you'll use some sort of SSH client to connect to it. Putty for windows is the most common. Then you'll use git, which is a source control program. Which you'll probably have to install on your host, which may or may not be allowed. If you can, this can be accomplished a number of ways, you'll want to read the git documentation, it will depend largely on what linux distribution you're running. CD is change directory, basic command line stuff. sudo on the last line is telling the system to run the command as root, which it will ask you the password for, which you may not have access to on your host. Sounds like you're gonna have an uphill battle on shared hosting. You may want to opt for a VPS instead.
If your shared host is a LAMP system with no command line access you're not going to get very far with Socket.IO. The instructions you posted assume you have command line access and that you've installed the node.js runtime on your system.
If you really want to try this I recommend you get a VPS of your own (I use prgmr.com) to test it out. For what it's worth I found the Socket.IO platform pretty nice to use once I got it up and running.

Categories