refresh("?m=server");
return;
}
if ( !isPortValid($rhost_port) ){
print_failure( enter_valid_ip );
$view->refresh("?m=server");
return;
}
require_once('includes/lib_remote.php');
$remote = new OGPRemoteLibrary($rhost_ip,$rhost_port,$encryption_key,$timeout);
$status = $remote->status_chk();
if($status === 0)
{
print_failure( agent_offline . "
" . could_not_add_server . " " . $rhost_ip );
echo create_back_button($_GET['m']);
return;
}
elseif($status === -1)
{
print_failure( encryption_key_mismatch . "
" . could_not_add_server . " " . $rhost_ip );
echo create_back_button($_GET['m']);
return;
}
$rhost_user_name = trim($remote->exec('echo %USERNAME%'));
if( $rhost_user_name == '%USERNAME%' ) $rhost_user_name = trim($remote->exec('whoami'));
$rhost_id = $db->addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$timeout,$use_nat,$display_public_ip);
if ( !$rhost_id )
{
print_failure( could_not_add_server ." ".$rhost_ip." ". to_db );
$view->refresh("?m=server");
return;
}
print_success( added_server ." $rhost_ip ". with_port ." $rhost_port ". to_db_succesfully );
$iplist = $remote->discover_ips();
if ( empty($iplist) )
print_failure( unable_discover ." ".$rhost_ip.". ". set_ip_manually );
else
{
print_success( found_ips ." (".implode(",",$iplist).") ". 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( failed_add_ip ." (".$remote_ip.") ". for_remote_server );
}
}
$view->refresh("?m=server");
return;
}
}
?>