Beispiel #1
0
 /**
  * Tests server connectivity
  */
 function connectTests()
 {
     global $fmdb, $__FM_CONFIG;
     $return = null;
     /** Get server list */
     $result = basicGetList('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_name', 'server_');
     if (!$fmdb->num_rows) {
         return __('There are no servers defined.');
     }
     /** Process server list */
     $num_rows = $fmdb->num_rows;
     $results = $fmdb->last_result;
     for ($x = 0; $x < $num_rows; $x++) {
         $return .= sprintf(__("Running tests for %s\n"), $results[$x]->server_name);
         /** ping tests */
         $return .= "\t" . str_pad(__('Ping:'), 15);
         if (pingTest($results[$x]->server_name)) {
             $return .= __('success');
         } else {
             $return .= __('failed');
         }
         $return .= "\n";
         /** SQL tests */
         $return .= "\t" . str_pad($results[$x]->server_type . ':', 15);
         $port = $results[$x]->server_port ? $results[$x]->server_port : $__FM_CONFIG['fmSQLPass']['default']['ports'][$results[$x]->server_type];
         if (socketTest($results[$x]->server_name, $port, 10)) {
             $return .= __('success') . ' (tcp/' . $port . ')';
         } else {
             $return .= __('failed') . ' (tcp/' . $port . ')';
         }
         $return .= "\n\n";
     }
     return $return;
 }
 function buildServerConfig($serial_no)
 {
     global $fmdb, $__FM_CONFIG, $fm_name;
     /** Check serial number */
     basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', sanitize($serial_no), 'server_', 'server_serial_no');
     if (!$fmdb->num_rows) {
         return sprintf('<p class="error">%s</p>', __('This server is not found.'));
     }
     $server_details = $fmdb->last_result;
     extract(get_object_vars($server_details[0]), EXTR_SKIP);
     $response = null;
     switch ($server_update_method) {
         case 'cron':
             if ($action == 'buildconf') {
                 /* set the server_update_config flag */
                 setBuildUpdateConfigFlag($serial_no, 'conf', 'update');
                 $response = sprintf('<p>%s</p>' . "\n", __('This server will be updated on the next cron run.'));
             } else {
                 $response = sprintf('<p>%s</p>' . "\n", __('This server receives updates via cron - please manage the server manually.'));
             }
             break;
         case 'http':
         case 'https':
             /** Test the port first */
             if (!socketTest($server_name, $server_update_port, 10)) {
                 return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: could not access %s using %s (tcp/%d).'), $server_name, $server_update_method, $server_update_port));
             }
             /** Remote URL to use */
             $url = $server_update_method . '://' . $server_name . ':' . $server_update_port . '/' . $_SESSION['module'] . '/reload.php';
             /** Data to post to $url */
             $post_data = array('action' => 'buildconf', 'serial_no' => $server_serial_no);
             $post_result = @unserialize(getPostData($url, $post_data));
             if (!is_array($post_result)) {
                 /** Something went wrong */
                 if (empty($post_result)) {
                     return sprintf('<p class="error">%s</p>', sprintf(__('It appears %s does not have php configured properly within httpd or httpd is not running.'), $server_name));
                 }
                 return $response . '<p class="error">' . $post_result . '</p>' . "\n";
             } else {
                 if (count($post_result) > 1) {
                     $response .= '<textarea rows="7" cols="100">';
                     /** Loop through and format the output */
                     foreach ($post_result as $line) {
                         $response .= "[{$server_name}] {$line}\n";
                     }
                     $response .= "</textarea>\n";
                 } else {
                     $response .= "<p>[{$server_name}] " . $post_result[0] . '</p>';
                 }
             }
             break;
         case 'ssh':
             /** Test the port first */
             if (!socketTest($server_name, $server_update_port, 10)) {
                 return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: could not access %s using %s (tcp/%d).'), $server_name, $server_update_method, $server_update_port));
             }
             /** Get SSH key */
             $ssh_key = getOption('ssh_key_priv', $_SESSION['user']['account_id']);
             if (!$ssh_key) {
                 return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: SSH key is not <a href="%s">defined</a>.'), getMenuURL(_('General'))));
             }
             $temp_ssh_key = sys_get_temp_dir() . '/fm_id_rsa';
             if (file_exists($temp_ssh_key)) {
                 @unlink($temp_ssh_key);
             }
             if (@file_put_contents($temp_ssh_key, $ssh_key) === false) {
                 return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: could not load SSH key into %s.'), $temp_ssh_key));
             }
             @chmod($temp_ssh_key, 0400);
             $ssh_user = getOption('ssh_user', $_SESSION['user']['account_id']);
             if (!$ssh_user) {
                 return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: SSH user is not <a href="%s">defined</a>.'), getMenuURL(_('General'))));
             }
             /** Test SSH authentication */
             exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$server_update_port} -l {$ssh_user} {$server_name} 'ls /usr/local/{$fm_name}/{$_SESSION['module']}/fw.php'", $post_result, $retval);
             if ($retval) {
                 /** Something went wrong */
                 @unlink($temp_ssh_key);
                 return sprintf('<p class="error">%s</p>' . "\n", __('Could not login via SSH.'));
             }
             unset($post_result);
             /** Run build */
             exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$server_update_port} -l {$ssh_user} {$server_name} 'sudo php /usr/local/{$fm_name}/{$_SESSION['module']}/fw.php {$action} " . implode(' ', $options) . "'", $post_result, $retval);
             @unlink($temp_ssh_key);
             if ($retval) {
                 /** Something went wrong */
                 return '<p class="error">' . ucfirst($friendly_action) . ' failed.</p>' . "\n";
             } else {
                 if (!count($post_result)) {
                     $post_result[] = ucfirst($friendly_action) . ' was successful.';
                 }
                 if (count($post_result) > 1) {
                     $response .= '<textarea rows="4" cols="100">';
                     /** Loop through and format the output */
                     foreach ($post_result as $line) {
                         $response .= "[{$server_name}] {$line}\n";
                     }
                     $response .= "</textarea>\n";
                 } else {
                     $response .= "<p>[{$server_name}] " . $post_result[0] . '</p>';
                 }
             }
             break;
     }
     /* reset the server_build_config flag */
     if (!strpos($response, strtolower('failed'))) {
         setBuildUpdateConfigFlag($serial_no, 'no', 'build');
     }
     $tmp_name = getNameFromID($serial_no, 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_', 'server_serial_no', 'server_name');
     addLogEntry(ucfirst($friendly_action) . " was performed on server '{$tmp_name}'.");
     return $response;
 }
Beispiel #3
0
/**
 * Changes a PostgreSQL user password
 *
 * @since 1.0
 * @package facileManager
 * @subpackage fmSQLPass
 *
 * @param string $server_name Hostname of the database server
 * @param integer $server_port Server port to connect to
 * @param string $admin_user User to login with
 * @param string $admin_pass User password to login with
 * @param string $user Database user to change
 * @param string $user_password New password
 * @param string $server_group Server group to process
 * @return string
 */
function changePostgreSQLUserPassword($server_name, $server_port, $admin_user, $admin_pass, $user, $user_password, $server_group)
{
    global $__FM_CONFIG;
    /** Connect to remote server */
    $verbose_output = ' --> Connecting to PostreSQL ';
    if (!socketTest($server_name, $server_port, 5)) {
        return $verbose_output . "[failed] - Could not connect to {$server_name} on tcp/{$server_port}\n";
    }
    $remote_connection = pg_connect("host='{$server_name}' port='{$server_port}' user='******' password='******' dbname='postgres'");
    if (pg_connection_status($remote_connection) === PGSQL_CONNECTION_OK) {
        $verbose_output .= "[ok]\n";
    } else {
        $verbose_output .= '[failed] - ' . pg_last_error() . "\n";
        return $verbose_output;
    }
    @pg_close($remote_connection);
    return $verbose_output;
}
Beispiel #4
0
 /**
  * Upgrades the client sotware
  *
  * @since 1.1
  * @package facileManager
  */
 function doClientUpgrade($serial_no)
 {
     global $fmdb, $__FM_CONFIG, $fm_name;
     /** Check permissions */
     if (!currentUserCan('manage_servers', $_SESSION['module'])) {
         echo buildPopup('header', _('Error'));
         printf('<p>%s</p>', _('You do not have permission to manage servers.'));
         echo buildPopup('footer', _('OK'), array('cancel_button' => 'cancel'));
         exit;
     }
     /** Process server group */
     if ($serial_no[0] == 'g') {
         $group_servers = $this->getGroupServers(substr($serial_no, 1));
         if (!is_array($group_servers)) {
             return $group_servers;
         }
         $response = null;
         foreach ($group_servers as $serial_no) {
             if (is_numeric($serial_no)) {
                 $response .= $this->doClientUpgrade($serial_no) . "\n";
             }
         }
         return $response;
     }
     /** Check serial number */
     basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', sanitize($serial_no), 'server_', 'server_serial_no');
     if (!$fmdb->num_rows) {
         return sprintf(_('%d is not a valid serial number.'), $serial_no);
     }
     $server_details = $fmdb->last_result;
     extract(get_object_vars($server_details[0]), EXTR_SKIP);
     $response[] = $server_name;
     if ($server_installed != 'yes') {
         $response[] = ' --> ' . _('Failed: Client is not installed.') . "\n";
     }
     if (count($response) == 1) {
         switch ($server_update_method) {
             case 'cron':
                 /* Servers updated via cron require manual upgrades */
                 $response[] = ' --> ' . _('This server needs to be upgraded manually with the following command:');
                 $response[] = " --> sudo php /usr/local/{$fm_name}/{$_SESSION['module']}/\$(ls /usr/local/{$fm_name}/{$_SESSION['module']} | grep php | grep -v functions) upgrade";
                 addLogEntry(sprintf(_('Upgraded client scripts on %s.'), $server_name));
                 break;
             case 'http':
             case 'https':
                 /** Test the port first */
                 if (!socketTest($server_name, $server_update_port, 10)) {
                     $response[] = ' --> ' . sprintf(_('Failed: could not access %s using %s (tcp/%d).'), $server_name, $server_update_method, $server_update_port);
                     break;
                 }
                 /** Remote URL to use */
                 $url = $server_update_method . '://' . $server_name . ':' . $server_update_port . '/' . $_SESSION['module'] . '/reload.php';
                 /** Data to post to $url */
                 $post_data = array('action' => 'upgrade', 'serial_no' => $server_serial_no);
                 $post_result = @unserialize(getPostData($url, $post_data));
                 if (!is_array($post_result)) {
                     /** Something went wrong */
                     if (empty($post_result)) {
                         $response[] = ' --> ' . sprintf(_('It appears %s does not have php configured properly within httpd or httpd is not running.'), $server_name);
                         break;
                     }
                 } else {
                     if (count($post_result) > 1) {
                         /** Loop through and format the output */
                         foreach ($post_result as $line) {
                             if (strlen(trim($line))) {
                                 $response[] = " --> {$line}";
                             }
                         }
                     } else {
                         $response[] = " --> " . $post_result[0];
                     }
                     addLogEntry(sprintf(_('Upgraded client scripts on %s.'), $server_name));
                 }
                 break;
             case 'ssh':
                 /** Test the port first */
                 if (!socketTest($server_name, $server_update_port, 10)) {
                     $response[] = ' --> ' . sprintf(_('Failed: could not access %s using %s (tcp/%d).'), $server_name, $server_update_method, $server_update_port);
                     break;
                 }
                 /** Get SSH key */
                 $ssh_key = getOption('ssh_key_priv', $_SESSION['user']['account_id']);
                 if (!$ssh_key) {
                     $response[] = ' --> ' . sprintf(_('Failed: SSH key is not %sdefined</a>.'), '<a href="' . getMenuURL(_('General')) . '">');
                     break;
                 }
                 $temp_ssh_key = sys_get_temp_dir() . '/fm_id_rsa';
                 if (file_exists($temp_ssh_key)) {
                     @unlink($temp_ssh_key);
                 }
                 if (@file_put_contents($temp_ssh_key, $ssh_key) === false) {
                     $response[] = ' --> ' . sprintf(_('Failed: could not load SSH key into %s.'), $temp_ssh_key);
                     break;
                 }
                 @chmod($temp_ssh_key, 0400);
                 $ssh_user = getOption('ssh_user', $_SESSION['user']['account_id']);
                 if (!$ssh_user) {
                     return sprintf('<p class="error">%s</p>' . "\n", sprintf(_('Failed: SSH user is not <a href="%s">defined</a>.'), getMenuURL(_('General'))));
                 }
                 unset($post_result);
                 exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$server_update_port} -l {$ssh_user} {$server_name} 'sudo php /usr/local/{$fm_name}/{$_SESSION['module']}/\$(ls /usr/local/{$fm_name}/{$_SESSION['module']} | grep php | grep -v functions) upgrade 2>&1'", $post_result, $retval);
                 @unlink($temp_ssh_key);
                 if ($retval) {
                     /** Something went wrong */
                     $post_result[] = _('Client upgrade failed.');
                 } else {
                     if (!count($post_result)) {
                         $post_result[] = _('Config build was successful.');
                         addLogEntry(sprintf(_('Upgraded client scripts on %s.'), $server_name));
                     }
                 }
                 if (count($post_result) > 1) {
                     /** Loop through and format the output */
                     foreach ($post_result as $line) {
                         if (strlen(trim($line))) {
                             $response[] = " --> {$line}";
                         }
                     }
                 } else {
                     $response[] = " --> " . $post_result[0];
                 }
                 break;
         }
         $response[] = null;
     }
     return implode("\n", $response);
 }
Beispiel #5
0
 /**
  * Tests server connectivity
  */
 function connectTests()
 {
     global $fmdb, $__FM_CONFIG;
     $return = null;
     /** Load ssh key for use */
     $ssh_key = getOption('ssh_key_priv', $_SESSION['user']['account_id']);
     $temp_ssh_key = sys_get_temp_dir() . '/fm_id_rsa';
     if ($ssh_key) {
         if (file_exists($temp_ssh_key)) {
             @unlink($temp_ssh_key);
         }
         $ssh_key_loaded = @file_put_contents($temp_ssh_key, $ssh_key);
         @chmod($temp_ssh_key, 0400);
     }
     $ssh_user = getOption('ssh_user', $_SESSION['user']['account_id']);
     /** Get server list */
     $result = basicGetList('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_name', 'server_');
     /** Process server list */
     $num_rows = $fmdb->num_rows;
     $results = $fmdb->last_result;
     for ($x = 0; $x < $num_rows; $x++) {
         $return .= sprintf(__("Running tests for %s\n"), $results[$x]->server_name);
         /** ping tests */
         $return .= "\t" . str_pad(__('Ping:'), 15);
         if (pingTest($results[$x]->server_name)) {
             $return .= __('success');
         } else {
             $return .= __('failed');
         }
         $return .= "\n";
         /** remote port tests */
         $return .= "\t" . str_pad(__('Remote Port:'), 15);
         if ($results[$x]->server_update_method != 'cron') {
             if (socketTest($results[$x]->server_name, $results[$x]->server_update_port, 10)) {
                 $return .= __('success') . ' (tcp/' . $results[$x]->server_update_port . ")\n";
                 if ($results[$x]->server_update_method == 'ssh') {
                     $return .= "\t" . str_pad(__('SSH Login:'******'no SSH key defined');
                     } elseif ($ssh_key_loaded === false) {
                         $return .= sprintf(__('could not load SSH key into %s'), $temp_ssh_key);
                     } elseif (!$ssh_user) {
                         $return .= __('no SSH user defined');
                     } else {
                         exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$results[$x]->server_update_port} -l {$ssh_user} {$results[$x]->server_name} uptime", $post_result, $retval);
                         if ($retval) {
                             $return .= __('ssh key login failed');
                         } else {
                             $return .= __('success');
                         }
                     }
                 } else {
                     /** php tests */
                     $return .= "\t" . str_pad(__('http page:'), 15);
                     $php_result = getPostData($results[$x]->server_update_method . '://' . $results[$x]->server_name . '/' . $_SESSION['module'] . '/reload.php', null);
                     if ($php_result == 'Incorrect parameters defined.') {
                         $return .= __('success');
                     } else {
                         $return .= __('failed');
                     }
                 }
             } else {
                 $return .= __('failed') . ' (tcp/' . $results[$x]->server_update_port . ')';
             }
         } else {
             $return .= __('skipping (host updates via cron)');
         }
         $return .= "\n";
         /** dns tests */
         $return .= "\t" . str_pad(__('DNS:'), 15);
         $port = 53;
         if (socketTest($results[$x]->server_name, $port, 10)) {
             $return .= __('success') . ' (tcp/' . $port . ')';
         } else {
             $return .= __('failed') . ' (tcp/' . $port . ')';
         }
         $return .= "\n";
         $return .= "\n";
     }
     @unlink($temp_ssh_key);
     return $return;
 }
Beispiel #6
0
/**
 * Runs the installer
 *
 * @since 1.0
 * @package facileManager
 */
function installFM($proto, $compress)
{
    global $argv, $module_name, $data;
    unset($data['SERIALNO']);
    echo fM("Welcome to the {$module_name} installer.\n\n");
    echo fM("Please answer the following questions and the necessary configurations will be performed for you.\n\n");
    /** facileManager host **/
    echo "Please enter the location of the facileManager interface:\n";
    echo "    Examples include:\n";
    echo "\tfm.mydomain.com\n";
    echo "\tfm.mydomain.com:8443\n";
    echo "\tmydomain.com/fm\n";
    echo "\thttp://fm.mydomain.com/facileManager\n\n";
    echo 'Please enter the location of the facileManager interface: ';
    if (defined('FMHOST')) {
        $serverhost = FMHOST;
        echo FMHOST . "\n";
    } else {
        $serverhost = trim(fgets(STDIN));
    }
    /** Get server name from input */
    $server_location = getServerPath($serverhost);
    extract($server_location);
    $data['config'] = array();
    /** Run tests */
    echo fM("  --> Testing {$hostname} via https...");
    if (socketTest($hostname, 443)) {
        echo "ok\n";
        $proto = 'https';
    } else {
        echo "failed\n";
        echo fM("  --> Testing {$hostname} via http...");
        if (socketTest($hostname, 80)) {
            echo "ok\n";
            $proto = 'http';
        } else {
            echo "failed\n\n";
            echo fM("Cannot access {$hostname} with http or https.  Please correct this before proceeding.\n");
            exit(1);
        }
    }
    $data['config'][] = array('FMHOST', 'facileManager server', $hostname . '/' . $path);
    /** Account key **/
    $key = 'default';
    while (!isset($key)) {
        echo fM('Please enter your account key: ');
        $key = trim(fgets(STDIN));
    }
    $data['compress'] = $compress;
    $data['AUTHKEY'] = $key;
    $data['config'][] = array('AUTHKEY', 'Account number', $key);
    /** Test the authentication */
    echo fM('  --> Checking account details...');
    $url = "{$proto}://{$hostname}/{$path}admin-accounts.php?verify";
    $raw_data = getPostData($url, $data);
    $raw_data = $data['compress'] ? @unserialize(gzuncompress($raw_data)) : @unserialize($raw_data);
    echo $raw_data . "\n\n";
    if ($raw_data != 'Success') {
        echo "Installation failed.  ";
        echo !strlen($raw_data) ? fM("Could not communicate properly with {$hostname}.  Failed to access {$url}.") : fM('Please check your account key.');
        echo "\n";
        exit(1);
    }
    /** Server serial number **/
    $data['server_name'] = exec('hostname -f', $output, $rc);
    if ($rc > 0 || empty($data['server_name'])) {
        $data['server_name'] = php_uname('n');
    }
    $data['server_os'] = PHP_OS;
    $data['server_os_distro'] = detectOSDistro();
    echo fM('Please enter the serial number for ' . $data['server_name'] . ' (or leave blank to create new): ');
    if (defined('SERIALNO')) {
        $serialno = $data['server_serial_no'] = SERIALNO;
        echo SERIALNO . "\n";
    } else {
        $serialno = trim(fgets(STDIN));
    }
    $url = "{$proto}://{$hostname}/{$path}admin-servers.php?genserial";
    /** Process new server */
    if (empty($serialno)) {
        /** Generate new serial number */
        echo fM('  --> Generating new serial number: ');
        $serialno = $data['server_serial_no'] = generateSerialNo($url, $data);
        echo $serialno . "\n";
    }
    /** Add new server */
    echo fM('  --> Adding ' . $data['server_name'] . ' to the database...');
    $add_server_result = moduleAddServer($url, $data);
    extract($add_server_result, EXTR_OVERWRITE);
    echo fM($add_result);
    $data['SERIALNO'] = $serialno;
    $data['config'][] = array('SERIALNO', 'Server unique serial number', $serialno);
    $data = installFMModule($module_name, $proto, $compress, $data, $server_location, $url);
    /** Save the file */
    saveFMConfigFile($data);
    /** Complete installation */
    $url = "{$proto}://{$hostname}/{$path}admin-servers.php?install";
    $raw_data = getPostData($url, $data);
    /** Add log entry */
    addLogEntry('Client installed successfully.');
    echo fM("Installation is complete. Please login to the UI to ensure the server settings are correct.\n");
    /** chmod and prepend php to this file */
    chmod($argv[0], 0755);
    $contents = file_get_contents($argv[0]);
    $bin = '#!' . findProgram('php');
    if (strpos($contents, $bin) === false) {
        $contents = $bin . "\n" . $contents;
        file_put_contents($argv[0], $contents);
    }
    exit;
}
Beispiel #7
0
 function buildZoneConfig($domain_id)
 {
     global $fmdb, $__FM_CONFIG, $fm_name;
     /** Check domain_id and soa */
     $parent_domain_ids = getZoneParentID($domain_id);
     if (!isset($parent_domain_ids[2])) {
         $query = "SELECT * FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}domains d, fm_{$__FM_CONFIG['fmDNS']['prefix']}soa s WHERE domain_status='active' AND d.account_id='{$_SESSION['user']['account_id']}' AND s.soa_id=d.soa_id AND d.domain_id IN (" . join(',', $parent_domain_ids) . ")";
     } else {
         $query = "SELECT * FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}domains d, fm_{$__FM_CONFIG['fmDNS']['prefix']}soa s WHERE domain_status='active' AND d.account_id='{$_SESSION['user']['account_id']}' AND\n\t\t\t\ts.soa_id=(SELECT soa_id FROM fm_dns_domains WHERE domain_id={$parent_domain_ids[2]})";
     }
     $result = $fmdb->query($query);
     if (!$fmdb->num_rows) {
         return sprintf('<p class="error">%s</p>' . "\n", __('Failed: There was no SOA record found for this zone.'));
     }
     $domain_details = $fmdb->last_result;
     extract(get_object_vars($domain_details[0]), EXTR_SKIP);
     $name_servers = $this->getNameServers($domain_name_servers, array('masters'));
     /** No name servers so return */
     if (!$name_servers) {
         return sprintf('<p class="error">%s</p>' . "\n", __('There are no DNS servers hosting this zone.'));
     }
     /** Loop through name servers */
     $name_server_count = $fmdb->num_rows;
     $response = '<textarea rows="12" cols="85">';
     $failures = false;
     for ($i = 0; $i < $name_server_count; $i++) {
         switch ($name_servers[$i]->server_update_method) {
             case 'cron':
                 /** Add records to fm_{$__FM_CONFIG['fmDNS']['prefix']}track_reloads */
                 foreach ($this->getZoneCloneChildren($domain_id) as $child_id) {
                     $this->addZoneReload($name_servers[$i]->server_serial_no, $child_id);
                 }
                 /** Set the server_update_config flag */
                 setBuildUpdateConfigFlag($name_servers[$i]->server_serial_no, 'yes', 'update');
                 $response .= '[' . $name_servers[$i]->server_name . '] ' . __('This zone will be updated on the next cron run.') . "\n";
                 break;
             case 'http':
             case 'https':
                 /** Test the port first */
                 if (!socketTest($name_servers[$i]->server_name, $name_servers[$i]->server_update_port, 10)) {
                     $response .= '[' . $name_servers[$i]->server_name . '] ' . sprintf(__('Failed: could not access %s (tcp/%d).'), $name_servers[$i]->server_update_method, $name_servers[$i]->server_update_port) . "\n";
                     $failures = true;
                     break;
                 }
                 /** Remote URL to use */
                 $url = $name_servers[$i]->server_update_method . '://' . $name_servers[$i]->server_name . ':' . $name_servers[$i]->server_update_port . '/' . $_SESSION['module'] . '/reload.php';
                 /** Data to post to $url */
                 $post_data = array('action' => 'reload', 'serial_no' => $name_servers[$i]->server_serial_no, 'domain_id' => $domain_id);
                 $post_result = unserialize(getPostData($url, $post_data));
                 if (!is_array($post_result)) {
                     /** Something went wrong */
                     return '<div class="error"><p>' . $post_result . '</p></div>' . "\n";
                 } else {
                     if (count($post_result) > 1) {
                         /** Loop through and format the output */
                         foreach ($post_result as $line) {
                             $response .= '[' . $name_servers[$i]->server_name . "] {$line}\n";
                             if (strpos(strtolower($line), 'fail')) {
                                 $failures = true;
                             }
                         }
                     } else {
                         $response .= "[{$name_servers[$i]->server_name}] " . $post_result[0] . "\n";
                         if (strpos(strtolower($post_result[0]), 'fail')) {
                             $failures = true;
                         }
                     }
                 }
                 /** Set the server_update_config flag */
                 setBuildUpdateConfigFlag($name_servers[$i]->server_serial_no, 'yes', 'update');
                 break;
             case 'ssh':
                 /** Test the port first */
                 if (!socketTest($name_servers[$i]->server_name, $name_servers[$i]->server_update_port, 10)) {
                     $response .= '[' . $name_servers[$i]->server_name . '] ' . sprintf(__('Failed: could not access %s (tcp/%d).'), $name_servers[$i]->server_update_method, $name_servers[$i]->server_update_port) . "\n";
                     $failures = true;
                     break;
                 }
                 /** Get SSH key */
                 $ssh_key = getOption('ssh_key_priv', $_SESSION['user']['account_id']);
                 if (!$ssh_key) {
                     return '<p class="error">' . sprintf(__('Failed: SSH key is not <a href="%s">defined</a>.'), getMenuURL(_('Settings'))) . '</p>' . "\n";
                 }
                 $temp_ssh_key = sys_get_temp_dir() . '/fm_id_rsa';
                 if (file_exists($temp_ssh_key)) {
                     @unlink($temp_ssh_key);
                 }
                 if (@file_put_contents($temp_ssh_key, $ssh_key) === false) {
                     return '<p class="error">' . sprintf(__('Failed: could not load SSH key into %s.'), $temp_ssh_key) . '</p>' . "\n";
                 }
                 @chmod($temp_ssh_key, 0400);
                 $ssh_user = getOption('ssh_user', $_SESSION['user']['account_id']);
                 if (!$ssh_user) {
                     return '<p class="error">' . sprintf(__('Failed: SSH user is not <a href="%s">defined</a>.'), getMenuURL(_('Settings'))) . '</p>' . "\n";
                 }
                 unset($post_result);
                 exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$name_servers[$i]->server_update_port} -l {$ssh_user} {$name_servers[$i]->server_name} 'sudo php /usr/local/{$fm_name}/{$_SESSION['module']}/dns.php zones id={$domain_id}'", $post_result, $retval);
                 @unlink($temp_ssh_key);
                 if (!is_array($post_result)) {
                     /** Something went wrong */
                     return sprintf('<p class="error">%s</p>' . "\n", $post_result);
                 } else {
                     if (!count($post_result)) {
                         $post_result[] = __('Zone reload was successful.');
                     }
                     if (count($post_result) > 1) {
                         /** Loop through and format the output */
                         foreach ($post_result as $line) {
                             $response .= '[' . $name_servers[$i]->server_name . "] {$line}\n";
                             if (strpos(strtolower($line), 'fail')) {
                                 $failures = true;
                             }
                         }
                     } else {
                         $response .= "[{$name_servers[$i]->server_name}] " . $post_result[0] . "\n";
                         if (strpos(strtolower($post_result[0]), 'fail')) {
                             $failures = true;
                         }
                     }
                 }
                 /** Set the server_update_config flag */
                 setBuildUpdateConfigFlag($name_servers[$i]->server_serial_no, 'yes', 'update');
                 break;
         }
     }
     $response .= "</textarea>\n";
     /** Reset the domain_reload flag */
     if (!$failures) {
         global $fm_dns_records;
         if (!isset($fm_dns_records)) {
             include ABSPATH . 'fm-modules/fmDNS/classes/class_records.php';
         }
         $fm_dns_records->updateSOAReload($domain_id, 'no');
     }
     addLogEntry(sprintf(__("Reloaded zone '%s'."), displayFriendlyDomainName($domain_name)));
     return $response;
 }