Archive for December, 2009

CUPS: Setting printer quotas and file system considerations

Thursday, December 10th, 2009

The Common Unix Print Server (CUPS) has become the standard in Linux. Line Print (LP), although frequently used in Sun shops, is lightweight and easy to use, but lacks support and development. LP provides great command line options; however, with the advent of a graphical user interface (GUI) World, the command line has been superseded by the “click”. CUPS provides the “click” consideration, but Administrators need to address printer quotas and file system considerations.

File system considerations? Just install cups and you are done. Right? Not necessarily, because you need to consider a couple of very important aspects of a print server spool directory, input/output (IO) and number of files. I/O is a concern due to the spool directory being a pass-through directory. The number of files is a concern, because the spool directory could be expected to manage tens-of-thousands of files if you are printing labels. Here are a few recommendations to think about:

  • What is the fastest disks we have for the spool directory?
  • Are there other applications running on the server?
  • Create “/var/spool” on a separate partition?
  • What file system format will provide the least overhead and handle the number of files we will be sending to the print server spool directory?
  • Did you create an exclusion directive in netbackup for the spool directory? I would not back up the spool directory, because it should be empty (unless there is a problem) and the competition for I/O on the file system may result in printer slowness.
  • Did we create a cronjob to monitor the file system and alert someone when the number of files is building? Monitoring and notification are excellent methods to know when CUPS, network and or a printer is experiencing problems and for “tweaking” configurations.

Configurations are a concern when dealing with the health of CUPS. CUPS has default quotas in the cupsd.conf file. Adjustments are required for enterprise deployment. I would recommend the following adjustments:

  1. PreserveJobHistory Yes TO PreserveJobHistory No . This might seem like a great option to keep on or use the default “Yes”, but this can cause problems with another setting. If a job has gone to the printer and printed, why save the job? This will not effect the jobs in the queue if a printer goes down or is unreachable.
  2. MaxJobs 500 TO MaxJobs <what ever number you will have at one time in the spool directory>. You need to set this up to the max number of jobs from all printers at one time and give yourself a buffer. If the CUPS spool directory hits this number, CUPS will stop working on print jobs. You will need to stop cups, delete the old files in the spool directory and restart cups. If you keep the default PreserveJobHistory setting, CUPS will include old jobs in the MaxJobs count.
    Why not set it to 0 (unlimited)? If you do not perform routine maintenance on the spool directory, it will fill if there is a printer issue. If you did not place “/var/spool” on a separate directory as recommended, you will need to use a recover CD to mount “/” and clean up the spool directory in order for your system to restart.
  3. MaxJobsPerPrinter 0 TO MaxJobsPerPrinter <your value>. This is a tricky setting if you are printing labels. If the label printer goes down and jobs are still being sent to the label printer you could fill the spool directory if the setting left at unlimited. Not to mention you will hit your MaxJobs setting and have to clean-up CUPS.

After reading this article, you should have a good understanding of what is required to ensure a healthy CUPS environment in regard to file system and printer quota consideratios. Please leave comments about how you resolved problems with your CUPS environment. As always, please patronize the sponsors of this page. They make this possible.

PHP: Free password generator code to generate random passwords of varying lengths for web applications

Saturday, December 5th, 2009

Here is some php script you can use to create a password generator on your server, computer or web site. The html form uses a php action to point back to itself. There is a working version here: Password Generator.

Passwords and userids are hard to create. Being human we tend to follow the path of least resistance. In regard to passwords and userids, we tend to follow distinctive patterns in their creation. Using a password and userid generator enables you to use the strength of a computer to create random passwords and userids.

All this script goes on one page. Open a new file and call it whatever you want as long as it has a .php extension. Here is the form part of the script:

<html>
<body>
<form name="create_password" action=" <?php echo $_SERVER['PHP_SELF']
 ?> " method="post">
<table align="center"><tr><th colspan="2">
Select a length and complexity to create a password.
You <br />can also use this to generate userids, because userids
<br /> should also be unique. NOTE: The passwords are randomly
<br /> generated, so you have the only record.<br />
<i> Make sure you write the password down!</i></th></tr>
<tr><td valign="top" align="left">
<label style="font-weight:bold;text-decoration:underline">Length
</label><br />
<input type="radio" name="length" value="4" >4 characters<br />
<input type="radio" name="length" value="8" >8 characters<br />
<input type="radio" name="length" value="12" checked >12 characters
<br />
<input type="radio" name="length" value="16" >16 characters<br />
<input type="radio" name="length" value="20" >20 characters<br />
</td><td valign="top">
<label style="font-weight:bold;text-decoration:underline">Characters
</label><br />
<input type="radio" name="characters" value='1'>numbers<br />
<input type="radio" name="characters" value="2" >letters<br />
<input type="radio" name="characters" value="3" checked >numbers
and letters<br />
<input type="radio" name="characters" value="4">numbers, letters
and characters<br />
</td></tr><tr><td colspan="2"><input type="submit" name="submit"
value="Get Password">
</form>

Once you have this code pasted into the file with the .php extension it is now time to add the php code that makes this work. Here it is:

<?php
function passwdgen(){
$passlength="";
$characters="";
$mypasswd="";
$mystring="";
$passlength=$_POST['length'];
$characters=$_POST['characters'];
switch ($characters){
case 1:
	while ($passlength){
	$mystring = mt_rand(0,9);
	$mypassword = $mypassword . $mystring;
	$passlength--;
	}
	break;
case 2:
	while ($passlength){
	$letter_array = array("a","b","c","d","e","f","g",
	"h","i","j","k","l","m","n","o","p","q","r","s","t"
	,"u","v","w","x","y","z","A","B","C","D","E","F","G",
	"H","I","J","K","L","M","N","O","P","Q","R","S","T",
	"U","V","W","X","Y","Z");
	$myletterstring = $letter_array[mt_rand(0,52)];
	$mypassword = $mypassword . $myletterstring;
	$passlength--;
	}
	break;
case 3:
while ($passlength){
	$letter_number_array = array("a","b","c","d","e","f","g",
	"h","i","j","k","l","m","n","o","p","q","r","s","t","u",
	"v","w","x","y","z","A","B","C","D","E","F","G","H","I",
	"J","K","L","M","N","O","P","Q","R","S","T","U","V","W",
	"X","Y","Z", "0","1","2","3","4","5","6","7","8","9");
	$myletterandnumberstring =
        $letter_number_array[mt_rand(0,61)];
	$mypassword = $mypassword . $myletterandnumberstring;
	$passlength--;
	}
	break;
case 4:
	while ($passlength){
	$letter_number_character_array = array("a","b","c","d","e"
        ,"f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"
        ,"u","v","w","x","y","z","A","B","C","D","E","F","G","H","I",
	"J","K","L","M","N","O","P","Q","R","S","T","U","V","W",
	"X","Y","Z", "0","1","2","3","4","5","6","7","8","9", "!",
        "#","$","(",")","+","/");
	$myletternumbercharacter =
$letter_number_character_array[mt_rand(0,68)];
	$mypassword = $mypassword . $myletternumbercharacter;
	$passlength--;
	}
	break;
}
return  $mypassword;
}
?>
</td></tr><tr><th colspan="2">
 <?php echo "PASSWORD: " . passwdgen(); ?>
</th></tr></table>
</body>
</html>

Once you have that code pasted under the form script, save the document and open the php file in a web browser and you should be able to start working with generating your own passwords and userids. You will need to change the special characters to ASCII or the PHP interpreter may give you difficulties.

If it does not work make sure you are opening the page on a web server that supports php. With Apache, that might mean moving the file to the /var/www directory on your system and going to localhost/file_name.php.

Enjoy and do not let creating passwords and userid become a problem any more. Here is the link once more for the working version of this script: Password Generator.

As always, please check out this web sites sponsors so we can keep bringing you this information.