Skip to content

Instantly share code, notes, and snippets.

@dex4er
Created February 19, 2021 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dex4er/7bd2243688aa4cf6645c21fdfa5f82b2 to your computer and use it in GitHub Desktop.
Save dex4er/7bd2243688aa4cf6645c21fdfa5f82b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
## The fake API service for OpenVPN that allows to use client with simple setup mode.
use Mojo::File;
use Mojo::Util 'xml_escape';
use Mojolicious::Lite;
post '/RPC2' => sub {
my ($c) = @_;
my $methodName = eval { $c->req->dom->at('methodName')->text } // '';
if ($methodName eq 'GetSession') {
$c->render(text => q{<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>status</name>
<value>
<int>0</int>
</value>
</member>
<member>
<name>session_id</name>
<value>
<string>AS_AAAAAAAAAAAAAAAAAAAAAA==</string>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>});
} elsif ($methodName eq 'GetUserlogin') {
my $client_conf = xml_escape(Mojo::File->new('/etc/openvpn/client.conf')->slurp) =~ s/^/ /gr;
$c->render(text => qq{<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value>
<string>
$client_conf
</string>
</value>
</param>
</params>
</methodResponse>});
} else {
$c->render(text => 'Not supported', status => 500);
}
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment