Exemplo n.º 1
0
function exec_ogp_module()
{
    global $view;
    global $db;
    #This will add a remote host to the list
    if (isset($_REQUEST['add_remote_host'])) {
        $rhost_ip = trim($_POST['remote_host']);
        $rhost_name = trim($_POST['remote_host_name']);
        $rhost_user_name = trim($_POST['remote_host_user_name']);
        $rhost_port = trim($_POST['remote_host_port']);
        $rhost_ftp_ip = trim($_POST['remote_host_ftp_ip']);
        $rhost_ftp_port = trim($_POST['remote_host_ftp_port']);
        $encryption_key = trim($_POST['remote_encryption_key']);
        $timeout = trim($_POST['timeout']);
        $use_nat = trim($_POST['use_nat']);
        if (empty($rhost_ip)) {
            print_failure(get_lang('enter_ip_host'));
            $view->refresh("?m=server");
            return;
        }
        if (empty($rhost_user_name)) {
            print_failure(get_lang('enter_unix_user_name'));
            $view->refresh("?m=server");
            return;
        }
        if (!isPortValid($rhost_port)) {
            print_failure(get_lang('enter_valid_ip'));
            $view->refresh("?m=server");
            return;
        }
        $rhost_id = $db->addRemoteServer($rhost_ip, $rhost_name, $rhost_user_name, $rhost_port, $rhost_ftp_ip, $rhost_ftp_port, $encryption_key, $timeout, $use_nat);
        if (!$rhost_id) {
            print_failure("" . get_lang('could_not_add_server') . " " . $rhost_ip . " " . get_lang('to_db') . "");
            $view->refresh("?m=server");
            return;
        }
        print_success("" . get_lang('added_server') . " {$rhost_ip} " . get_lang('with_port') . " {$rhost_port} " . get_lang('to_db_succesfully') . "");
        require_once 'includes/lib_remote.php';
        $remote = new OGPRemoteLibrary($rhost_ip, $rhost_port, $encryption_key);
        $iplist = $remote->discover_ips();
        if (empty($iplist)) {
            print_failure("" . get_lang('unable_discover') . " " . $rhost_ip . ". " . get_lang('set_ip_manually') . "");
        } else {
            print_success("" . get_lang('found_ips') . " (" . implode(",", $iplist) . ") " . get_lang('for_remote_server') . "");
            foreach ($iplist as $remote_ip) {
                $remote_ip = trim($remote_ip);
                if (empty($remote_ip)) {
                    continue;
                }
                if (!$db->addRemoteServerIp($rhost_id, $remote_ip)) {
                    print_failure("" . get_lang('failed_add_ip') . " (" . $remote_ip . ") " . get_lang('for_remote_server') . "");
                }
            }
        }
        $view->refresh("?m=server");
        return;
    }
}