LUALoriotPro WEB site

LoriotPro scripting documentation
Extensions for LUA language

Table of contents Search function

Print the current page Mail this  link UTUBE Channel version française

Developing WEB pages on LoriotPro

Dynamic page with LUA scripts

Table of contents

Introduction

Configuring the WEB server for HLUA XLUA support

Configuring the user profil

Access to HLUA or XLUA files

Access to HLUA or XLUA files from a standard URL

Access to HLUA or XLUA files attached to a user profile

File attached to global script

Creation of  WEB page as HLUA / XLUA files

A very basic example in hlua (The “Hello World” Web page)

A very basic example in xlua (The “Hello World” Web page)

WEB file naming convention and structure

Access LoriotPro global variables and the http header variables

Testing a WEB page in the script  editor

Example of advanced WEB pages written in LUA XML (XLUA).

Limitation of HLUA, XLUA WEB pages

Introduction

LoriotPro include a WEB server and thus is remotely accessible from any Internet browser. This feature allows remote users to see the monitoring platform partially or globally.

Since the version 6 of LoriotPro Extended Edition, the creation of web pages dedicated to the display of networks and systems monitoring information is accessible to all. The WEB interface can be extended at will with user design pages or by LUTEUS at your demand.

The dynamic web page of LoriotPro offers first hand information, because the collection of information by SNMP can be made in real time when fetching the Web pages.

This functionality is possible through integration and support of the LUA scripting language directly in HTML, the equivalent of other technologies like ASP, PHP or JAVASCRIPT. The scripts are executed and integrated server-side, in other words by LoriotPro itself. The user receives Web pages formatted in HTML or XML / XSL.

The interpretation of LUA scripts directly from the LoriotPro Web server can generate dynamic pages destined for the web browser of the user requesting the page.

The LoriotPro web server is able to identify two new file extensions that support embedded LUA scripts, HLUA for pages coded in HTML and XLUA for pages encoded in XML.

Upon receipt of a request from a browser to a page of these types, the LoriotPro web server interprets the page containing the LUA code portions and dynamically generates the page in HTML or XML.

As a reminder, the LoriotPro software integrates the LUA scripting language as well as hundreds of proprietary LUA management functions. The solution LoriotPro offers a development environment dedicated to the administration, the monitoring and the automation of networks, servers and intelligent architectures. The available extension functions exploit the standard communication and management protocols that are IP, TCP and SNMP.

The synopsis below trace the operating principle.

HLUA-XLUA.jpg

Step 1 - The client navigator request a WEB page with a hlua or xlua extension.

Step 2 - The LoriotPro WEB server recognizes the extension and gives the LUA code to the internal LoriotPro LUA interpreter.

Step 3 - The Code is executed and internal requests are submitted to LoriotPro (LUA functions and LoriotPro proprietary functions).

Step 4 - If step 3 include SNMP function step 4 is performed.  SNMP requests are sent to the network device.

Step 5 - Reponses are send back to LoriotPro by the network device.

Step 6 - LoriotPro provides the results to the LUA interpreter.

Step 7 - The WEB page is dynamically created with the collected SNMP values and given back to the WEB server.

Step 8 – The page is send back to the client navigator.

Configuring the WEB server for HLUA XLUA support

Before calling WEB page with embedded LUA scripts, it is necessary to check that the WEB server is properly setup.

In the services tab of LoriotPro, select the HTTP ISAPI Server process and right click to select the Properties option.

Verify that the Permit LUA process is checked.

parmit LUA

Configuring the user profil

When accessing the WEB server, an authentication is required. The user that is use for this authentication can have limited rights for LUA access.

To define these rights you must access the User Rights Manager.

In the services tab of LoriotPro, select the HTTP ISAPI Server process and right click to select the Properties option.

Select the User Rights Manager button.

There is another way for accessing the User right manager window. Double click on the service HTTP ISAPI SERVER and select the User Manager button.

The User Rights Manager is displayed.

Two options are available for each user that control the capability for this user to launch LUA script from a WEB page.

They are accessible at this right end of the row.

The options are : Global LUA and  Local LUA.

Remark: These options can be use as variable directlry in the LUA script to perform further checking and control.

Options

functions

Global LUA

This user can Access all WEB page with embedded LUA script  

Local LUA

This user can only access WEB page with embedded LUA script that are located in the user file directory.

For example if the user login name is : admin

The directory is :

bin/www/user/admin

Access to HLUA or XLUA files

The file extension HLUA are used to generate standard HTML files, the files XLUA are used to generate XML files.

Extension on the LoriotPro WEB server

Type of file created for the client browser

HLUA hlua

html

XLUA xlua

xml

Access to HLUA or XLUA files from a standard URL

The files containing the LUA scripting can be called as any file through a standard URL:

Example from the web browser client.

http://127.0.0.1:8010/hlua/sample01.hlua?host1=dns.domain.fr&host2=123.8.1.1

Access to HLUA or XLUA files attached to a user profile

It is possible to place the files HLUA, XLUA directly in the directory of a user with a profile.

Note: Each user has a dedicated directory in the tree: bin/www/user/xxx

The WEB page become visible in the list of available report for that user (here admin).

The default icon use for this type of WEB page is .

A comment is displayed on the right side

This one can be created and modified directrly in the hlua or xlua file

Here under the first 5 line of the file where the comment sis defined

--<!-- <img border=0 src='/img/status11.jpg'>your comment here !!-->

--<!-- level 0 -->

--<!--

-- OEMSNMPManager V6.00 Web File To Script LUA File

-- Generated by the OEMSNMPManager Editor Wizard at : Thu Dec 10 16:33:55 2009

It is possible to change the icon and the comment

--<!-- <img border=0 src='/img/PollerProcess32.jpg'>Sample comment  !!-->

--<!-- level 0 -->

--<!--

-- OEMSNMPManager V6.00 Web File To Script LUA File

-- Generated by the OEMSNMPManager Editor Wizard at : Thu Dec 10 16:33:55 2009

File attached to global script

The same way i is possible to provide WEB pages LUA (HLUA, XLUA) as global (accessible by all users)  is you put them in the directory : bin/www/rep/ 

 

The files are then visible as Global report (WEB pages) in the Global Reports options.

Creation of  WEB page as HLUA / XLUA files

L’éditeur intégré à LoriotPro permet de générer et tester des fichiers de type HLUA ou XLUA.

Remarque : l’utilisation de fichier HLUA ou XLUA est possible dans les différentes éditions de LoriotPro mais l’éditeur intégré n’est disponible quand version Extended.

Le lancement de l’éditeur s’effectue depuis le menu principal du logiciel.

The integrated script editor of LoriotPro helps you to generate and test WEB pages based on HLUA XLUA files.

Note: Use the file or HLUA XLUA is possible in the various editions LoriotPro.

To create a new WEB page:

 tools>Script Editor

The documentation for using the editor is available from the help option.

And for French reader as pdf file.

To create a new WEB page use the New Wizard option of the Files option of the Script Editor.

By default the HLUA or XLUA file will be located in the directory bin/www/hlua.

The Wizard create a skeleton for the new WEB page with predefined variables.

The proposed file contains the basic functions to facilitate the integration of text in the HTML file generated. All code is commented out.

By removing the tags - [[ And ]] -  you get a minimum working dynamic WEB page.

The file can mix native HTML code and LUA. You need to enclose the portions of code with LUA tags <lua> </ lua>. The tag <lua> is located at the beginning of LUA code and the tag </ lua> at the end. There can be multiple sections mixing native XML HTML tags and / or LUA.

The principle of coding is to generate output file in append mode for writing HTML. The file name is defined with the variable HLUA_outputfile.

The Web server provides a set of script variables that helps the coding.

For the interpreter all portions of code LUA is seen as one piece and all variables defined in higher sections of code are used in the lower section of code. The LUA language being interpreted, variables must be defined in the good order and before utilization.

Some functions are provided by the Wizard to help you write HTML text in the output file. Only the function w (val) can be used to write the output file.

fp=nil;

function open()

       if fp~=nil then close() end

       fp=lp.Fopen(HLUA_outputfile,'at');

       return fp;

end

function close()

       if fp==nil then return end

       lp.Fclose(fp);

       fp=nil;

end

function w(val)

       open();

       if fp==nil then return end

       lp.Fprintf(fp,val);

       close();

end

It may be necessary to modify these functions to perform specific tests or formatting of text written in the output file.

A very basic example in hlua (The “Hello World” Web page)

Using the editor and the information given previously, let’s start to create a very basic example of WEB page that will display the Hello World text.

In the editor we open a new Web script file called test.hlua with the following code:

<lua>

-- Input values

-- lp_index index for this script ".1"

-- lp_oid SNMP OID for this script "ifnumber"

-- lp_host default ip address for this script "127.0.0.1"

-- Output Values

   lp_value = 0;

   lp_buffer ="error";

-- dofile(lp.GetPath().."/config/script/loriotinit.lua"); -- to support define

-- lp.InitLuaPath(); -- to support luaforwindows librairies and hook print function

function open()

      if fp~=nil then close() end

      fp=lp.Fopen(HLUA_outputfile,'at');

      return fp;

end

function close()

      if fp==nil then return end

      lp.Fclose(fp);

      fp=nil;

end

function w(val)

      open();

      if fp==nil then return end

      lp.Fprintf(fp,val);

      close();

end

w("<html><body><h1>Hello world</h1></body></html>");

</lua>

We first  declare the 3 functions (w, close,open) that help us to write data in the output file.

The w function is then use to write few HTML tags and text in the output stream.

The file test.hlua is saved in the /bin/www/hlua directory

In the navigator we just have to type the link below to display the Web page.

http://127.0.0.1:8010/hlua/test.hlua

A very basic example in xlua (The “Hello World” Web page)

We will write the same page in XML instead of HTML

The code generate XML format.

Beware to use single quote when you enclose attribute in XML tag

<lua>

-- Input values

-- lp_index index for this script ".1"

-- lp_oid SNMP OID for this script "ifnumber"

-- lp_host default ip address for this script "127.0.0.1"

-- Output Values

   lp_value = 0;

   lp_buffer ="error";

-- dofile(lp.GetPath().."/config/script/loriotinit.lua"); -- to support define

-- lp.InitLuaPath(); -- to support luaforwindows librairies and hook print function

function open()

      if fp~=nil then close() end

      fp=lp.Fopen(HLUA_outputfile,'at');

      return fp;

end

function close()

      if fp==nil then return end

      lp.Fclose(fp);

      fp=nil;

end

function w(val)

      open();

      if fp==nil then return end

      lp.Fprintf(fp,val);

      close();

end

w("<?xml version='1.0' encoding='utf-8'?>");

w("<WebPage>");

w("    <PageTitle>Hello world</PageTitle>");

w("</WebPage>");

</lua>

The page is called with the following link : http://127.0.0.1:8010/hlua/test.xlua

As we have no XSL stylesheet attached we simply display the XML contains in the navigator.

 

To format the XML we can create a simple xsl stylesheet called test.xsl that we save in the same directory as the test.xlua file.

Code for the XSL stylesheet

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

    <xsl:template match="/">

        <html xmlns="http://www.w3.org/1999/xhtml">

            <head>

                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

                <title>Test example of xlua</title>

            </head>

            <body>

                <h1>

                    <xsl:value-of select="WebPage/PageTitle"/>

                </h1>

            </body>

        </html>

    </xsl:template>

</xsl:stylesheet>

In the xlua code we add the following line (red) for applying the XSL stylesheet.

w("<?xml version='1.0' encoding='utf-8'?>");

w("<?xml-stylesheet href='test.xsl' type='text/xsl'?>");

w("<WebPage>");

w("   <PageTitle>Hello world</PageTitle>");

w("</WebPage>");

</lua>

A call to http://127.0.0.1:8010/hlua/test.xlua display a formatted web page.

Remark: in the code it is possible to add some \n and \ t escape code at the end of each line for a better formatting of the XML file.

WEB file naming convention and structure

The file extension HLUA are used to generate standard HTML files, the files XLUA are used to generate XML files.

Extension on the LoriotPro WEB server

Type of file created for the client browser

HLUA hlua

html

XLUA xlua

xml

The files are placed in the directory /bin /www/hlua or in the directories dedicated to Users reports or Global Reports.


If the file is used in HLUA directories global reports or users Reports, you can specify an icon and a title to the report entry that will be displayed in the web interface. It is necessary to change the first two lines of code to provide information to the web server allowing it to present the file correctly in the interface.

--<!-- <img border=0 src='/img/status11.jpg'>your comment here !!-->

--<!-- level 0 -->

There is three zone than can be modified:

Zone 1 : The icon

Zone 2 : The comment

Zone 3 : The« level » of the script : The script level defined the right for a user to launch a script. Only users with a higher level can launch it.

--<!-- <img border=0 src='/img/status11.jpg'>your comment here !!-->

--<!-- level 0 -->

Example of WEB file with multiple and mixed code sections, The LUA code sections are green and the natif HTML code is black.

Click here to display the code

<html>

<title>sample HLUA multi session script</title>

<Head></head>

<body>

<lua>

fp=nil;

function open()

       if fp~=nil then close() end

       fp=lp.Fopen(HLUA_outputfile,'at');

       return fp;

end

function close()

       if fp==nil then return end

       lp.Fclose(fp);

       fp=nil;

end

function w(val)

       open();

       if fp==nil then return end

       lp.Fprintf(fp,val);

       close();

end

</lua>

<b>start of the HTML page</b><br>

<lua>

for i=0,5 do

str=string.format("first session line %i<br>",i);

w(str);

end

</lua>

<b>Middle of the HTML page</b><br>

<lua>

for i=0,5 do

str=string.format("second session line %i<br>",i);

w(str);

end

</lua>

<b>end of the HTML page</b><br>

</body>

</html>

 

 Access LoriotPro global variables and the http header variables

The LoriotPro global variables and the http header variables are accessible within the WEB as LUA variable.

Remark: Some of the variable are not necessarily provided, this can be dependant from the WEB browser used.. 

Variables

Description

HLUA_outputfile 

C’est le nom du fichier temporaire qui sera envoyé au  browser web distant. L’ensemble des écritures devant générer la page web dynamique sera sauvegardé dans ce fichier en mode append.

Pour simplifier l’opération quelques fonctions LUA sont définit dans une portion du code pour simplifier l’opération d’écriture.

This is the name of temporary file that will be sent to the remote web browser. All entries used to generate the dynamic web page will be saved in this file in append mode.

To simplify the coding  a few LUA functions are previously defined to simplify the final writing operation.

--<lua>

function open()

      if fp~=nil then close() end

      fp=lp.Fopen(HLUA_outputfile,'at');

      return fp;

end

function close()

      if fp==nil then return end

      lp.Fclose(fp);

      fp=nil;

end

function w(val)

      open();

      if fp==nil then return end

      lp.Fprintf(fp,val);

       lp.Print(val);

      close();

end

function g(val)

v=lp.atof(val);

if v==0 then return ("0"); end

str1=string.format("%.1f",v);

--replace les .0 en rien

return(str1);

end

</lua>

HLUA_IP           

Provide the  IP address of the client side (The browser)

HLUA_Username           

Provide the user name used to loging

HLUA_URL           

The URL of the page

HLUA_Cookie           

Any provided cookies if exist

HLUA_Extra           

The parameters provided in the URL

HLUA_Referer           

The previous WEB page requested by the browser

HLUA_RemoteHost           

The DNS name of the client (remote browser)

HLUA_Request           

 

HLUA_user_name           

The user login name found in the session

HLUA_user_uid           

The UID of the object of the Directory attached to this session.

HLUA_user_database            

Right for this session to access the local database

1 yes 0 no

HLUA_user_browsedir           

Right for this session to access the directory:

1 yes 0 no

HLUA_user_events           

Right for this session to access  events files:

1 yes 0 no

HLUA_user_level           

The user level for this user session

HLUA_user_map           

Right for this session to access the MAP at level 3 :

1 yes 0 no

HLUA_user_php           

Right for this session to access PHP (obsolet) :

1 yes 0 no

HLUA_user_script           

Right for this session to execute scripts of type REP :

1 yes 0 no

HLUA_user_syslog           

Right for this session to access syslog files :

1 yes 0 no

HLUA_user_traps           

Right for this session to access TRAP log file :

1 yes 0 no

HLUA_user_global_lua           

Right for this session to execute global LUA scripts :

1 yes 0 no

HLUA_user_local_lua           

Right for this session to access user LUA script:

1 yes 0 no

HLUA_Value           

A table where LUA variable can be passed by the URL and used after in the LUA code.

The code below parse the LUA table variables

for key,value in pairs(HLUA_Value) do lp.Fprintf(fp,'[',key,'] [',value,']<br>') end

   

Here under an example of the usage of this variables

Click here to display the code

--<!-- <img border=0 src='/img/status11.jpg'>your comment here !!-->

--<!-- level 0 -->

--<!--

-- OEMSNMPManager V6.00 Web File To Script LUA File

-- Generated by the OEMSNMPManager Editor Wizard at : Thu Dec 10 16:33:55 2009

--------------------------------------------------------------------

-- if global to run correctly this file is located to path bin/www/hlua/xxxx.hlua

-- if local to run correctly this file is located to path bin/www/usr/username/xxxx.hlua

--------------------------------------------------------------------

-- Use this line of code if you want use some defined OEMSNMPManager LUA Define

-- dofile(lp.GetPath().."/config/script/loriotinit.lua");

--------------------------------------------------------------------

-- Input values imported by the Web Server and passed to this script

--------------------------------------------------------------------

-- HLUA_outputfile  the file name to append (sending by the server to the client)

-- HLUA_IP            IP address of the client

-- HLUA_Username            client login user name

-- HLUA_URL            The URL for this page

-- HLUA_Cookie            The Cookie if exist

-- HLUA_Extra            The URL value part no parsed

-- HLUA_Referer            The last URL used by the client

-- HLUA_RemoteHost            The DNS Name of the client if exist

-- HLUA_Request            The number of this Trap received (no acked)

-- HLUA_user_name            The name find in policy

-- HLUA_user_uid            The available directory root for this client

-- HLUA_user_database            The database access : 1 Yes 0 No

-- HLUA_user_browsedir            The web directory browsing access : 1 Yes 0 No

-- HLUA_user_events            The events files access : 1 Yes 0 No

-- HLUA_user_level            The client level : 1 Yes 0 No

-- HLUA_user_map            The network MAP access : 1 Yes 0 No

-- HLUA_user_php            The PHP access  : 1 Yes 0 No

-- HLUA_user_script            The REP script access : 1 Yes 0 No

-- HLUA_user_syslog            The syslog files access : 1 Yes 0 No

-- HLUA_user_traps            The traps files access : 1 Yes 0 No

-- HLUA_user_global_lua            The global lua web access : 1 Yes 0 No

-- HLUA_user_local_lua            The local lua web access : 1 Yes 0 No

-- HLUA_Value            The table with parsed URL value (value name is index)

-- use this part to simulate an Event to debug your script

--[[

HLUA_outputfile='c:/test.html';              --  

HLUA_IP='';                          --  

HLUA_Username='';                    --  

HLUA_URL='';                          --  

HLUA_Cookie='';                    --  

HLUA_Extra='';                    --  

HLUA_Referer='';                    --  

HLUA_RemoteHost='';              --  

HLUA_Username='';                    --  

HLUA_Request='';                    --  

HLUA_user_name='';              --  

HLUA_user_uid='';                    --  

HLUA_user_database='';        --  

HLUA_user_browsedir='';       --  

HLUA_user_events='';              --  

HLUA_user_host_event='';       --  

HLUA_user_level='';              --  

HLUA_user_map='';                    --  

HLUA_user_php='';                    --  

HLUA_user_script='';              --  

HLUA_user_syslog='';              --  

HLUA_user_traps='';              --  

HLUA_user_syslog='';              --  

HLUA_user_global_lua='';       --  

HLUA_user_local_lua='';       --  

HLUA_Value={};                        --  

HLUA_Value['ip']='127.0.0.1';  --  

-- use this part to simulate an Event to debug your script

 ]]--

--------------------------------------------------------------------

--  Start of your program ------------------------------------------

--------------------------------------------------------------------

-- TODO: Add your message handler code here and/or call default

-- use this part to simulate an Event to debug your script

-->

--<lua>

function open()

--lp.Print(HLUA_outputfile,'\n');

fp=lp.Fopen(HLUA_outputfile,'at');

--if (fp) then lp.Print('test open file'); end

return fp;

end

function write(fp,val)

if fp==nil then return nil end

lp.Fprintf(fp,val);

return 1

end

function close(fp)

if fp==nil then return nil end

lp.Fclose(fp);

return 1;

end

function f1(fp)

--lp.SendSyslog(lp_host,'test 1');

--lp.SendSyslog(lp_host,HLUA_outputfile);

if fp then

--lp.Print('test f1 \n');

lp.Fprintf(fp,'HLUA_outputfile=',HLUA_outputfile ,'<br>');

lp.Fprintf(fp,'HLUA_IP=',HLUA_IP ,'<br>');

lp.Fprintf(fp,'HLUA_Username=',HLUA_Username,'<br>');

lp.Fprintf(fp,'HLUA_URL=',HLUA_URL,'<br>');

lp.Fprintf(fp,'HLUA_Cookie=',HLUA_Cookie,'<br>');

lp.Fprintf(fp,'HLUA_Extra=',HLUA_Extra,'<br>');

lp.Fprintf(fp,'HLUA_Referer=',HLUA_Referer,'<br>');

lp.Fprintf(fp,'HLUA_RemoteHost=',HLUA_RemoteHost,'<br>');

lp.Fprintf(fp,'HLUA_Username=',HLUA_Username,'<br>');

lp.Fprintf(fp,'HLUA_Request=',HLUA_Request,'<br>');

lp.Fprintf(fp,'HLUA_user_name=',HLUA_user_name,'<br>');

lp.Fprintf(fp,'HLUA_user_uid=',HLUA_user_uid,'<br>');

lp.Fprintf(fp,'HLUA_user_database=',HLUA_user_database,'<br>');

lp.Fprintf(fp,'HLUA_user_browsedir=',HLUA_user_browsedir,'<br>');

lp.Fprintf(fp,'HLUA_user_events=',HLUA_user_events,'<br>');

lp.Fprintf(fp,'HLUA_user_host_event=',HLUA_user_host_event,'<br>');

lp.Fprintf(fp,'HLUA_user_level=',HLUA_user_level,'<br>');

lp.Fprintf(fp,'HLUA_user_map=',HLUA_user_map,'<br>');

lp.Fprintf(fp,'HLUA_user_php=',HLUA_user_php,'<br>');

lp.Fprintf(fp,'HLUA_user_script=',HLUA_user_script,'<br>');

lp.Fprintf(fp,'HLUA_user_syslog=',HLUA_user_syslog,'<br>');

lp.Fprintf(fp,'HLUA_user_traps=',HLUA_user_traps,'<br>');

lp.Fprintf(fp,'HLUA_user_global_lua=',HLUA_user_global_lua,'<br>');

lp.Fprintf(fp,'HLUA_user_local_lua=',HLUA_user_local_lua,'<br>');

lp.Fprintf(fp,'<hr>');

for key,value in pairs(HLUA_Value) do lp.Fprintf(fp,'[',key,'] [',value,']<br>') end

end

end

--</lua>

<b> put some html tag </b><br>

--<lua>

open(); f1(fp); close(fp);

--</lua>

 

The execution of this code provides the following display in the browser.

Testing a WEB page in the script  editor

You can access WEB page written as HLUA or XLUA directly from the LoriotPro LUA script editor.

Contrary to a classical LUA script, access to a WEB page with embedded LUA script is done from the menu option Run HLUA, XLUA script of the F6 key.

The script execution will output the result directly in your default browser.

Pour débuguer ce type de script il est possible d’utiliser la commande lp.Print(xxx) dans le code pour avoir un affichage dans la fenêtre de sortie classique de l’éditeur.

Si nous rajoutons la ligne suivante au code précédent.

To debug this type of script it is possible to use the command lp.Print (xxx) in the code to get a display in the usual editor output window.


We add the following code (green) to the previous code for debugging purpose.

<lua>

for i=0,5 do

str=string.format("first session line %i<br>",i);

lp.Print(str,"\n");

w(str);

end

</lua>

We have a possible control of the code in the standard output window at runtime.

It is possible that the LUA interpreter detects a syntax error in your code. In this case a message is displayed in the standard window to indicate the location of the error.

Note: in this case the generated HTML page is not displayed.


Example: a syntax error is introduced in the code:

<lua>

for i=0,5 do

str=string.format("first session line %i<br>",i);

lp.Print(str,"\n");

w(str);

end

</lua>

When we execute the upper code, we have an error message and a notepad window is displayed with a copy of the section of the code affected by the error. The line number provided in the standard output window match the section of code copied in the text file and open with notepad. This method is used for ease of debugging WEB page file with multiple and complex sections.

Example of advanced WEB pages written in LUA XML (XLUA).

Lorsqu’un browser distant demande une page possédant les extensions  HLUA ou XLUA au serveur Web intégré à LoriotPro, si le fichier existe, LoriotPro interprète ce fichier pour transformer les portions contenant du script LUA en texte compréhensible par le browser distant (HTML ou XML).

Exemple :

Cette exemple complexe browse la Directory de LoriotPro et génère dynamiquement des barre graphe du statuts des équipements présent en fonction de leurs usages.

When a browser requests a page with remote extensions or HLUA XLUA the to the LoriotPro WEB server, if the file exists, LoriotPro interprets the file containing the sections of the LUA script and convert in html or XML stream understandable by the remote browser (HTML or XML) .

Example:

This complex example, browse the Directory LoriotPro and dynamically generates bar graph of the status of the devices according to their current availability.

Cet exemple est disponible sur http://127.0.0.1:8010/hlua/AvailabilityOverview.xlua

Dans cet exemple le fichier AvailabilityOverview.xlua appelé par le browser Mozilla possède une extension indiquant au server Web que ce fichier contient du code LUA et qu’il doit être interprété avant d’être envoyé au browser.

Voici le code XML  résultant généré pour le browser

<?xml version='1.0' encoding='utf-8'?>

<?xml-stylesheet href='AvailabilityOverview.xsl' type='text/xsl'?>

<AvailabilityOverview>

        <AvailNode>

        <Icon>Root32.jpg</Icon>

        <Desc><![CDATA[total]]></Desc>

        <UnTo lnk='TotalOverview.xlua'><![CDATA[20/20]]></UnTo>

        <AvailBlue lnk="testblue"><![CDATA[5]]></AvailBlue>

        <AvailGreen lnk="testgreen"><![CDATA[25]]></AvailGreen>

        <AvailRed lnk="testred"><![CDATA[70]]></AvailRed>

        </AvailNode>

        <AvailNode>

        <Icon>d_server.gif</Icon>

        <Desc><![CDATA[server]]></Desc>

        <UnTo lnk='ServerOverview.xlua'><![CDATA[1/20]]></UnTo>

        <AvailBlue lnk="testblue"><![CDATA[100]]></AvailBlue>

        </AvailNode>

        <AvailNode>

        <Icon>d_router.gif</Icon>

        <Desc><![CDATA[router]]></Desc>

        <UnTo lnk='RouterOverview.xlua'><![CDATA[5/20]]></UnTo>

        <AvailGreen lnk="testgreen"><![CDATA[40]]></AvailGreen>

        <AvailRed lnk="testred"><![CDATA[60]]></AvailRed>

        </AvailNode>

        <AvailNode>

        <Icon>Interro.gif</Icon>

        <Desc><![CDATA[other]]></Desc>

        <UnTo lnk='OtherOverview.xlua'><![CDATA[14/20]]></UnTo>

        <AvailGreen lnk="testgreen"><![CDATA[21]]></AvailGreen>

        <AvailRed lnk="testred"><![CDATA[79]]></AvailRed>

        </AvailNode>

</AvailabilityOverview>

 

Remarque : Nous n’avons reproduit ici les fichiers CSS et XSL (il se trouve dans le répertoire www/hlua).   

Voici le contenue du fichier XLUA utilisé pour la génération :

Les portions de code LUA sont encadrées des balises <lua> ….. </lua>.

Dans cette exemple les portions de code LUA  seront interprétées par le server Web avant d’être envoyé au browser distant.

Click here to display the code

<lua>

-- OEMSNMPManager V6.00

-- To run correctly this file is located to bin/config/script

-- Input values

-- lp_index index for this script ".1"

-- lp_oid SNMP OID for this script "ifnumber"

-- lp_host default ip address for this script "127.0.0.1"

-- Output Values

   lp_value = 0;

   lp_buffer ="error";

-- dofile(lp.GetPath().."/config/script/loriotinit.lua"); -- to support define

-- lp.InitLuaPath(); -- to support luaforwindows librairies and hook print function

--HLUA_outputfile="c:\test.html"

icon={};link={};

LP_LUA_ISDEVICE_AUTO = 0;icon[0]="Interro.gif";link[0]="OtherOverview.xlua";

LP_LUA_ISDEVICE_HOST = 1;icon[1]="d_host01.gif";link[1]="HostOverview.xlua";

LP_LUA_ISDEVICE_SERVER = 2;icon[2]="d_server.gif";link[2]="ServerOverview.xlua";

LP_LUA_ISDEVICE_HUB = 3;icon[3]="d_hub.gif";link[3]="HubOverview.xlua";

LP_LUA_ISDEVICE_SWITCH = 4;icon[4]="d_switch.gif";link[4]="SwitchOverview.xlua";

LP_LUA_ISDEVICE_ROUTER = 5;icon[5]="d_router.gif";link[5]="RouterOverview.xlua";

LP_LUA_ISDEVICE_PRINTER = 6;icon[6]="d_printer.gif";link[6]="PrinterOverview.xlua";

LP_LUA_ISDEVICE_PHONE = 7;icon[7]="d_phone.gif";link[7]="PhoneOverview.xlua";

LP_LUA_ISDEVICE_TOTAL = 8;icon[8]="Root32.jpg";link[8]="TotalOverview.xlua";

function open()

      if fp~=nil then close() end

      fp=lp.Fopen(HLUA_outputfile,'at');

      return fp;

end

function close()

      if fp==nil then return end

      lp.Fclose(fp);

      fp=nil;

end

function w(val)

      open();

      if fp==nil then return end

      lp.Fprintf(fp,val);

       lp.Print(val);

      close();

end

function g(val)

v=lp.atof(val);

if v==0 then return ("0"); end

str1=string.format("%.1f",v);

--replace les .0 en rien

return(str1);

end

function GetStat(uid)

lp.Print(uid," start\n");

                        stat[LP_LUA_ISDEVICE_AUTO][6]="other";

                        stat[LP_LUA_ISDEVICE_HOST][6]="host";

                        stat[LP_LUA_ISDEVICE_SERVER][6]="server";

                        stat[LP_LUA_ISDEVICE_HUB][6]="hub";

                        stat[LP_LUA_ISDEVICE_SWITCH][6]="switch";

                        stat[LP_LUA_ISDEVICE_ROUTER][6]="router";

                        stat[LP_LUA_ISDEVICE_PRINTER][6]="printer";

                        stat[LP_LUA_ISDEVICE_PHONE][6]="phone";

                        stat[LP_LUA_ISDEVICE_TOTAL][6]="total";

a=lp.GetAllHostFromContainer(uid,"ar");

      if (a~=nil) then

      host_number=a;

            for i=0,a-1 do

                  --lp.Print(string.format("ip(%i) = %s %s\n",i+1,ar[i]));

                  if lp.GetIPInformation(ar[i],"b") then

                              lp.Print(string.format("Device type = %s \n",b.device_type));     

                        r=LP_LUA_ISDEVICE_TOTAL;

                        if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end  

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        if b.device_type == LP_LUA_ISDEVICE_AUTO then

                                  r=LP_LUA_ISDEVICE_AUTO;

                                  if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end

                                  if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                                  if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                                  if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                                  if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                                  if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                                  end

                        if b.device_type == LP_LUA_ISDEVICE_HOST then

                                  r=LP_LUA_ISDEVICE_HOST;

                                  if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end 

                                  if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                                  if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                                  if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                                  if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                                  if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                                  end

                        if b.device_type == LP_LUA_ISDEVICE_SERVER then

                                  r=LP_LUA_ISDEVICE_SERVER;

                                  if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end

                                  if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                                  if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                                  if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                                  if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                                  if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                                  end

                        if b.device_type == LP_LUA_ISDEVICE_HUB then

                                  r=LP_LUA_ISDEVICE_HUB;

                                  if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end

                                  if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                                  if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                                  if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                                  if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                                  if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                                  end

                        if b.device_type == LP_LUA_ISDEVICE_SWITCH then

                                  r=LP_LUA_ISDEVICE_AUTO;

                                  if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end 

                                  if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                                  if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                                  if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                                  if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                                  if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                                  end

                        if b.device_type == LP_LUA_ISDEVICE_ROUTER then

                                  r=LP_LUA_ISDEVICE_ROUTER;

                                  if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end

                                  if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                                  if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                                  if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                                  if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                                  if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                                  end

                        if b.device_type == LP_LUA_ISDEVICE_PRINTER then

                                  r=LP_LUA_ISDEVICE_PRINTER;

                                  if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end

                                  if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                                  if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                                  if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                                  if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                                  if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                                  end

                        if b.device_type == LP_LUA_ISDEVICE_PHONE then

                                  r=LP_LUA_ISDEVICE_PHONE;

                                  if b.status ~= 0 then stat[r][5]=stat[r][5]+1; end

                                  if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                                  if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                                  if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                                  if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                                  if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                                  end

                  end

            end

--callcul des moyennes

      for i=0,8 do -- pour chaque type d'objet

            for j=1,4 do -- pour chaque statut du bleu au rouge (violet non pris en compte

            if stat[i][5]>0 then

                  --stat[i][7+j]= math.ceil((stat[i][j]/stat[i][5])*100);

                     if (stat[i][j]/stat[i][5])*100 > math.floor((stat[i][j]/stat[i][5])*100)+ 0.5 then

                        stat[i][7+j]= math.ceil((stat[i][j]/stat[i][5])*100);

                     else stat[i][7+j]= math.floor((stat[i][j]/stat[i][5])*100);

                     end

            else

                  stat[i][7+j]=0;

            end

            lp.Print(stat[i][7+j],' ');

            end

      lp.Print('\n');

      end

      lp.Print("end\n");

      return (host_number);

      end

return (nil);     

end

stat={};

--init les values de la matrice

for i=0,8 do -- tableau des types de host excepté le total     

      stat[i]={}; --status     

      for j=0,10 do

            stat[i][j]=0;

      end

end

if (GetStat("world")) then

for i=0,8 do

      for j=0,10 do

            lp.Print(g(stat[i][j]),' ');

      end

      lp.Print('\n');

      end

end

--génération du fichier de sortie xml

xsltemplate = "AvailabilityOverview.xsl";

--xsltemplate = nil;

w("<?xml version='1.0' encoding='utf-8'?>\n");

if xsltemplate ~= nil then

      w("<?xml-stylesheet href='"..xsltemplate.."' type='text/xsl'?>\n");

end

w("<AvailabilityOverview>\n");

ordre={};

ordre[0]=8;--LP_LUA_ISDEVICE_TOTAL

ordre[1]=1;--LP_LUA_ISDEVICE_SERVER

ordre[2]=2;--LP_LUA_ISDEVICE_HOST

ordre[3]=5;--LP_LUA_ISDEVICE_ROUTER

ordre[4]=4;--LP_LUA_ISDEVICE_SWITCH

ordre[5]=3;--LP_LUA_ISDEVICE_HUB

ordre[6]=6;--LP_LUA_ISDEVICE_PRINTER

ordre[7]=7;--LP_LUA_ISDEVICE_PHONE

ordre[8]=0;--LP_LUA_ISDEVICE_AUTO

for i=0,8 do

if (stat[ordre[i]][5]>0) then

      w("\t<AvailNode>\n");

            w("\t<Icon>"..icon[ordre[i]].."</Icon>\n");

            w("\t<Desc><![CDATA["..stat[ordre[i]][6].."]]></Desc>\n");

            w("\t<UnTo lnk='"..link[ordre[i]].."'><![CDATA["..stat[ordre[i]][5].."/"..stat[ordre[0]][5].."]]></UnTo>\n");

            --w("\t<AvailMagenta lnk=".."\"testmagenta\"".."><![CDATA["..stat[ordre[i]][7].."]]></AvailMagenta>\n");

              if stat[ordre[i]][8] > 0 then

                  w("\t<AvailBlue lnk=".."\"testblue\"".."><![CDATA["..stat[ordre[i]][8].."]]></AvailBlue>\n");

              end

              if stat[ordre[i]][9] > 0 then

            w("\t<AvailGreen lnk=".."\"testgreen\"".."><![CDATA["..stat[ordre[i]][9].."]]></AvailGreen>\n");

              end

              if stat[ordre[i]][10] > 0 then

            w("\t<AvailYellow lnk=".."\"testyellow\"".."><![CDATA["..stat[ordre[i]][10].."]]></AvailYellow>\n");

              end

              if stat[ordre[i]][11] > 0 then

            w("\t<AvailRed lnk=".."\"testred\"".."><![CDATA["..stat[ordre[i]][11].."]]></AvailRed>\n");

              end

      w("\t</AvailNode>\n");

       end

       end

w("</AvailabilityOverview>\n");

</lua>

 

In this example the entire file is done in LUA and there is only one piece of code. It is possible to produce mixed files that will contain portions of code like HTML or XML and LUA scripting. In another example this code is mixed (LUA portions are green).

Click here to display the code

--<lua>

-- OEMSNMPManager V6.00

-- To run correctly this file is located to bin/config/script

-- Input values

-- lp_index index for this script ".1"

-- lp_oid SNMP OID for this script "ifnumber"

-- lp_host default ip address for this script "127.0.0.1"

-- Output Values

   lp_value = 0;

   lp_buffer ="error";

-- dofile(lp.GetPath().."/config/script/loriotinit.lua"); -- to support define

-- lp.InitLuaPath(); -- to support luaforwindows librairies and hook print function

--HLUA_outputfile="c:\test.html"

LP_LUA_ISDEVICE_AUTO = 0;

LP_LUA_ISDEVICE_HOST = 1;

LP_LUA_ISDEVICE_SERVER = 2;

LP_LUA_ISDEVICE_HUB = 3;

LP_LUA_ISDEVICE_SWITCH = 4;

LP_LUA_ISDEVICE_ROUTER = 5;

LP_LUA_ISDEVICE_PRINTER = 6;

LP_LUA_ISDEVICE_PHONE = 7;

LP_LUA_ISDEVICE_TOTAL = 8;

function open()

      if fp~=nil then close() end

      fp=lp.Fopen(HLUA_outputfile,'at');

      return fp;

end

function close()

      if fp==nil then return end

      lp.Fclose(fp);

      fp=nil;

end

function w(val)

      open();

      if fp==nil then return end

      lp.Fprintf(fp,val);

       lp.Print(val);

      close();

end

function g(val)

v=lp.atof(val);

if v==0 then return ("0"); end

str1=string.format("%.1f",v);

--replace les .0 en rien

return(str1);

end

function GetStat(uid)

lp.Print(uid," start\n");

                        stat[LP_LUA_ISDEVICE_AUTO][6]="other";

                        stat[LP_LUA_ISDEVICE_HOST][6]="host";

                        stat[LP_LUA_ISDEVICE_SERVER][6]="server";

                        stat[LP_LUA_ISDEVICE_HUB][6]="hub";

                        stat[LP_LUA_ISDEVICE_SWITCH][6]="switch";

                        stat[LP_LUA_ISDEVICE_ROUTER][6]="router";

                        stat[LP_LUA_ISDEVICE_PRINTER][6]="printer";

                        stat[LP_LUA_ISDEVICE_PHONE][6]="phone";

                        stat[LP_LUA_ISDEVICE_TOTAL][6]="total";

a=lp.GetAllHostFromContainer(uid,"ar");

      if (a~=nil) then

      host_number=a;

            for i=0,a-1 do

                  --lp.Print(string.format("ip(%i) = %s \n",i+1,ar[i]));

                  if lp.GetIPInformation(ar[i],"b") then

                        r=LP_LUA_ISDEVICE_TOTAL;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        if b.device_type == LP_LUA_ISDEVICE_AUTO then

                        r=LP_LUA_ISDEVICE_AUTO;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        end

                        if b.device_type == LP_LUA_ISDEVICE_HOST then

                        r=LP_LUA_ISDEVICE_HOST;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        end

                        if b.device_type == LP_LUA_ISDEVICE_SERVER then

                        r=LP_LUA_ISDEVICE_SERVER;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        end

                        if b.device_type == LP_LUA_ISDEVICE_HUB then

                        r=LP_LUA_ISDEVICE_HUB;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        end

                        if b.device_type == LP_LUA_ISDEVICE_SWITCH then

                        r=LP_LUA_ISDEVICE_AUTO;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        end

                        if b.device_type == LP_LUA_ISDEVICE_ROUTER then

                        r=LP_LUA_ISDEVICE_ROUTER;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        end

                        if b.device_type == LP_LUA_ISDEVICE_PRINTER then

                        r=LP_LUA_ISDEVICE_PRINTER;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        end

                        if b.device_type == LP_LUA_ISDEVICE_PHONE then

                        r=LP_LUA_ISDEVICE_PHONE;

                        stat[r][5]=stat[r][5]+1;

                        if b.status == 0 then stat[r][0]=stat[r][0]+1; end

                        if b.status == 1 then stat[r][1]=stat[r][1]+1; end

                        if b.status == 2 then stat[r][2]=stat[r][2]+1; end

                        if b.status == 3 then stat[r][3]=stat[r][3]+1; end

                        if b.status == 4 then stat[r][4]=stat[r][4]+1; end

                        end

                  end

            end

--callcul des moyennes

      for i=0,8 do

            for j=0,4 do

            if stat[i][5]>0 then

            stat[i][7+j]=(stat[i][j]/stat[i][5])*100;

            else

            stat[i][7+j]=0;

            end

            lp.Print(stat[i][7+j],' ');

            end

      lp.Print('\n');

      end

      lp.Print("end\n");

      return (host_number);

      end

return (nil);     

end

stat={};

--init les values de la matice

for i=0,8 do -- tableau des types de host

stat[i]={}; --status

for j=0,11 do

stat[i][j]=0;

end

end

if (GetStat("world")) then

for i=0,8 do

for j=0,11 do

lp.Print(g(stat[i][j]),' ');

end

lp.Print('\n');

end

end

--</lua>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<META HTTP-EQUIV='Refresh' CONTENT='5'>

<META HTTP-EQUIV='Pragma' CONTENT='no-cache' >

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Document sans nom</title>

<link href="sample.css" rel="stylesheet" type="text/css" />

</head>

<body>

<table class="tbdef" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td colspan="4"><span class="tdtitle1">Availability Overview</span></td>

  </tr>

  <tr>

    <td colspan="4">&nbsp;</td>

  </tr>

  <tr>

    <td colspan="4" class="tdtitle2">Current status</td>

  </tr>

  <tr>

    <th class="tbdef">&nbsp;</th>

    <th class="tbdef">Description</th>

    <th class="tbdef">Units/Total</th>

    <th class="tbdef">Availability in % of total</th>

  </tr>

  <tr>

    <td class="tdtxt">&nbsp;</td>

    <td class="tdtxt">Global Availability</td>

    <td class="tdtxt">254/254</td>

    <td class="tdtxt">

    <div class="apDiv1">

      <div class="bg1" style="width:10%;"><a href="/lien">10</a></div>

      <div class="bg2" style="width:25%;">25</div>

      <div class="bg3" style="width:15%;">15</div>

      <div class="bg4" style="width:50%;">50</div>

    </div></td>

  </tr>

<lua>

for i=0,8 do

if (stat[i][5]>0) then

  w(string.format("<tr>"));

  w(string.format('<td class="tdtxt"><img src="img/Interro.gif" alt="interrop->" width="32" height="32" /></td>'));

  w(string.format('<td class="tdtxt">%s Availability</td>',stat[i][6]));

  w(string.format('<td class="tdtxt">%i/%i</td>',stat[i][5],stat[8][5]));

  w(string.format('<td class="tdtxt">'));

  w(string.format('<div class="apDiv1">'));

  w(string.format('<div class="bg0" style="width:%i%%;">%i</div>',stat[i][7],stat[i][7]));

  w(string.format('<div class="bg1" style="width:%i%%;">%i</div>',stat[i][8],stat[i][8]));

  w(string.format('<div class="bg2" style="width:%i%%;">%i</div>',stat[i][9],stat[i][9]));

  w(string.format('<div class="bg3" style="width:%i%%;">%i</div>',stat[i][10],stat[i][10]));

  w(string.format('<div class="bg4" style="width:%i%%;">%i</div>',stat[i][11],stat[i][11]));

  w(string.format('</div></td>'));

  w(string.format("</tr>\n"));

  end

  end

</lua>

</table>

<p>&nbsp;</p>

</body>

</html>

 

When interpreting the file HLUA or XLUA, the web server reproduces unchanged the portions outside the tag <lua> ... </ lua> but interprets the code portions located between  <lua> ... </ lua> as LUA code.

 To do this the Web server creates temporary files and provides the LUA script a number of parameters to enable it to achieve the dynamic integration.

Limitation of HLUA, XLUA WEB pages

The WEB pages defined as HLUA XLUA files can exploit all the LUA functions of LoriotPro. So they can write and read in the Directory and make any kind of treatment. However, because of how they use libraries LPAV specific active-view functions are not usable. The use of window and booksellers that generate popup or dialog boxes are not usable because the window would appear on the station or turn LoriotPro and would block the session.

It is recommended to write simple and fast code to avoid hanging  and overload of the process (threads) allocated to the Web server. The script files and HLUA XLUA must be written in a logical non-blocking and fast execution.

The web page generated by the script is sent to the client browser when finished. It is therefore necessary that the generation is quick to avoid a timeout on the client side.


www.loriotpro.com