Python OpenVPN Script - python

I am attempting to write a python script for linux to start openvpn and have been running into a problem getting openvpn to start using subprocess.
I am using the following to start openvpn:
openvpn_cmd = ['sudo', 'openvpn', '--config', 'client.cfg', '--auth-user-pass', 'hmaauth.conf']
prog = subprocess.Popen(openvpn_cmd)
But I get the following error back from OpenVPN:
Options error: --nobind doesn't make sense unless used with --remote
The config file is downloaded directly from the VPN service website prior to running the subprocess command, so I can't (and shouldn't have to) change anything in the configuration.
I've heard this can happen if you don't run with root privileges, but I'm already doing that...
Does anyone have any suggestions as to why I am getting this error?
I have a working shell script that starts openvpn using the following:
sudo openvpn --config client.cfg --auth-user-pass hmaauth.conf
Which should be exactly what I have in my python script.
Thanks in advance for your advice.

Ok, the problem here is that I'm dumb. I was downloading a config file that didn't have the remote server for the VPN specified, now I understand the 'no remote' error.
Now that I have that cleared up we're good to go.

Related

Pycharm debugger "waiting for connections" but running still working

I am trying to debug django project with docker-compose interpreter.
Here is my pycharm configurations
But when I trying to debug it project still running but debugger is still waiting for connection and break point not working
I think that structure of my project have problem cause i'm try to debug other project it still working.
Here is my project structure
What am i doing wrong?
To whomever else it might help, the problem in my case was that I attempted to use the debugger coupled with a run inside a Docker container functionality.
I also happened to have all ports published on that container which prevented the debugger to connect. Publishing only ports I actually needed, resolved the problem.
Check the running ports on your machine. In my case, the port that PyCharm wanted to use for debugging (127.0.0.1:xxxx) was being used by another program on my laptop.
You can check the running ports using the following command on mac:
lsof -i -P | grep -i "listen"
Or, the following command once you know which port PyCharm is trying to use (usually you can see that on top of the console tab of PyCharm after starting debugging process):
sudo lsof -i :xxxxx
After running that, you should see a list with PID numbers, names of program etc. Then you can kill the running process on that port using the PID:
sudo kill -9 PID
Or, just restart your computer.
If that doesn't work, then it might be due to using already-existing Python module names. Make sure the names of the Python files in your project isn't the same as any other library/code from python.

VirtualBox command works correct in bash, but does not work in nginx

We have a project on nginx/Django, using VirtualBox.
When we try to run command VBoxManage list runningvms in nginx, we have the next error:
Failed to initialize COM because the global settings directory '/.config/VirtualBox' is not accessible!
If we run this command in console, it works fine.
What can we do to make it working good in nginx?
Other details:
nginx is runned by user "www-data", console - by the other user (Administrator).
We have fixed the issue.
There was wrong environment variable "Home" (os.environ['HOME']). We changed it, and so the problem was gone.
Using Python API for VB instead of ssh can really help you with that problem, as RegularlyScheduledProgramming suggested - we added Python API too.
Thanks!

Python Fabric is hanging

I've got an instance running on AWS EC2. Doing this:
ssh -i keyname.pem user#box.com
Works!
Using Fabric to deploy my stuff now:
fab -i keyname.pem -k deploy:host=user#box.com
Same key, same user/host, but it hangs miserably! No logging, just hangs.
Does anyone know how different are ssh settings that Fabric is trying to use from those in the system? I thought it is just wrap around SSH shell commands (I'm running all that from Cygwin if it matters). Completely stuck with this.
I've googled out a few threads where people complain about that, but all I found is recommendations to update Fabric. I have the newest one from cheese shop (Fabric v1.10.1, Paramiko v1.15.2), still this strange behavior to hang without saying anything.
Have you try to set env with all the information?
`from fabric.api import env
env.env_name = 'user'
env.key_filename = 'keyname.pem'
env.hosts = ['box.com']`
I hit this same error before. Try ssh-ing into the server with ssh from terminal before using fabric. Sometimes is needs to be added to known-hosts, and fabric at times won't prompt you for this...

Installing and Starting a CherryPy server script as Windows service (using sc.exe)

I am trying to install and start a simple CherryPy server as a Windows service.
Here is the script: (Removed some lines to cut it short. It's fully working when executing manually from the command-line)
app = AdminMediaHandler(django.core.handlers.wsgi.WSGIHandler())
logged_app = TransLogger(app)
server = wsgiserver.CherryPyWSGIServer( ('127.0.0.1', 8632), logged_app, server_name='localhost', numthreads=20 )
try:
server.start()
except KeyboardInterrupt:
server.stop()
I'm using sc.exe to install and start the service. Installation goes fine, but I can't seem to start the service.
The command used is: (note there're spaces in the paths, though I'm handeling this with double-quotes, and the binPath is working when executing its string manually through the command-line)
> sc.exe create "ServiceName" binPath= "\"C:\Path to Python\python.exe\" \"C:\Path to CherryPy Script\cherryserver.py\""
> sc.exe start "ServiceName"
I keep getting this error, no matter if attempting to start the service using sc.exe or through services.msc GUI:
[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
From what I understand, this is happenning because python.exe doesn't implement the Windows Service API.
I do not wish to create an .exe from the script, using py2exe.
I have found this answer that suggests to install the service using different tools than sc.exe, called srvany.exe & instsrv.exe. However, I can't find them in the Win2K Resource Kit website.
Does anybody know how to install & start this .py as a Windows succesfully?
Does anybody know
CherryPy ships with a module for starting as a Windows service. See this other SO question for instructions on how to install and run it. You'll probably want to switch from your current approach (of passing the Django app directly to the WSGIServer) and use cherrypy.tree.graft instead.
I prefer nssm for installing normal scripts as a service.
You can copy the nssm.exe in the C:\Windows\system32 or C:\Windows\SysWOW64 directory depending on your system. After that you are able to install a Service as follow:
nssm install yourservicename
For a python script you must set the application path to your python.exe and the argument is your script self.
Other common commands for start/stop/edit your service are:
nssm start yourservicename
nssm stop yourservicename
nssm edit yourservicename
I eventually used ServiceInstaller aka SMaster, as stated in this answer. The URL in the given answer is broken, and I couldn't find a working URL. I just had srunner.exe available locally beforehand.
Note there was another obstacle to overcome though, as ServiceInstaller can't handle files with spaces in their paths.
So, I used the old DOS path formatting for service registration.
Instead of registering C:\Program Files\MyApp\python.exe, I registered C:\PROGRA~1\MyApp\python.exe.

Open Python shell through SSH

I'm using this tool to set up a ssh server on Windows. I'm trying to open the standard Python shell through a remote ssh connection but I simply can't get it to work. If I type 'python' in my ssh command line nothing happens, it just seems to wait for more input. My server machine however, shows a new python process running after I do this.
Running scripts works fine, though.
Do I need to use another Python shell, some other ssh server, some different configs?
Thanks
My guess is that Python is not recognising the stdin on the SSH shell as a terminal. I don't know why that would be.
However, try running "python -i" to overcome it.
The problem is probably that you're running the Windows Python executable, which expects a Windows console environment to run in, over a channel which doesn't support the features of Windows console. You might find Andy Koppe's conin to be useful.

Categories

Resources