2011-01-29 20:35 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)

* contrib/hbnetio/utils/hbnetioq/hbnetioq.hbp
  + contrib/hbnetio/utils/hbnetioq/manageips.ui
  * contrib/hbnetio/utils/hbnetioq/netiosrq.prg
  * contrib/hbnetio/utils/hbnetioq/netiosrq.qrc
  + contrib/hbnetio/utils/hbnetioq/refresh.png
    + Implemented: activate/deactivate banning IPs from connecting 
      to server. This implementation provides for the -ini=cINIFile 
      command line switch. <cINIFile> contains the info about IPs.
      User-interface to manage activations is via toolbar button 
      which allows to <Add><Delete><Save> IPs and also to flag 
      to activate/deactivate IPs on-the-go.

      TODO: take use of console daemon by separating the user inetrface.
            Hopefully by next week.
This commit is contained in:
Pritpal Bedi
2011-01-30 22:39:58 +00:00
parent 3742c1f6f6
commit 600de4ff05
6 changed files with 206 additions and 8 deletions

View File

@@ -16,6 +16,22 @@
The license applies to all entries newer than 2009-04-28.
*/
2011-01-30 14:38 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbnetio/utils/hbnetioq/hbnetioq.hbp
+ contrib/hbnetio/utils/hbnetioq/manageips.ui
* contrib/hbnetio/utils/hbnetioq/netiosrq.prg
* contrib/hbnetio/utils/hbnetioq/netiosrq.qrc
+ contrib/hbnetio/utils/hbnetioq/refresh.png
+ Implemented: activate/deactivate banning IPs from connecting
to server. This implementation provides for the -ini=cINIFile
command line switch. <cINIFile> contains the info about IPs.
User-interface to manage activations is via toolbar button
which allows to <Add><Delete><Save> IPs and also to flag
to activate/deactivate IPs on-the-go.
TODO: take use of console daemon by separating the user inetrface.
Hopefully by next week.
2011-01-30 20:00 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* src/rtl/Makefile
- src/rtl/base64.prg

View File

@@ -18,6 +18,8 @@
netiosrq.prg
netiosrq.qrc
manageips.ui
# Always build in shared mode for these platforms because the
# tool is included in std distro and we want to minimize its size.
{_HB_BUILD_&(!(HB_BUILD_DYN='no')&(win|wce|os2))}-shared

View File

@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogManageIPs</class>
<widget class="QDialog" name="DialogManageIPs">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>269</width>
<height>382</height>
</rect>
</property>
<property name="windowTitle">
<string>Manage Incoming Connections</string>
</property>
<widget class="QListWidget" name="listIPs">
<property name="geometry">
<rect>
<x>8</x>
<y>8</y>
<width>253</width>
<height>333</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="buttonAdd">
<property name="geometry">
<rect>
<x>8</x>
<y>352</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
<widget class="QPushButton" name="buttonDelete">
<property name="geometry">
<rect>
<x>96</x>
<y>352</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
<widget class="QPushButton" name="buttonSave">
<property name="geometry">
<rect>
<x>184</x>
<y>352</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -40,7 +40,8 @@ REQUEST __HB_EXTERN__
#define _NETIOSRV_nCompressionLevel 9
#define _NETIOSRV_nStrategy 10
#define _NETIOSRV_cPassword 11
#define _NETIOSRV_MAX_ 11
#define _NETIOSRV_cINI 12
#define _NETIOSRV_MAX_ 12
#define DAT_CONNSOCKET 1
#define DAT_SERIAL 2
@@ -80,6 +81,8 @@ Function Main( ... )
FOR EACH cParam IN { ... }
DO CASE
CASE Lower( Left( cParam, 5 ) ) == "-ini="
netiosrv[ _NETIOSRV_cINI ] := AllTrim( SubStr( cParam, 6 ) )
CASE Lower( Left( cParam, 6 ) ) == "-port="
netiosrv[ _NETIOSRV_nPort ] := Val( SubStr( cParam, 7 ) )
CASE Lower( Left( cParam, 7 ) ) == "-iface="
@@ -139,6 +142,7 @@ Function Main( ... )
/*----------------------------------------------------------------------*/
CLASS NetIOServer
DATA netiosrv
DATA nNumConxn INIT 0
DATA oDlg
DATA oBrw
@@ -155,6 +159,7 @@ CLASS NetIOServer
DATA lChanging INIT .f.
DATA lQuit INIT .f.
DATA nCurRec INIT 1
DATA aIPs INIT {}
DATA aData INIT { { NIL, ; // hSock
0 , ; // nSerial
.F., ; // lActive
@@ -192,6 +197,8 @@ CLASS NetIOServer
METHOD lastRec()
METHOD recNo()
METHOD goto( nRec )
METHOD readINI()
METHOD manageIPs()
ENDCLASS
@@ -205,6 +212,8 @@ METHOD NetIOServer:new()
METHOD NetIOServer:create( netiosrv )
LOCAL nEvent, mp1, mp2, oXbp
::netiosrv := netiosrv
netiosrv[ _NETIOSRV_pListenSocket ] := ;
netio_mtserver( netiosrv[ _NETIOSRV_nPort ],;
netiosrv[ _NETIOSRV_cIFAddr ],;
@@ -224,6 +233,8 @@ METHOD NetIOServer:create( netiosrv )
ELSE
QResource():registerResource_1( hbqtres_netiosrq(), ":/resource" )
::readINI()
::pMtx := hb_mutexCreate()
::cTitle := "NetIO Server [ " + netiosrv[ _NETIOSRV_cIFAddr ] + " : " + ;
ltrim( str( int( netiosrv[ _NETIOSRV_nPort ] ) ) ) + " : " + ;
@@ -272,11 +283,12 @@ METHOD NetIOServer:create( netiosrv )
/*----------------------------------------------------------------------*/
METHOD NetIOServer:custom_netio_server( pConnectionSocket )
::register_connection( pConnectionSocket )
BEGIN SEQUENCE
netio_server( pConnectionSocket )
END SEQUENCE
::unregister_connection( pConnectionSocket )
IF ::register_connection( pConnectionSocket )
BEGIN SEQUENCE
netio_server( pConnectionSocket )
END SEQUENCE
::unregister_connection( pConnectionSocket )
ENDIF
RETURN NIL
/*----------------------------------------------------------------------*/
@@ -294,6 +306,10 @@ METHOD NetIOServer:register_connection( pConnectionSocket )
ENDIF
ENDIF
IF !empty( ::aIPs ) .AND. ascan( ::aIPs, {|e_| e_[ 1 ] == cIP .AND. e_[ 2 ] == "Y" } ) > 0
RETURN .f.
ENDIF
IF hb_mutexLock( ::pMtx )
IF ::aData[ 1,2 ] == 0
::aData[ 1 ] := { pConnectionSocket, 1, .t., pad( cIP, 15 ), nPort, dtoc( date() ) + " " + time(), space( 18 ), 0, 0, 0 }
@@ -306,7 +322,7 @@ METHOD NetIOServer:register_connection( pConnectionSocket )
::oDlg:title := ::cTitle + " - " + ltrim( str( ::nNumConxn, 6, 0 ) )
::refresh()
RETURN NIL
RETURN .t.
/*----------------------------------------------------------------------*/
@@ -330,7 +346,7 @@ METHOD NetIOServer:unregister_connection( pConnectionSocket )
/*----------------------------------------------------------------------*/
METHOD NetIOServer:execEvent( cEvent, p )
LOCAL qEvent, oMenu, txt_, s
LOCAL qEvent, oMenu, txt_, s, cTmp, cTmp1, qItem, n, oXbp
SWITCH cEvent
CASE "browser_contextMenu"
@@ -368,6 +384,9 @@ METHOD NetIOServer:execEvent( cEvent, p )
CASE "Exit"
PostAppEvent( xbeP_Quit, , , ::oDlg )
EXIT
CASE "IPs"
::manageIPs()
EXIT
ENDSWITCH
EXIT
CASE "QEvent_WindowStateChange"
@@ -412,12 +431,103 @@ METHOD NetIOServer:execEvent( cEvent, p )
CASE "qSystemTrayIcon_close"
PostAppEvent( xbeP_Quit, NIL, NIL, ::oDlg )
EXIT
CASE "ips_buttonDelete"
IF p:q_listIPs:currentRow() >= 0
qItem := p:q_listIPs:takeItem( p:q_listIPs:currentRow() )
IF ( n := ascan( ::aIPs, {|e_| e_[ 1 ] == qItem:text() } ) ) > 0
hb_adel( ::aIPs, n, .t. )
ENDIF
ENDIF
EXIT
CASE "ips_buttonSave"
FOR n := 1 TO p:q_listIPs:count()
qItem := p:q_listIPs:item( n - 1 )
IF ( n := ascan( ::aIPs, {|e_| e_[ 1 ] == qItem:text() } ) ) > 0
::aIPs[ n, 2 ] := iif( qItem:checkState() == Qt_Checked, "Y", " " )
ENDIF
NEXT
oXbp := XbpFileDialog():new( ::oDlg ):create()
oXbp:title := "File name to save IPs ?"
oXbp:center := .t.
cTmp := oXbp:saveAs( iif( empty( ::netiosrv[ _NETIOSRV_cINI ] ), "", ::netiosrv[ _NETIOSRV_cINI ] ) )
IF ! empty( cTmp )
cTmp1 := ""
aeval( ::aIPs, {|e_| cTmp1 += "netiosrv_ip=" + e_[ 1 ] + ";" + e_[ 2 ] + chr( 13 ) + chr( 10 ) } )
hb_memowrit( cTmp, cTmp1 )
ENDIF
p:done( 0 )
EXIT
CASE "ips_buttonAdd"
IF ! empty( cTmp := QInputDialog():getText( ::oDlg:oWidget, "Manage Connections", "IPv4:IPv6:" ) )
qItem := QListWidgetItem()
qItem:setFlags( Qt_ItemIsUserCheckable + Qt_ItemIsEnabled + Qt_ItemIsSelectable )
qItem:setText( cTmp )
qItem:setCheckState( 0 )
p:q_listIPs:addItem( qItem )
aadd( ::aIPs, { cTmp, " " } )
ENDIF
EXIT
ENDSWITCH
RETURN 0
/*----------------------------------------------------------------------*/
METHOD NetIOServer:manageIPs()
LOCAL oUI, a_, qItem
oUI := hbqtui_ManageIPs( ::oDlg:oWidget )
oUI:setWindowFlags( Qt_Dialog )
oUI:q_buttonAdd:connect( "clicked()", {|| ::execEvent( "ips_buttonAdd", oUI ) } )
oUI:q_buttonDelete:connect( "clicked()", {|| ::execEvent( "ips_buttonDelete", oUI ) } )
oUI:q_buttonSave:connect( "clicked()", {|| ::execEvent( "ips_buttonSave", oUI ) } )
FOR EACH a_ IN ::aIPs
qItem := QListWidgetItem()
qItem:setFlags( Qt_ItemIsUserCheckable + Qt_ItemIsEnabled + Qt_ItemIsSelectable )
qItem:setText( a_[ 1 ] )
qItem:setCheckState( iif( empty( a_[ 2 ] ), Qt_Unchecked, Qt_Checked ) )
oUI:q_listIPs:addItem( qItem )
NEXT
oUI:exec()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD NetIOServer:readINI()
LOCAL cBuffer, aTxt, s, n
IF empty( ::netiosrv[ _NETIOSRV_cINI ] )
RETURN Self
ENDIF
IF hb_fileExists( ::netiosrv[ _NETIOSRV_cINI ] )
cBuffer := hb_memoread( ::netiosrv[ _NETIOSRV_cINI ] )
IF ! empty( cBuffer )
aTxt := hb_atokens( strtran( cBuffer, chr( 13 ) ), chr( 10 ) )
FOR EACH s IN aTxt
s := alltrim( s )
IF left( lower( s ), 11 ) == "netiosrv_ip"
IF ( n := at( "=", s ) ) > 0
s := alltrim( substr( s, n + 1 ) )
IF ( n := at( ";", s ) ) > 0
aadd( ::aIPs, { substr( s, 1, n-1 ), substr( s, n+1 ) } )
ELSE
aadd( ::aIPs, { s, " " } )
ENDIF
ENDIF
ENDIF
NEXT
ENDIF
ENDIF
RETURN Self
/*----------------------------------------------------------------------*/
METHOD NetIOServer:showDlgBySystemTrayIconCommand()
::oSys:hide()
@@ -740,6 +850,7 @@ METHOD NetIOServer:buildToolBar()
oTBar:addItem( "Exit" , ":/exit.png" , , , , , "Exit" )
oTBar:addItem( , , , , , XBPTOOLBAR_BUTTON_SEPARATOR )
oTBar:addItem( "Terminate", ":/terminate.png", , , , , "Terminate" )
oTBar:addItem( "ManageIPs", ":/refresh.png" , , , , , "IPs" )
oTBar:addItem( "About" , ":/about.png" , , , , , "About" )
oTBar:addItem( "Help" , ":/help.png" , , , , , "Help" )

View File

@@ -6,5 +6,6 @@
<file>help.png</file>
<file>about.png</file>
<file>terminate.png</file>
<file>refresh.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB