Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pstaender/d298214e0ba4273a41d3ba0a1966a7a3 to your computer and use it in GitHub Desktop.
Save pstaender/d298214e0ba4273a41d3ba0a1966a7a3 to your computer and use it in GitHub Desktop.
<?php
$pass = 'yourpassword';
$user = 'yourusername';
// which config file to update
$nginxFile = '/etc/nginx/sites-enabled/mydyndns.domain.com';
$authUser = (isset($_SERVER['PHP_AUTH_USER'])) ? $_SERVER['PHP_AUTH_USER'] : null;
$authPass = (isset($_SERVER['PHP_AUTH_PW'])) ? $_SERVER['PHP_AUTH_PW'] : null;
$ip = (isset($_GET['ip'])) ? $_GET['ip'] : null;
if (($authUser === $user) && ($authPass === $pass) && ($ip)) {
if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $ip)) && ($content = file_get_contents($nginxFile))) {
$content = file_get_contents($nginxFile);
$content = preg_replace('/([\s\t]*proxy_pass[\s\t]+)(http[s]*:\/\/)(.+?)(\:)/i', '${1}${2}'.$ip.'${4}', $content);
file_put_contents($nginxFile, $content);
exit("updated");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment