Dragon2fly/vpngate-with-proxy

Add redirect-gateway setting to config file

partisansb opened this issue · 9 comments

          Sorry for misunderstanding you. So you need the DNS **appeared** in the `user_script.sh` so that you can inform your **firewall** to **allow connections** to them. It is better not to change the source code of main program since other people don't have that need. Instead, let do entire job within `user_script.sh` only. The below code will parse DNS from `config.ini`, remove `,` and store the result in `dns` variable.
dns=$(cat config.ini | grep -o -P '(?<=^dns = ).*')
dns="${dns//,/}"
echo $dns

Then, just use your dns to do what ever needed with your firewall.

Perhaps, you should write about your use-case somewhere for other people to follow.

Thanks :)

Originally posted by @Dragon2fly in #2 (comment)

I'm trying to achieve the same thing as this person here, but having issues. I think my issue might be slightly different however as I am using Debian VM rather than Fedora VM.

I am able to get a connection, however other App VM's connecting through the vpn can't get web browser access. Does you're script create a .ovpn config file? As I need to add the setting of "redirect-gateway def1" to it somehow.

Where would I go about doing that? Many thanks

Hi @partisansb

You would start here

vpn_file = server.write_file(self.use_proxy, self.ip, self.port)

Add your setting to the file before writing it out to .ovpn or before the OpenVPN is called.

can someone write me a script that automatically reconnects if the connection is lost like vpngate client after a while?
image

hi @bomayso

Just add your option here

        extra_option = ['keepalive 5 30\r\n',  # prevent connection drop due to inactivity timeout
                        '%s' % ('connect-retry 2\r\n' if self.proto == 'tcp' else ''),
                        'resolv-retry 2\r\n',
                        ]

The options that control the reconnection are the followings:

--connect-retry n [max]
Wait n seconds between connection attempts (default=5). Repeated reconnection attempts are slowed down after 5 retries per remote by doubling the wait time after each unsuccessful attempt. The optional argument max specifies the maximum value of wait time in seconds at which it gets capped (default=300).

--connect-retry-max n
n specifies the number of times each --remote or <connection> entry is tried. Specifying n as one would try each entry exactly once. A successful connection resets the counter. (default=unlimited).

Bản thân script này đã có chức năng ý rồi hả bạn, tại test thử ngắt mạng đi thì không thấy nó tự kết nối.

Mặc định openvpn sẽ retry vô hạn. Nhưng chương trình này chỉ cho kết nối lại tối đa 3 lần nếu lỗi ở server vpn.
Còn những lỗi ở máy bạn hay do đường truyền bị ngắt thì chương trình sẽ dừng luôn nhé.
Việc thử lại quá nhiều lần sẽ dẫn đến nguy cơ bị block ở proxy hay firewall.

Số lần retry tối đa

self.max_retry = 3

Code check điều kiện retry khi kết nối fail. Nếu không thỏa cái if này thì sẽ dừng kết nối.

elif self.is_connected and 'Restart pause, ' in line and self.dropped_time <= self.max_retry:

Hi, I've customised your cli script so it can run int he background automatically at start up.

I'm not so familiar with the python code you have used so how would I go about adding it...

I tried :
vpn_file = vpn_list[ranked[chose]]."/nredirect-gateway def1".write_file()

But it didn't work...

Thanks for your time, I've been using this script for a long time now and love it, just want to make it work better for me, thank you.

hi @partisansb

You could try to add your line here

        extra_option = ['keepalive 5 30\r\n',  # prevent connection drop due to inactivity timeout
                        '%s' % ('connect-retry 2\r\n' if self.proto == 'tcp' else ''),
                        'resolv-retry 2\r\n',
                        'redirect-gateway def1\r\n'    # <--- added gateway redirecting option
                        ]

Sorry in the delay getting back to you. I'm getting getting a connection and the script runs without errors, but my vm's are not getting a browser connection though it... Where can I check the .ovpn file thats being made?

Thanks

This is working as it should thank you