@rem This is file x_general.cmd.
@rem This file has to be edited by the administrator to include all necessary routing information.
@rem The information included here is only for demonstration purposes, it does not represent real data.
@rem
@rem Network-Address at the tele-office
@rem |
@rem | Subnet-Mask to define the range Network-Address:Subnet-Mask of the tele-office
@rem | |
@rem | | external IP-Adress of VPN-Router at the tele-office
@rem | | |
@rem | | | local VPN-router to the tele-office
@rem | | | |
@rem | | | | local ISDN-router as backup-line to the tele-office
@rem | | | | |
@rem | | | | | Logging-level
@rem | | | | | | 0 = no logging
@rem | | | | | | 1 = logging all events
@rem | | | | | | 2 = logging all events
@rem | | | | | | + error popups
@rem | | | | | | 3 = logging off events
@rem | | | | | | + popups for all events
@rem | | | | | |
call %1 10.1.100.0 255.255.255.0 192.168.5.30 10.1.1.55 10.1.1.76 3
call %1 10.1.200.0 255.255.255.0 192.168.10.90 10.1.1.55 10.1.1.77 3
rem Please add additional lines with the same format as above if necessary .......
@echo off
rem Filename: x_routingN.cmd.
rem This is the main routing file.
rem It should be startet automatically at boot time.
rem Constants to specify.
rem Log-files to log events. Several names of log-files are possible.
rem Names must not include blanks!
rem Please set this environment variable to empty (not blank!)
rem to disable all logfiles.
set X_LogFiles=c:\routing_logfile.txt
rem Names of computers for including events in the event-log
rem Pease set this environment variable to empty (not blank!)
rem to disable this entries in the event-log.
set X_EventLogs=%COMPUTERNAME%
@rem Names of computers/users for popup messages
@rem Pease set this environment variable to empty (not blank!)
@rem to disable all popups.
set x_Popups=%COMPUTERNAME% Administrator
@rem Time delay between checks of the routes.
@rem Please be sure to define a correct value for program SLEEP.
@rem Otherwise SLEEP will terminate immediately without any error.
@rem This will result in PINGing all the time without any delay!!!
set x_TimeDelay=300
rem On every retry, routing checks if the Stopfile exist.
rem If it exists, routing stops automatically.
set x_StopFile=%TEMP%\stopfile.stop
rem Temporary directory with change-access for this process
set x_temp=%temp%
rem Log program start.
title Routing active ...
call x_log I 60000 Routing starts
:nextTurn
rem Save currents routes for comparison
route print >%x_temp%\x_routes.txt
rem Activate general table with routing command.
call x_general.cmd x_routing1.cmd
rem Time delay between routing retries.
sleep %x_TimeDelay% >nul
rem Check if Stopfile exists.
if [%x_StopFile]==[] goto nextTurn
if not exist %x_StopFile% goto nextTurn
rem Delete temporary files.
del %x_StopFile% 1>nul 2>nul
del %x_temp%\x_routes.txt 1>nul 2>nul
rem Log program stop.
call x_log I 60001 Routing stops
rem Fully exit program now.
exit
@echo off
@rem Filename: x_routing1.cmd.
@rem Functionality and parameters
@rem if ping PAR3 possible
@rem then route change PAR1 mask PAR2 PAR4 -p
@rem else route change PAR1 mask PAR2 PAR5 -p
@rem end (*if*)
@rem PAR6 = 0 for no logging
@rem 1 for logging all events
@rem 2 for logging all events and popups for error messages
@rem 3 for logging all events and popups for all events
@rem Assumtions:
@rem - %x_temp%\x_routes.txt holds the output of the route-command.
@rem - %x_temp% is set to a directory with change-access
rem Garantee that route exists.
findstr /r /c:" *%1 *%2 " %x_temp%\x_routes.txt >nul
if errorlevel 1 route add %1 mask %2 %4 >nul
rem Check if external firewall is accessible via ISP.
ping -n 3 -l 32 %3 | find "Reply from %3: bytes=32 time" >nul
if not errorlevel 1 goto isp_ok
rem Check if backup route has to be activated.
findstr /r /c:" *%1 *%2 *%5 " %x_temp%\x_routes.txt >nul
if not errorlevel 1 goto done
rem Active backup route.
route change %1 mask %2 %5 >nul
rem Do logging and popups according to logging-level.
if [%6]==[] goto done
if [%6]==[0] goto done
call x_log E 60003 Backup route to %1:%2 set up via %5
if not [%6]==[1] for %%a in (%x_popups%) do net send %%a Backup route to %1:%2 set up via %5 >nul
goto done
:isp_ok
rem Check if primary route has to be activated.
findstr /r /c:" *%1 *%2 *%4 " %x_temp%\x_routes.txt >nul
if not errorlevel 1 goto done
rem Active primary route.
route change %1 mask %2 %4 >nul
rem Do logging and popups according to logging-level.
if [%6]==[] goto done
if [%6]==[0] goto done
call x_log W 60002 Normal route to %1:%2 set up via %4
if [%6]==[3] for %%a in (%x_popups%) do net send %%a Normal route to %1:%2 set up via %4 >nul
:done
@echo off
@rem Filename: x_display1.cmd.
@rem Function: Displays if current route for PAR1:PAR2 is via PAR4 (ISP_OK) or PAR5 (BACKUP).
@rem Assumtion(s): %x_temp%\x_routesD.txt holds the output of the route-command.
set x_disp1=(UNDEF!!) Route %1:%2 undefined!! (%4 / %5 ??)
findstr /r /c:" *%1 *%2 *%4 " %x_temp%\x_routesD.txt >nul && set x_disp1=(ISP_OK) Route %1:%2 via %4
findstr /r /c:" *%1 *%2 *%5 " %x_temp%\x_routesD.txt >nul && set x_disp1=(BACKUP!) Route %1:%2 via %5
echo %x_disp1%
@echo off
@rem Filename: x_displayN.cmd.
@rem Function: This is a program to display the current local routing status on the screen.
@rem Assumtion(s): %temp% is set to a directory with change-access
rem Constant: Directory for temporary file(s)
set x_temp=%TEMP%
title Routing status
cls
echo Current routing status ...
rem Save currents routes for comparison
route print >%x_temp%\x_routesD.txt
rem Activate general table with display command.
call x_general.cmd x_display1.cmd
rem Delete temporary file.
del %x_temp%\x_routesD.txt 1>nul 2>nul
@echo off
@rem Filename: x_log.cmd.
@rem
@rem Parameters:
@rem PAR1 gives the severity code as needed for program LOGEVENT from the ResourceKit.
@rem PAR2 gives an event ID as needed/defined for program LOGEVENT from the ResourceKit.
@rem PAR3 to PARx define the message text
rem Is there anything to do?
if [%X_LogFiles%%X_EventLogs%]==[] goto done
rem Transfer a correct message type from PAR1 to ENV x_Severity.
set x_Severity=F
for %%a in (s S i I w W e E f F) do if [%%a]==[%1] set x_Severity=%%a
rem Transfer message type in readable form from PAR1 to ENV x_type.
set x_type= UNDEF!!!!
if [%1]==[s] set x_type= SUCCESS
if [%1]==[S] set x_type= SUCCESS
if [%1]==[i] set x_type=INFORMATION
if [%1]==[I] set x_type=INFORMATION
if [%1]==[w] set x_type= WARNING!
if [%1]==[W] set x_type= WARNING!
if [%1]==[e] set x_type= ERROR!!
if [%1]==[E] set x_type= ERROR!!
if [%1]==[f] set x_type= FAILURE!!!
if [%1]==[F] set x_type= FAILURE!!!
rem Save the ID of the event (PAR2).
set x_EventID=%2
rem Transfer all parameters starting with PAR3 to ENV x_msg.
set x_msg=
:x_msg
shift
set x_msg=%x_msg% %2
if not [%3]==[] goto x_msg
rem Check if log-function to logfile(s) needed.
if [%x_LogFiles%]==[] goto no_logfile
rem Get current date and time for logfile(s).
set x_time=xx:xx:xx
set x_date=xx-xx-xx
del %x_temp%\date_to_env.cmd 1>nul 2>nul
if exist %x_temp%\date_to_env.cmd goto no_date
envdate2 x >%x_temp%\date_to_env.cmd
if not exist %x_temp%\date_to_env.cmd goto no_date
call %x_temp%\date_to_env.cmd
del %x_temp%\date_to_env.cmd 1>nul 2>nul
:no_date
rem Write data to logfile(s).
for %%a in (%x_LogFiles%) do echo %x_date% %x_time% %COMPUTERNAME% %x_type% %x_msg% >>%%a
echo %x_date% %x_time% %COMPUTERNAME% %x_type% %x_msg%
:no_logfile
rem Create entry in the event log(s).
for %%a in (%x_EventLogs%) do logevent -m %%a -s %x_Severity% -r ROUTING -e %x_EventID% "%x_type% %x_msg%%" >nul
:done
/* Filename: EnvDate2.C */
#include <dos.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
char buf1[128], buf2[128];
if (argc!=2) return 1;
_strdate(buf1);
_strtime(buf2);
/* here we do not care of the problem that there might be */
/* midnight between retrieving time and retrieving date */
printf( "set %s_date=%c%c-%c%c-%c%c\n", argv[1], buf1[6], buf1[7], buf1[0], buf1[1], buf1[3], buf1[4]);
printf( "set %s_time=%s\n", argv[1], buf2);
return 0;
}