2010-01-16 11:39 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)

* contrib/hbnetio/utils/netiosrv.prg
    ! Fixed server not setting password.
    + Added command history support.
    + Added sysinfo command.
    + Added clipboard paste support.
    + Implemented suggestions by Przemek (QOUT(), HB_STRCLEAR())
This commit is contained in:
Viktor Szakats
2010-01-16 10:40:33 +00:00
parent 2c7b6af1ce
commit edba3b4829
2 changed files with 88 additions and 28 deletions

View File

@@ -17,6 +17,14 @@
past entries belonging to author(s): Viktor Szakats.
*/
2010-01-16 11:39 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbnetio/utils/netiosrv.prg
! Fixed server not setting password.
+ Added command history support.
+ Added sysinfo command.
+ Added clipboard paste support.
+ Implemented suggestions by Przemek (QOUT(), HB_STRCLEAR())
2010-01-16 09:53 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/contrib/hbwin/win_tprn.prg
* updated some comments

View File

@@ -25,6 +25,11 @@
#include "hbhrb.ch"
#include "color.ch"
#include "hbgtinfo.ch"
#include "inkey.ch"
#include "setcurs.ch"
/* netio_mtserver() needs MT HVM version */
REQUEST HB_MT
@@ -52,19 +57,24 @@ PROCEDURE Main( ... )
LOCAL cCommand
LOCAL cPassword
LOCAL aParam
LOCAL bKeyDown
LOCAL bKeyUp
LOCAL bKeyIns
LOCAL bKeyPaste
LOCAL GetList := {}
LOCAL aHistory, nHistIndex
HB_Logo()
netiosrv[ _NETIOSRV_nPort ] := 2941
netiosrv[ _NETIOSRV_cIFAddr ] := "0.0.0.0"
netiosrv[ _NETIOSRV_cRootDir ] := hb_dirBase()
netiosrv[ _NETIOSRV_cRootDir ] := hb_dirBase()
netiosrv[ _NETIOSRV_lRPC ] := .F.
netiosrv[ _NETIOSRV_lEncryption ] := .F.
aParam := hb_AParams()
FOR EACH cParam IN aParam
FOR EACH cParam IN { ... }
DO CASE
CASE Lower( Left( cParam, 6 ) ) == "-port="
netiosrv[ _NETIOSRV_nPort ] := Val( SubStr( cParam, 7 ) )
@@ -75,7 +85,6 @@ PROCEDURE Main( ... )
CASE Lower( Left( cParam, 6 ) ) == "-pass="
cPassword := SubStr( cParam, 7 )
hb_StrClear( @cParam )
hb_StrClear( @aParam[ cParam:__enumIndex() ] )
CASE Lower( Left( cParam, 5 ) ) == "-rpc="
netiosrv[ _NETIOSRV_cRPCFFileName ] := SubStr( cParam, 6 )
netiosrv[ _NETIOSRV_cRPCFHRB ] := hb_hrbLoad( netiosrv[ _NETIOSRV_cRPCFFileName ] )
@@ -99,14 +108,15 @@ PROCEDURE Main( ... )
SetCancel( .F. )
netiosrv[ _NETIOSRV_pListenSocket ] := netio_mtserver( netiosrv[ _NETIOSRV_nPort ],;
netiosrv[ _NETIOSRV_cIFAddr ],;
netiosrv[ _NETIOSRV_cRootDir ],;
iif( Empty( netiosrv[ _NETIOSRV_cRPCFHRB ] ), netiosrv[ _NETIOSRV_lRPC ], hb_hrbGetFunSym( netiosrv[ _NETIOSRV_cRPCFHRB ], _RPC_FILTER ) ),;
@cPassword )
netiosrv[ _NETIOSRV_pListenSocket ] := ;
netio_mtserver( netiosrv[ _NETIOSRV_nPort ],;
netiosrv[ _NETIOSRV_cIFAddr ],;
netiosrv[ _NETIOSRV_cRootDir ],;
iif( Empty( netiosrv[ _NETIOSRV_cRPCFHRB ] ), netiosrv[ _NETIOSRV_lRPC ], hb_hrbGetFunSym( netiosrv[ _NETIOSRV_cRPCFHRB ], _RPC_FILTER ) ),;
@cPassword )
netiosrv[ _NETIOSRV_lEncryption ] := ! Empty( cPassword )
hb_StrClear( @cPassword ) /* Attempt to clear plain text pw from memory */
cPassword := NIL
IF Empty( netiosrv[ _NETIOSRV_pListenSocket ] )
OutStd( "Cannot start server." + hb_osNewLine() )
@@ -116,12 +126,52 @@ PROCEDURE Main( ... )
OutStd( hb_osNewLine() )
OutStd( "hbnetiosrv command prompt:", hb_osNewLine() )
aHistory := { "quit" }
nHistIndex := Len( aHistory ) + 1
/* Command prompt */
DO WHILE .T.
OutStd( "hbnetiosrv$ " )
ACCEPT TO cCommand
OutStd( hb_osNewLine() )
cCommand := Space( 128 )
QQOut( "hbnetiosrv$ " )
@ Row(), Col() GET cCommand PICTURE "@S" + hb_ntos( MaxCol() - Col() + 1 ) COLOR hb_ColorIndex( SetColor(), CLR_STANDARD ) + "," + hb_ColorIndex( SetColor(), CLR_STANDARD )
SetCursor( iif( ReadInsert(), SC_INSERT, SC_NORMAL ) )
bKeyIns := SetKey( K_INS, ;
{|| SetCursor( iif( ReadInsert( ! ReadInsert() ), ;
SC_NORMAL, SC_INSERT ) ) } )
bKeyUp := SetKey( K_UP, ;
{|| iif( nHistIndex > 1, ;
cCommand := PadR( aHistory[ --nHistIndex ], Len( cCommand ) ), ) } )
bKeyDown := SetKey( K_DOWN, ;
{|| cCommand := PadR( iif( nHistIndex < Len( aHistory ), ;
aHistory[ ++nHistIndex ], ;
( nHistIndex := Len( aHistory ) + 1, "" ) ), Len( cCommand ) ) } )
bKeyPaste := SetKey( K_ALT_V, {|| hb_gtInfo( HB_GTI_CLIPBOARDPASTE ) } )
READ
SetKey( K_DOWN, bKeyPaste )
SetKey( K_DOWN, bKeyDown )
SetKey( K_UP, bKeyUp )
SetKey( K_INS, bKeyIns )
QQOut( hb_osNewLine() )
QQOut( hb_osNewLine() )
cCommand := AllTrim( cCommand )
IF Empty( aHistory ) .OR. ! ATail( aHistory ) == cCommand
IF Len( aHistory ) < 64
AAdd( aHistory, cCommand )
ELSE
ADel( aHistory, 1 )
aHistory[ Len( aHistory ) ] := cCommand
ENDIF
ENDIF
nHistIndex := Len( aHistory ) + 1
/* TODO: - on the fly change of RPC filter modules
- listing active connections
@@ -132,22 +182,24 @@ PROCEDURE Main( ... )
- showing number of open files
- listing transferred bytes
- gracefully shutting down server by waiting for connections to close and not accept new ones
- pausing server
- Command history with up/down
- More powerful cmdline editor
- cut/paste support */
- pausing server */
DO CASE
CASE Lower( cCommand ) == "quit"
EXIT
CASE Lower( cCommand ) == "config"
ShowConfig( netiosrv )
CASE Lower( cCommand ) == "sysinfo"
QQOut( "OS: " + OS(), hb_osNewLine() )
QQOut( "Harbour: " + Version(), hb_osNewLine() )
QQOut( "C Compiler: " + hb_Compiler(), hb_osNewLine() )
QQOut( "Memory: " + hb_ntos( Memory( 0 ) ) + "KB", hb_osNewLine() )
CASE Lower( cCommand ) == "help"
OutStd( "config - Show server configuration", hb_osNewLine() )
OutStd( "quit - Stop server and exit", hb_osNewLine() )
QQOut( "config - Show server configuration", hb_osNewLine() )
QQOut( "sysinfo - Show system/build information", hb_osNewLine() )
QQOut( "quit - Stop server and exit", hb_osNewLine() )
CASE ! Empty( cCommand )
OutStd( "Error: Unknown command.", hb_osNewLine() )
QQOut( "Error: Unknown command.", hb_osNewLine() )
ENDCASE
ENDDO
@@ -162,11 +214,11 @@ PROCEDURE Main( ... )
STATIC PROCEDURE ShowConfig( netiosrv )
OutStd( "Listening on: " + netiosrv[ _NETIOSRV_cIFAddr ] + ":" + hb_ntos( netiosrv[ _NETIOSRV_nPort ] ) + hb_osNewLine() )
OutStd( "Root filesystem: " + netiosrv[ _NETIOSRV_cRootDir ] + hb_osNewLine() )
OutStd( "RPC support: " + iif( netiosrv[ _NETIOSRV_lRPC ], "enabled", "disabled" ) + hb_osNewLine() )
OutStd( "Encryption: " + iif( netiosrv[ _NETIOSRV_lEncryption ], "enabled", "disabled" ) + hb_osNewLine() )
OutStd( "RPC filter module: " + iif( Empty( netiosrv[ _NETIOSRV_cRPCFHRB ] ), iif( netiosrv[ _NETIOSRV_lRPC ], "not set (WARNING: unsafe open server)", "not set" ), netiosrv[ _NETIOSRV_cRPCFFileName ] ) + hb_osNewLine() )
QQOut( "Listening on: " + netiosrv[ _NETIOSRV_cIFAddr ] + ":" + hb_ntos( netiosrv[ _NETIOSRV_nPort ] ), hb_osNewLine() )
QQOut( "Root filesystem: " + netiosrv[ _NETIOSRV_cRootDir ], hb_osNewLine() )
QQOut( "RPC support: " + iif( netiosrv[ _NETIOSRV_lRPC ], "enabled", "disabled" ), hb_osNewLine() )
QQOut( "Encryption: " + iif( netiosrv[ _NETIOSRV_lEncryption ], "enabled", "disabled" ), hb_osNewLine() )
QQOut( "RPC filter module: " + iif( Empty( netiosrv[ _NETIOSRV_cRPCFHRB ] ), iif( netiosrv[ _NETIOSRV_lRPC ], "not set (WARNING: unsafe open server)", "not set" ), netiosrv[ _NETIOSRV_cRPCFFileName ] ), hb_osNewLine() )
RETURN