Skip to content

Instantly share code, notes, and snippets.

Created July 14, 2010 03:23
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 anonymous/474973 to your computer and use it in GitHub Desktop.
Save anonymous/474973 to your computer and use it in GitHub Desktop.
<?php
function get_certificate_ip($ssl_key) {
$ip_addresses = array('127.0.0.1', '192.168.0.2');
$path = "/Users/adrian/test";
$pattern = "{$path}/{$ssl_key}__*.assign";
$files = glob($pattern);
if (sizeof($files) == 1) {
$pattern = "/^{$ssl_key}__(.*)\.assign$/";
preg_match($pattern, basename($files[0]), $matches);
return $matches[1];
}
elseif (sizeof($files) == 0) {
foreach ($ip_addresses as $ip) {
$pattern = "{$path}/*__{$ip}.assign";
$files = glob($pattern);
if (sizeof($files) == 0) {
touch("{$path}/{$ssl_key}__{$ip}.assign");
return $ip;
}
}
}
return FALSE; // generate error
}
print_r(get_certificate_ip("mykey1"));
print_r(get_certificate_ip("mykey2"));
print_r(get_certificate_ip("mykey3"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment