Registrations to Open-AudIT forums are now closed. To ask any new questions please visit Opmantek Community Questions.

Open-AudIT

What's on your network?
It is currently Fri Mar 29, 2024 5:45 am

All times are UTC + 10 hours




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 posts ] 
Author Message
 Post subject: Barcode om summary page
PostPosted: Thu Mar 05, 2009 12:05 am 
Offline
Newbie

Joined: Fri Mar 07, 2008 8:15 pm
Posts: 14
Hi,

I found some php code to generate a barcode and it works fine.
Does anybody knows how to implement this code into the pc summary view so it shows a barcode when you click on a pc ?
I only want to insert this piece of code into the summary but it doesn't work, can anybody help me ?
<IMG SRC="barcode.php?barcode=123456&width=320&height=100">
Of course the numbers 12345 should be the computername. If someone could also help me with that, then i'm a very happy person :D

barcode.php
[code]
<?php
/*===========================================================================*/
/* PHP Barcode Image Generator v1.0 [9/28/2000]
Copyright (C)2000 by Charles J. Scheffold - cs@sid6581.net


---
UPDATE 5/10/2005 by C.Scheffold
Changed FontHeight to -2 if no text is to be displayed (this eliminates
the whitespace at the bottom of the image)
---
UPDATE 03/12/2005 by C.Scheffold
Added '-' character to translation table
---
UPDATE 09/21/2002 by Laurent NAVARRO - ln@altidev.com - http://www.altidev.com
Updated to be compatible with register_globals = off and on
---
UPDATE 4/6/2001 - Important Note! This script was written with the assumption
that "register_globals = On" is defined in your PHP.INI file! It will not
work as-is and as described unless this is set. My PHP came with this
enabled by default, but apparently many people have turned it off. Either
turn it on or modify the startup code to pull the CGI variables in the old
fashioned way (from the HTTP* arrays). If you just want to use the functions
and pass the variables yourself, well then go on with your bad self.
---

This code is hereby released into the public domain.
Use it, abuse it, just don't get caught using it for something stupid.


The only barcode type currently supported is Code 3 of 9. Don't ask about
adding support for others! This is a script I wrote for my own use. I do
plan to add more types as time permits but currently I only require
Code 3 of 9 for my purposes. Just about every scanner on the market today
can read it.


PARAMETERS:
-----------
$barcode = [required] The barcode you want to generate


$type = (default=0) It's 0 for Code 3 of 9 (the only one supported)

$width = (default=160) Width of image in pixels. The image MUST be wide
enough to handle the length of the given value. The default
value will probably be able to display about 6 digits. If you
get an error message, make it wider!


$height = (default=80) Height of image in pixels

$format = (default=jpeg) Can be "jpeg", "png", or "gif"

$quality = (default=100) For JPEG only: ranges from 0-100


$text = (default=1) 0 to disable text below barcode, >=1 to enable


NOTE: You must have GD-1.8 or higher compiled into PHP
in order to use PNG and JPEG. GIF images only work with
GD-1.5 and lower. (http://www.boutell.com)


ANOTHER NOTE: If you actually intend to print the barcodes
and scan them with a scanner, I highly recommend choosing
JPEG with a quality of 100. Most browsers can't seem to print
a PNG without mangling it beyond recognition.


USAGE EXAMPLES FOR ANY PLAIN OLD HTML DOCUMENT:
-----------------------------------------------


<IMG SRC="barcode.php?barcode=HELLO&quality=75">


<IMG SRC="barcode.php?barcode=123456&width=320&height=200">


*/
/*=============================================================================*/


//-----------------------------------------------------------------------------
// Startup code
//-----------------------------------------------------------------------------


if(isset($_GET["text"])) $text=$_GET["text"];
if(isset($_GET["format"])) $format=$_GET["format"];
if(isset($_GET["quality"])) $quality=$_GET["quality"];
if(isset($_GET["width"])) $width=$_GET["width"];
if(isset($_GET["height"])) $height=$_GET["height"];
if(isset($_GET["type"])) $type=$_GET["type"];
if(isset($_GET["barcode"])) $barcode=$_GET["barcode"];




if (!isset ($text)) $text = 1;
if (!isset ($type)) $type = 1;
if (empty ($quality)) $quality = 100;
if (empty ($width)) $width = 160;
if (empty ($height)) $height = 80;
if (!empty ($format)) $format = strtoupper ($format);
else $format="PNG";


switch ($type)
{
default:
$type = 1;
case 1:
Barcode39 ($barcode, $width, $height, $quality, $format, $text);
break;
}


//-----------------------------------------------------------------------------
// Generate a Code 3 of 9 barcode
//-----------------------------------------------------------------------------
function Barcode39 ($barcode, $width, $height, $quality, $format, $text)
{
switch ($format)
{
default:
$format = "JPEG";
case "JPEG":
header ("Content-type: image/jpeg");
break;
case "PNG":
header ("Content-type: image/png");
break;
case "GIF":
header ("Content-type: image/gif");
break;
}


$im = ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
$White = ImageColorAllocate ($im, 255, 255, 255);
$Black = ImageColorAllocate ($im, 0, 0, 0);
//ImageColorTransparent ($im, $White);
ImageInterLace ($im, 1);



$NarrowRatio = 20;
$WideRatio = 55;
$QuietRatio = 35;


$nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio));
$Pixels = $width / $nChars;
$NarrowBar = (int)(20 * $Pixels);
$WideBar = (int)(55 * $Pixels);
$QuietBar = (int)(35 * $Pixels);


$ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2);

if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
{
ImageString ($im, 1, 0, 0, "Image is too small!", $Black);
OutputImage ($im, $format, $quality);
exit;
}

$CurrentBarX = (int)(($width - $ActualWidth) / 2);
$Color = $White;
$BarcodeFull = "*".strtoupper ($barcode)."*";
settype ($BarcodeFull, "string");

$FontNum = 3;
$FontHeight = ImageFontHeight ($FontNum);
$FontWidth = ImageFontWidth ($FontNum);
if ($text != 0)
{
$CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth * strlen($BarcodeFull)) / 2);
ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$BarcodeFull", $Black);
}
else
{
$FontHeight=-2;
}


for ($i=0; $i<strlen($BarcodeFull); $i++)
{
$StripeCode = Code39 ($BarcodeFull[$i]);


for ($n=0; $n < 9; $n++)
{
if ($Color == $White) $Color = $Black;
else $Color = $White;


switch ($StripeCode[$n])
{
case '0':
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$NarrowBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $NarrowBar;
break;


case '1':
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$WideBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $WideBar;
break;
}
}


$Color = $White;
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$QuietBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $QuietBar;
}


OutputImage ($im, $format, $quality);
}


//-----------------------------------------------------------------------------
// Output an image to the browser
//-----------------------------------------------------------------------------
function OutputImage ($im, $format, $quality)
{
switch ($format)
{
case "JPEG":
ImageJPEG ($im, "", $quality);
break;
case "PNG":
ImagePNG ($im);
break;
case "GIF":
ImageGIF ($im);
break;
}
}


//-----------------------------------------------------------------------------
// Returns the Code 3 of 9 value for a given ASCII character
//-----------------------------------------------------------------------------
function Code39 ($Asc)
{
switch ($Asc)
{
case ' ':
return "011000100";
case '$':
return "010101000";
case '%':
return "000101010";
case '*':
return "010010100"; // * Start/Stop
case '+':
return "010001010";
case '|':
return "010000101";
case '.':
return "110000100";
case '/':
return "010100010";
case '-':
return "010000101";
case '0':
return "000110100";
case '1':
return "100100001";
case '2':
return "001100001";
case '3':
return "101100000";
case '4':
return "000110001";
case '5':
return "100110000";
case '6':
return "001110000";
case '7':
return "000100101";
case '8':
return "100100100";
case '9':
return "001100100";
case 'A':
return "100001001";
case 'B':
return "001001001";
case 'C':
return "101001000";
case 'D':
return "000011001";
case 'E':
return "100011000";
case 'F':
return "001011000";
case 'G':
return "000001101";
case 'H':
return "100001100";
case 'I':
return "001001100";
case 'J':
return "000011100";
case 'K':
return "100000011";
case 'L':
return "001000011";
case 'M':
return "101000010";
case 'N':
return "000010011";
case 'O':
return "100010010";
case 'P':
return "001010010";
case 'Q':
return "000000111";
case 'R':
return "100000110";
case 'S':
return "001000110";
case 'T':
return "000010110";
case 'U':
return "110000001";
case 'V':
return "011000001";
case 'W':
return "111000000";
case 'X':
return "010010001";
case 'Y':
return "110010000";
case 'Z':
return "011010000";
default:
return "011000100";
}
}


?>
[/code]


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 03, 2009 5:46 am 
Offline
Newbie

Joined: Wed Jan 30, 2008 6:17 am
Posts: 28
That could be very handy. I'd like to see it.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 03, 2009 5:58 pm 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
There are a number of barcode packages out there written in PHP, but I cant simply include them, as their license may be at odds with the OA license.

Let me look in to this, and see what I can come up with. BTW do you need a particular type of barcode (i.e. Code39 or whatever, but bear in mind, only a few barcode types support a full character set CODE-128 for example)

What size of image, and where would be the best place to place it.

(For those of you worried that I am going to clutter up the nice tidy OA interface with horrible black lines, I will make this optional)

_________________
Andrew

[size=85]OA Server: Windows XP/ XAMPP, Mandriva/Apache, Ubuntu
Auditing: 300+ Wstns, 20+ Srvrs, Thin clients, Linux boxes, Routers, etc
OS's: Windows XP , W2K Srvr, W2K3 Srvr, W2K8, Vista, Windows 7, Linuxes (and a Mac at home)
LDAP: Active Directory[/size]


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 03, 2009 8:43 pm 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
Added this using GPLed code128.class.php (header below)

To enable this, update to SVN 1144 set the following in your include_config.php

[code]
$show_summary_barcode = TRUE ;
[/code]

Looks OK to me, but let me know if you want any changes.

[code]
#===========================================================================
#= Script : phpCode128
#= File : code128.class.php
#= Version: 0.1
#= Author : Mike Leigh
#= Email : mike@mikeleigh.com
#= Website: http://www.mikeleigh.com/scripts/phpcode128/
#= Support: http://www.mikeleigh.com/forum
#===========================================================================
#= Copyright (c) 2006 Mike Leigh
#= You are free to use and modify this script as long as this header
#= section stays intact
#=
#= This file is part of phpCode128.
#=
#= phpFile is free software; you can redistribute it and/or modify
#= it under the terms of the GNU General Public License as published by
#= the Free Software Foundation; either version 2 of the License, or
#= (at your option) any later version.
[/code]

_________________
Andrew

[size=85]OA Server: Windows XP/ XAMPP, Mandriva/Apache, Ubuntu
Auditing: 300+ Wstns, 20+ Srvrs, Thin clients, Linux boxes, Routers, etc
OS's: Windows XP , W2K Srvr, W2K3 Srvr, W2K8, Vista, Windows 7, Linuxes (and a Mac at home)
LDAP: Active Directory[/size]


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 04, 2009 3:02 am 
Offline
Contributor

Joined: Fri Sep 28, 2007 12:07 am
Posts: 189
Very sweet.

Comments:

1. Would be nice to create a custom tag. For example, use the BIOS Asset Tag rather than the machine name.
2. Ability to add a custom field at top of tag e.g. "My Company Name" OR "1-888-999-9999 - Helpdesk"
3. Query to display machines with their respective tags.
4. Query to list/export specific tags if you want to reprint and apply to systems.

This is by far the best addition here for some time. Excellent job!

Jason

_________________
OA Deployment:
Windows 2003 with XAMPP install
80 Windows Servers
250 Windows workstations (mixed XP and 2000)
5 MACs
Multiple printers, switches, routers, firewalls, and other servers (ESX, AIX etc.)


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 04, 2009 8:24 pm 
Offline
Open-AudIT Fellow

Joined: Thu May 17, 2007 5:47 pm
Posts: 568
Location: Italy
I have
[code]
Warning: imagepng() [function.imagepng]: Unable to open 'barcode.png' for writing: Permission denied in ...\lib\barcode\image.class.php on line 31
[/code]
It's due to default permissions set on my OA site root allowing only RX to the Anonymous web user. If I allow also write permissions to barcode.png (like I did for include_config.php), all is fine.
I tried changing line 31 in the function SaveImage of image.class.php with
[code]
if (is_writable($filename))
{imagePNG($image, $filename);} else {echo __("The file ") . $filename . __(" is not writable");}
[/code]
but it seems that is_writable returns True even if that file isn't so.

_________________
Edoardo


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 04, 2009 9:09 pm 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
Another option would be to have the image created in the scripts folder if you have that writable, or have the barcode.png file set writable by the setup script or elsewhere.

How did we get around this issue with the creation of the Disk Usage images and the remote management script. Did we not simply keep the file in memory prior to posting it to the requesting browser.

_________________
Andrew

[size=85]OA Server: Windows XP/ XAMPP, Mandriva/Apache, Ubuntu
Auditing: 300+ Wstns, 20+ Srvrs, Thin clients, Linux boxes, Routers, etc
OS's: Windows XP , W2K Srvr, W2K3 Srvr, W2K8, Vista, Windows 7, Linuxes (and a Mac at home)
LDAP: Active Directory[/size]


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 04, 2009 10:06 pm 
Offline
Open-AudIT Fellow

Joined: Thu May 17, 2007 5:47 pm
Posts: 568
Location: Italy
I don't have the script folder writable. I didn't have a chance to look how the Disk Usage images are generated, but they works fine for me, so it could be the right fix to try.

_________________
Edoardo


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 05, 2009 10:24 am 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
The graphs use a separate image generator script ( see below) :D

I will recode something similar when I have a bit of time. It may be a week or so, if you feel the urge, step in first.

[code]
<?php
header("Content-type: image/png");

$scale = '2';
$width = '5';
$height = '100';

$top = ($height - $_GET['disk_percent']) *$scale;

$disk_warning = $_GET['disk_free_warn'] ;

$image = imagecreate($width, ($height *$scale));

// Set "Empty" Colour
$empty = imagecolorallocate( $image, 210, 210, 210 );
// Set "Full" Colour

$full = imagecolorallocate( $image, 156, 190, 222 );

imagefilledrectangle ($image, 0, $top, $width, ($scale *$height), $full);

// Set "Warning" Colour

$warn = imagecolorallocate( $image, 239, 40, 41 );

imagerectangle($image, 0, ((100-$disk_warning)*$scale), $width, (((100-$disk_warning)*$scale) + 1), $warn );

imagepng($image);
?>
[/code]
system_graphs_image.php

_________________
Andrew

[size=85]OA Server: Windows XP/ XAMPP, Mandriva/Apache, Ubuntu
Auditing: 300+ Wstns, 20+ Srvrs, Thin clients, Linux boxes, Routers, etc
OS's: Windows XP , W2K Srvr, W2K3 Srvr, W2K8, Vista, Windows 7, Linuxes (and a Mac at home)
LDAP: Active Directory[/size]


Top
 Profile  
Reply with quote  
PostPosted: Thu May 14, 2009 12:02 am 
Offline
Newbie

Joined: Wed Jan 30, 2008 6:17 am
Posts: 28
When I enable barcodes I get this...


[code]Warning: include_once(lib\barcode\code128.class.php) [function.include-once]: failed to open stream: No such file or directory in /var/www/system.php on line 80

Warning: include_once() [function.include]: Failed opening 'lib\barcode\code128.class.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/system.php on line 80

Fatal error: Class 'phpCode128' not found in /var/www/system.php on line 91[/code]


Top
 Profile  
Reply with quote  
PostPosted: Fri May 15, 2009 9:23 pm 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
Check that you fully dowloaded the latest SVN, sounds to me like there is something missing.

_________________
Andrew

[size=85]OA Server: Windows XP/ XAMPP, Mandriva/Apache, Ubuntu
Auditing: 300+ Wstns, 20+ Srvrs, Thin clients, Linux boxes, Routers, etc
OS's: Windows XP , W2K Srvr, W2K3 Srvr, W2K8, Vista, Windows 7, Linuxes (and a Mac at home)
LDAP: Active Directory[/size]


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 29, 2009 11:51 am 
Offline
Contributor

Joined: Fri Jul 04, 2008 6:46 am
Posts: 153
Location: USA - WI
That error is actually because Linux needs the forward slashes for the path. I think if the forward slashes are used instead it would still work on Windows. Don't have anything to test that theory on though :p

Oh, and sorry to bump an older thread. I remembered seeing this talked about and wanted to enable it, but didn't know how to at first. I like the barcode though...nice addition!

_________________
OA Server: Debian Squeeze w/ Apache2
Auditing: 700 Workstations, 250 or so Retail Terminals, about 75 Servers
OS's: Windows XP/2003/2008/2008 R2/Vista/7, Debian
LDAP: Active Directory 2008 R2


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 30, 2009 10:52 pm 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
Fixed that, should have spotted it sooner.. also fixed isset($show_summary_barcode) AND ($show_summary_barcode === TRUE) to also allow isset($show_summary_barcode) AND ($show_summary_barcode === 'y') in other words you can now set $show_summary_barcode as TRUE or 'y' and the barcode will appear.

_________________
Andrew

[size=85]OA Server: Windows XP/ XAMPP, Mandriva/Apache, Ubuntu
Auditing: 300+ Wstns, 20+ Srvrs, Thin clients, Linux boxes, Routers, etc
OS's: Windows XP , W2K Srvr, W2K3 Srvr, W2K8, Vista, Windows 7, Linuxes (and a Mac at home)
LDAP: Active Directory[/size]


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 13, 2010 3:09 am 
Offline
Moderator
User avatar

Joined: Tue Jan 25, 2005 3:09 am
Posts: 2140
Location: Scotland
Old topic this, I know, but I needed to fix this on my Linux box, so I modded the page, and included new fonts.

Fixed issue with Barcode on System Summary.
Added GPLed Liberation Fonts from Redhat
Added comments to include_config_defaults.php
Modified barcode dimensions. Tested from Linux.

Can someone test this from Windows to ensure I haven't broken it for the Windows version.

To test, add or modify the lines in your include_config as follows.
[code]
$show_summary_barcode = TRUE ;
$summary_barcode_font = './lib/fonts-ttf/LiberationMono-BoldItalic.ttf';
[/code]

Available fonts are..

LiberationSans-Regular.ttf
LiberationMono-Bold.ttf
LiberationSerif-BoldItalic.ttf
LiberationSans-BoldItalic.ttf
LiberationSans-Bold.ttf
LiberationSans-Italic.ttf
LiberationMono-Regular.ttf
LiberationSerif-Italic.ttf
LiberationMono-BoldItalic.ttf
LiberationSerif-Regular.ttf
LiberationMono-Italic.ttf

You can still point the path to some other local font as before, but this eliminates the need to check to see if a particular font is available on the web server.


:D Enjoy.

_________________
Andrew

[size=85]OA Server: Windows XP/ XAMPP, Mandriva/Apache, Ubuntu
Auditing: 300+ Wstns, 20+ Srvrs, Thin clients, Linux boxes, Routers, etc
OS's: Windows XP , W2K Srvr, W2K3 Srvr, W2K8, Vista, Windows 7, Linuxes (and a Mac at home)
LDAP: Active Directory[/size]


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 posts ] 

All times are UTC + 10 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group