function whmcs_get_customer_name($userid)
{
    lg_debug2("search customer name for userid {$userid}");
    $sql = "SELECT firstname,lastname FROM tblclients WHERE id='{$userid}';";
    lg_debug2("{$sql}");
    $q = mysql_query($sql);
    $firstname = mysql_result($q, 0, 0);
    $lastname = mysql_result($q, 0, 1);
    lg_debug2("firstname: {$firstname} lastname: {$lastname}");
    return mysql_result($q, 0, 0) . " " . mysql_result($q, 0, 1);
}
function validate_dns_domainname($untested_string)
{
    if (strlen($untested_string) <= 253 and strlen($untested_string) >= 1) {
        if (preg_match("/^[0-9a-zA-Z]+\\.[0-9a-zA-Z]+(((\\.[0-9a-zA-Z]+)?\\.[0-9a-zA-Z]+)?\\.[0-9a-zA-Z]+)?\$/", $untested_string)) {
            return $untested_string;
        } else {
            lg_debug2("String is no valid dns domainname(Pattern match failed)");
            return false;
        }
    } else {
        lg_debug2("String is no valid dns_hostname(too long)");
        return false;
    }
}
function citrix_set_vcore_count($xen_server, $vm_name, $vcore_count)
{
    $ssh_key_file = "/var/www/.ssh/id_citrix_vminfo";
    lg_debug("SSH-Connection to {$xen_server} to set vcores of {$vm_name} to {$vcore_count}");
    $ssh_options = "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no";
    $ssh_command = "/usr/bin/ssh 2>&1 {$ssh_options} -i {$ssh_key_file} -l citrix_info {$xen_server}  /usr/bin/sudo /usr/local/bin/citrix_set_vcores {$vm_name} {$vcore_count}";
    lg_debug("{$ssh_command}");
    $ssh_output = popen("{$ssh_command}", "r");
    do {
        $line = fgets($ssh_output);
        lg_debug2($line);
    } while ($line);
    pclose($ssh_output);
    return $vnc_port;
}