Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
function detectChrootDir()
{
    switch (PHP_OS) {
        case 'Linux':
            $os = detectOSDistro();
            if (in_array($os, array('Redhat', 'CentOS', 'ClearOS', 'Oracle'))) {
                if ($chroot_dir = getParameterValue('^ROOTDIR', '/etc/sysconfig/named')) {
                    return $chroot_dir;
                }
            }
            if (in_array($os, array('Debian', 'Ubuntu', 'Fubuntu'))) {
                if ($flags = getParameterValue('^OPTIONS', '/etc/default/bind9')) {
                    $flags = explode(' ', $flags);
                    if (in_array('-t', $flags)) {
                        return $flags[array_search('-t', $flags) + 1];
                    }
                }
            }
            break;
        case 'OpenBSD':
            $chroot_dir = '/var/named';
            foreach (array('/etc/rc.conf.local', '/etc/rc.conf') as $rcfile) {
                if ($chroot_dir = getParameterValue('^named_chroot', $rcfile)) {
                    break;
                }
            }
            return $chroot_dir;
        case 'FreeBSD':
            if ($chroot_dir = getParameterValue('^named_chroot', '/etc/rc.conf')) {
                return $chroot_dir;
            }
            if ($flags = getParameterValue('^named_flags', '/etc/rc.conf')) {
                $flags = explode(' ', $flags);
                if (in_array('-t', $flags)) {
                    return $flags[array_search('-t', $flags) + 1];
                }
            }
    }
    return null;
}
Ejemplo n.º 3
0
function getStartupScript($fw)
{
    $distros = array('iptables' => array('Arch' => findProgram('systemctl') . ' reload iptables', 'Debian' => findProgram('iptables-restore') . ' < __FILE__', 'Ubuntu' => findProgram('iptables-restore') . ' < __FILE__', 'Fubuntu' => findProgram('iptables-restore') . ' < __FILE__', 'Fedora' => '/etc/init.d/iptables restart', 'Redhat' => '/etc/init.d/iptables restart', 'CentOS' => '/etc/init.d/iptables restart', 'ClearOS' => '/etc/init.d/iptables restart', 'Oracle' => '/etc/init.d/iptables restart', 'SUSE' => findProgram('service') . ' SuSEfirewall2 restart', 'Gentoo' => findProgram('iptables-restore') . ' < __FILE__', 'Slackware' => '/etc/rc.d/rc.iptables restart'), 'pf' => array('FreeBSD' => findProgram('pfctl') . ' -d -F all -f __FILE__', 'OpenBSD' => findProgram('pfctl') . ' -d -F all -f __FILE__'), 'ipfilter' => array('FreeBSD' => findProgram('ipf') . ' -Fa -f __FILE__', 'SunOS' => findProgram('ipf') . ' -Fa -f __FILE__'), 'ipfw' => array('FreeBSD' => findProgram('sh') . ' __FILE__', 'Apple' => findProgram('sh') . ' __FILE__'));
    $os = detectOSDistro();
    if (array_key_exists($os, $distros[$fw])) {
        return $distros[$fw][$os];
    }
    return false;
}