php-general Digest 27 Oct 2005 05:07:59 -0000 Issue 3760

Topics (messages 224684 through 224706):

Re: Decompress a zlib'd string in PHP
        224684 by: Ben
        224687 by: Graham Anderson
        224688 by: Jochem Maas
        224695 by: Jochem Maas
        224697 by: Graham Anderson
        224704 by: Richard Lynch
        224706 by: Graham Anderson

Re: zipped files
        224685 by: Richard Lynch

regex and global vars problem
        224686 by: Jason Gerfen
        224689 by: Jasper Bryant-Greene
        224690 by: Jason Gerfen
        224691 by: Jasper Bryant-Greene
        224692 by: Jason Gerfen
        224693 by: Jasper Bryant-Greene
        224698 by: Jochem Maas

str_split() and errors?
        224694 by: Jason Gerfen
        224696 by: Ben
        224699 by: James Richardson
        224703 by: Richard Lynch

Windows XP installation confusion.
        224700 by: Vizion
        224702 by: Richard Lynch

Re: MySql connection error on win XP for script that works  on Freebsd 5.3
        224701 by: Vizion

Re: moving website from windows to linux hosting
        224705 by: Oliver Grätz

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Graham Anderson said the following on 10/26/2005 09:07 AM:

I'm sure if I can decompress the string, then it will not be too hard to do the rest :)

To decompress the string you'll want gzuncompress. More on zlib & php: http://ca.php.net/manual/en/ref.zlib.php

The on-line manual is your friend :-).

- Ben

--- End Message ---
--- Begin Message --- Just to show I am not a total leech, I did consult the manual before I posted the question :)

The compressor in the file data says: dcomzlib

I tried the below with gzinflate and with gzuncompress.
Both give errors:
 gzinflate(): data error
gzuncompress(): data error

The below is the copy/pasted hex of the compressed movie header in the Quicktime Movie File FYI ,I did not compress the string myself...it is compressed automatically when a Quicktime movie is exported.

$compressed = "DE789CB552BF6F133114F65D2852A50A7568E14041B2A00B120CB081549514860CA9545 15431743167E7CE8AED3B9D9D2B65E9D4FF0484F8079810EC8C0C8CFC2BE1D9E7FB91A4A 008C44B7CF67B7EFEDE67BF0FA1B59F32CB4A849090654A61465F2FD21B762014BE72234 0F6DFDA9CB3EC3F6D56F6FC92F520FEC1146402EB133371357B6DCD1AAD3D3B9BAD5E37B 09F07CEDD61D46898FB4C68D39EF0B8EE6CB8262927B0C092FEE6EE080D613C4EA928ECB E4C4561D81B43F2FC914309822FD120CF05C32F218C0F1800E2215154303810BC935C8D2 171944857204A2050B19D39F3C4EE5BD0151FB62143810C115C0319B15991F9EEC90C042 71A3F27A64306EDD08A4C9F166CDC29B16141FCFA9336AF05CC2FB4D1B493B3EF082ED09 ABB42659BB6BF16B372AF264CB1D23E318AB471FDA811EA5EF4A1523C1F6FC616ECBDF57 B7B6D2CCEDAFCF007CCBB7146D9C2E3DDD38CA80E96B5ED098862F1616F4DA9B10CAF292 299EBE2C36A234CFE20D3D0E734323DFF3B99462223B4835567AF20DFE0FD8AF27DD2956 FC929F38A0188E0F3CD4A31C710CE96F4FBCCEB77ABACF41B7474FB5F75F8CDEB70BCA0C 3E302501B1F7EB668E55E818780B60CFDA55DC6FA4071490CCF14BADCB0BBCABF6AF336B A549BBD6D98EF78795DB7F21A1D1DE27D124F92229BAAFA5E273EE3EE477D5A2068DE01A 10C9F7293E2112FD9912109C38785058E72314D64567266D17653809256F81BB139CB55A 6EC7A3D17E4CC01FF027425F9B1";

$string = pack("H*", $compressed);
$uncompressed = gzinflate($string);
//$uncompressed = gzuncompress($string);
echo $uncompressed;

?>


On Oct 26, 2005, at 10:20 AM, Jochem Maas wrote:

Graham Anderson wrote:

How do you decompress a zlib'd string located in a file with  php ?
I need to dynamically write a password string into a movie file.....
It appears that in QuickTime movie API, all sprite variables/ values are zlib'd inside the movie file
So I need to:
find the string
decompress a zlib'd string inside a file.
change its value => password=new_password
recompress the new value
write the zlib'd string back to the file
I'm sure if I can decompress the string, then it will not be too hard to do the rest :)


I'm sure if you spent 5 seconds searching the manual you would find this page:
http://php.net/manual/en/function.gzuncompress.php

and this one:

http://php.net/manual/en/function.gzcompress.php

(HINT: I typed http://php.net/zlib into the address bar to find them)


'the rest' involves find your substring's beginning and ending offset and then using those values to 'splice' the new substring (aka password) into the file/stream, I can visualize how ot do it but have never actually needed to do something like that ... I would say the compress/decompress is the easier part personally ...
buy hey as long as you get it working :-)



many thanks


back at ya, I learnt some stuff answering (hopefully) you question ;-)


g


--- End Message ---
--- Begin Message ---
Graham Anderson wrote:
How do you decompress a zlib'd string located in a file with  php ?

I need to dynamically write a password string into a movie file.....
It appears that in QuickTime movie API, all sprite variables/values are zlib'd inside the movie file

So I need to:
find the string
decompress a zlib'd string inside a file.
change its value => password=new_password
recompress the new value
write the zlib'd string back to the file

I'm sure if I can decompress the string, then it will not be too hard to do the rest :)

I'm sure if you spent 5 seconds searching the manual you would find this page:
http://php.net/manual/en/function.gzuncompress.php

and this one:

http://php.net/manual/en/function.gzcompress.php

(HINT: I typed http://php.net/zlib into the address bar to find them)


'the rest' involves find your substring's beginning and ending offset and then
using those values to 'splice' the new substring (aka password) into the 
file/stream,
I can visualize how ot do it but have never actually needed to do something like
that ... I would say the compress/decompress is the easier part personally ...
buy hey as long as you get it working :-)



many thanks

back at ya, I learnt some stuff answering (hopefully) you question ;-)

g


--- End Message ---
--- Begin Message ---
Graham Anderson wrote:
Just to show I am not a total leech, I did consult the manual before I posted the question :)

ack.


The compressor in the file data says: dcomzlib

I tried the below with gzinflate and with gzuncompress.
Both give errors:
 gzinflate(): data error
gzuncompress(): data error

The below is the copy/pasted hex of the compressed movie header in the Quicktime Movie File FYI ,I did not compress the string myself...it is compressed automatically when a Quicktime movie is exported.

$compressed = "DE789CB552BF6F133114F65D2852A50A7568E14041B2A00B120CB081549514860CA9545 15431743167E7CE8AED3B9D9D2B65E9D4FF0484F8079810EC8C0C8CFC2BE1D9E7FB91A4A 008C44B7CF67B7EFEDE67BF0FA1B59F32CB4A849090654A61465F2FD21B762014BE72234 0F6DFDA9CB3EC3F6D56F6FC92F520FEC1146402EB133371357B6DCD1AAD3D3B9BAD5E37B 09F07CEDD61D46898FB4C68D39EF0B8EE6CB8262927B0C092FEE6EE080D613C4EA928ECB E4C4561D81B43F2FC914309822FD120CF05C32F218C0F1800E2215154303810BC935C8D2 171944857204A2050B19D39F3C4EE5BD0151FB62143810C115C0319B15991F9EEC90C042 71A3F27A64306EDD08A4C9F166CDC29B16141FCFA9336AF05CC2FB4D1B493B3EF082ED09 ABB42659BB6BF16B372AF264CB1D23E318AB471FDA811EA5EF4A1523C1F6FC616ECBDF57 B7B6D2CCEDAFCF007CCBB7146D9C2E3DDD38CA80E96B5ED098862F1616F4DA9B10CAF292 299EBE2C36A234CFE20D3D0E734323DFF3B99462223B4835567AF20DFE0FD8AF27DD2956 FC929F38A0188E0F3CD4A31C710CE96F4FBCCEB77ABACF41B7474FB5F75F8CDEB70BCA0C 3E302501B1F7EB668E55E818780B60CFDA55DC6FA4071490CCF14BADCB0BBCABF6AF336B A549BBD6D98EF78795DB7F21A1D1DE27D124F92229BAAFA5E273EE3EE477D5A2068DE01A 10C9F7293E2112FD9912109C38785058E72314D64567266D17653809256F81BB139CB55A 6EC7A3D17E4CC01FF027425F9B1";

$string = pack("H*", $compressed);

ok I don't understand pack() very well at all, but why are you using it
here? as far as I can tell gzinflate()/gzuncompress() don't work on binary
strings. what happens is you don't use pack()?

$uncompressed = gzinflate($string);
//$uncompressed = gzuncompress($string);
echo $uncompressed;

?>


On Oct 26, 2005, at 10:20 AM, Jochem Maas wrote:

Graham Anderson wrote:

How do you decompress a zlib'd string located in a file with  php ?
I need to dynamically write a password string into a movie file.....
It appears that in QuickTime movie API, all sprite variables/ values are zlib'd inside the movie file
So I need to:
find the string
decompress a zlib'd string inside a file.
change its value => password=new_password
recompress the new value
write the zlib'd string back to the file
I'm sure if I can decompress the string, then it will not be too hard to do the rest :)


I'm sure if you spent 5 seconds searching the manual you would find this page:
http://php.net/manual/en/function.gzuncompress.php

and this one:

http://php.net/manual/en/function.gzcompress.php

(HINT: I typed http://php.net/zlib into the address bar to find them)


'the rest' involves find your substring's beginning and ending offset and then using those values to 'splice' the new substring (aka password) into the file/stream, I can visualize how ot do it but have never actually needed to do something like that ... I would say the compress/decompress is the easier part personally ...
buy hey as long as you get it working :-)



many thanks


back at ya, I learnt some stuff answering (hopefully) you question ;-)


g




--- End Message ---
--- Begin Message ---
If I remove pack, I get the error:
gzuncompress(): data error

$uncompressed = gzuncompress($the_string);
echo $uncompressed;


in my hex editor, the movie header contains:
ftypqt   qt  PmoovHcmovdcomzlib4cmvd

From the Quicktime Docs, 'dcomzlib' is supposed to be the compression method for the below string:

fixúµRøo1ˆ](R•
[EMAIL PROTECTED]∞ÅTïÜ©TQT1t1gÁŒäÌ;ùù+eÈ‘ˇѯòÏåå¸+·ŸÁ˚맆ƒK|ˆ{~˛figø°
...and so on


has anyone had experience with this ?
g

On Oct 26, 2005, at 12:15 PM, Jochem Maas wrote:

Graham Anderson wrote:

Just to show I am not a total leech, I did consult the manual before I posted the question :)


ack.


The compressor in the file data says: dcomzlib
I tried the below with gzinflate and with gzuncompress.
Both give errors:
 gzinflate(): data error
gzuncompress(): data error
The below is the copy/pasted hex of the compressed movie header in the Quicktime Movie File FYI ,I did not compress the string myself...it is compressed automatically when a Quicktime movie is exported. $compressed = "DE789CB552BF6F133114F65D2852A50A7568E14041B2A00B120CB081549514860CA9 545 15431743167E7CE8AED3B9D9D2B65E9D4FF0484F8079810EC8C0C8CFC2BE1D9E7FB91 A4A 008C44B7CF67B7EFEDE67BF0FA1B59F32CB4A849090654A61465F2FD21B762014BE72 234 0F6DFDA9CB3EC3F6D56F6FC92F520FEC1146402EB133371357B6DCD1AAD3D3B9BAD5E 37B 09F07CEDD61D46898FB4C68D39EF0B8EE6CB8262927B0C092FEE6EE080D613C4EA928 ECB E4C4561D81B43F2FC914309822FD120CF05C32F218C0F1800E2215154303810BC935C 8D2 171944857204A2050B19D39F3C4EE5BD0151FB62143810C115C0319B15991F9EEC90C 042 71A3F27A64306EDD08A4C9F166CDC29B16141FCFA9336AF05CC2FB4D1B493B3EF082E D09 ABB42659BB6BF16B372AF264CB1D23E318AB471FDA811EA5EF4A1523C1F6FC616ECBD F57 B7B6D2CCEDAFCF007CCBB7146D9C2E3DDD38CA80E96B5ED098862F1616F4DA9B10CAF 292 299EBE2C36A234CFE20D3D0E734323DFF3B99462223B4835567AF20DFE0FD8AF27DD2 956 FC929F38A0188E0F3CD4A31C710CE96F4FBCCEB77ABACF41B7474FB5F75F8CDEB70BC A0C 3E302501B1F7EB668E55E818780B60CFDA55DC6FA4071490CCF14BADCB0BBCABF6AF3 36B A549BBD6D98EF78795DB7F21A1D1DE27D124F92229BAAFA5E273EE3EE477D5A2068DE 01A 10C9F7293E2112FD9912109C38785058E72314D64567266D17653809256F81BB139CB 55A 6EC7A3D17E4CC01FF027425F9B1";
$string = pack("H*", $compressed);


ok I don't understand pack() very well at all, but why are you using it here? as far as I can tell gzinflate()/gzuncompress() don't work on binary
strings. what happens is you don't use pack()?


$uncompressed = gzinflate($string);
//$uncompressed = gzuncompress($string);
echo $uncompressed;
?>
On Oct 26, 2005, at 10:20 AM, Jochem Maas wrote:

Graham Anderson wrote:


How do you decompress a zlib'd string located in a file with  php ?
I need to dynamically write a password string into a movie file..... It appears that in QuickTime movie API, all sprite variables/ values are zlib'd inside the movie file
So I need to:
find the string
decompress a zlib'd string inside a file.
change its value => password=new_password
recompress the new value
write the zlib'd string back to the file
I'm sure if I can decompress the string, then it will not be too hard to do the rest :)



I'm sure if you spent 5 seconds searching the manual you would find this page:
http://php.net/manual/en/function.gzuncompress.php

and this one:

http://php.net/manual/en/function.gzcompress.php

(HINT: I typed http://php.net/zlib into the address bar to find them)


'the rest' involves find your substring's beginning and ending offset and then using those values to 'splice' the new substring (aka password) into the file/stream, I can visualize how ot do it but have never actually needed to do something like that ... I would say the compress/decompress is the easier part personally ...
buy hey as long as you get it working :-)




many thanks



back at ya, I learnt some stuff answering (hopefully) you question ;-)



g





--- End Message ---
--- Begin Message ---
On Wed, October 26, 2005 12:34 pm, Graham Anderson wrote:
> The compressor in the file data says: dcomzlib

Okay, now we are getting somewhere.

dcomzlib is, most likely, not the same as zlib.

> I tried the below with gzinflate and with gzuncompress.
> Both give errors:
>   gzinflate(): data error
> gzuncompress(): data error

And this pretty much clinches it, mostly, assuming you passed in the
right data.

"DE789CB552BF6F133114F65D2852A50A7568E14041B2A00B120CB081549514860CA9545

And this is just "data" with not much we can do to guess about its
format.

However, I surfed to http://info.com/dcomzlib and the very first link
(also the only one in English) was to:

http://sourceforge.net/mailarchive/forum.php?forum_id=9050&max_rows=25&style=nested&viewmonth=200205

where somebody pretty much tells you how to decompress this, I think.

(I didn't read the WHOLE thing, mind you)

S/He also raises the question of the legality of doing this, which you
may also wish to consider before proceeding.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
Hi Richard :)

Looks like all he did was change a couple of atoms names...BEFORE the compressed movie header stuff :(
All in all.... is all pretty basic stuff.

I am more interested in what comes AFTER dcomzlib.
Quicktime automatically decompressed the movie header when it plays a file, so there has to be way to decompress it?
As far as legality, I am hacking my own files :)

Ultimately, I want to write a password variable into the Quicktime  file
My hope is that all movie variables are also compressed with dcomzlib...as they are no where to be found by looking at the hex :(
If I can find the variables, then I can rewrite them :)

I know several members of the Quicktime Engineering team, and no one has made a peep.
But, they will not tell me the answer either ;)
Maybe they are waiting to sue me the moment I figure it out ;)


Here is a 'test' movie I created:
These two examples are the SAME file...One has a compressed movie header. The other is uncompressed
So...one has dcomzlib, and one is not

Uncompressed Movie Header:
ftypqt   qt  fimoovlmvhdøÜ
bøÜ
[EMAIL PROTECTED] ßtrak\tkhdøÜ
bøÜ
[EMAIL PROTECTED]@- $edtselstXmdia mdhdøÜ
bøÜ
bXXH9hdlrmhlrtextapp2æApple Text Media [EMAIL PROTECTED],text


Compressed Movie Header
ftypqt qt PmoovHcmov dcomzlib4cmvdfixúµRøo1ˆ](R•Ç:¥p† Y– [EMAIL PROTECTED] CÜT™(™∫ò≥sg≈ˆùŒŒïva„/!˛&;##ˇJxˆ˘~$)(Òü˝ûüø˜=˚ChÌßÃ≤!$dôRò— ◊∑W§Ö/›ê˝∑6Á,˚{Õ û_≤ƒ?òÇL`}b&ÆfØ≠Y£µgg≥’Έsflπ;å
sü    m⁄◊ù
◊$ÂX“flÙé–∆£îä¬ÓÀTÜΩ6$œ:î ¯
Ú\0¸¬¯Ä EÉ¡;[EMAIL PROTECTED]:d– ≠»Ùi¡∆ùƒØ?iÛJ¿¸\M;9˚é‡≠π*€¥Ôk1+˜r¬+Ì£H˜5B˝}®œ«õ± {Á~ÔIã≥6?¸ÛnúQ∂pyw5#™Éem{¢XºÿõSj,√´äHÊ^

does this provide any clues ?

g

Hi,
    On the MPlayer samples FTP, there is an example of a MOV file that
is presumably "protected" in:
  ftp://ftp.mplayerhq.hu/MPlayer/samples/MOV/protected_mov/
Has anyone looked closely at the file? I was trying to figure out what was
protected about it. The first 32 bytes are:

  00 00 22 B6  68 24 2E 6D  00 00 22 AE  62 30 72 29  ..".h$.m..".b0r)
  00 00 00 0C  64 63 6F 6D  7A 6C 69 62  00 00 22 9A  ....dcomzlib..".

The "dcomzlib" tag looks familiar. I had a hunch and changed a few of the
bytes to:

  00 00 22 B6  6D 6F 6F 76  00 00 22 AE  63 6D 6F 76  ..".moov..".cmov
  00 00 00 0C  64 63 6F 6D  7A 6C 69 62  00 00 22 9A  ....dcomzlib..".

And then I was able to parse the file with a custom QT parser I
assembled:




On Oct 26, 2005, at 7:53 PM, Richard Lynch wrote:

On Wed, October 26, 2005 12:34 pm, Graham Anderson wrote:

The compressor in the file data says: dcomzlib


Okay, now we are getting somewhere.

dcomzlib is, most likely, not the same as zlib.


I tried the below with gzinflate and with gzuncompress.
Both give errors:
  gzinflate(): data error
gzuncompress(): data error


And this pretty much clinches it, mostly, assuming you passed in the
right data.

"DE789CB552BF6F133114F65D2852A50A7568E14041B2A00B120CB081549514860CA95 45

And this is just "data" with not much we can do to guess about its
format.

However, I surfed to http://info.com/dcomzlib and the very first link
(also the only one in English) was to:

http://sourceforge.net/mailarchive/forum.php? forum_id=9050&max_rows=25&style=nested&viewmonth=200205

where somebody pretty much tells you how to decompress this, I think.

(I didn't read the WHOLE thing, mind you)

S/He also raises the question of the legality of doing this, which you
may also wish to consider before proceeding.

--
Like Music?
http://l-i-e.com/artists.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
On Wed, October 26, 2005 5:44 am, Clive wrote:
> does any one have code/examples for unzipping a file thats been
> uploaded
> to a server. I would prefer a class rather than something that uses
> zip.lib as it may not be configured on the server.

$path = "/full/path/to/uploaded/file.zip";
exec("/full/path/to/bin/unzip $path", $output, $error);
if ($error){
  die("OS Error: $error<br />\n" . nl2br($output));
}
$unzipped = str_replace(".zip", '', $path);
$file = file_get_contents($unzipped);

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message --- I am having a problem with a couple of function I have written to check for a type of string, attempt to fix it and pass it back to the main function. Any help is appreciated.

<?php

/*
* ex. 00:AA:11:BB:22:CC
*/
function chk_mac( $mac ) {
if( ( eregi( "^[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}$", $mac ) ) || ( !eregi( "^[0-9a-fA-F]$", $mac ) ) {
 return 0;
} else {
 return 1;
}
}

/*
* check validity of MAC & do replacements if necessary
*/
function fix_mac( $mac ) {
global $mac;

if( eregi( "^[0-9A-Fa-f-\:]$", $mac ) ) {
    $mac1 = $mac;
    echo "MAC: $mac1<br>";
   }

   /* strip the dash & replace with a colon */
if( eregi( "^[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}$", $mac ) ) {
 $mac1 = preg_replace( "/\-/", ":", $mac );
 echo "MAC: $mac1<br>";
   }
/* add a colon for every two characters */
if( eregi( "^[0-9A-Fa-f]{12}$", $mac ) ) {
 /* split up the MAC and assign new var names */
@list( $mac_1, $mac_2, $mac_3, $mac_4, $mac_5, $mac_6 ) = @str_split( $mac, 2 );
 /* put it back together with the required colons */
$mac1 = $mac_1 . ":" . $mac_2 . ":" . $mac_3 . ":" . $mac_4 . ":" . $mac_5 . ":" . $mac_6;
 echo "MAC: $mac1<br>";
}
return $mac1;
}

// do our checks to make sure we are using these damn things right
$mac1 = "00aa11bb22cc";
$mac2 = "00-aa-11-bb-22-cc";
$mac3 = "00:aa:11:bb:22:cc";
$mac4 = "zz:00:11:22:ff:xx";

if( chk_mac( $mac1 ) != 0 ) {
$mac = fix_mac( $mac1 );
   echo $mac1 . " converted to " . $mac . "<br>";
} else {
echo "$mac1 is valid.<br>";
}

if( chk_mac( $mac2 ) != 0 ) {
$mac = fix_mac( $mac2 );
   echo $mac2 . " converted to " . $mac . "<br>";
} else {
echo "$mac2 is valid.<br>";
}

if( chk_mac( $mac3 ) != 0 ) {
$mac = fix_mac( $mac3 );
   echo $mac3 . " converted to " . $mac . "<br>";
} else {
echo "$mac3 is valid.<br>";
}

if( chk_mac( $mac4 ) != 0 ) {
$mac = fix_mac( $mac4 );
   echo $mac4 . " converted to " . $mac . "<br>";
} else {
echo "$mac4 is valid.<br>";
}


?>

--
Jason Gerfen

"My girlfriend threated to
leave me if I went boarding...
I will miss her."
~ DIATRIBE aka FBITKK

--- End Message ---
--- Begin Message ---
On Wed, 2005-10-26 at 11:15 -0600, Jason Gerfen wrote:
> I am having a problem with a couple of function I have written to check 
> for a type of string, attempt to fix it and pass it back to the main 
> function.  Any help is appreciated.
[snip]

Would you mind telling us what the problem was?

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

--- End Message ---
--- Begin Message ---
Um I did actually, but I will re-interate the problem with more detail.

the vars $mac1, $mac2, & $mac3 are to get passed to the chk_mac() function which determines if it is a valid hex representation of a h/w address, if it does not meet the criteria of having a ":" separating every two characters it then passes the var to the fix_mac() function which attempts to fix the string or h/w address by either replacing any "-" with a ":" or to break the h/w address up and insert a ":" every two characters. I also believe this is the one you should be playing with as the last post I added a new regex which wasn't working.

Any help is appreciated.

<?php

/*
* function to check validity of MAC address for the ISC DHCPD daemon
* ex. 00:AA:11:BB:22:CC
*/
function chk_mac( $mac ) {
if( ( eregi( "^[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}$", $mac ) ) {
 return 0;
} else {
 return 1;
}
}

/*
* check validity of MAC & do replacements if necessary
*/
function fix_mac( $mac ) {
global $mac;

if( eregi( "^[0-9A-Fa-f-\:]$", $mac ) ) {
    $mac1 = $mac;
    echo "MAC: $mac1<br>";
   }

   /* strip the dash & replace with a colon */
if( eregi( "^[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}$", $mac ) ) {
 $mac1 = preg_replace( "/\-/", ":", $mac );
 echo "MAC: $mac1<br>";
   }
/* add a colon for every two characters */
if( eregi( "^[0-9A-Fa-f]{12}$", $mac ) ) {
 /* split up the MAC and assign new var names */
@list( $mac_1, $mac_2, $mac_3, $mac_4, $mac_5, $mac_6 ) = @str_split( $mac, 2 );
 /* put it back together with the required colons */
$mac1 = $mac_1 . ":" . $mac_2 . ":" . $mac_3 . ":" . $mac_4 . ":" . $mac_5 . ":" . $mac_6;
 echo "MAC: $mac1<br>";
}
return $mac1;
}

// do our checks to make sure we are using these damn things right
$mac1 = "00aa11bb22cc";
$mac2 = "00-aa-11-bb-22-cc";
$mac3 = "00:aa:11:bb:22:cc";
$mac4 = "zz:00:11:22:ff:xx";

if( chk_mac( $mac1 ) != 0 ) {
$mac = fix_mac( $mac1 );
   echo $mac1 . " converted to " . $mac . "<br>";
} else {
echo "$mac1 is valid.<br>";
}

if( chk_mac( $mac2 ) != 0 ) {
$mac = fix_mac( $mac2 );
   echo $mac2 . " converted to " . $mac . "<br>";
} else {
echo "$mac2 is valid.<br>";
}

if( chk_mac( $mac3 ) != 0 ) {
$mac = fix_mac( $mac3 );
   echo $mac3 . " converted to " . $mac . "<br>";
} else {
echo "$mac3 is valid.<br>";
}

if( chk_mac( $mac4 ) != 0 ) {
$mac = fix_mac( $mac4 );
   echo $mac4 . " converted to " . $mac . "<br>";
} else {
echo "$mac4 is valid.<br>";
}


?>

Jasper Bryant-Greene wrote:

On Wed, 2005-10-26 at 11:15 -0600, Jason Gerfen wrote:
I am having a problem with a couple of function I have written to check for a type of string, attempt to fix it and pass it back to the main function. Any help is appreciated.
[snip]

Would you mind telling us what the problem was?



--
Jason Gerfen

"My girlfriend threated to
leave me if I went boarding...
I will miss her."
~ DIATRIBE aka FBITKK

--- End Message ---
--- Begin Message ---
On Wed, 2005-10-26 at 12:07 -0600, Jason Gerfen wrote:
> Um I did actually, but I will re-interate the problem with more detail.
> 
> the vars $mac1, $mac2, & $mac3 are to get passed to the chk_mac() 
> function which determines if it is a valid hex representation of a h/w 
> address, if it does not meet the criteria of having a ":" separating 
> every two characters it then passes the var to the fix_mac() function 
> which attempts to fix the string or h/w address by either replacing any 
> "-" with a ":" or to break the h/w address up and insert a ":" every two 
> characters.  I also believe this is the one you should be playing with 
> as the last post I added a new regex which wasn't working.

OK, you've told us what your code does. Now can you explain what the
problem is? "A new regex which wasn't working" is a bit vague.

* Does it throw an error?
  - If so, can we have the error message?

* Does it mark invalid strings as valid?
  - Or vice versa?

Just posting a pile of code with an explanation of what it does and
leaving the rest of us to figure out what the problem is, is not helping
us to help you.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

--- End Message ---
--- Begin Message --- The code I just showed you is supposed to do the following, the chk_mac() returns a true or false on the vars $mac1, $mac2 and $mac3. $mac3 is the only var that should not be thrown into the fix_mac() function which is working correctly. The problem is when $mac1 and $mac2 get put into the fix_mac() function nothing is being returned.

I am not recieving any error codes, just an empty var.

Sample output:

00aa11bb22cc converted to
00-aa-11-bb-22-cc converted to
00:aa:11:bb:22:cc is valid.

As you can see $mac3 is a valid example of a h/w address where $mac1 & $mac2 were returned from the fix_mac() function as an empty string.

Jasper Bryant-Greene wrote:

On Wed, 2005-10-26 at 12:07 -0600, Jason Gerfen wrote:
Um I did actually, but I will re-interate the problem with more detail.

the vars $mac1, $mac2, & $mac3 are to get passed to the chk_mac() function which determines if it is a valid hex representation of a h/w address, if it does not meet the criteria of having a ":" separating every two characters it then passes the var to the fix_mac() function which attempts to fix the string or h/w address by either replacing any "-" with a ":" or to break the h/w address up and insert a ":" every two characters. I also believe this is the one you should be playing with as the last post I added a new regex which wasn't working.

OK, you've told us what your code does. Now can you explain what the
problem is? "A new regex which wasn't working" is a bit vague.

* Does it throw an error?
 - If so, can we have the error message?

* Does it mark invalid strings as valid?
 - Or vice versa?

Just posting a pile of code with an explanation of what it does and
leaving the rest of us to figure out what the problem is, is not helping
us to help you.



--
Jason Gerfen

"My girlfriend threated to
leave me if I went boarding...
I will miss her."
~ DIATRIBE aka FBITKK

--- End Message ---
--- Begin Message ---
On Wed, 2005-10-26 at 12:24 -0600, Jason Gerfen wrote:
> The code I just showed you is supposed to do the following, the 
> chk_mac() returns a true or false on the vars $mac1, $mac2 and $mac3.  
> $mac3 is the only var that should not be thrown into the fix_mac() 
> function which is working correctly.  The problem is when $mac1 and 
> $mac2 get put into the fix_mac() function nothing is being returned.
> 
> I am not recieving any error codes, just an empty var.
> 
> Sample output:
> 
> 00aa11bb22cc converted to
> 00-aa-11-bb-22-cc converted to
> 00:aa:11:bb:22:cc is valid.
> 
> As you can see $mac3 is a valid example of a h/w address where $mac1 & 
> $mac2 were returned from the fix_mac() function as an empty string.

OK, thanks for that. I've rewritten your function below in much cleaner
code. Some of the situations you've used regexps in, string functions
would work fine. They're also much faster.

The below function works fine in my testing. I removed the special-case
for a valid MAC address at the start since your regexp was throwing
errors and there was no need since you already checked if it was valid
with chk_mac() (which by the way should return true or false, not 1 or
0, but meh).

<?php
function fix_mac( $mac ) {

        if( eregi(

                "^[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}$",
                $mac
        ) ) {

                $mac_final = str_replace( '-', ':', $mac );

        } else if( eregi( "^[0-9A-Fa-f]{12}$", $mac ) ) {

                $mac_array = str_split( $mac, 2 );
                $mac_final = implode( ':', $mac_array );

        } else {

                return false;

        }

        echo "MAC: $mac_final";
        return $mac_final;

}
?>

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

--- End Message ---
--- Begin Message ---
gonna jump on your thread there Jasper, I would
like to comment on your function and ask you a question:

which is 'better' (for what), preg_*() or ereg[i]*()?

Jasper Bryant-Greene wrote:
On Wed, 2005-10-26 at 12:24 -0600, Jason Gerfen wrote:

The code I just showed you is supposed to do the following, the chk_mac() returns a true or false on the vars $mac1, $mac2 and $mac3. $mac3 is the only var that should not be thrown into the fix_mac() function which is working correctly. The problem is when $mac1 and $mac2 get put into the fix_mac() function nothing is being returned.

I am not recieving any error codes, just an empty var.

Sample output:

00aa11bb22cc converted to
00-aa-11-bb-22-cc converted to
00:aa:11:bb:22:cc is valid.

As you can see $mac3 is a valid example of a h/w address where $mac1 & $mac2 were returned from the fix_mac() function as an empty string.


OK, thanks for that. I've rewritten your function below in much cleaner
code. Some of the situations you've used regexps in, string functions
would work fine. They're also much faster.

The below function works fine in my testing. I removed the special-case
for a valid MAC address at the start since your regexp was throwing
errors and there was no need since you already checked if it was valid
with chk_mac() (which by the way should return true or false, not 1 or
0, but meh).

<?php
function fix_mac( $mac ) {

        if( eregi(

                "^[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}\-" .
                "[0-9A-Fa-f]{2}$",

this string concatenation looks a bit naff.
although on second thoughts I can see why you did it this way.
down to personal choice :-).

the use of double quotes means strictly speaking
you should be escaping the backslash and dollar sign (and the
parentheseses?) although i would recommend single quotes.

I would have used preg_match(), something like
(I'm using double quotes because of the php -r '' btw :-):

php -r '

$d  = "([0-9A-Fa-f]{2})";
$q  = "{$d}[\\-:]?";
$re = "#^{$q}{$q}{$q}{$q}{$q}{$d}\$#";
foreach(array("900030ABAB0C",
              "90-00-30-AB-AB-0C",
              "90:00:30:AB:AB:0C",
              "90-00-30:AB:AB-0C",
              "90:JJ:30:AB:AB-0C") as $str) {
    $matches = array();
    if (preg_match($re, $str, $matches)) {
        $mac = join(":", array_slice($matches, 1));
        echo "good mac: $mac\n";
    } else {
        echo "bad mac: $str\n";
    }
}

// and as a function:

function getMAC($str)
{
    static $re;
    if (!isset($re)) {
        $d  = "([0-9A-Fa-f]{2})"; $q = "{$d}[\\-:]?";
        $re = "#^{$q}{$q}{$q}{$q}{$q}{$d}\$#";
    }

    return (preg_match($re, $str, $matches)) ? join(":", array_slice($matches, 
1)) : null;
}

foreach(array("900030ABAB0C",
              "90-00-30-AB-AB-0C",
              "90:00:30:AB:AB:0C",
              "90-00-30:AB:AB-0C",
              "90:JJ:30:AB:AB-0C") as $str) {
    if ($mac = getMAC($str)) {
        echo "good mac: $mac\n";
    } else {
        echo "bad mac: $str\n";
    }
}

'

                $mac
        ) ) {

                $mac_final = str_replace( '-', ':', $mac );

        } else if( eregi( "^[0-9A-Fa-f]{12}$", $mac ) ) {

                $mac_array = str_split( $mac, 2 );
                $mac_final = implode( ':', $mac_array );

        } else {

                return false;

        }

        echo "MAC: $mac_final";
        return $mac_final;

white space is nice but too many blank lines lead to overscroll ;-)


}
?>


--- End Message ---
--- Begin Message --- I am recieving this error in the logs when attempting to split strings with str_split(). I am not sure but isn't this a default function for PHP, as in there aren't any dependant packages involved during the ./confgure time?

Errors:
PHP Fatal error:  Call to undefined function:  str_split() in file.php on line 
21

--
Jason Gerfen

"My girlfriend threated to
leave me if I went boarding...
I will miss her."
~ DIATRIBE aka FBITKK

--- End Message ---
--- Begin Message ---
Jason Gerfen said the following on 10/26/2005 12:12 PM:
I am recieving this error in the logs when attempting to split strings with str_split(). I am not sure but isn't this a default function for PHP, as in there aren't any dependant packages involved during the ./confgure time?

Errors:
PHP Fatal error: Call to undefined function: str_split() in file.php on line 21


Did you read the second comment on the str_split manual page? I suspect you're using php4.

http://ca.php.net/manual/en/function.str-split.php

- Ben

--- End Message ---
--- Begin Message ---
If you want to use this function in PHP4, you can use the PEAR package
PHP_Compat from http://pear.php.net/



On Wed, 2005-10-26 at 12:19 -0700, Ben wrote:
> Jason Gerfen said the following on 10/26/2005 12:12 PM:
> > I am recieving this error in the logs when attempting to split strings 
> > with str_split().  I am not sure but isn't this a default function for 
> > PHP, as in there aren't any dependant packages involved during the 
> > ./confgure time?
> > 
> > Errors:
> > PHP Fatal error:  Call to undefined function:  str_split() in file.php 
> > on line 21
> > 
> 
> Did you read the second comment on the str_split manual page?  I suspect 
> you're using php4.
> 
> http://ca.php.net/manual/en/function.str-split.php
> 
> - Ben
> 
-- 
===================================
James T. Richardson, Jr.
eXcellence in IS Solutions, Inc.
[EMAIL PROTECTED]
-----------------------------------
Office: 713-862-9200
Voicemail: 713-339-7226
Fax: 713-586-3224
===================================

--- End Message ---
--- Begin Message ---
On Wed, October 26, 2005 2:12 pm, Jason Gerfen wrote:
> I am recieving this error in the logs when attempting to split strings
> with str_split().  I am not sure but isn't this a default function for
> PHP, as in there aren't any dependant packages involved during the
> ./confgure time?
>
> Errors:
> PHP Fatal error:  Call to undefined function:  str_split() in file.php
> on line 21

The (PHP 5) notion near the top of this page:
http://php.net/str_split
was intended to inform you that it was added in, and is available only
in, PHP 5 and later.

There may be a backwards-compatible function written in <?php ... ?>
code in PECL or PEAR.

The User-Contributed notes at the above link may also have a function
to duplicate functionality in earlier versions.

Or you could upgrade, of course.

And, of course, in future you'll know to check the version info in the
manual so you'll know right off what's going on.  It's a VERY nice
feature of the on-line manual, I must say.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---

Hi

In Install.text for php 5.0.5 on Page 3:

Heading Manual Installation Steps
"Previous editions of the manual suggest moving various ini and DLL files into 
your SYSTEM folder......we advise remove all these files (like php.ini and 
PHP related DLLs from the Windows System folder..."

While some files in the Windows folder are clearly php related in that they 
are of the form
php*.*

other files are not so easily distinguished.

I wonder if someone has a list of the files that should be deleted bearing in 
mind I have just removed an installation of php 4.3.10 and php 5.0.5. I would 
like to make sure that the windows system32 folder is clean! It would be nice 
if such a list was added to install.txt

thanks

david





-- 
40 yrs navigating and computing in blue waters.
English Owner & Captain of British Registered 60' bluewater Ketch S/V Taurus.
 Currently in San Diego, CA. Sailing bound for Europe via Panama Canal after 
completing engineroom refit.

--- End Message ---
--- Begin Message ---
On Wed, October 26, 2005 6:42 pm, Vizion wrote:
> your SYSTEM folder......we advise remove all these files (like php.ini
> and
> PHP related DLLs from the Windows System folder..."

> I wonder if someone has a list of the files that should be deleted
> bearing in
> mind I have just removed an installation of php 4.3.10 and php 5.0.5.
> I would
> like to make sure that the windows system32 folder is clean! It would
> be nice
> if such a list was added to install.txt

If all else fails, you could just download the PHP .zip files and open
them up, without un-zipping, and see the list of files.

Errrm, not in that wack wizard mode, but classic mode of WinZip.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Wednesday 26 October 2005 08:35,  the author Jay Blanchard contributed to 
the dialogue on-
 RE: [PHP] MySql connection error on win XP for script that works  on Freebsd 
5.3: 

>[snip]
>I have searched the mysql website and located an article which shows
>reference
>to this error indicating that the client may need to be upgraded but as I am
>
>using the mysql-5.0.13-rc-win32.zip package I am cautious about assuming
>that
>that is the actual cause.
>[/snip]
>
>http://us3.php.net/mysqli
>
>"The mysqli extension allows you to access the functionality provided by
>MySQL 4.1 and above."
Thanks for that -- I have decided to upgrade to 5.0.5 -
I did see that file before posting but I think I must have got the wrong 
impression on first read

thanks again

david
-- 
40 yrs navigating and computing in blue waters.
English Owner & Captain of British Registered 60' bluewater Ketch S/V Taurus.
 Currently in San Diego, CA. Sailing bound for Europe via Panama Canal after 
completing engineroom refit.

--- End Message ---
--- Begin Message ---
pedro mpa schrieb:

> (Like changing directory paths from \ to / ).

Ahem... shouldn't you havee used "/" on the Windows machine, too?
The "\" comes from the DOS era of the Windows OS, but the "/" is the
world standard and Windows Servers perfectly work with "/". Even the
Windows explorer is able to translate "/" to "\".


OLLi

--- End Message ---

Reply via email to