--- joko/ToolBox/Windows/VpnDial/src/Module_Main.bas 2005/10/07 20:59:27 1.5 +++ joko/ToolBox/Windows/VpnDial/src/Module_Main.bas 2005/10/08 00:22:10 1.6 @@ -15,10 +15,25 @@ ' http://www.activevb.de/rubriken/apikatalog/deklarationen/rasenumentries.html ' http://www.dotnet247.com/247reference/msgs/18/93960.aspx +' contains all ras entry objects Public RasEntries As New Collection + +' globals to store connection name and state Public ConnectionName As String Public ConnectionOnline As Boolean -Public ScriptName_Up As String, ScriptName_Down As String + +' globals to store information about action to do on up|down +Enum ActionTypes + RUN_SCRIPT + ADD_ROUTE +End Enum +Public ActionType As ActionTypes + +Public ScriptName As String +Public RouteNet As String, RouteMask As String + +Const RouteMaskDefault As String = "255.255.255.0" + Sub Main() @@ -94,12 +109,21 @@ conName = cmdline.getArgument("monitor") If conName <> "" Then - If cmdline.hasSwitch("up") Then - ScriptName_Up = cmdline.getArgument("up") + ' run script + If cmdline.hasSwitch("script") Then + ActionType = RUN_SCRIPT + ScriptName = cmdline.getArgument("script") End If - If cmdline.hasSwitch("down") Then - ScriptName_Down = cmdline.getArgument("down") + ' add a route with target network via gateway + If cmdline.hasSwitch("net") Then + ActionType = ADD_ROUTE + RouteNet = cmdline.getArgument("net") + If cmdline.hasSwitch("mask") Then + RouteMask = cmdline.getArgument("mask") + Else + RouteMask = RouteMaskDefault + End If End If 'Set rasItem = RasEntries(conName) @@ -141,38 +165,46 @@ ' callback from MonitorRASStatusAsync Public Sub detectOnlineOfflineChange() - Dim newState As Boolean + Dim isOnline As Boolean Dim script_name As String, script_args As String Dim cmd As String - newState = RasIsOnline(ConnectionName) + isOnline = RasIsOnline(ConnectionName) - If ConnectionOnline <> newState Then - 'MsgBox newState - - ' connection goes online - If newState = True Then - If ScriptName_Up <> "" Then - script_name = ScriptName_Up - End If - - ' connection goes offline - Else - If ScriptName_Down <> "" Then - script_name = ScriptName_Down - End If + If ConnectionOnline <> isOnline Then + 'MsgBox isOnline - End If + Select Case ActionType + + Case RUN_SCRIPT: + script_name = ScriptName + If script_name <> "" Then + script_args = Chr(34) & DetermineClientIP(ConnectionName) & Chr(34) & " " & Chr(34) & DetermineServerIP(ConnectionName) & Chr(34) + cmd = App.Path & "\" & script_name & " " & script_args + End If + + Case ADD_ROUTE: + ' connection goes online + If isOnline = True Then + script_name = "route" + script_args = "add " & RouteNet & " mask " & RouteMask & " " & DetermineClientIP(ConnectionName) + cmd = script_name & " " & script_args + + ' connection goes offline + Else + ' Nothing to do in this case + + End If + + End Select - If script_name <> "" Then - script_args = Chr(34) & DetermineClientIP(ConnectionName) & Chr(34) & " " & Chr(34) & DetermineServerIP(ConnectionName) & Chr(34) - cmd = App.Path & "\" & script_name & " " & script_args + If cmd <> "" Then 'MsgBox cmd On Error Resume Next Shell cmd, vbHide On Error GoTo 0 End If - ConnectionOnline = newState + ConnectionOnline = isOnline End If End Sub