Small script for the dynamic creation of htaccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .htaccess | |
Allow from hostname.dyndns.com | |
# This is not working |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Config | |
**/ | |
$ouputFile = "/httpdocs/.htaccess"; | |
$config = "./htaccess.txt"; | |
$output = "order deny,allow\n"; | |
$output .= "deny from all\n"; | |
$handle = fopen($config, "r"); | |
$outputHandler = fopen($ouputFile, "w"); | |
// read config | |
if ($handle) { | |
while (!feof($handle)) | |
{ | |
$line = fgets($handle); | |
if(preg_match($line, "/#"/)) continue; | |
if(is_valid_ip_address($line)) | |
{ | |
$ip = $line; | |
} | |
else | |
{ | |
$ip = gethostbyname(trim($line)); | |
} | |
$output .= "# ".trim($line)."\n"; | |
$output .= "Allow from ".$ip."\n"; | |
$ip=0; | |
} | |
fclose($handle); | |
} | |
// write htaccess | |
if($outputHandler) | |
{ | |
fwrite($outputHandler, $output); | |
fclose($outputHandler); | |
} | |
function is_valid_ip_address ($string) | |
{ | |
return preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $string, $result); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# all the IP/hostnames and DynDNS-Hostnames you like to allow | |
hostname.dyndns.com | |
200.122.23.66 | |
hostname2.dyndns.org | |
captns.ch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment