Skip to content

Instantly share code, notes, and snippets.

@Incognito-Coder
Last active March 29, 2022 19:45
Show Gist options
  • Save Incognito-Coder/5e44df201322081739a1eb97dcec4ce2 to your computer and use it in GitHub Desktop.
Save Incognito-Coder/5e44df201322081739a1eb97dcec4ce2 to your computer and use it in GitHub Desktop.
a PHP script that helps you convert SurfShark OpenVPN hosts to ip or merge credentials to ovpn
<?php
function Builder($mode = 'h2i', $user = null, $pass = null)
{
$file = 'Surfshark_Config.zip';
if (!is_file('Surfshark_Config.zip')) {
copy('https://my.surfshark.com/vpn/api/v1/server/configurations', $file);
}
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
$zip->extractTo($path . '/configs/');
$zip->close();
$files = array_diff(scandir($path . '/configs'), array('..', '.'));
foreach ($files as $FILE) {
$editor = file_get_contents($path . '/configs/' . $FILE);
preg_match_all('/remote (.*?) (.*?)/', $editor, $match);
$ips = [];
$domains = [];
foreach ($match[1] as $server) {
$host2ip = gethostbyname($server);
array_push($ips, $host2ip);
array_push($domains, $server);
}
if ($mode == 'h2i') {
file_put_contents($path . '/configs/' . $FILE, str_replace($domains, $ips, $editor));
} elseif ($mode == 'merge') {
$xxx = str_replace($domains, $ips, $editor);
$xxx .= sprintf("<auth-user-pass>\n%s\n%s\n</auth-user-pass>", $user, $pass);
file_put_contents($path . '/configs/' . $FILE, $xxx);
}
echo "\033[32mDone: $FILE\033[0m" . PHP_EOL;
}
echo "Credit : Alireza Ah-Mand";
} else {
echo "Doh! I couldn't open $file";
}
}
echo "
o-o o o o--o o--o o-o o o O o--o o o o-o o--o o--o o o o o o--o o o
| | | | | | | | | / \ | | | / o o | | | |\ | | | | | |\ |
o-o | | O-Oo O-o o-o O--O o---oO-Oo OO | | O--o O-o | \ | o o O--o | \ |
| | | | \ | | | | | || \ | \ o o | | | \| \ / | | \|
o--o o-o o o o o--o o o o oo o o o o-o o o--o o o o o o o
[+] This is a fork from SurfSocks project by Incognito Coder.
";
$u = readline('Enter User: ');
$p = readline('Enter Password: ');
Builder('merge', $u, $p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment