SearchSearch   

Axis camera and PHP

 
   Webmaster Forums (Home) -> PHP RSS
Next:  PEAR auth package - how does setSessionname work?  
Author Message
Stefano

External


Since: Aug 12, 2007
Posts: 5



(Msg. 1) Posted: Sun Aug 12, 2007 7:18 pm
Post subject: Axis camera and PHP
Archived from groups: comp>lang>php (more info?)

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
Back to top
Ulf Kadner

External


Since: Aug 12, 2007
Posts: 5



(Msg. 2) Posted: Sun Aug 12, 2007 7:18 pm
Post subject: Re: Axis camera and PHP
Archived from groups: per prev. post (more info?)

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
\<_)
^^
Back to top
Stefano

External


Since: Aug 12, 2007
Posts: 5



(Msg. 3) Posted: Sun Aug 12, 2007 7:18 pm
Post subject: Re: Axis camera and PHP
Archived from groups: per prev. post (more info?)

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.TakeThisOut@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
> \<_)
> ^^
Back to top
Ulf Kadner

External


Since: Aug 12, 2007
Posts: 5



(Msg. 4) Posted: Sun Aug 12, 2007 7:18 pm
Post subject: Re: Axis camera and PHP
Archived from groups: per prev. post (more info?)

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? Smile

> 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
\<_)
^^
Back to top
Stefano

External


Since: Aug 12, 2007
Posts: 5



(Msg. 5) Posted: Mon Aug 13, 2007 8:42 am
Post subject: Re: Axis camera and PHP
Archived from groups: per prev. post (more info?)

> 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
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> PHP
Page 1 of 1

 
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 vote in polls in this forum