2011-02-01 00:32 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)

* contrib/hbnetio/utils/hbnetio/netiosrv.prg
  * contrib/hbnetio/utils/hbnetio/netiocon.prg
    + Added console commands to add/remove filters.
    + Added rpc and console commands to list filters.
This commit is contained in:
Viktor Szakats
2011-01-31 23:33:54 +00:00
parent b96ebc81ea
commit 654d35ce81
3 changed files with 94 additions and 18 deletions

View File

@@ -16,6 +16,12 @@
The license applies to all entries newer than 2009-04-28.
*/
2011-02-01 00:32 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbnetio/utils/hbnetio/netiosrv.prg
* contrib/hbnetio/utils/hbnetio/netiocon.prg
+ Added console commands to add/remove filters.
+ Added rpc and console commands to list filters.
2011-01-31 22:50 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* src/rtl/hbfilehi.prg
+ PATHNORMALIZE(): Will now strip double pathseps, except the
@@ -238,7 +244,7 @@
+ src/rtl/base64d.c
+ Replaced HB_BASE64DECODE() with an optimized C implementation.
The core code is borrowed from libb64 project
(http://sourceforge.net/projects/libb64) and has been places
(http://sourceforge.net/projects/libb64) and has been placed
to public domain by author Chris Venter.
I've reformatted the code and made some minor modifications.
I had used the Harbour license for the whole file.

View File

@@ -56,23 +56,33 @@ PROCEDURE hbnetiocon_cmdUI( cIP, nPort, cPassword )
nHistIndex := Len( aHistory ) + 1
hCommands := { ;
"?" => { "" , "Synonym for 'help'." , {|| cmdHelp( hCommands ) } },;
"exit" => { "" , "Exit console." , {|| lQuit := .T. } },;
"clear" => { "" , "Clear screen." , {|| Scroll(), SetPos( 0, 0 ) } },;
"connect" => { "[<ip[:port>]]" , "Connect." , {| cCommand | cmdConnect( cCommand, @pConnection, @cIP, @nPort ) } },;
"disconnect" => { "" , "Disconnect." , {|| cmdDisconnect( @pConnection ) } },;
"sysinfo" => { "" , "Show system/build information." , {|| cmdSysInfo( pConnection ) } },;
"showconf" => { "" , "Show server configuration." , {|| cmdServerConfig( pConnection ) } },;
"show" => { "" , "Show list of connections." , {|| cmdConnInfo( pConnection, .F. ) } },;
"showadmin" => { "" , "Show list of management connections." , {|| cmdConnInfo( pConnection, .T. ) } },;
"noconn" => { "" , "Disable incoming connections." , {|| cmdConnEnable( pConnection, .F. ) } },;
"conn" => { "" , "Enable incoming connections." , {|| cmdConnEnable( pConnection, .T. ) } },;
"nologconn" => { "" , "Disable logging incoming connections." , {|| cmdConnLogEnable( pConnection, .F. ) } },;
"logconn" => { "" , "Enable logging incoming connections." , {|| cmdConnLogEnable( pConnection, .T. ) } },;
"stop" => { "[<ip:port>|all]", "Stop specified connection(s)." , {| cCommand | cmdConnStop( pConnection, cCommand ) } },;
"clientinfo" => { "[<ip:port>" , "Show client details." , {| cCommand | cmdConnClientInfo( pConnection, cCommand ) } },;
"quit" => { "" , "Stop server and exit console." , {|| cmdShutdown( pConnection ), lQuit := .T. } },;
"help" => { "" , "Display this help." , {|| cmdHelp( hCommands ) } } }
"?" => { "" , "Synonym for 'help'." , {|| cmdHelp( hCommands ) } },;
"exit" => { "" , "Exit console." , {|| lQuit := .T. } },;
"clear" => { "" , "Clear screen." , {|| Scroll(), SetPos( 0, 0 ) } },;
"connect" => { "[<ip[:port>]]" , "Connect." , {| cCommand | cmdConnect( cCommand, @pConnection, @cIP, @nPort ) } },;
"disconnect" => { "" , "Disconnect." , {|| cmdDisconnect( @pConnection ) } },;
"sysinfo" => { "" , "Show system/build information." , {|| cmdSysInfo( pConnection ) } },;
"showconf" => { "" , "Show server configuration." , {|| cmdServerConfig( pConnection ) } },;
"show" => { "" , "Show list of connections." , {|| cmdConnInfo( pConnection, .F. ) } },;
"showadmin" => { "" , "Show list of management connections." , {|| cmdConnInfo( pConnection, .T. ) } },;
"noconn" => { "" , "Disable incoming connections." , {|| cmdConnEnable( pConnection, .F. ) } },;
"conn" => { "" , "Enable incoming connections." , {|| cmdConnEnable( pConnection, .T. ) } },;
"nologconn" => { "" , "Disable logging incoming connections." , {|| cmdConnLogEnable( pConnection, .F. ) } },;
"logconn" => { "" , "Enable logging incoming connections." , {|| cmdConnLogEnable( pConnection, .T. ) } },;
"filt" => { "" , "Show filters." , {|| cmdConnFilters( pConnection, .F. ) } },;
"filtadmin" => { "" , "Show filters for management connections." , {|| cmdConnFilters( pConnection, .T. ) } },;
"allowadd" => { "<ip|host>" , "Add allow filter" , {| cCommand | cmdConnFilterMod( pConnection, cCommand, "hbnetiomgm_allowadd" ) } },;
"allowdel" => { "<ip|host>" , "Remove allow filter" , {| cCommand | cmdConnFilterMod( pConnection, cCommand, "hbnetiomgm_allowdel" ) } },;
"blockadd" => { "<ip|host>" , "Add block filter" , {| cCommand | cmdConnFilterMod( pConnection, cCommand, "hbnetiomgm_blockadd" ) } },;
"blockdel" => { "<ip|host>" , "Remove block filter" , {| cCommand | cmdConnFilterMod( pConnection, cCommand, "hbnetiomgm_blockdel" ) } },;
"allowaddadmin" => { "<ip|host>" , "Add allow filter for management connections" , {| cCommand | cmdConnFilterMod( pConnection, cCommand, "hbnetiomgm_allowaddadmin" ) } },;
"allowdeladmin" => { "<ip|host>" , "Remove allow filter for management connections" , {| cCommand | cmdConnFilterMod( pConnection, cCommand, "hbnetiomgm_allowdeladmin" ) } },;
"blockaddadmin" => { "<ip|host>" , "Add block filter for management connections" , {| cCommand | cmdConnFilterMod( pConnection, cCommand, "hbnetiomgm_blockaddadmin" ) } },;
"blockdeladmin" => { "<ip|host>" , "Remove block filter for management connections" , {| cCommand | cmdConnFilterMod( pConnection, cCommand, "hbnetiomgm_blockdeladmin" ) } },;
"stop" => { "[<ip:port>|all]", "Stop specified connection(s)." , {| cCommand | cmdConnStop( pConnection, cCommand ) } },;
"clientinfo" => { "[<ip:port>" , "Show client details." , {| cCommand | cmdConnClientInfo( pConnection, cCommand ) } },;
"quit" => { "" , "Stop server and exit console." , {|| cmdShutdown( pConnection ), lQuit := .T. } },;
"help" => { "" , "Display this help." , {|| cmdHelp( hCommands ) } } }
lQuit := .F.
@@ -520,3 +530,40 @@ STATIC PROCEDURE cmdConnLogEnable( pConnection, lValue )
ENDIF
RETURN
STATIC PROCEDURE cmdConnFilterMod( pConnection, cCommand, cRPC )
LOCAL aToken
IF Empty( pConnection )
QQOut( "Not connected.", hb_eol() )
ELSE
aToken := hb_ATokens( cCommand, " " )
IF Len( aToken ) > 1
IF netio_funcexec( pConnection, cRPC, aToken[ 1 ] )
QQOut( "Done", hb_eol() )
ELSE
QQOut( "Failed", hb_eol() )
ENDIF
ELSE
QQOut( "Error: Invalid syntax.", hb_eol() )
ENDIF
ENDIF
RETURN
STATIC PROCEDURE cmdConnFilters( pConnection, lManagement )
LOCAL aArray
LOCAL hFilter
IF Empty( pConnection )
QQOut( "Not connected.", hb_eol() )
ELSE
aArray := netio_funcexec( pConnection, iif( lManagement, "hbnetiomgm_filtersadmin", "hbnetiomgm_filters" ) )
FOR EACH hFilter IN aArray
QQOut( hFilter[ "cType" ],;
hFilter[ "cAddress" ], hb_eol() )
NEXT
ENDIF
RETURN

View File

@@ -221,6 +221,8 @@ PROCEDURE Main( ... )
"hbnetiomgm_allowdeladmin" => {| ... | netiomgm_rpc_filtermod( netiomgm, netiomgm[ _NETIOSRV_hAllow ], .F., ... ) } ,;
"hbnetiomgm_blockaddadmin" => {| ... | netiomgm_rpc_filtermod( netiomgm, netiomgm[ _NETIOSRV_hBlock ], .T., ... ) } ,;
"hbnetiomgm_blockdeladmin" => {| ... | netiomgm_rpc_filtermod( netiomgm, netiomgm[ _NETIOSRV_hBlock ], .F., ... ) } ,;
"hbnetiomgm_filters" => {| ... | netiomgm_rpc_filters( netiosrv ) } ,;
"hbnetiomgm_filtersadmin" => {| ... | netiomgm_rpc_filters( netiomgm ) } ,;
"hbnetiomgm_stop" => {| ... | netiomgm_rpc_stop( netiosrv, ... ) } ,;
"hbnetiomgm_conn" => {| ... | netiomgm_rpc_conn( netiosrv, .T. ) } ,;
"hbnetiomgm_noconn" => {| ... | netiomgm_rpc_conn( netiosrv, .F. ) } ,;
@@ -620,6 +622,27 @@ STATIC FUNCTION netiomgm_rpc_filtermod( netiosrv, hList, lAdd, cAddress )
RETURN lSuccess
STATIC FUNCTION netiomgm_rpc_filters( netiosrv )
LOCAL cType
LOCAL hFilter
LOCAL cAddress
LOCAL aArray := {}
hb_mutexLock( netiosrv[ _NETIOSRV_mtxFilters ] )
FOR EACH cType, hFilter IN { "allow", "block" }, { netiosrv[ _NETIOSRV_hAllow ], netiosrv[ _NETIOSRV_hBlock ] }
FOR EACH cAddress IN hFilter
AAdd( aArray, {;
"cType" => cType,;
"cAddress" => cAddress:__enumKey() } )
NEXT
NEXT
hb_mutexUnlock( netiosrv[ _NETIOSRV_mtxFilters ] )
RETURN aArray
STATIC FUNCTION ConnStatusStr( nStatus )
SWITCH nStatus