Axis camera and PHP

This is a discussion on Axis camera and PHP within the PHP Language forums, part of the PHP Programming Forums category; I have to send a restart command to an IP camera from a PHP script. The command is as follow: ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-12-2007
Stefano
 
Posts: n/a
Default Axis camera and PHP

I have to send a restart command to an IP camera from a PHP script. The
command is as follow:

http://192.168.1.5/axis-cgi/admin/restart.cgi

where 192.168.1.5 is the address of the camera.

In PHP, my idea was to open a socket connection and send the command, with
the following code:

$host="192.168.1.5" ;
$target="/axis-cgi/admin/restart.cgi" ;
$port=80 ;
$timeout=60;
$br="\r\n" ;
$usarname="root";
$password="password_root";
$sk=fsockopen($host,$port,$errnum,$errstr,$timeout ) ;
if(!is_resource($sk)){
exit("Connection failed: ".$errnum." ".$errstr) ;
}
else{
$headers = "GET ".$target." HTTP/1.1".$br ;
$headers.="Accept: */*".$br ;
$headers.="Accept-Language: it".$br ;
$headers.="Host: ".$host.$br ;
$headers.="Authorization: Basic root:password_root".$br.$br;
fputs($sk,$headers) ;

When printing $sk I see the error message

401 Unauthorized
You client does not have permission to get URL /axis-cgi/admin/restart.cgi
from this server

Seems there is something wrong with authentication.

Any idea ?
Is there somebody who uses PHP with Axis camera ? How do you send API
commands to the camera ?


Thank you for your help.

Stefano



Reply With Quote
  #2 (permalink)  
Old 08-12-2007
Ulf Kadner
 
Posts: n/a
Default Re: Axis camera and PHP

Stefano wrote:
> I have to send a restart command to an IP camera from a PHP script. The
> command is as follow:
>
> http://192.168.1.5/axis-cgi/admin/restart.cgi
>
> $headers.="Authorization: Basic root:password_root".$br.$br;


Dont know if this is the right header.
I use allways PHPs CURL extension. It works fine.

e.g.: curl_setopt($curl, CURLOPT_HTTPAUTH, 'username:password');
http://php.net/curl

It requires also an min. PHP version 5.*
PHP 4.4.2+ supports it to but official documentation says "avialable for
version 5 and above". May it helps you.

So long, Ulf

--
_,
_(_p> Ulf [Kado] Kadner
\<_)
^^
Reply With Quote
  #3 (permalink)  
Old 08-12-2007
Stefano
 
Posts: n/a
Default Re: Axis camera and PHP

Ulf,
thank you a lot for your answer. I've never used Curl before and I am trying
to do right now what you suggested.

So, after curl_init(), using the function :

curl_setopt($curl, CURLOPT_HTTPAUTH, 'username:password');

I get the same error message as before: 401 Unauthorized.

But looking at curl_setopt() specifications, the option CURLOPT_HTTPAUTH can
be set to values CURLAUTH_BASIC, CURLAUTH_DIGEST and so on depending by the
authentication methods to use.
So I should write for example:

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

Seems that username:password is not accepted as CURLOPT_HTTPAUTH set value.
In that case where should I specify login and password ?

Thank you again.

Stefano


"Ulf Kadner" <dr_logic@gmx.net> ha scritto nel messaggio
news:f9nji0$fdc$02$1@news.t-online.com...
> Stefano wrote:
>> I have to send a restart command to an IP camera from a PHP script. The
>> command is as follow:
>>
>> http://192.168.1.5/axis-cgi/admin/restart.cgi
>>
>> $headers.="Authorization: Basic root:password_root".$br.$br;

>
> Dont know if this is the right header.
> I use allways PHPs CURL extension. It works fine.
>
> e.g.: curl_setopt($curl, CURLOPT_HTTPAUTH, 'username:password');
> http://php.net/curl
>
> It requires also an min. PHP version 5.*
> PHP 4.4.2+ supports it to but official documentation says "avialable for
> version 5 and above". May it helps you.
>
> So long, Ulf
>
> --
> _,
> _(_p> Ulf [Kado] Kadner
> \<_)
> ^^



Reply With Quote
  #4 (permalink)  
Old 08-13-2007
Ulf Kadner
 
Posts: n/a
Default Re: Axis camera and PHP

Stefano wrote:

> So, after curl_init(), using the function :
>
> curl_setopt($curl, CURLOPT_HTTPAUTH, 'username:password');
>
> I get the same error message as before: 401 Unauthorized.


Right. It was my failure. Better to read my posting before send.
Yesterday i used it like my example but with PROXY* Paramater. worry? :-)

> curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
>
> Seems that username:password is not accepted as CURLOPT_HTTPAUTH set value.
> In that case where should I specify login and password ?


The fast and bad way is URL-injection like this:
http://username:password@example.com/...

The other and better way is to change youre code at line:
$headers.="Authorization: Basic root:password_root".$br.$br;

to:
$headers .= 'Authorization: Basic '
. base64_encode('root:password_root') . $br . $br);

The RFC says username:password must be Base64 encoded.

By the way: A good PHP-Library for doing something more with
http/ftp/... (by a easy way) is Snoopy.
http://sourceforge.net hosts it.

--
_,
_(_p> Ulf [Kado] Kadner
\<_)
^^
Reply With Quote
  #5 (permalink)  
Old 08-13-2007
Stefano
 
Posts: n/a
Default Re: Axis camera and PHP

> The other and better way is to change youre code at line:
> $headers.="Authorization: Basic root:password_root".$br.$br;
>
> to:
> $headers .= 'Authorization: Basic '
> . base64_encode('root:password_root') . $br . $br);
>


YYYEEEESSSSS !!!!
It works now !

To be honest, I tryed the function base64_encode() before but colon was
outside base64_encode.

Thank you very much Ulf. I was working around that problem since last week.

Regards.
Stefano



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:11 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0