;TIMECHEK 1.2 - Calculate online time for ISP ;*************************************************************************** ;* TIMECHEK.WAS * ;* Copyright (C) 1993 Datastorm Technologies, Inc. * ;* All rights reserved. * ;* * ;* Written by: Larry Dorman * ;* * ;* TIMECHEK will open the connection log maintained by PROCOMM PLUS 3.x * ;* for Windows and determine the number of connections and the total time * ;* connected to the selected dial up internet service provider for a given * ;* month. * ;* * ;* TIMECHEK returns a report indicating the number of connections to the * ;* selected service, the average time per connection, the total time used, * ;* and the free time remaining. Free time remaining is obtained by * ;* subtracting time used from user input free hours available. * ;* * ;* This ASPECT SCRIPT is intended only as a sample of ASPECT * ;* programming. DATASTORM makes no warranty of any kind, express or * ;* implied, including without limitation, any warranties of * ;* merchantability and/or fitness for a particular purpose. Use of * ;* this program is at your own risk. * ;* * ;*************************************************************************** ;*************************************************************************** ;* Global Definitions * ;*************************************************************************** ;----------------------- Number of Free Hours ----------------------------- ; Change the '20' to the number of hours you want used as the default. #define DEFFREEHOURS 20 ;Default # of free hours for service ;--------------- DO NOT CHANGE ANYTHING BELOW THIS LINE------------------- #define TIMEKEY "DISCONNECT -" ;Key to find time lines in log file #define NOERROR 0 ;No error has occured #define CANCELLED 1 ;User cancelled action #define LOGNOTFOUND 2 ;Log file couldn't be located #define CANTOPENSVCLIST 3 ;Can't open SVCLIST file ;*************************************************************************** ;* Global Variables * ;*************************************************************************** integer MonthNum ;Month number string NumHours ;Number of hours string SvcName ;Service Name string SvcList = $PWLOCALPATH ;Service list data file string StatsTitle ;Title for stats dialog string Stats1 ;Output line for stats dialog string Stats2 ;Output line for stats dialog string Stats3 ;Output line for stats dialog string Stats4 ;Output line for stats dialog ;*************************************************************************** ;* Main * ;* * ;* Calls: GetSvcNames,GetParams,SearchLog,ShowStats,ShowError * ;*************************************************************************** proc Main integer Error = NOERROR ;Error code integer NumCalls = 0 ;Number of calls integer FreeHours = DEFFREEHOURS ;Number of free hours long MinUsed = 0 ;Total minutes used GetSvcNames(&Error) ;Get the Service Name if ! Error ;Continue if no error GetParams(&Error,&FreeHours) ;Get parameters to work in endif if ! Error ;Continue if no error SearchLog(&Error,&NumCalls,&MinUsed) ;Search log file for info endif if ! Error ;Continue if no error ShowStats(FreeHours,NumCalls,MinUsed) ;Show data for service provider endif if Error ShowError(Error) ;Show any errors that occured endif endproc ;*************************************************************************** ;* GetSvcNames (Integer) * ;* * ;* Fetch current service name and determine whether it is a dial up * ;* connection or a network connection. * ;* * ;* Called by: Main * ;* Calls: None * ;*************************************************************************** proc GetSvcNames param integer Error ;Error code integer DialUp = 0 ;DialUp flag integer SvcCount ;Number of services setup integer ConNumber ;Connection Number string OrigSvc ;Original service addfilename SvcList "SVCLIST.DAT" ;Add file name to path fetch internet connection OrigSvc ;Get original service name if fopen 0 SvcList create text ;Open service list file itemcount internet connection SvcCount ;Count number of services if SvcCount ;If there are any services SvcCount -- ;Reduce service count by 1 for ConNumber = 0 upto SvcCount ;Go through each service set internet connection ConNumber ;Set as current service fetch internet connection SvcName DialUp ;Get name of service if DialUp ;Is this a dial up service? fputs 0 SvcName ;Put it in the service list endif endfor fclose 0 ;Close the file set internet connection OrigSvc ;Restore original service fetch internet connection OrigSvc DialUp if DialUp strcpy SvcName OrigSvc endif endif else Error = CANTOPENSVCLIST ;If file wasn't opened, set error endif endproc ;*************************************************************************** ;* GetParams (Integer,Integer) * ;* * ;* Get number of free hours included with service and month to compute * ;* time used for. * ;* * ;* Called by: Main * ;* Calls: DrawDialog1 * ;*************************************************************************** proc GetParams param integer Error ;Error code param integer FreeHours ;Number of free hours integer Event = 0 ;Dialog event ID string Month ;Month to use strfmt NumHours "%d" FreeHours ;Number of hours as a string substr Month $DATE 0 2 ;Get current month atoi Month MonthNum ;Convert month to a number DrawDialog1() ;Draw dialog box for input while ! Event ;Wait for event dlgevent 0 Event ;Return event ID if Event < 18 ;If event isn't OK or Cancel Event = 0 ;Zero out event, not needed endif endwhile if Event == 19 ;If cancel was selected Error = CANCELLED ;Return error status endif atoi NumHours FreeHours ;Set number of free hours endproc ;*************************************************************************** ;* DrawDialog1 () * ;* * ;* Draw dialog box to get input from user. * ;* * ;* Called by: GetParams * ;* Calls: None * ;*************************************************************************** proc DrawDialog1 dialogbox 0 168 64 103 143 7 "Parameters" fcombobox 13 3 13 97 45 dropdownlist SVCLIST SvcName sort text 14 3 4 57 8 "Selected Service" left editbox 15 78 31 20 12 NumHours 4 text 16 3 33 74 8 "Free Hours per Month:" left radiogroup 17 MonthNum radiobutton 1 5 48 45 10 "January" radiobutton 2 5 61 45 10 "February" radiobutton 3 5 74 45 10 "March" radiobutton 4 5 87 45 10 "April" radiobutton 5 5 100 45 10 "May" radiobutton 6 5 113 45 10 "June" radiobutton 7 53 48 45 10 "July" radiobutton 8 53 61 45 10 "August" radiobutton 9 53 74 45 10 "September" radiobutton 10 53 87 45 10 "October" radiobutton 11 53 100 45 10 "November" radiobutton 12 53 113 45 10 "December" endgroup pushbutton 18 8 128 40 12 "O&K" ok default pushbutton 19 56 128 40 12 "Ca&ncel" cancel enddialog endproc ;*************************************************************************** ;* SearchLog (Integer,Integer,Long) * ;* * ;* Search connection log file for connections to service provider and add * ;* up connect times. * ;* * ;* Called by: Main * ;* Calls: OpenLog,CheckDate,LogTime * ;*************************************************************************** proc SearchLog param integer Error ;Error code param integer NumCalls ;Number of calls param long MinUsed ;Minutes used integer Usable ;Usable data flag string LineOfData ;Line of data OpenLog(&Error) ;Open log file if ! Error ;Continue if no error while not feof 0 ;While not end of file fgets 0 LineOfData ;Get a line of data CheckDate(&Usable,LineOfData) ;Check the date of the entry if Usable ;Does line have usable data? if strfind LineOfData TIMEKEY matchcase ;Does this line contain time data? if strfind LineOfData SvcName matchcase ;Is this line for the correct service? LogTime(&MinUsed,LineOfData) ;Log the time used NumCalls ++ ;Increment number of calls endif endif endif endwhile endif endproc ;*************************************************************************** ;* OpenLog (Integer) * ;* * ;* Open the connection log file. * ;* * ;* Called by: SearchLog * ;* Calls: None * ;*************************************************************************** proc OpenLog param integer Error string ConLog = $PWLOCALPATH ;Connection log location addfilename ConLog "PW3.GLC" ;Append file name if not fopen 0 CONLOG READ TEXT ;Open the connection log Error = LOGNOTFOUND ;Unable to open, log as error endif endproc ;*************************************************************************** ;* CheckDate (Integer,String) * ;* * ;* See if data falls in correct date range. * ;* * ;* Called by: SearchLog * ;* Calls: None * ;*************************************************************************** proc CheckDate param integer Usable ;Usable data flag param string LineOfData ;Line of data integer LogMonth ;Month in log file string Month ;Month Usable = 0 ;Set as unusable strextract Month LineOfData "/" 0 ;Get month number atoi Month LogMonth ;Convert to number if MonthNum == LogMonth ;Is it the same month? Usable = 1 ;Mark as usable data endif endproc ;*************************************************************************** ;* LogTime (Long,String) * ;* * ;* Log the time used on this connection in minutes. One minute is added * ;* as a buffer to account for partial minutes. * ;* * ;* Called by: SearchLog * ;* Calls: None * ;*************************************************************************** proc LogTime param long MinUsed ;Minutes used param string LineOfData ;Line of data integer Hours ;Number of hours integer Minutes ;Number of minutes string HourField ;Hour field string MinuteField ;Minute field string TimeField ;Time field strextract TimeField LineOfData "`t" 2 ;Pull time field from line of data substr HourField TimeField 0 2 ;Pull hour field from time field substr MinuteField TimeField 3 2 ;Pull minute field from time field atoi HourField Hours ;Convert hour field to number atoi MinuteField Minutes ;Convert minute field to number MinUsed += ((Hours*60)+Minutes)+1 ;Calculate minutes used and increment total endproc ;*************************************************************************** ;* ShowStats (Integer,Integer,Long) * ;* * ;* Generate and display stats for the selected connection. * ;* * ;* Called by: Main * ;* Calls: CalcHourMin,DrawDialog2 * ;*************************************************************************** proc ShowStats param integer FreeHours ;Number of free hours param integer NumCalls ;Total number of calls param long MinUsed ;Total minutes used integer Event ;Event flag long AvgMins ;Average minutes used long FreeMins ;Free minutes long MinsLeft ;Minutes left string Month ;Month monthstr MonthNum Month ;Convert number to month name strfmt StatsTitle "Service statistics for %s" Month ;Format title with month strfmt Stats1 "%d" NumCalls ;Format number of calls Stats2 = CalcHourMin(MinUsed) ;Format time used if NumCalls ;If calls have been made AvgMins = MinUsed / NumCalls ;Calculate average minutes per call else Avgmins = 0 ;Average call is 0 minutes endif Stats3 = CalcHourMin(AvgMins) ;Format average time FreeMins = FreeHours * 60 ;Calculate number free minutes MinsLeft = FreeMins - MinUsed ;Caculate minutes left Stats4 = CalcHourMin(MinsLeft) ;Format time left DrawDialog2() ;Generate stats dialog while ! Event ;Wait for an event dlgevent 0 Event ;Check for event if Event != 8 ;Check for finish button Event = 0 ;Reset event endif endwhile endproc ;*************************************************************************** ;* CalcHourMin (Long) * ;* * ;* Convert minutes to hours and minutes and return formatted string. * ;* * ;* Called by: ShowStats * ;* Calls: None * ;*************************************************************************** func CalcHourMin : string param long MinUsed ;Minutes used integer Hours ;Hours integer Minutes ;Minutes string LineOfData ;Formatted line of data Hours = MinUsed / 60 ;Calculate hours Minutes = MinUsed - (Hours*60) ;Calculate minutes strfmt LineOfData "%02d hours %02d minutes" Hours,Minutes ;Format hours and minutes return LineOfData ;Return formatted data endfunc ;*************************************************************************** ;* DrawDialog2 * ;* * ;* Display formatted stats. * ;* * ;* Called by: ShowStats * ;* Calls: None * ;*************************************************************************** proc DrawDialog2 dialogbox 0 0 0 180 92 7 StatsTitle text 2 1 10 70 8 "Service Name:" right text 3 1 22 70 8 "Number of Calls:" right text 4 1 34 70 8 "Total Time Used:" right text 5 1 46 70 8 "Average Call Time:" right text 6 1 58 70 8 "Free Time Available:" right pushbutton 8 3 78 173 12 "Finished" ok default text 9 73 10 100 8 SvcName left text 10 73 22 100 8 Stats1 left text 11 73 34 100 8 Stats2 left text 12 73 46 100 8 Stats3 left text 13 73 58 100 8 Stats4 left enddialog endproc ;*************************************************************************** ;* ShowError (Integer) * ;* * ;* Let user know what type of error has occured. * ;* * ;* Called by: Main * ;* Calls: None * ;*************************************************************************** proc ShowError param integer Error switch Error case 1 usermsg "Cancel selected. Script completed." endcase case 2 usermsg "Unable to locate defined log file. Script completed." endcase case 3 usermsg "Unable to create service list file. Script completed." endcase endswitch endproc