HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

[hylafax-users] Resend Utility for Windows



I've got several Hylafax servers running at branch offices using WHFC as the client software. I couldn't find an easy way to re-send failed faxes from within WHFC if the retries were exceeded so I set out searching google and ran across a decent little command line utility written by Phil Abercrombie in April of 1997. The script was targeted to linux command line and you would have to already know the number of the failed job. Most of my users are nowhere near experienced enough to ssh into a server and run a command to resend a fax so I used the best parts of Phil's script and packaged it up into a neat Perl/Tk package that can be packaged with perl2exe and installed on the end users machine. The utility is configured with a config.ini file placed in the same directory with the script or packaged exe file and/or dlls (if -tiny was passed to perl2exe). Code for the utility and example INI file are included below. Code should run on just about any platform with Perl & Tk..Feel free to use this as you see fit.

Thanks,
Brent Davidson


------------------- Fax_Resend.pl ------------------- #!/usr/bin/perl # Window Hylafax Resend Utility # (c) Copyright Brent Davidson - March 2008 # based on original command line script written by # (c) Copyright Phil Abercrombie - April 1997 # This is distributed under the GPL and is # free for ANY use. Do not redistrbiute # without providing source code. use strict; use warnings; use Net::FTP; require Tk; use Tk; use Tk::Dialog; use Tk::DialogBox; use Tk::Optionmenu; use Config::Tiny;

########## Define the Main Window ##########
my $mw=MainWindow->new(); # Create new Main Window container


########## Config Section ##########
my $Config = Config::Tiny->new(); # Create new config fiel object
$Config = Config::Tiny->read( 'config.ini' ); # Read config file


# Set global config variables from INI file
my $USERNAME = $Config->{setup}->{username} || errmsg ("Missing username entry in config.ini"); my $PASSWD = $Config->{setup}->{password} || errmsg ("Missing password entry in config.ini");
my $FAXSERVER = $Config->{setup}->{server} || errmsg ("Missing server entry in config.ini");
my $HYLAFAX = $Config->{setup}->{port} || 4559; # Default to port 4556 if no port specified in config.ini
my $debug = $Config->{setup}->{debug} || 0; # Default to no debugging unless specified in config.ini



########## Static Config ########## my $mwxsize = 410; # Main Window X Size my $mwysize = 150; # Main Window y Size

########## Globals ##########
my @jobs;
my @frslist;
my $frsjob;
my @srslist;
my $srsjob;
my $hfax;

########## Draw GUI Objects ##########
my @mwsize; # Create array to hold Main Window Size
push (@mwsize,"$mwxsize"); # Push Main Window width into size array
push (@mwsize,"$mwysize"); # Push Main Window height into size array
$mw->minsize(@mwsize); # Set Main Window Minimum size
$mw->maxsize(@mwsize); # Set Main Window Maximum size
$mw->title("Resend Fax"); # Set Main Window Title
my $swidth = $mw->screenwidth(); # Get users current screen width
my $sheight = $mw->screenheight(); # Get users currrent screen height
my $mwx=($swidth /2) - ($mwxsize/2); # Set Main Window X Start position to display main window center screen
my $mwy=($sheight /2) - ($mwysize/2); # Set Main Window X Start position to display main window center screen
$mw->MoveToplevelWindow($mwx,$mwy); # Move Main Window to calculated center screen position



# Create a frame in the main window to hold status message line and
# progress bar. Frame upper let corner is at 0,350 in main window.
# Frame spans entire width (400 Pixels) and is 45 Pixels high
my $statbar = $mw -> Frame()-> place(-width=>$mwxsize, -height=>30, -x=>0, -y=>0);
#$statbar->bind("<Destroy>"=>\&unmap); # Bind a call to our Quit routine to be sure drives were unmapped
# if the "X" box gets clicked. This could be bound to any of the
# main window objects or even the Main Window itself, although binding
# to the main window causes the code to be run multiple times.



# Create a text label in the status bar frame with # font ansi 10 bold. The "pack" command # centers the Label in the frame my $status = $statbar -> Label(-font=>"ansi 10 bold") -> pack;

my $fjlab = $mw -> Label(-text=>"Failed Jobs:", -font=>"ansi 10 bold") -> place(-x=>5, -y=> 30);

# create a drop-down menu to hold the list of Failed jobs available for resend.
my $fjoblist = $mw ->Optionmenu(-anchor=> 'w', -options=>\@frslist, -variable=>\$frsjob)->place(-x=>5,-y=>50,-width=>290);


# Create a Button labeled "Resend Failed" in the main window
# with a width of 60 pixels and bind it to procedure "fresend()" my $fresendb = $mw -> Button(-text=>"Resend Failed", -command=>\&fresend)->place(-x=>300, -y=>50, -width=>100);


my $sjlab = $mw -> Label(-text=>"Successfully Completed Jobs:", -font=>"ansi 10 bold") -> place(-x=>5, -y=> 90);

# create a drop-down menu to hold the list of Completed jobs available for resend.
my $sjoblist = $mw ->Optionmenu(-anchor=> 'w', -options=>\@srslist, -variable=>\$srsjob)->place(-x=>5,-y=>110,-width=>290);


# Create a Button labeled "Resend Completed" in the main window
# with a width of 60 pixels and bind it to procedure "fresend()"
my $sresendb = $mw -> Button(-text=>"Resend Completed", -command=>\&sresend)->place(-x=>300, -y=>110, -width=>100);


########## END GUI Objects ##########

########## Main Program :-P ##########
$mw->update(); # Update the main window to make sure everything is visible
hfconnect(); # Initialize connection to HylaFax Server
status ("Select Job to Resend."); # Place status message in Status bar MainLoop(); # Tk Main Loop interrupt handler.
########## Main Program :-P ##########



########## Sub hfconnect ##########
# Connect to Hylafax Server
sub hfconnect {
# Initialize the connection or dissplay an error message and exit
status ("Connecting to fax server..."); #Tell the user what we're doing
$hfax = new Net::FTP $FAXSERVER, Port=>$HYLAFAX or errmsg("Can't connect to fax server $FAXSERVER:$HYLAFAX"); $hfax->debug($debug); # Set debug state per config variable status ("Logging in."); #Tell the user what we're doing
$hfax->quot("USER", $USERNAME); # Login to server
if (check(331)){ # Check to see if Password is required
$hfax->quot("PASS", $PASSWD); # If yes, send password
check(); # Check to see if command completed successfully
} status("Retrieving job list..."); #Tell the user what we're doing
@jobs = $hfax->dir("doneq"); # Get a list of jobs currently in the "Done" queue in detailed format
check(); # Check to see if command completed successfully
parsejobs(); # populate the drop-down menu
}
########## END Sub hfconnect ##########


########## Sub parsejobs ##########
# Populate the drop-down menu
sub parsejobs {
status ("Populating menus."); # Tell the user what we're doing
foreach my $job (@jobs) { # loop through list of completed jobs retrieved from server
my ($jnum,$date,$time, $code, $user, $pnum, $pages, $retries, $err) = split (/\s+/,$job,9); # split desired info out of job listing
# note that not all of the info extracted above is used in this version.
# You can use the variables above as needed but be sure to look at the formatting
# of the data in each variable. Uncomment the next line if you want to
# look at all of the data fields. # dbgmsg ("$jnum,$date,$time, $code, $user, $pnum, $pages, $retries, $err"); if ($code eq 'F') { # If job code is failed
$fjoblist->addOptions("$jnum: $pnum - $err"); # Add this job to the list of failed jobs
} else { # otherwise job completed successfully
$sjoblist->addOptions("$jnum: $pnum"); # Add this job to the list of successful jobs
}
}
}
########## END Sub parsejobs ##########


########## Sub check ##########
# Check for successful completion
# of hylafax commands or compare
# return code to desired value
sub check(@){
my $code = $hfax->code; # Get current return code from hfax FTP object
return $code if grep($_==$code,@_); # if code passed as parameter is equal to the current status code we return the current code
return if $hfax->ok; # If Status is "OK" then we return nothing.
errmsg (sprintf ("%3d %s", $code)." $hfax->message"); # If the status code is not equal to code passed as parameter and
# status code is not "OK" then we print an error message and exit }
########## END Sub check ##########


########## Sub Fresend ##########
# Resend Failed job
sub fresend {
my ($job,undef) = split (/:/,$frsjob,2); # Split job number out of selected item
resend($job); # Begin re-send procedure
}
########## END Sub Fresend ##########


########## Sub Sresend ##########
# Resend completed/Successful job
sub sresend {
my ($job,undef) = split (/:/,$srsjob,2); # Split job number out of selected item
resend($job); # Begin re-send procedure }
########## END Sub Sresend ##########



########## Sub resend ##########
# resend job
sub resend {
my $job = shift @_; # Get job code passed as parameter
my @docs; # Init holder for list of documents in original fax
status("Preparing to resend Job #$job."); # Let the user know what we're doing
my $cx = $hfax->retr("doneq/q$job"); # Retrieve previous job data and store in $cx virtual file
check(); # Check to see if command completed successfully
while(<$cx>) { # Sift through data from previous send attempt
push(@docs,$2) if (/^!?(postscript|tiff):.*(docq.*)$/); # keep track of all tiff and postscript parts
} # by storing them in the @docs list
$cx->close; # close the virtual file
check(); # Check to see if command completed successfully status("Resend in progress."); # Let the user know what we're doing
$hfax->quot("JOB",$job); # Tell the server we want Job related commands
check(); # Check to see if the server says "OK"
$hfax->quot("JNEW"); # Tell the server we want to start a new job
check(); # Check to see if the server says "OK"
for(@docs) { # Walk through the pieces from the previous attempt
$hfax->quot("JPARM","DOCUMENT","$_"); # And add each piece to the new job
check(); # Make sure the server accepts the command
} $hfax->quot("JPARM", "SENDTIME", "NOW"); # Set job's sendtime
check(); # Make sure the server accepts the command
$hfax->quot("JPARM", "LASTTIME", "000259"); # Set job's killtime
check(); # Make sure the server accepts the command $hfax->quot("JSUBM"); # Submit the job
check(); # Make sure the command completed successfully
my ($jobno)= $hfax->message =~ /Job (\d+)/; # Get the number of the new job from Hylafax Server
status("Job $jobno submitted as clone of job $job\n"); # Let the user know that the job has been submitted
}
########## END Sub resend ##########



########## Sub ErrMsg ##########
# Display error messages
sub errmsg { # Universal Error Handler
my $message = shift @_; # Get the message from the call
$message = "Error: $message Exiting."; # Add some formatting to the message
my $response = $mw -> messageBox(-message=>$message, # Create a dialog box with the error message
-type=>'ok',-title=>'Error',-icon=>'error'); # an "OK" button and the error icon
Tk::exit(1); # exit the program.
}
########## End Sub ErrMsg ##########


########## Sub DbgMsg ##########
# Use for generating a message box to
# display Debugging info
sub dbgmsg { # Generate debug messages when needed
my $message = shift @_; # Get the message from the call
$message = "DEBUG: $message"; # Add DEBUG header to message
my $response = $mw -> messageBox(-message=>$message, # Create a dialog box with the message
-type=>'ok',-icon=>'info',-title=>'Debug'); # an OK Button and the info Icon
}
########## End Sub DbgMsg ##########


########## Sub Status ##########
# Update status box
sub status {
my $statmsg = shift @_; # Get desired status message text
$status->configure(-text=>$statmsg); # Insert text into Status label
$mw->update; # Refresh the main window so the change is visible.
}
########## END Sub Status ##########


########## END Fax_Resend.pl ##########


----------------------- Example Config.ini: ----------------------- [setup] username = root password = NULL server = 10.10.60.253


____________________ HylaFAX(tm) Users Mailing List _______________________ To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi On UNIX: mail -s unsubscribe hylafax-users-request@xxxxxxxxxxx < /dev/null *To learn about commercial HylaFAX(tm) support, mail sales@xxxxxxxxx*




Project hosted by iFAX Solutions