AXIS 2420, 2400, 2401 Php3 Guide

PHP3 Guide
2400/2401/2420
PHP3 Guide
WHY PHP? 3
1.1 W
PHP3 AND THE VIDEO SERVER 5
PHP3 SCRIPT 6
3.1 L
3.2 R
3.3 S
3.3.1 C
3.3.2 S
HAT IS PHP 4
IMITATIONS 6 EQUIREMENTS FOR GETTING STARTED: 7
CRIPTS 8
OMPLETE SCRIPT EXAMPLES 8
CRIPT GENERATED BY THE APPLICATION WIZARD 9
3.3.2.1 Get the script that the wizard in the Video Server has created 10
3.3.3 T
HE TASK-SCHEDULER 12
3.3.3.1 Syntax 13
3.3.3.2 Examples 14
3.3.4 P
3.3.5 H
UT A NEW OR CHANGED SCRIPT INSIDE THE VIDEO SERVER: 14
OW TO ACTIVATE THE SCRIPTS? 16
3.3.5.1 URL 16
3.3.5.2 Telnet 17
3.3.5.2.1 To enable Telnet support 17
TROUBLESHOOTING 20
4.1 PHP3
4.2 P
APPENDIX A – INCLUDED APPLICATION 21
5.1 I
5.2 T
5.2.1 B
5.3 T
5.3.1 O
SCRIPT RELATED PROBLEMS 20
RODUCT RELATED PROBLEMS 20
NTRODUCTION 21
HE SHELL - SH 21
UILT IN COMMANDS 22
HE IMAGE-BUFFER - BUFFERD 22
PTIONS 22
5.3.1.1 By Default 23
5.3.2 EXAMPLES 24
5.4 T
5.4.1
5.4.2
5.4.3
5.4.4
5.4.5
5.4.6 E
HE PHP-LIBS 25
ALERT.LIB 25 FTP.LIB 26 LOG.LIB 27 MAIL.LIB 27 PPP.LIB 28
XAMPLES OF USAGE 30
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 1
PHP3 Guide
6 APPENDIX B - SHELL COMMANDS 32
6.1 C
7.1 S
OMMANDS 32
APPENDIX C - PHP3 SCRIPT EXAMPLES 35
CRIPT EXAMPLES 36
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 2
PHP3 Guide
1 Why PHP?
PHP, which stands for "PHP: Hypertext Preprocessor" was chosen as the scripting language to use in some Axis Video products since:
! PHP is a well-known and widely used scripting language; in Feb 2001 an
estimate of 23% of all Internet web servers used PHP (nearest "competing" script language was Perl with about 7%).
! The language syntax closely resembles Java, Perl and C, making it easy to learn
for anyone with basic programming skills.
! Version 3, PHP3 could easily be scaled down to a smaller footprint required for
embedded devices.
! PHP enables the creation of dynamic web pages quickly; the PHP code is simply
embedded into the HTML code. At the most basic level PHP can do anything that any other scripting language or CGI program can do, such as collect html form data and generate dynamic page content.
! PHP is a complete scripting language with functionality such as file operations,
network sockets, e-mail client (SMTP) and an FTP client. All very useful in Network Camera applications.
The integration of event handling in Axis Video products, and a powerful scripting language such as PHP, gives knowledgeable developers endless opportunities to tailor the functionality of Axis Video products to fit their specific needs.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 3
PHP3 Guide
1.1 What is PHP
PHP (officially "PHP: Hypertext Preprocessor") is a server-side HTML-embedded scripting language.
Simple answer, but what does that mean? An example:
Example 1-1. An introductory example
1 2 <html> 3 <head> 4 <title>Example</title> 5 </head> 6 <body> 7 <?PHP echo "Hi, I'm a PHP script!"; ?> 8 </body> 9 </html> 10
Notice how this is different from a CGI script written in other languages like Perl or C
-- instead of writing a program with lots of commands to output HTML, you write an HTML script with some embedded code to do something (in this case, output some text). The PHP code is enclosed in special start and end tags that allow you to jump into and out of PHP mode.
What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server. If you were to have a script similar to the above on your server, the client would receive the results of running that script, with no way of determining what the underlying code may be. You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve.
A lot of information about PHP can be found on the Internet:
http://www.PHP.net
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 4
PHP3 Guide
2 PHP3 and the Video Server
Axis has removed some functions from the standard PHP3, and created some additional functions to suit our products. The name of Axis´ modified version of PHP3 is called PHP3-Lite. The functions among others, that are removed are those that handle:
! Database functions ! PDF functions ! Mathematic functions
Axis recommends checking that PHP3-Lite supports the functions required before creating custom scripts. This can be checked by looking in the PHP3-Lite manual on our Web site: http://www.axis.com
There are some applications that are shipped with the Axis 2400/2401 products; besides these applications the additional PHP3-scripts that define extra functions are explained in Appendix A at the end of this document.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 5
PHP3 Guide
3 PHP3 script
Before making custom scripts Axis recommends looking at our PHP3-Lite manual (short description about this on the previous page). You can find the manual on the Axis Web site:
http://www.axis.com
Note: Axis Communications AB provides shown here will work for a particular application.
Axis Communications AB inflicted to any device as a result of the examples or instructions mentioned in this document.
Axis Communications AB reserves the right to change this document without prior notice.
cannot and will not be held liable for any damage
no guarantee that any of the examples
!!! WARNING !!!
Please keep in mind that the manufacturer of the flash chips estimates the number of writes to the flash chips to about 100,000. Writing a lot of temporary files to flash must thus be avoided. Use the ram disk mounted on /tmp instead.
3.1 Limitations
For the moment it is not possible to activate more than one script at a time. So if many scripts need to be running at the same time, then delay upgrading the Video Server with Linux!
Note: It´s not possible to downgrade to OSYS again, after having upgraded to Linux
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 6
PHP3 Guide
3.2 Requirements for getting started:
! Web browser ! FTP Client ! Text Editor
Recommended:
! FTP Server ! SMTP Server
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 7
PHP3 Guide
3.3 Scripts
Tip: A very useful program to fetch or upload a script to the product, is Ultra Edit;
This can be downloaded from the following Web site:
http://www.ultraedit.com/
Tip: To log all possible errors, include the row
error_reporting(E_ALL);
in the script.
Turn off this option with the row:
error_reporting(0);
3.3.1 Complete script examples
It´s possible to create scripts and put them inside the video server. In Appendix C of this document are complete PHP3 scripts that can be used, which are customized for the most common applications. To run these scripts a task.list file for each script is attached (read more about task.list in section 3.3.3). Scripts for the following applications are available:
! A script that will upload specified images buffers via FTP and the Ethernet
interface.
! A script that will upload specified image buffers via FTP and the Ethernet
interface, and also send a mail as specified
! A script that will upload specified sequential images via FTP and the Ethernet
interface. The uploaded images will be named according to the parameter $suffix.
! A script that will upload specified sequential images via FTP and the Ethernet
interface. The uploaded images will be ordered in a structure defined by their date.
! A script that will upload specified image buffers via SMTP and the Ethernet
interface.
! A script that will upload specified sequential images via FTP and the Ethernet
interface. The uploaded images will be ordered in a structure defined by their date. Upon alarm event (indicated by an existing file named according to $alarm_file) images from the alarm buffers will be uploaded and a mail will be sent as specified by the appropriate parameters.
How to upload a script to the video server and to run it is shown in section 3.3.4 and
3.3.5.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 8
PHP3 Guide
3.3.2 Script generated by the Application Wizard
The wizard in the video server can generate the most basic scripts, and these can then be extended and modified to fit a particular applications needs though Axis recommends creating the scripts from scratch and putting them inside the video server. How to accomplish the above, follow the instructions on the next page.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 9
PHP3 Guide
3.3.2.1 Get the script that the wizard in the Video Server has created
Start by going through the wizards in the Video Server, then open an FTP session to the Video Server. Follow the instructions below to see how this can be accomplished:
Open a DOS session and type the following commands:
1. Go to the path where the script is saved
Eg: c:\axis\php
2. ftp <ip-address to the camera>
Eg: ftp 10.13.9.73
3. Type the user name
Eg: user name: root
4. Type the password
Eg: password: pass
5. Type: bin
6. Type: hash
7. Type: cd etc At startup, utask reads the file /etc/task.list and parses it for event entries. Therefore, it must be fetched to be able to run the script in an automatic fashion. (See also section 3.3.3 The task-Scheduler.)
8. Type: get task.list
9. Type: cd php
10. Type ls to see the file names for the files that the wizard has created:
Ex: ls
11. Type: get <the script that is to be changed>
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 10
PHP3 Guide
Note: After having created a script with the application wizard, push the remove button or restart the unit before creating a new one! (This doesn't work if it's a script that has been created from scratch, then the script has to be killed by using telnet).
After following the steps on the previous page, it is possible to look at the script that the wizard in the Video Server has created (use for example Notepad to open the script).
Wizard Variables Explanation
$buffer_prefix=”“;
$source[] =
$image_format=““;
$file_format=““;
$pre = ;
$post = ;
$predelay = ;
$postdelay = ;
$host = "10.13.9.70";
The prefix of the name of the buffer(s) started. The index or the name(s) of the buffer(s) started. The value must match the bufferd arguments. The format of the images specified to be taken according to the HTTP-API. The name to be given to the local file, excluding the extension. Number of pre alarm images to be taken.
Number of post alarm images to be taken. Delay between pre images in milliseconds. Delay between post images in milliseconds. The server to upload to
$body = “”;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
The body to insert into the mail. Note that this must be specified and point
Revision 0.91 June 2001 11
PHP3 Guide
to valid file.
$user = "anonymous"; $pass = "pass"; $port = "21"; $passive_mode = "no";
$time = "0";
$delay = "0";
$destination =
$suffix = "date"; $suffix ="default";
The user to login as. The password to use for the user. The port to connect to. Choose passive mode on (“yes” or off
(“no”). The time, in seconds, to stay in the script. Specifies whether to leave the FTP-function or not, after upload,
($time="0") leave the FTP function ($time="-1") continue uploading
Specifies the (approximate) delay in milliseconds between image taken when $time="-1". The path to append to all uploads. This path must exist on the server prior to upload.
Do not change name of the file put on the server, i.e. overwrite the old file on server append the date to the name of the file put on the server.
$suffix ="sequence";
Append a sequence number to the name of the file put on the server.
$suffix ="sequence_max";
Append a sequence number to the name of the file put on the server up to a maximum number
$suffix_counter = 0"; $countermax ="";
Only used if $suffix ="sequence_max"
$startcount="";
shoot(2,30000);
Only used if suffix = "sequence"|"sequence_max" Set parameters for the image-format. Compose the command to run for image­taking.
3.3.3 The task-scheduler
The task-scheduler is used to start programs or scripts when certain events occur. The scripts can be shell-scripts or PHP3-scripts, and can start the buffering of images or upload files by using FTP or SMTP.
The task.list is the configuration file for utask which is a task-scheduler similar to cron or at. The task.list features event-detection, based on date and time, a simple socket for external events, and the ability to start any task and process management to avoid runaway childs processes.
At start-up, utask reads the file /etc/task.list and parses it for event entries. If the file /etc/task.list does not exist when utask is started, then utask goes into a stand-by mode. When /etc/task.list has been created, or modified, a SIGUSR1 need to be sent
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 12
PHP3 Guide
to utask in order for it to reread /etc/task.list. This can be done by issuing the system (Telnet) command 'kill -10 <utask-pid>'.
3.3.3.1 Syntax
An entry in /etc/task.list has the following syntax :
<event>%<program>:<args>;
<event> = is the event description <program> = is the program to start
<args> = are the arguments to be passed to <program>.
<event>
The maximum number of events is 64. An event description should contain one or more of the following definitions.
Definition Meaning
[hh:mm-hh:mm] - Time period time( h(...) m(...) s(...) ) - Time(hours,minutes,seconds) [dd/mm-dd/mm] - Date period date( w(...) m(...) d(...) ) - Date(day,month,date) pattern( (...) (...) ... ) - External events once - Start only once immune - Never interrupted
Time and Date values are given as a list of values (separated by a comma) and/or intervals (separated by a minus sign):
Hour = 0-23 Minute = 0-59 Seconds = 0-59 Day of the week = 0-6 ('0' means Sunday) Month = 1-12 Date = 1-31.
Patterns are defined as strings and follow the specific format <Client>:<Data>;
<Client>
Is the client application sending <Data> to utask. The Data has to be atomic i.e. if the client wants to notify two events at the same time, it has to write
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 13
PHP3 Guide
<Client>:<Data1>;<Client>:<Data2>;.
These patterns are read from /tmp/utasksocket. By default, if an event is trigged, the program runs, exits and starts again as long as the triggering event is valid.
utask start at most five (5) child-processes. When the maximum number of child processes has been exceeded, utask has to decide how to proceed. utask usually kills the process with the lowest priority (if the pending task has a higher priority than this process). The entries in the configuration file (task.list) are ordered by growing priority, i.e. later entries precede earlier entries.
'once'
Specifying 'once' tells utask to skip starting the program as long as the event has not been invalidated. utask checks for events ten times every second (if not in stand-by mode). Thus, if an event is specified to run at a certain point in time, say 'time(h(0) m(0) s(0) )', then this would run the program up to ten times since the event is active during a whole second.
'immune'
utask also provides the user with the possibility of protecting child processes to be prematurely killed by using the 'immune' tag in the script entry. An 'immune' script will always run until it terminates.
3.3.3.2 Examples
Here is an example of a task.list.
The first two entries uses PHP3 to execute scripts mentioned later in this document.
# FTP transfer once every 15 minutes uninterrupted. time(m(0,15,30,45)) immune once % /bin/php : ./ftp.php;
# Mail the current syslog once every day. time( h(0) m(0) s(0) ) once % /bin/php : ./mail_syslog.php;
# Sends and alert message every time I1 and I2 are high at the same time... pattern((IO1:H)(IO2:H)) once % alert : "Input 1 and 2 detected";
3.3.4 Put a new or changed script inside the Video Server:
If a new script is created or something has been modified in the script that the wizard has created, then the new file must be uploaded into the Video Server. To do this follow the instructions below:
Note: When writing the scripts use for example Notepad.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 14
PHP3 Guide
Upload a PHP3 file into the Video Server
1. Open a DOS session and open an FTP session from the path where the PHP3 file resides. Eg: c:\axis\PHP
2. Check that the file exists by typing dir Eg: c:\axis\PHP dir
3. If the file is to be executed as a link, then the file has to have the extension PHP3. If the file doesn't have this then rename the file with the DOS command ren. Eg: c:\axis\PHP ren script.doc (the old filename) script.php3 (the new filename)
4. If the file exists and has the correct filename, then open an FTP session to the Video Server: Eg: c:\axis\PHP ftp <the Video Server ip-address>
5. Then type the user name: Eg: c:\axis\PHP user name: root
6. Then type the password: Eg: c:\axis\PHP password: pass
7. Type: Eg: c:\axis\PHP cd etc/httpd/html
8. Then upload the file to the Video Server with the command: put Eg: c:\axis\PHP put <filnamn.php3>
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 15
PHP3 Guide
3.3.5 How to activate the scripts?
Important! Before activating a new script, restart the video server.
3.3.5.1 URL
This is the way Axis recommends to activate the scripts.
To activate the new script, follow the instructions below:
1. Open the browser (Tested browsers are Netscape and Internet Explorer)
2. Type the IP-address for the Video Server in the URL: Eg: 10.13.9.75/local
3. If the file doesn’t appear click the Refresh button in the browser. To activate the script select the file. (If it still doesn’t happens anything look at the log file for errors)
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 16
PHP3 Guide
3.3.5.2 Telnet
For development it might be useful to connect to the Network Camera by Telnet. Depending on what product is used, this is either enabled by default and have authentication or can be enabled by editing the /etc/inittab. If the product require editing of the /etc/inittab, there will be no authentication for the Telnet connection and no password will be required for access.
Important: Enable this option for experimental use only. Never leave the Telnet access enabled when having the Network Camera installed on a public site.
3.3.5.2.1 To enable Telnet support
Open an FTP session towards the Network Camera and type the commands viewed in bold below:
C:\Axis >ftp <ip address of camera> Connected to <ip address of camera> 220 Axis 2100 Network Camera 2.12 Feb 05 2001 ready. User (<ip address of camera>:(none)): root 331 User name okay, need password. Password: pass (if not changed from default) 230 User logged in, proceed. ftp> ascii ftp> cd /etc ftp> get inittab 200 Command okay. 150 Opening data connection. 226 Transfer complete. ftp: 1380 bytes received in 0,01Seconds 138,00Kbytes/sec.
At this stage, open the downloaded inittab file in an editor and find the following line:
#telnetd:3:respawn:/bin/telnetd
Remove the preceding ”#”:
telnetd:3:respawn:/bin/telnetd
Save the file
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 17
PHP3 Guide
Go back to the ftp session and continue:
ftp> put inittab 200 Command okay. 150 Opening data connection. 226 Transfer complete. ftp: 1414 bytes sent in 0,00Seconds 1414000,00Kbytes/sec. 250 Command successful. ftp> by 221 Goodbye.
Restart the camera and it will be possible to access with Telnet.
Activate the script through telnet
To activate the script through telnet, follow the instructions below:
1. Open a telnet connection to the Video Server.
2. Type the Video Server IP-address as the Host Name: Eg: 10.13.9.73
3. Then log in with the cameras user name and password Eg: user name: root Eg: password: pass
4. Type: cd etc/httpd/html
5. check that the file exists with the command ls Eg: ls
6. Then activate the script by typing: Eg: php <filename>
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 18
PHP3 Guide
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 19
PHP3 Guide
4 Troubleshooting
Tip: To log all possible errors include the following row in the script:
error_reporting(E_ALL);
Turn off this option with the following row:
error_reporting(0);
4.1 PHP3 script related problems
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
4.2 Product related problems
If any problems occur, please try these steps first before contacting a local supplier:
1. Consult the Axis product Users Guide Appendix A - Troubleshooting.
2. Go to the AXIS product Support Web, available from www.axis.com and verify that the product contains the latest available software version. Updated trouble shooting information and the latest software for the unit can be found here.
3. Consult the FAQ and technical notes on the Axis product support page for additional help.
4. Contact the local supplier, from whom the product was purchased, for assistance.
The Log file can prove a useful diagnostic tool when attempting to resolve any problems that might occur: from the records, events, and commands executed by the product since the last system. Always attache the log file and parameter list when contacting Axis support.
Support menu, click Log File to display the latest
Restart of the
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 20

Appendix A – Included Application

5 Appendix A – Included application
Note: The general rule is to not use a function when it’s usage
is not fully understood!
5.1 Introduction
This document explains some of the applications that are shipped with the Axis 2400/2401 products.
These applications are:
! sh, the shell used on the cameras (a modified sash) ! bufferd, a program for buffering images ! utask, a program for scheduling tasks (similar to cron or at).
Besides these applications the additional PHP3-scripts that define extra functions are explained.
The task-scheduler is used to start programs or scripts when certain events occur. The scripts can be shell-scripts or PHP3-scripts, and can start the buffering of images or upload files by using FTP or SMTP.
5.2 The shell - sh
sh is a rewrite of David Bell's sash.
The commands available in sh are essentially the same as the ones commonly used in other shells on any Linux/Un*x system, so the manual pages can often be of use. The difference is that the commands in sh have been simplified, i.e. options have been removed. Besides these modifications some commands have been added which are not part of the original, and thus not documented as a manual-page.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 21
Appendix A – Included Application
5.2.1 Built in commands
The shell includes a help command, which lists the available functions built in the shell (see also Appendix B).
5.3 The image-buffer - bufferd
The application bufferd captures images and stores them on the ram-disk in a FIFO-order, that is, the newest captured image overwrites the oldest.
By default initd starts a bufferd as a daemon. This daemon is listening for messages on the socket /tmp/bufferdsocket. As a consequence it would not be recommended to start several daemons as this would result in one daemon overwriting what the other daemons writes.
The preferred way of using bufferd is depicted in the example below. What happens when a call to bufferd is made is that the started process writes messages to the socket /tmp/bufferdsocket and then dies. Depending on which options are used when starting a buffer, bufferd starts one or two processes for handling image capturing. These processes capture a number of images according to the argument given.
5.3.1 Options
The valid parameters for bufferd are:
Option Meaning
-start Start a buffer.
-reset Remove a buffer.
-stop Stop a buffer. Start as a daemon.
-d
-buffername
<buffername>
-uri <request-
string>
This option should only be used when starting at start-up from initd or when the first instance is to be started.
The name of the buffer on which the options -start, -stop and ­reset should act. bufferd will create a directory in /tmp named <buffername> in which the images will be stored.
The request-uri. Specification of the image-format as described in the HTTP-API
specification (pdf-document). The protocol should be 'FTP'
instead of 'http'. The document can be found on our web site
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 22
Appendix A – Included Application
(www.axis.com) under Camera & Video developer pages.
-postdelay
<delay>
-predelay
<delay>
-pre <number>
-post <number>
-format <format-
string>
Delay between images in milliseconds.
Same as -postdelay but sets an additional variable.
Number of pre-alarm pictures, i.e. number of images to save before stopping the buffer.
Number of post-alarm pictures, i.e. the number of images to save after stopping the buffer.
Naming convention of the files.
-snapshot Take one picture.
-immediate Take one picture and stop the buffer.
5.3.1.1 By Default
If the option '-buffername' is omitted, the buffer used defaults to 'buffer' ('/tmp/buffer') The protocol-specification in the request-uri should be 'FTP', instead of 'http', as this does not generate http-specific headers.
The default delays (postdelay and predelay) are one(1) second (1000 milliseconds).
The default number of images before and after an alarm (pre and post) is 10.
The format-option specifies how the files are named.
Character-expansion is supported with %y (year), %m (month), %d (date), %H (hour), %M (minute) and %S (second) corresponding to the date and time the file was created.
Also supported is %i, which specifies the file-number, and can be followed by a number specifying how many digits are allowed.
The default format is 'snapshot_%y%m%d_%H%M%S_%i4'.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 23
Appendix A – Included Application
5.3.2 Examples
This example shows how to take one(1) image with camera one(1). The resulting image will be of size 640x480 and with other attributes set according to what the camera is set to. The image will be stored in /tmp/SNAP/ and named snapshot.
bufferd -start -buffername SNAP -snapshot -pre 1 -format snapshot -uri ftp://axis­cgi/jpg/1/fullsize.jpg
The following example can be used in a PHP3-script, and is equivalent to the example above.
function shoot() { $command = "bufferd -start -buffername SNAP"; $command .= " -snapshot -pre 1"; $command .= " -format snapshot"; $command .= " -uri ftp://axis­cgi/jpg/1/fullsize.jpg"; system($command); }
The following example creates a buffer that saves its images to the directory /tmp/ALARM/, where the files are named after the creation-time. The captured images will be half-sized (320x240) and captured every two(2) seconds by the first camera. Five(5) images before and two(2) images after the buffer is stopped, are saved.
bufferd -start -buffername ALARM -uri ftp://axis-cgi/jpg/1/halfsize.jpg -pre 5 -post 2 -postdelay 2000
This example shows how to stop the buffer started above.
bufferd -stop -buffername ALARM
This example resets (i.e. stops buffering and clears the directory) the buffer specified in the last example.
bufferd -reset -buffername ALARM
Let's say a method of buffering images is required, and when an arbitrary event occurs, read alarm; the images taken will be handled and the buffering should thereafter continue. The following example illustrates the steps to take (using the examples above):
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 24
Appendix A – Included Application
bufferd -start -buffername ALARM -uri ftp://axis-cgi/jpg/1/halfsize.jpg -pre 5 -post 2 -postdelay 2000
(This starts the buffer and can be specified in a start-up script or as an event for utask) When an event occurs, as specified for utask (see below) the following command sequence is used to handle the buffer:
bufferd -stop ALARM
{ handle images}
bufferd -reset ALARM bufferd -start -buffername ALARM -uri ftp://axis-cgi/jpg/1/halfsize.jpg -pre 5 -post 2 -postdelay 2000
The handling of the images can for instance be done with the PHP3-function 'ftp()' below (see also /usr/php/template_upload_cont.php3 on the device).
5.4 The PHP-libs
Included in the distributed firmware are a few PHP3-scripts that define functions, which are intended to help developers use the camera's functionality. These scripts are located in the directory /usr/php. Currently the included files are:
/usr/php/alert.lib /usr/php/ftp.lib /usr/php/log.lib /usr/php/mail.lib /usr/php/ppp.lib
In order to use these functions the files need to be included in the script using them. The arguments used in the function-calls are also required to be defined/declared in the calling script.
5.4.1 alert.lib
This script implements a function that connects to a host and leaves a message. This function requires an application be running on the contacted host that can handle the alert.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 25
Appendix A – Included Application
function alert($host,$protocol,$port,$message) { ... }
$host (not null) The host-name or address to send the alert to. $protocol Specify the protocol (0 = TCP, 1 = UDP). Default is '0' $port The port to connect to. Default is '15' $message the message to be sent (ASCII)
The timeout for a connection-attempt is 60 seconds. On error the function returns '1' (connection failed), '2' (a parameter was missing) or '$SOCK_CONNECT_FAILED'. If the connection failed this is logged in the syslog.
5.4.2 ftp.lib
This function has encapsulated the built-in PHP3-functions for FTP.
function ftp($host,$user,$pass,$time,$delay,$source,$des tination,$suffix,$countermax,$startcount,$port, $passive_mode) { ... }
$host (not null) FTP Host-name $user (not null) User-name $password (not null) Password
$time $delay delay between transfers in milliseconds.
transfer period in seconds (time < 0 is infinite (i.e. never leave this function), time >= 0 is once).
(not null) Source specification. If the source file is a directory then the command tries to
$source
$destination (not null) Destination specification. $suffix
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 26
transfer each file in this directory. When transferring a whole directory, time and delay are ignored.
Defines the type of stamp to be added to the filename. Valid o
tions are: "default", "date", "sequence",
Appendix A – Included Application
"sequence_max".
$countermax
$startcount $port Port on the FTP-server to connect to.
$passive_mode
On error, the function returns '1' (connection failed), '2' (login failed), '3' (upload failed), '4' (parameter error) or '5' (could not set passive mode). Parameter error occurs when any of $host, $user, $pass, $source or $destination is unspecified, or the parameter $suffix has an invalid value.
Defines the suffix maximum index. Only applies when $suffix = "sequence".
Defines start value for the suffix index. Only applies when $suffix = ("sequence"|"sequence_max").
Choose passive mode. "on" or "off". In passive mode, data connections are initiated by the client, rather than by the server.
5.4.3 log.lib
This function allows a PHP3-script to append an entry to the system log.
function log($message) { ... }
$message Message to be appended to the system log
The function makes a call to the PHP3-function 'error_log($message,0)'.
5.4.4 mail.lib
This function issues a system call to smtpclient.
function mail($subject,$from,$reply,$to,$copy,$file,$att ach) { ... }
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 27
Appendix A – Included Application
$subject Message subject (default is 'no subject') $from (not null) Message's author $reply Reply should be sent to this user (default is $from) $to (not null) Recipients $copy Copy the message to other recipients $file Message read from file $attach File to attach
The script requires that a valid mail-server has been entered in the settings for the camera.
Although the argument '$file' can be unspecified, this is NOT recommended as this sets smtpclient in interactive mode and thus locks the execution of PHP.
On error, the function returns '1' (no sender specified) or '2' (no recipient specified) otherwise the function returns '0'.
5.4.5 ppp.lib
These functions allow a PHP3-script to control the use of ppp-connections through the ppp-wrapper.
function ppp_getpid() { ... }
Called from ppp_start() and ppp_stop(). Returns current pppwrapper pid as reported by the file '/var/log/pppwrapper.pid'.
function ppp_getstat( $num_of_checks ) { ... }
Called from ppp_online(). Returns current ppp status by reading the pppstat.log.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 28
Appendix A – Included Application
Returns '1' if it reads "ON", otherwise returns '0'. $num_of_checks is the number of attempts to read the file '/tmp/pppstat.log'.
function ppp_start() { ... }
Called from ppp_online(). Sends SIGUSR1 (10) to the currently running ppp-wrapper. If the wrapper isn't running the function returns '-1' and an error is logged in the syslog.
function ppp_stop() { ... }
Called from ppp_offline(). Sends SIGUSR2 (12) to the currently running ppp-wrapper. If the wrapper isn't running the function returns '-1'and an error is logged in the syslog.
function ppp_online($behavior, $max_attempt, $ppp_interval) { ... }
Initialize ppp connection. Returns '1' if connection is established, '-1' on error and logs the error in the syslog. $behavior describes the type of behavior of the ppp connection (used when closing the connection) and be either "CloseAfter" or "Optimized". $max_attempt is the number of attempts to connect before failing. $ppp_interval is the delay in seconds between connection attempts.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 29
Appendix A – Included Application
function ppp_offline($behavior, $sec) { ... }
Close ppp connection $behavior describes the type of behavior of the ppp connection and can be either "CloseAfter" or "Optimized". $sec is the time in seconds to wait before calling ppp_stop() if $behaviour="CloseAfter". If $behaviour="Optimized" no waiting is done, ppp_stop is called immediatly.
5.4.6 Examples of usage
The first example depicts how to use the FTP-function in combination with the bufferd-example:
<?php
include "/usr/php/ftp.lib"; include "/usr/php/log.lib";
$host="host.domain"; $user="user"; $pass="password"; $time="0"; $delay="0"; $source="/tmp/SNAP/snapshot.jpg"; $destination="snapshot.jpg"; $suffix="date"; $countermax=""; $startcount=""; $port="21"; $passive_mode="on";
shoot();
$res = ftp($host, $user, $pass, $time, $delay, $source, $destination, $suffix, $countermax, $startcount, $port, $passive_mode);
if($res == 1) {
log("upload script - Could not connect the host");
} else if($res == 2) {
log("upload script - Could not login on host");
} else if($res == 3) {
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 30
Appendix A – Included Application
log("upload script - Could not put the file");
} else if($res == 4) {
log("upload script - something wrong with parameters");
} else if($res == 5) {
log("upload script - could not turn passive mode on/off"); }
?>
The second example depicts how to use the mail-function, and is the script mentioned as mail_syslog.php in the utask-example:
<?php
include "/usr/php/mail.lib"; include "/usr/php/log.lib";
$subject="Todays messages"; $from="root@camera.domain"; $reply=""; $to="cam-admin@host.domain"; $copy=""; $body="/var/log/messages"; $attach=""; $res = mail($subject, $from, $reply, $to, $copy, $body, $attach); if($res == 1) {
log("mail script - Could not send mail:no sender\n");
} else if($res == 2) {
log("mail script - Could not send mail:no recipient\n");
}
?>
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 31

Appendix B - Shell Commands

6 Appendix B - Shell Commands
6.1 Commands
Options
Command
([]=optional,
<>=required)
Description
cat cd [dirname] Change the current directory to
chgrp
chmod
chown clrbit <port> <bit> Clear IO pins.
setbit <port> <bit> Set IO pins. readbits <port> Read IO pins. cp <srcname>
<filename> [filename ...]
<gid> <filename> [filename ...]
<mode> <filename> [filename ...]
<uid> <filename> [filename ...]
[srcname ...] <destname>
Concatenate files and print on stdout
[dirname]. Default value of <dirname> is the environment variable '$HOME'
Change group identity of <filename> to <gid>
Change mode of <filename> to <mode>
Change owner identity <filename> to <uid>
Copy files.
If multiple <srcname> are specified,
<destname> must be a directory. dd df N/A Report file system disk space usage
echo [-neE] [arg ...] Output the <args> exec exit N/A Exit the shell.
quit N/A Same as exit above (???)
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 32
<infile> <outfile> <buffersize>
<filename> [arg ...]
Convert and copy
Replace shell with <filename>
Applies to the current <username>
using the shell.
Appendix B - Shell Commands
for <var> in <list> do
<cmd>
Conditional execution.
<name> is the name of the variable
which will be substituted by each
entry in <list>. <list> is string of
arguments separated by spaces.
<cmd> is the command that shall be
run for each entry in the list. if ( <var> <op>
<value> )
Conditional statement.
<op> can be any of ==, !=, >=, <=, <
or > .
No nested expressions or real
arithmetic, but if-statements can be
nested themselves.
'[' and ']' cannot be used because they
interfere with the wild-card
expansion. fi N/A End statement help N/A Display a list of built in commands kill [-sig] <pid> [pid
...]
Send signal <sig> to process <pid>.
Default signal is SIGTERM ln [-s] <srcname>
[srcname ...] <destname>
Make links between files.
When making a symbolic link (-s)
only one <srcname> may be
specified. <destname> must be an
accessible directory.
[-alidF]
ls
<filename>
List directory contents
[filename ...] mkdir mount [-t type]
<dirname>
[dirname ...]
<devname>
Make directories Mount a file system
Default type is 'minix'. <dirname> <ro|rw>
umount <filename> Unmount file system mv <srcname>
[srcname ...] <destname>
Move files.
If multiple <srcname> are specified,
<destname> must be a directory.
ps N/A Report process status pwd N/A
Print the absolute file name of the
current working directory
reboot N/A Reboot the system
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.91 June 2001 33
Appendix B - Shell Commands
rm
rmdir
setenv <name> <value>
sethostname <hostname>
setdomainname [domainname]
<filename> [filename ...]
<dirname> [dirname ...]
Remove files
Remove empty directories
Change or add an environment
variable
Set the environment variable
$HOSTNAME to <hostname>
Set the environment variable
$DOMAINNAME to <domainname>
sleep [sec] Suspend the shell for <sec> seconds source <filename>
Read and execute in current shell
environment
. <filename> Same as 'source' above
Set the status-led color, where
<color> is one of 'off', 'green',
'yellow' and 'red'.
• green - the indicator flashes briefly and
momentarily displays orange during the
start-up and
statusled <color>
self-test routines; the indicator then
displays green to indicate a healthy unit
status.
• red - the indicator will display red only
if a problem with the AXIS 2400/2401
has occurred.
Refer to Appendix A - Troubleshooting.
(Available on Axis 2400)
su <username> Change user-id to <username>. syslog
<message> [message ...]
Send messages to the system logger sync N/A Flush file system buffers selectspeed <device> <speed> touch <filename>
[filename ...]
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Select data-rate <speed> on device <device>
Change file timestamps.
If <filename> does not exist, a file <filename> is created.
Revision 0.91 June 2001 34

Appendix C - PHP3 Script Examples

7 Appendix C - PHP3 Script Examples
On the following pages complete PHP3 scripts can be found, which are customized for the most common applications. To run these scripts a task.list file for each script is attached. This is needed because utask reads the file /etc/task.list at startup, and parses it for event entries. Therefore, it must be fetched to be able to run the script in an automatic fashion. (See also section 3.3.3 The task-Scheduler.) The script and task.list files can be downloaded from Axis web site (www.axis.com)
Note: Axis Communications AB provides no guarantee that any of the examples shown here will work for a particular application.
Axis Communications AB inflicted to any device as a result of the examples or instructions mentioned in this document.
Axis Communications AB reserves the right to change this document without prior notice.
cannot and will not be held liable for any damage
!!! WARNING !!!
Please keep in mind that the manufacturer of the flash chips estimates the number of writes to the flash chips to about 100,000. Writing a lot of temporary files to flash must thus be avoided. Use the ram disk mounted on /tmp instead.
Tip: To log all possible errors, include the row
error_reporting(E_ALL);
in the script.
Turn off this option with the row:
error_reporting(0);
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 35
Appendix C - PHP3 Script Examples
7.1 Script examples
Important: Before using the scripts on the following pages please read chapter
1 and 2 in this document.
This script will upload these specified images
buffers via FTP and the Ethernet interface
(alarm_ftp_net.php3)
Edit your own parameters below this line.
<?
$buffer_prefix = "CAM"; // The prefix of the name
//of the buffer(s) started
$sources = "1"; // The index of the name(s)
//of the buffer(s) started
$image_format = "fullsize"; // The format of the images
//specified to be taken //according to the HTTP-API
$pre = 2; // Number of pre alarm
//images to be taken
$post = 2; // Number of post alarm
//images to be taken
$predelay = 1000; // Delay between pre images
//in milliseconds
$postdelay = 1000; // Delay between post
//images in milliseconds
$ftp_server = "10.13.9.130"; // The server to upload to $port = "21"; // The port to connect to $user = "user"; // The user to login as $pass = "pass"; // The pass to use for the
//user
$passive_mode = "no"; // Choose passive mode on
//("yes") or off ("no"). //(See documentation on FTP //protocol)
$destination = "upload/2400test"; // The path to append to
//all uploads. This path //must exist on the server //prior to upload.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 36
Appendix C - PHP3 Script Examples
There is no need to edit anything below this line
for($c=0;$c<(strlen($sources));$c++) { // Stop the, by utask,
//started buffers
$command="bufferd -stop -buffername ".$buffer_prefix.substr($sources,$c,1); system($command);
}
error_reporting(0);
for($c=0;$c<(strlen($sources));$c++) { // For each buffer specified
$status_file = "/tmp/".$buffer_prefix.substr($sources,$c,1)."/status";
while(!is_file($status_file)) { // Wait until bufferd is
//ready with the images, i.e. //the status file is present
sleep(($predelay+$postdelay)/1000); } unlink($status_file);
} error_reporting(E_ALL); $session = ftp_connect($ftp_server, $port);
if($session) { // Connection successfully
//established
if(ftp_login($session, $user, $pass)) { // Successful login attempt
if (!ftp_pasv($session, $passive_mode == "yes"))
{
error_log("Could not set passive mode",0);
}
else
{ // Passive mode successfully
//set
for($i=0;$i < (strlen($sources));$i++)
{ // For each buffer specified
$directory="/tmp/".$buffer_prefix.substr($sources, $i,1); $buffer_handle = opendir($directory);
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 37
Appendix C - PHP3 Script Examples
}
else
{
}
}
else
{
}
While($file_name = readdir($buffer_handle)) { // And for each file in the
//corresponding buffer /directory
if(($file_name != ".") &&($file_name != ".."))
{ // That is a regular file
$file = "/tmp/".$buffer_prefix.substr($sources,$i,
1)."/".$file_name; $destination_name = $destination . $buffer_prefix.substr($sources,$i,1); $destination_name .= strchr($file_name,"_");
// extract timestamp from //src, append to dst
if(!ftp_put($session, $destination_name,
$file, FTP_BINARY)) { // Upload that file to the
//FTP server
error_log("Could not upload file ".$file." as
".$destination_name."\n",0); } unlink($file);
} } closedir($buffer_handle);
}
}
error_log("Could not login as ".$user." on ".$ftp_server,0);
ftp_quit($session);
error_log("Could not connect to ".$ftp_server,0);
error_log("Restarting buffer(s)",0);
for($c=0;$c<(strlen($sources));$c++) { // Reset and restart buffers
$command="bufferd -reset -buffername ".$buffer_prefix.substr($sources,$c,1); system($command); $command="bufferd -start -buffername ".$buffer_prefix.substr($sources,$c,1)." -pre ".strval($pre)." ­post ".strval($post)." -predelay ".strval($predelay)." -postdelay ".strval($postdelay)." -uri ftp://jpg/".substr($sources,$c,1)."/".$image_format.".jpg"; system($command);
}
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 38
Appendix C - PHP3 Script Examples
TASK.LIST
(Needed to run the script above and it’s important that the file is named task.list)
once immune % /bin/bufferd : -start -buffername CAM1 -pre 2 -post 2 ­predelay 1000 -postdelay 1000 -uri ftp://jpg/1/fullsize.jpg;
date(w(0,1,2,3,4,5,6)) pattern((IO0:/)) immune once % /bin/sh : -c php /etc/httpd/html/alarm_ftp_net.php3;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 39
Appendix C - PHP3 Script Examples
This script will upload specified image buffers via FTP and
the Ethernet interface, and also send a mail as specified.
(alarm_ftp_note_smtp_net.php3)
Edit your own parameters below this line.
<?
$buffer_prefix = "CAM"; // The prefix of the name of the
//buffer(s) started
$sources = "1"; // The index of the name(s) of
//the buffer(s) started
$imageformat = "fullsize"; // The format of the images
//specified to be taken according //to the HTTP-API
$pre = 2; // Number of pre alarm images to
//be taken
$post = 2; // Number of post alarm images to
//be taken
$predelay = 1000; // Delay between pre images in
//milliseconds
$postdelay = 1000; // Delay between post images in
//milliseconds
$ftp_server = "10.13.9.130"; // The server to upload to $port = "21"; // The port to connect to $user = "user"; // The user to login as $pass = "pass"; // The pass to use for the user $passive_mode = "no"; // Choose passive mode on ("yes")
//or off ("no"). (See //documentation on FTP protocol)
$destination = "upload/ae2400"; // The path to append to all
//uploads. This path must exist //on the server prior to upload.
$smtp_server = "193.13.178.2"; // The server to use as mail
//server
$subject = "'Alarm trigged'"; // The subject to use in the mail $from = "someone@somewhere.com"; // The specified sender $reply = " someone@somewhere.com "; // The specified receiver of
//replies
$cc = " someone@somewhere.com "; // The specified receiver of a
//copy of this mail
$body = "/tmp/var/log/messages"; // The body to insert into the
//mail. Note that this must be //specified and point to valid //file
$to = " someone@somewhere.com "; // The specified recipient
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 40
Appendix C - PHP3 Script Examples
There is no need to edit anything below this line.
for($c=0;$c<(strlen($sources));$c++) {
$command="bufferd -stop -buffername ".$buffer_prefix.substr($sources,$c,1); system($command);
}
$command = "smtpclient"; $command .=" -L -S ".$smtp_server; $command .=" -s ".$subject; $command .=" -f ".$from; $command .=" -r ".$reply; $command .=" -c ".$cc; $command .=" -b ".$body; $command .=" ".$to; exec($command);
error_reporting(0);
for($c=0;$c<(strlen($sources));$c++) {
$status_file = "/tmp/".$buffer_prefix.substr($sources,$c,1)."/status"; while(!is_file($status_file)) {
sleep(($predelay+$postdelay)/1000); } unlink($status_file);
}
error_reporting(E_ALL); $session = ftp_connect($ftp_server, $port); if($session) { // Connection successfully
//established
if(ftp_login($session, $user, $pass)) { // Successful login attempt
if (!ftp_pasv($session, $passive_mode == "yes"))
{
error_log("Could not set passive mode",0);
}
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 41
);
Appendix C - PHP3 Script Examples
else
{ // Passive mode successfully set
for($i=0;$i < (strlen($sources));$i++)
{ // For each buffer specified
$directory="/tmp/".$buffer_prefix.substr($sources,$i,1); $buffer_handle = opendir($directory);
while($file_name = readdir($buffer_handle)) { // And for each file in the
//corresponding buffer directory
if(($file_name != ".") &&($file_name != ".."))
{ // That is a regular file
$file = "/tmp/".$buffer_prefix.substr($sources,$i,1)."/".$file_ name; $destination_name = $destination . $buffer_prefix.substr($sources,$i,1); $destination_name .= strchr($file_name,"_");
// extract timestamp from src, append //to dst
if(!ftp_put($session, $destination_name, $file,
FTP_BINARY)) { // Upload that file to the ftp server
error_log("Could not upload file ".$file." as
".$destination_name."\n",0); } unlink($file);
} } closedir($buffer_handle);
}
}
}
else
{
error_log("Could not login as ".$user." on ".$ftp_server,0); } ftp_quit($session);
}
else
{
error_log("Could not connect to ".$ftp_server,0);
}
error_log("Restarting buffer(s)",0); for($c=0;$c<(strlen($sources));$c++) {
$command="bufferd -reset -buffername ".$buffer_prefix.substr($sources,$c,1);
system($command
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 42
Appendix C - PHP3 Script Examples
$command="bufferd -start -buffername ".$buffer_prefix.substr($sources,$c,1)." -pre ".strval($pre)." ­post ".strval($post)." -predelay ".strval($predelay)." -postdelay ".strval($postdelay)." -uri ftp://jpg/".substr($sources,$c,1)."/".$imageformat.".jpg"; system($command);
}
?>
TASK.LIST
(Needed to run the script above and it’s important that the file is named task.list)
once immune % /bin/bufferd : -start -buffername CAM1 -pre 2 -post 2 ­predelay 1000 -postdelay 1000 -uri ftp://jpg/1/fullsize.jpg;
date(w(0,1,2,3,4,5,6)) pattern((IO0:/)) immune once % /bin/sh : -c php /etc/httpd/html/alarm_ftp_note_smtp_net.php3;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 43
Appendix C - PHP3 Script Examples
This script will upload these specified sequential images
via FTP and the Ethernet interface. The uploaded images
will be named according to the parameter $suffix.
(seq_ftp_net.php3)
Edit your own parameters below this line.
<?
$buffer_prefix = "SNAP"; // The prefix of the name
//of the buffer(s) started
$sources = "1"; // The index of the name(s)
//of the buffer(s) started
$image_format = "fullsize"; // The format of the images
//specified to be taken //according to the HTTP-API
$delay = 2000; // Delay between images
//taken
$file_format = "snapshot"; // The name to be given to
//the local file, excluding //the extension
$ftp_server = "10.13.9.130"; // The server to upload to $port = "21"; // The port to connect to $user = "user"; // The user to login as $pass = "pass"; // The pass to use for the
//user
$passive_mode = "no"; // Choose passive mode on
//("yes") or off ("no"). //(See documentation on FTP //protocol)
$destination = "upload/2400"; // The path to append to
//all uploads. This path //must exist on the server //prior to upload.
$time = 10; // The time, in seconds, to
//stay in this script. A //value of -1 means //indefinetly.
$suffix= "date"; // The type of suffix to
//use on the uploaded //files. Either of "date" //for datum //$suffix = "sequence"; // Or "sequence" for an //index //$counter_max = 10; // Limited by an integer
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 44
Appendix C - PHP3 Script Examples
//$suffix = "sequence_max"; // Or "sequence_max" for an //index up to the internal //maximum integer
There is no need to edit anything below this line.
<?
error_reporting(E_ALL); function conv($value) { // A function for converting
//single digit integers into //two digit integers
if($value < 10) {
$value = "0$value"; } return strval($value);
}
for($c=0;$c<(strlen($sources));$c++) { // Start the buffers as
//specified by the parameters //above
//$command="bufferd -reset -buffername //".$buffer_prefix.substr($sources,$c,1); //system($command); $command="bufferd -start -buffername "; $command.=$buffer_prefix.substr($sources,$c,1); $command.=" -snapshot -pre 1 -predelay "; $command.=strval($delay); $command.=" -uri ftp://jpg/"; $command.=substr($sources,$c,1); $command.="/"; $command.=$image_format; $command.=".jpg -format "; $command.=$file_format; system($command);
}
error_reporting(0); $current_counter = 1; if($fd = fopen("/tmp/counter","r")) { // If the sought after file
//exist, retrieve the index to //start at
while($buf = fread($fd,8))
{
$current_counter .= $buf; } $current_counter = intval($current_counter); fclose($fd);
}
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 45
Appendix C - PHP3 Script Examples
if(($suffix=="sequence") && $current_counter > $counter_max) { // If the loaded index exceeds
//the specified maximum, reset //index
$current_counter = 1; if($fd = fopen("/tmp/counter","w")) {
$buf = fwrite($fd,strval($current_counter));
fclose($fd); }
} error_reporting(E_ALL); $session = ftp_connect($ftp_server, $port); if($session) { // Connection successfully
//established if(ftp_login($session, $user, $pass)) { // Successful login attempt
if (!ftp_pasv($session, $passive_mode == "yes"))
{
ftp_quit($session); error_log("Could not set passive mode",0);
}
else { // Passive mode successfully
//set
$start_time = gettimeofday(); $current_time = $start_time; $session_time = 0; $inc = 0; $active_buffer = -1; $failures=0; while( ($failures<(strlen($sources)*2)) && ( ($session_time<$time)||($time==-1) )) { //Upload images as long as
//not too many errors have
//occurred and session time
//hasn't been exceeded
$loop_start = gettimeofday(); $active_buffer++; if($active_buffer==strlen($sources))
{ // Loop through the indexes
//specified as sources
$active_buffer=0; } $source_file="/tmp/".$buffer_prefix.substr($sour ces,$active_buffer,1)."/".$file_format.".jpg";
// Build the destination name //according to the suffix //specified
$dest=$destination.$buffer_prefix.substr($source s,$active_buffer,1);
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 46
Appendix C - PHP3 Script Examples
if($suffix == "date") {
$tinfo = getdate(time());
$dest .= "_" . conv($tinfo["year"]);
$dest .= "-" . conv($tinfo["mon"]);
$dest .= "-" . conv($tinfo["mday"]);
$dest .= "_";
$dest .= conv($tinfo["hours"]);
$dest .= conv($tinfo["minutes"]);
$dest .= conv($tinfo["seconds"]); } else if($suffix == "sequence_max") {
$dest .= "_" . strval($current_counter);
$inc++;
if($inc >= strlen($sources))
{
$current_counter++; error_reporting(0); if($fd = fopen("/tmp/counter","w")) {
} error_reporting(E_ALL); $inc = 0;
} } else if($suffix == "sequence") {
if($current_counter > $counter_max)
{
$counter = 1; } $dest .= "_" . strval($current_counter); $inc++; if($inc >= $buffer_count) {
$current_counter++;
error_reporting(0);
if($fd = fopen("/tmp/counter","w"))
{
}
error_reporting(E_ALL);
$inc = 0; }
}
$buf = fwrite($fd,strval($current_cou nter)); fclose($fd);
$buf = fwrite($fd,strval($current_cou nter)); fclose($fd);
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 47
Appendix C - PHP3 Script Examples
$dest .= ".jpg"; error_reporting(0); if(is_file($source_file)) { // If the source file is a
if(!ftp_put($session, $dest, $source_file, FTP_BINARY)) { // Upload the source file
$failures++;
error_log("Could not upload file
".$source_file." as ".$dest." on
".$ftp_server,0); }
else
{ // If successful upload,
$failures=0;
unlink($source_file); }
}
else
{
error_reporting(E_ALL); $failures++; error_log("No such file: ".$source_file,0);
} $current_time = gettimeofday(); $ellapsed = ($current_time["sec"] ­$loop_start["sec"]) * 1000000;
//present
//remove the uploaded file //indicating capture of a new //image
if($current_time["usec"] > $loop_start["usec"])
$ellapsed += $current_time["usec"] ­$loop_start["usec"];
else
$ellapsed -= $current_time["usec"] -
$loop_start["usec"]; $wait = ($delay * 1000) / strlen($sources);
if($ellapsed < $wait) { // Wait if needed (in order to
//follow the delay specified //and spread the traffic)
usleep($wait - $ellapsed);
}
// Calculate session time
$session_time = ($current_time["sec"] ­$start_time["sec"]);
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 48
Appendix C - PHP3 Script Examples
else
$session_time -= ($current_time["usec"] -
$start_time["usec"])/1000000;
} if($session_time>=$time) error_log("Timed upload complete",0); if($failures>=(strlen($sources)*2)) error_log("Too many consecutive failures",0);
}
}
else
{
ftp_quit($session); error_log("Could not log in as ".$user." on
".$ftp_server,0); } ftp_quit($session);
}
else
{
error_log("Could not connect to ".$ftp_server.":".$port,0);
}
for($c=0;$c<(strlen($sources));$c++) { // Reset buffers
//$command="bufferd -stop -buffername //".$buffer_prefix.substr($sources,$c,1); //system($command); $command="bufferd -reset -buffername ".$buffer_prefix.substr($sources,$c,1); system($command);
}
?>
TASK.LIST
(Needed to run the script above and it’s important that the file is named task.list)
date(w(0,1,2,3,4,5,6)) pattern((IO0:/)) immune once % /bin/sh : -c php /etc/httpd/html/seq_ftp_net.php3;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 49
Appendix C - PHP3 Script Examples
This script will upload these specified sequential images
via FTP and the Ethernet interface. The uploaded images
will be ordered in a structure defined by their date.
(seq_ftp_net_structured.php3)
Edit your own parameters below this line.
<?
$buffer_prefix = "SNAP"; // The prefix of the name
//of the buffer(s) started
$sources = "1"; // The index of the name(s)
//of the buffer(s) started
$image_format = "fullsize"; // The format of the images
//specified to be taken //according to the HTTP-API
$delay = 2000; // Delay between images
//taken
$file_format = "snapshot"; // The name to be given to
//the local file, excluding //the extension
$ftp_server = "10.13.9.130"; // The server to upload to $port = "21"; // The port to connect to $user = "user"; // The user to login as $pass = "pass"; // The pass to use for the
//user
$passive_mode = "no"; // Choose passive mode on
//("yes") or off ("no"). //(See documentation on FTP //protocol)
$destination = "upload/2400"; // The path to append to
//all uploads. This path //must exist on the server //prior to upload.
$time = 60; // The time, in seconds, to
//stay in this script. A //value of -1 means //indefinetly.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 50
Appendix C - PHP3 Script Examples
There is no need to edit anything below this line.
error_reporting(0); function conv($value) { // A function for converting
//single digit integers into //two digit integers
if($value < 10) {
$value = "0$value"; } return strval($value);
}
for($c=0;$c<(strlen($sources));$c++) { // Start the buffers as
//specified by the parameters //above
$command="bufferd -start -buffername "; $command.=$buffer_prefix.substr($sources,$c,1); $command.=" -snapshot -pre 1 -predelay "; $command.=strval($delay); $command.=" -uri ftp://jpg/"; $command.=substr($sources,$c,1); $command.="/"; $command.=$image_format; $command.=".jpg -format "; $command.=$file_format; system($command);
}
$session = ftp_connect($ftp_server, $port);
if($session) { // Connection successfully
//established
if(ftp_login($session, $user, $pass)) { // Successful login attempt
if (!ftp_pasv($session, $passive_mode == "yes"))
{
ftp_quit($session); error_log("Could not set passive mode",0);
}
else
// Passive mode successfully //set
$start_time = gettimeofday(); $current_time = $start_time; $session_time = 0; $inc = 0; $active_buffer = -1; $failures=0;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 51
Appendix C - PHP3 Script Examples
for($c=0;$c<strlen($sources);$c++) { // Build initial paths on
//server
$dest = $destination.$buffer_prefix.substr($sources,$c,1) ; ftp_mkdir($session,$dest);
}
while( ($failures<(strlen($sources)*2)) && ( ($session_time<$time)||($time==-1) ))
{ // Upload images as long as
//not too many errors have //occured and session time //hasn't been exceeded
$loop_start = gettimeofday(); $active_buffer++;
if($active_buffer==strlen($sources)) { // Loop through the indexes
//specified as sources
$active_buffer=0;
}
$source_file="/tmp/".$buffer_prefix.substr($sourc es,$active_buffer,1)."/".$file_format.".jpg";
$tinfo = getdate(time());
// Build the destination path //both for the script and on //the server
$dest = $destination.$buffer_prefix.substr($sources,$acti ve_buffer,1); $dest .= "/" . conv($tinfo["year"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["mon"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["mday"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["hours"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["minutes"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["seconds"]); $dest .= "_" .$loop_start["usec"].".jpg"; $structure_info=$tinfo; error_reporting(0);
if(is_file($source_file)) { // If the source file is a
//present
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 52
Appendix C - PHP3 Script Examples
if(!ftp_put($session, $dest, $source_file, FTP_BINARY)) { // Upload the source file
$failures++; error_log("Could not upload file ".$source_file." as ".$dest." on ".$ftp_server,0);
}
else
{ // If successful upload,
$failures=0; unlink($source_file);
}
}
else
{
error_reporting(E_ALL); $failures++;
error_log("No such file: ".$source_file,0); } $current_time = gettimeofday(); $ellapsed = ($current_time["sec"] ­$loop_start["sec"]) * 1000000;
//remove the uploaded file //indicating capture of a new //image
if($current_time["usec"] > $loop_start["usec"])
$ellapsed += $current_time["usec"] -
$loop_start["usec"];
else
$ellapsed -= $current_time["usec"] -
$loop_start["usec"];
$wait = ($delay * 1000) / strlen($sources);
if($ellapsed < $wait) { //Wait if needed (in order to
//follow the delay specified //and spread the traffic)
usleep($wait - $ellapsed); }
// Calculate session time $session_time = ($current_time["sec"] ­$start_time["sec"]);
if($current_time["usec"] > $start_time["usec"])
$session_time += ($current_time["usec"] ­$start_time["usec"])/1000000;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 53
Appendix C - PHP3 Script Examples
else
$session_time -= ($current_time["usec"] ­$start_time["usec"])/1000000;
}
if($session_time>=$time) error_log("Timed upload complete",0); if($failures>=(strlen($sources)*2)) error_log("Too many consecutive failures",0);
}
}
else
{
error_log("Could not log in as ".$user." on
".$ftp_server,0); } ftp_quit($session);
}
else
{
error_log("Could not connect to ".$ftp_server.":".$port,0);
}
error_log("Cleaning up",0); for($c=0;$c<(strlen($sources));$c++) { // Reset buffers
//$command="bufferd -stop ­//buffername //".$buffer_prefix.substr($sources, //$c,1); //system($command);
$command="bufferd -reset -buffername ".$buffer_prefix.substr($sources,$c,1); system($command);
}
?>
TASK.LIST
(Needed to run the script above and it’s important that the file is named task.list)
date(w(0,1,2,3,4,5,6)) pattern((IO0:/)) immune once % /bin/sh : -c php /etc/httpd/html/seq_ftp_net_structured.php3;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 54
Appendix C - PHP3 Script Examples
This script will upload image buffers specified
by use of SMTP and the Ethernet interface
(alarm_smtp_net.php3)
Edit your own parameters below the line.
<?
$buffer_prefix = "CAM"; // The prefix of the name
//of the buffer(s) started
$sources = "1"; // The index of the name(s)
//of the buffer(s) started
$image_format = "fullsize"; // The format of the images
//specified to be taken //according to the HTTP-API
$pre = 2; // Number of pre alarm
images //to be taken
$post = 2; // Number of post alarm
//images to be taken
$predelay = 1000; // Delay between pre images
//in milliseconds
$postdelay = 1000; // Delay between post
//images in milliseconds
$smtp_server = "mail.somewhere.com"; // The server to use as
//mail server
$subject = "test"; // The subject to use in
//the mail
$from = " $reply = " someone@somewhere.com "; // The specified receiver
$cc = " someone@somewhere.com "; // The specified receiver
$body = "/tmp/var/log/messages"; // The body to insert into
$to = " someone@somewhere.com "; // The specified recipient
someone@somewhere.com"; // The specified sender
//of replies
//of a copy of this mail
//the mail. Note that this //must be specified and //point to valid file
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 55
Appendix C - PHP3 Script Examples
There is no need to edit anything below the line.
error_reporting(E_ALL); error_log("Stopping buffer(s)",0);
for($c=0;$c<(strlen($sources));$c++)
{ // Stop the, by utask,
//started buffers
$command="bufferd -stop -buffername ".$buffer_prefix.substr($sources,$c,1); system($command);
}
for($c=0;$c<(strlen($sources));$c++) { // For each buffer
//specified
$status_file = "/tmp/".$buffer_prefix.substr($sources,$c,1)."/status"; error_reporting(0);
while(!is_file($status_file)) { // Wait until bufferd is
//ready with the images, //i.e. the status file is //present
sleep(($predelay+$postdelay)/1000); } unlink($status_file);
} error_reporting(E_ALL);
for($c=0;$c<(strlen($sources));$c++) { // For each buffer, mail
//the directory containing //the images taken
$command = "smtpclient"; $command .=" -S ".$smtp_server; $command .=" -b ".$body; $command .=" -M 2 -d /tmp/".$buffer_prefix.substr($sources,$c,1); $command .=" -s ".$subject; $command .=" -f ".$from; $command .=" -r ".$reply; $command .=" -c ".$cc; $command .=" ".$to; system($command);
}
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 56
Appendix C - PHP3 Script Examples
error_log("Restarting buffer(s)",0);
for($c=0;$c<(strlen($sources));$c++) { // Reset and restart
//buffers
$command="bufferd -reset -buffername ".$buffer_prefix.substr($sources,$c,1); system($command); $command="bufferd -start -buffername ".$buffer_prefix.substr($sources,$c,1)." -pre ".strval($pre)." ­post ".strval($post)." -predelay ".strval($predelay)." ­postdelay ".strval($postdelay)." -uri ftp://jpg/".substr($sources,$c,1)."/".$image_format.".jpg"; system($command);
}
?>
TASK.LIST
(Needed to run the script above and it’s important that the file is named task.list)
once immune % /bin/bufferd : -start -buffername CAM1 -pre 2 -post 2 ­predelay 1000 -postdelay 1000 -uri ftp://jpg/1/fullsize.jpg;
date(w(0,1,2,3,4,5,6)) pattern((IO0:/)) immune once % /bin/sh : -c php /etc/httpd/html/alarm_smtp_net.php3;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 57
Appendix C - PHP3 Script Examples
This script will upload sequential images specified by use of
FTP and the Ethernet interface. The uploaded images will be
ordered in a structure defined by their date. Upon alarm event
(indicated by an existing file named according to $alarm_file)
images from the alarm buffers will be uploaded and a m ail
will be sent as specified by the appropriate parameters
(seq_ftp_alarm_ftp_note_smtp_net.php3)
Edit your own parameters below the line.
<?
$seq_buffer_prefix = "SNAP"; // The prefix of the name
//the buffer(s) started for //sequential images
$seq_sources = "1"; // The index of the name(s)
//of the buffer(s) started //for sequential images
$seq_seq_image_format = "fullsize"; // The format of the images
//specified to be taken //according to the HTTP-API //for sequential images
$delay = 2000; // Delay, in milliseconds,
//between sequential images
$file_format = "snapshot"; // The name to be given to
//the local file, excluding //the extension
$ftp_server = "10.13.9.130"; // The server to upload to $port = "21"; // The port to connect to $user = "user"; // The user to login as $pass = "pass"; // The pass to use for the
//user
$passive_mode = "no"; // Choose passive mode on
//("yes") or off ("no"). //(See documentation on FTP //protocol)
$seq_destination = "upload/"; // The path to append to
//sequential uploads. This //path must exist on the //server prior to upload.
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 58
Appendix C - PHP3 Script Examples
$time = 60; // The time, in seconds, to
//stay in this script. A //value of -1 means //indefinetly.
$alarm_file = "/tmp/alarm"; // The file that indicates
//an alarm event by its //presence
// Do not change the following 2 parameters
function handle_alarm($session,$alarm_file) { // A function for handling
//alarm events by sending a //note by use of SMTP and //uploading the alarm //buffers by using FTP
$alarm_buffer_prefix = "CAM"; // The prefix of the name
//of the buffer(s) started //for the alarm images
$alarm_sources = "1"; // The index of the name(s)
//of the buffer(s) started //for alarm images
$alarm_image_format = "fullsize"; // The format of the images
//specified to be taken //according to the HTTP-API //for alarm images
$alarm_destination = "upload1/"; // The path to append to
//alarm uploads. This path //must exist on the server //prior to upload.
$pre = 2; // Number of pre images $post = 2; // Number of post images $predelay = 1000; // Delay, in milliseconds,
//between pre images
$postdelay = 1000; // Delay, in milliseconds,
//between post images
$smtp_server = "mail.somewhere.com"; // The server to use as
//mail server
$subject = "'Alarm trigged'"; // The subject to use in
//the mail
$from = " someone@somewhere.com "; // The specified sender $reply = " someone@somewhere.com "; // The specified receiver
//of replies
$cc = " someone@somewhere.com "; // The specified receiver
//of a copy of this mail
$body = "/tmp/var/log/messages"; // The body to insert into
//the mail. Note that this //must be specified and //point to valid file
$to = " someone@somewhere.com "; // The specified recipient
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 59
Appendix C - PHP3 Script Examples
There is no need to edit anything below the line.
error_reporting(0); unlink($alarm_file); error_reporting(E_ALL);
for($c=0;$c<(strlen($alarm_sources));$c++) { // Stop the alarm buffers
$command="bufferd -stop -buffername ".$alarm_buffer_prefix.substr($alarm_sources,$c,1); system($command);
}
// Send the mail
$command = "smtpclient"; $command .=" -S ".$smtp_server; $command .=" -s ".$subject; $command .=" -f ".$from; $command .=" -r ".$reply; $command .=" -c ".$cc; $command .=" -b ".$body; $command .=" ".$to; exec($command);
for($b=0;$b<(strlen($alarm_sources));$b++)
{ // Wait for the buffers to
//stop, as indicated by an //existing status file in //the buffer directories
$status_file = "/tmp/".$alarm_buffer_prefix.substr($alarm_sources,$b,1)."/statu s"; error_reporting(0);
while(!is_file($status_file)) {
sleep(($predelay+$postdelay)/1000); } error_reporting(E_ALL); unlink($status_file);
}
if($session) { // Connection is
//established for($i=0;$i < (strlen($alarm_sources));$i++) { // For each source
//specified
$directory="/tmp/".$alarm_buffer_prefix.substr($alarm_sour ces,$i,1); $buffer_handle = opendir($directory);
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 60
Appendix C - PHP3 Script Examples
while($file_name = readdir($buffer_handle)) {
if(($file_name != ".") &&($file_name != "..")) { // And for each regular
$file = "/tmp/".$alarm_buffer_prefix.substr($alarm_sou rces,$i,1)."/".$file_name; $destination_name = $alarm_destination.$alarm_buffer_prefix.substr ($alarm_sources,$i,1); $destination_name .= strchr($file_name,"_");
if(!ftp_put($session, $destination_name, $file, FTP_BINARY)) { // Upload file
error_log("Could not upload file ".$file." as
".$destination_name."\n",0); } unlink($file);
} } closedir($buffer_handle);
}
}
else
{
error_log("Could not upload alarmbuffer. Session closed",0);
}
//file in that directory
error_log("Restarting buffer(s)",0);
for($c=0;$c<(strlen($alarm_sources));$c++)
{ // Reset and restart
//buffers
$command="bufferd -reset -buffername ".$alarm_buffer_prefix.substr($alarm_sources,$c,1); system($command); $command="bufferd -start -buffername ".$alarm_buffer_prefix.substr($alarm_sources,$c,1)." -pre ".strval($pre)." -post ".strval($post)." -predelay ".strval($predelay)." -postdelay ".strval($postdelay)." -uri ftp://jpg/".substr($alarm_sources,$c,1)."/".$alarm_image_format. ".jpg"; system($command);
}
//function handle_alarm()
}
function conv($value) { // A function for
//converting single digit
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 61
Appendix C - PHP3 Script Examples
//integers into two digit //integers
if($value < 10) {
$value = "0$value";
} return strval($value);
}
for($c=0;$c<(strlen($seq_sources));$c++) { // For each source
//specified, start a buffer
$command="bufferd -start -buffername "; $command.=$seq_buffer_prefix.substr($seq_sources,$c,1); $command.=" -snapshot -pre 1 -predelay "; $command.=strval($delay); $command.=" -uri ftp://jpg/"; $command.=substr($seq_sources,$c,1); $command.="/"; $command.=$seq_image_format; $command.=".jpg -format "; $command.=$file_format; system($command);
}
$session = ftp_connect($ftp_server, $port);
if($session) { // Connection successfully
//established if(ftp_login($session, $user, $pass)) { // Successful login attempt
if (!ftp_pasv($session, $passive_mode == "yes"))
{
ftp_quit($session); error_log("Could not set passive mode",0);
}
else { // Passive mode
//successfully set
$start_time = gettimeofday(); $current_time = $start_time; $session_time = 0; $inc = 0; $active_buffer = -1; $failures=0;
error_reporting(0);
for($c=0;$c<strlen($seq_sources);$c++) { // Build initial paths
$dest = $seq_destination.$seq_buffer_prefix.substr($seq_sources,$c,1);
ftp_mkdir($session,$dest);
} error_reporting(E_ALL); //converting single digit
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 62
Appendix C - PHP3 Script Examples
while( ($failures<(strlen($seq_sources)*2)) && ( ($session_time<$time)||($time==-1) )) { // Upload images as long as
// Check if an alarm has trigged
error_reporting(0);
if(is_file($alarm_file)) {
handle_alarm($session,$alarm_file); } error_reporting(E_ALL); $loop_start = gettimeofday(); $active_buffer++;
//not too many errors have //occured and session time //hasn't been exceeded
if($active_buffer==strlen($seq_sources)) { // Loop through the indexes
//specified as sources
$active_buffer=0; }
$source_file="/tmp/".$seq_buffer_prefix.substr ($seq_sources,$active_buffer,1)."/".$file_form at.".jpg";
$tinfo = getdate(time());
// Build the destination //path both for the script //and on the server
error_reporting(0); $dest = $seq_destination.$seq_buffer_prefix.substr($se q_sources,$active_buffer,1); $dest .= "/" . conv($tinfo["year"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["mon"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["mday"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["hours"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["minutes"]); ftp_mkdir($session,$dest); $dest .= "/" . conv($tinfo["seconds"]); $dest .= "_" .$loop_start["usec"].".jpg"; $structure_info=$tinfo;
if(is_file($source_file))
{ // If the source file is a
//present
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 63
Appendix C - PHP3 Script Examples
if(!ftp_put($session, $dest,
$source_file, FTP_BINARY))
{ // Upload the source file
$failures++; error_log("Could not upload file ".$source_file." as ".$dest." on ".$ftp_server,0);
}
else
{ // If successful upload,
//remove the uploaded file //indicating capture of a //new image
$failures=0;
unlink($source_file); } error_reporting(E_ALL);
}
else
{
error_reporting(E_ALL); $failures++; error_log("No such file: ".$source_file,0);
} $current_time = gettimeofday(); $ellapsed = ($current_time["sec"] ­$loop_start["sec"]) * 1000000;
if($current_time["usec"] > $loop_start["usec"])
$ellapsed += $current_time["usec"] ­$loop_start["usec"];
else
$ellapsed -= $current_time["usec"] ­$loop_start["usec"];
$wait = ($delay * 1000) / strlen($seq_sources);
error_reporting(0);
if(is_file($alarm_file)) {
handle_alarm($session,$alarm_file);
} error_reporting(E_ALL);
if($ellapsed < $wait)
{ // Wait if needed (in order
//to follow the delay //specified and spread the //traffic)
usleep($wait - $ellapsed);
}
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 64
Appendix C - PHP3 Script Examples
// Calculate session time
$session_time = ($current_time["sec"] ­$start_time["sec"]);
if($current_time["usec"] > $start_time["usec"])
$session_time += ($current_time["usec"]
- $start_time["usec"])/1000000;
else
$session_time -= ($current_time["usec"]
- $start_time["usec"])/1000000;
error_reporting(0);
if(is_file($alarm_file)) {
handle_alarm($session,$alarm_file);
} error_reporting(E_ALL);
} if($session_time>=$time) error_log("Timed upload complete",0); if($failures>=(strlen($seq_sources)*2)) error_log("Too many consecutive failures",0);
}
}
else
{
error_log("Could not log in as ".$user." on
".$ftpserver,0); } ftp_quit($session);
}
else
{
error_log("Could not connect to ".$ftp_server.":".$port,0);
}
error_log("Cleaning up",0);
for($c=0;$c<(strlen($seq_sources));$c++) {
//$command="bufferd -stop -buffername //".$seq_buffer_prefix.substr($seq_sources,$c,1); //system($command); $command="bufferd -reset -buffername ".$seq_buffer_prefix.substr($seq_sources,$c,1); system($command);
}
?>
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 65
Appendix C - PHP3 Script Examples
TASK.LIST
(Needed to run the script above and it’s important that the file is named task.list)
once immune % /bin/bufferd : -start -buffername CAM1 -pre 2 -post 2 ­predelay 1000 -postdelay 1000 -uri ftp://jpg/1/fullsize.jpg;
date(w(0,1,2,3,4,5,6)) pattern((IO0:/)) immune once % /bin/sh : -c php /etc/httpd/html/seq_ftp_alarm_ftp_note_smtp_net.php3;
date(w(0,1,2,3,4,5,6)) pattern((IO3:/)) immune once % /bin/sh : -c touch /tmp/alarm;
Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application.
Revision 0.9 May 2001 66
Loading...