コード例 #1
0
ファイル: functions.php プロジェクト: pclemot/facileManager
/**
 * 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;
}
コード例 #2
0
     $module = $_POST['module_name'] ? $_POST['module_name'] : $_SESSION['module'];
     $data['server_serial_no'] = generateSerialNo($module);
 }
 if (array_key_exists('addserial', $_GET)) {
     /** Client expects an array for a good return */
     $data = $_POST;
     /** Does the record already exist for this account? */
     basicGet('fm_' . $__FM_CONFIG[$_POST['module_name']]['prefix'] . 'servers', $_POST['server_name'], 'server_', 'server_name');
     if ($fmdb->num_rows) {
         $server_array = $fmdb->last_result;
         $_POST['server_id'] = $server_array[0]->server_id;
         $update_server = moduleAddServer('update');
     } else {
         if (getOption('client_auto_register')) {
             /** Add new server */
             $add_server = moduleAddServer('add');
             if ($add_server !== true) {
                 $data = _('Could not add server to account.') . "\n";
             }
         } else {
             $data = _('Client automatic registration is not allowed.') . "\n";
         }
     }
 }
 /** Client installs */
 if (array_key_exists('install', $_GET)) {
     /** Set flags */
     $data = basicUpdate('fm_' . $__FM_CONFIG[$_POST['module_name']]['prefix'] . 'servers', $_POST['SERIALNO'], 'server_installed', 'yes', 'server_serial_no');
     if (function_exists('moduleCompleteClientInstallation')) {
         moduleCompleteClientInstallation();
     }