Miscellaneous
|
|
|
|
<? /*
Author: Nathan Cassano <nathan@cjhunter.com>
Version: 1.0
Example:
$test = new smb_print();
$test->host = "cannondale";
$test->printer = "hp";
$test->smbclient = "/usr/bin/smbclient";
$test->file_prefix = "form";
$test->temp_dir = "/usr/tmp";
$test->copies = 2;
$test->log = 1;
if($test->send("Testing,n Testing testing") != 0){
echo "Error";
}else{
echo "Done";
}
*/
class smb_print {
var $host;
var $printer;
var $smbclient = "/usr/bin/smbclient";
var $temp_dir = "/tmp";
var $file_prefix = "msg";
var $copies = 1;
var $log = 0;
function send($message)
{
/* Make sure smbclient path is correct */
if(!is_executable($this->smbclient)){
die("Error: '$this->smbclient' invalid smbclient path"); }
/* Write message to file */
$message_filename = tempnam($this->temp_dir, $this->file_prefix);
$message_file = fopen($message_filename,"w");
fputs($message_file, "n$messagex0C");
fclose($message_file);
/* create the shell script */
$script = "$this->smbclient \\\\$this->host\\$this->printer -P -N -c 'translate on; printmode text; lcd $this->temp_dir; print $message_filename; quit;' > /dev/null 2>&1";
/* write shell script to file */
$script_filename = tempnam($this->temp_dir, "sh");
$script_file = fopen($script_filename,"w");
fputs($script_file, "$script");
fclose($script_file);
/* make readable and executable*/
chmod($script_filename, 0555);
/* run the script the number of $copies times */
for($i = 0; $i < $this->copies; $i++){
system($script_filename, $return);
}
/* log or delete message file */
if(!$this->log){
unlink($message_filename); }
/* delete script */
unlink($script_filename);
return $return;
}
}
?>
|
|
|
Usage Example
|
<?
$test = new smb_print();
$test->host = "cannondale";
$test->printer = "hp";
$test->smbclient = "/usr/local/samba/bin/smbclient";
$test->file_prefix = "form";
$test->temp_dir = "/usr/tmp";
$test->copies = 2;
$test->log = 1;
if($test->send("Testing,n Testing testing") != 0){
echo "Error";
}else{
echo "Done";
} ?>
|
|
|
Rate This Script
|
|
|
|