2012-05-08 17:43:45 +02:00
< ? php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
2013-04-10 09:57:54 +02:00
$id_agente = get_parameter ( " id_agente " );
// This extension is usefull only if the agent has associated IP
$address = agents_get_address ( $id_agente );
2013-04-23 13:02:18 +02:00
if ( ! empty ( $address ) || empty ( $id_agente )) {
2013-04-10 09:57:54 +02:00
extensions_add_opemode_tab_agent ( 'ssh_gateway' , 'SSH Gateway' , 'extensions/ssh_gateway/secure_console.png' , " ssh_gateway " , " v1r1 " );
}
2012-05-08 17:43:45 +02:00
function ssh_gateway () {
2012-07-10 11:21:19 +02:00
2012-05-08 17:43:45 +02:00
$SERVER_ADDR = $_SERVER [ 'SERVER_ADDR' ];
2012-07-10 11:21:19 +02:00
2012-05-08 17:43:45 +02:00
$HOST = get_parameter ( " host " , " " );
$USER = get_parameter ( " user " , " " );
2013-04-12 13:10:13 +02:00
$PORT = get_parameter ( " port " , 0 );
2012-07-10 11:21:19 +02:00
2012-05-08 17:43:45 +02:00
// TODO: Put aditional filtering for ";" and "&" characters in user & host for security
// because these params are passed to server exec() call :)
2012-07-10 11:21:19 +02:00
2012-05-08 17:43:45 +02:00
$COMMIT = get_parameter ( " commit " , 0 );
$MODE = get_parameter ( " mode " , " ssh " );
2012-07-10 11:21:19 +02:00
2012-05-08 17:43:45 +02:00
if ( $MODE == " telnet " )
$USER = " <auto> " ;
2012-07-10 11:21:19 +02:00
2012-05-08 17:43:45 +02:00
$id_agente = get_parameter ( " id_agente " );
2013-04-23 13:02:18 +02:00
2013-04-10 09:57:54 +02:00
$ip = db_get_sql ( " SELECT direccion FROM tagente WHERE id_agente = $id_agente " );
2012-07-10 11:21:19 +02:00
if ( $HOST == " " )
2012-05-08 17:43:45 +02:00
$HOST = $ip ;
2012-07-10 11:21:19 +02:00
if (( $HOST == " " ) OR ( $USER == " " )) {
if ( $COMMIT == 1 ) {
2013-05-23 17:42:32 +02:00
ui_print_error_message ( __ ( " You need to specify a user and a host address " ));
2012-05-08 17:43:45 +02:00
}
2013-04-23 13:02:18 +02:00
2012-05-08 17:43:45 +02:00
echo " <form method=post> " ;
echo " <table class=databox cellspacing=4 cellpadding=4> " ;
echo " <td> " . __ ( " Host address " ) . " <td><input type=text size=25 value=' $HOST ' name=host> " ;
echo " <tr> " ;
2013-10-11 13:59:27 +02:00
echo " <td> " . __ ( " User " ) . " <td><input type=text size=25 value=' $USER ' name=user> " . ui_print_help_tip ( __ ( 'For security reasons the following characters are not allowed: %s' , '< > | ` $ ; &' ), true );
2013-04-12 13:10:13 +02:00
echo " <tr> " ;
2013-04-23 13:02:18 +02:00
echo " <td> " . __ ( " Port (use 0 for default) " ) . " <td><input type=text size=5 value=' $PORT ' name=port> " ;
2012-05-08 17:43:45 +02:00
echo " <tr><td> " ;
echo __ ( " Connect mode " ) . " <td><select name=mode> " ;
2012-07-10 11:21:19 +02:00
if ( $MODE == " telnet " ) {
2012-05-08 17:43:45 +02:00
echo " <option>telnet " ;
echo " <option>ssh " ;
2012-07-10 11:21:19 +02:00
}
else {
2012-05-08 17:43:45 +02:00
echo " <option>ssh " ;
echo " <option>telnet " ;
2012-07-10 11:21:19 +02:00
}
2012-05-08 17:43:45 +02:00
echo " </select> " ;
2012-07-10 11:21:19 +02:00
2012-05-08 17:43:45 +02:00
echo " <input type=submit name=connect class='sub upd' value= " . __ ( " Connect " ) . " > " ;
echo " <td><input type=hidden name=commit value=1> " ;
echo " </form></table> " ;
}
2012-07-10 11:21:19 +02:00
2012-05-08 17:43:45 +02:00
else {
2013-04-23 13:02:18 +02:00
if ( $MODE == " telnet " ) {
if ( $PORT == 0 )
$PORT = 23 ;
}
else {
if ( $PORT == 0 )
$PORT = 22 ;
}
2012-05-08 17:43:45 +02:00
if ( $MODE == " ssh " )
2013-04-12 13:10:13 +02:00
echo " <iframe style='border: 0px' src='http:// " . $SERVER_ADDR . " :8022/anyterm.html?param=-p $PORT $USER @ $HOST ' width='100%' height=550> " ;
2012-05-08 17:43:45 +02:00
else
2013-04-12 13:10:13 +02:00
echo " <iframe style='border: 0px' src='http:// " . $SERVER_ADDR . " :8023/anyterm.html?param= $HOST $PORT ' width='100%' height=550> " ;
2012-07-10 11:21:19 +02:00
echo " </iframe> " ;
2012-05-08 17:43:45 +02:00
}
}
2013-04-10 09:57:54 +02:00
?>