OpenACS wiki

来源:互联网 发布:图转文软件 编辑:程序博客网 时间:2024/06/05 14:48
此文章转载于 http://sourceforge.net/p/openacs/wiki/Scripting/

Configurations script

OpenACS supports configuration scripts written in JavaScript. If you want to use scripts to configure CPE you must have a script named ‘Default’ because this is the script the server will try to run on CPE Inform request when it has no configuration files or firmware update requests pending .

Functions

logger

Function provides access to standard application server logger facility.

logger('My message');   // message with default severity WARNING is logged.logger('severe', 'Error message');logger('warning', 'Warning message');logger('info', 'Informational message');

call

Function lets to run another script.

call('script_name');

Variables

cpedb

cpedb global variable provides acces to CPE bean in database, namely to properties field. They can be accessed as usual javascript properties. To save them back to database method Save should be used. This object is intended to assign configuration properties for user.

var someprop = cpedb.someprop;cpedb.someprop = 'new_value_for_someprop';cpedb.Save();

cpe

cpe global variable provides access to all the CPE variables and RPC calls specified in TR-069.

Properties

Inform - exposes Inform request which triggered configuration script to run.

Methods

GetRPCMethods () - return arrays of methods supported by CPE.

// this will output supported methods to server consolevar methods = cpe.GetRPCMethods();for (i = 0; i < methods.length; i++) {       logger('Method: '+methods[i]);}

Download

Download(commandKey, what_to_download, url, username, password, file_size, file_name) - Tells CPE to start downloading configuration or firmware depending on what_to_download parameter (possible values as specified in TR-069)

var response = cpe.Download("daCommand", "3 Vendor Configuration File","http://192.168.1.1:8080/kkonf", "", "",000,"user.ini");logger("st="+response.StartTime+" ct="+CompleteTime+" status="+response.Status);

GetParameterValues

GetParameterValues (array_of_parameter_names) - return array of object with properties name and value.

var parameters = new Array();parameters[0] = 'InternetGatewayDevice.DeviceSummary';var response = cpe.GetParameterValues(parameters);logger(response[0].name+'='+response[0].value);

SetParameterValues

SetParameterValues (params_array, commandKey) - sets parameter values. Params_array is array of objects having properties name and value.

var parameters = new Array();parameters[0] = {name: 'InternetGatewayDevice.IPPingDiagnostics.Host', value: '192.168.0.1'};// Encode parameter using default type xsd:stringparameters[1] = {name: 'InternetGatewayDevice.IPPingDiagnostics.NumberOfRepetitions', value: '2'};// set encoding typeparameters[2] = {name: 'InternetGatewayDevice.IPPingDiagnostics.NumberOfRepetitions', value: '2', type: 'xsd:unsignedInt'};cpe.SetParameterValues(parameters, "commandKey");

AddObject

AddObject (top_object_name, parameterKey) - creates new object instance. Returns object with properties Status and InstanceNumber.

DeleteObject

DeleteObject (object_name, parameterKey) - delete object. Returns integer status.

SetParameterAttributes

SetParameterAttributes (params_array) - set attributes for parameters. Returns nothing.

var parameters = new Array();parameters[0]=new Object;parameters[0].Name='InternetGatewayDevice.IPPingDiagnostics.NumberOfRepetitions';parameters[0].Notification=0;parameters[0].NotificationChange=true;parameters[0].AccessListChange=true;parameters[0].AccessList= new Array();parameters[0].AccessList[0]='subscriber';cpe.SetParameterAttributes(parameters);

GetParameterAttributes

GetParameterAttributes (parameter_names_array)

var p=new Array(); p[0]='InternetGatewayDevice.ManagementServer.PeriodicInformEnable'; var r = cpe.GetParameterAttributes (p);

Reboot

Reboot (commandKey) - reboots cpe.

cpe.Reboot("commandKey");

FactoryReset

FactoryReset - resets cpe to factory default settings. Method is optional in cpe so not all of them has support for it.

cpe.FactoryReset();

ScheduleInform

ScheduleInform (seconds_to_delay, commandKey) - request the CPE to schedule a one-time Inform method call (separate from its periodic Inform method calls) sometime in the future. Method is optional in cpe so not all of them has support for it.

cpe.ScheduleInform(3600, "commandKey"); // schedule inform in one hour

X_00000C_ShowStatus

X_00000C_ShowStatus (array_of_show_commands) - Cisco proprietary method to run several show commands and get their output.

var commands = new Array();commands[0] = "show version";commands[1] = "show running";var response = cpe.X_00000C_ShowStatus(commands);var thecommand = response[0].Command;var itsoutput = response[0].Response;

X_JUNGO_COM_RGCommand

X_JUNGO_COM_RGCommand (telnet_command) - jungo.com OpenRG based firmware proprietary method to run command.

var response = cpe.X_JUNGO_COM_RGCommand("net ifconfig");var result = response.Result; // output of commandvar status = response.Status; // status - 0 if succes

SyncParameterValues

SyncParameterValues - check and synchronize parameter values on cpe.

var parameters = new Array();parameters[0] = {Name: 'InternetGatewayDevice.ManagementServer.PeriodicInformEnable', Value: '1'};parameters[1] = {Name: 'InternetGatewayDevice.ManagementServer.PeriodicInformInterval', Value: '300'};cpe.SyncParameterValues(parameters);

db

This object allows to work with database. The database can be the same the openacs uses to store data as well as external datasource configured similar to datasource in [1] step 3

This would run SELECT query on datasource named the data_source_name.

db.Query(data_source_name, select_statement)

This would run query on openacs datasource “java:ACS”.

db.Query(select_statement)

it is equivalent to

db.Query("java:ACS", select_statement)

returns array of objects with fields name as in query e.g.

try {    var rs = db.Query("SELECT id,serialno FROM hostsbean")    logger("Rows found = "+rs.length)    for (i = 0; i < rs.length; i++) {        logger("id = "+rs[i].id+" serialno= "+rs[i].serialno);    }} catch (e) {    logger("DS exception: "+e.message)}

To run INSERT or UPDATE queries use Update function.

db.Update(data_source_name, update_statement)

This would run query on openacs datasource “java:ACS”.

db.Update(select_statement)

returns count of rows affected e.g.

try {    var rs = db.Update("INSERT id,serialno INTO hostsbean VALUES (NULL,'12345')")} catch (e) {    logger("DS exception: "+e.message)}
0 0
原创粉丝点击