This is the core of the ACS engine where you can perform logic based on the type of request the device has sent. All scripts are written in Javascript.
Call is used to call another another script.
call ('script_name');
Logger is used to log a message to the app server logger. Either with a default severity with a single value or with the JBoss Severity prefixed in lower case:
logger ('Normal message'); logger ('severe', 'Error message');
The cpe global variable provides all the CPE variables and RPC calls specific to the CPE.
The cpedb global variable provides access to the CPE configuration specific properties record in the database. To save any property modified you muse use the Save method.
Retrieve property value:
var newproperty = cpedb.newproperty;
Set property value:
cpedb.newproperty = 'newpropertyvalue'; cpedb.Save();
Inform - exposes Inform request which triggered configuration script to run.
GetRPCMethods() - Return arrays of methods supported by CPE.
Print the methods supported by the CPE to the logger
var methods=cpe.GetRPCMethods(); for (i=0; i<methods.length; i++) { logger('Method: '+methods[i]); }
GetParameterValues(array_of_parameter_names) - Return array of object with properties "name" and "value" as the name and the value of each property.
var cpeparameters=new Array(); cpeparameters[0]='InternetGatewayDevice.DeviceSummary'; var cperesponse=cpe.GetParameterValues(cpeparameters); logger(cpeparameters[0].name+'='+cperesponse[0].value);
SetParameterValues(paramsarray, commandKey) - Sets parameter values. paramsarray is array of objects having properties name and value and type (if required) starting at 0. The commandKey always needs to be set either to a blank value or the CPE's commandKey. The commandKey parameter is optional.
var parameters = new Array(); parameters[0] = {name: 'InternetGatewayDevice.IPPingDiagnostics.Host', value: '192.168.0.1'}; // Encode parameter using default type xsd:string parameters[1] = {name: 'InternetGatewayDevice.IPPingDiagnostics.NumberOfRepetitions', value: '2'}; // set encoding type parameters[2] = {name: 'InternetGatewayDevice.IPPingDiagnostics.NumberOfRepetitions', value: '2', type: 'xsd:unsignedInt'}; cpe.SetParameterValues (parameters, "commandKey");
GetParameterAttributes(parameter_names_array)
var p=new Array(); p[0]='InternetGatewayDevice.ManagementServer.PeriodicInformEnable'; var r = cpe.GetParameterAttributes(p); var parameters = new Array(); parameters[0]='InternetGatewayDevice'; var response=cpe.GetParameterAttributes(parameters); for (i = 0; i < response.length; i++) { logger ('parameterattribute: '+response[i].Name+' Notification :'+response[i].Notification); }
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);
AddObject(top_object_name, commandKey) - Creates new object instance. Returns object with properties Status and InstanceNumber.
var AddVoiceProfile = new Object(); AddVoiceProfile = 'InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.'; var xResponse = cpe.AddObject(AddVoiceProfile , "commandKey");
DeleteObject (object_name, commandKey) - Delete object from CPE. Returns integer status.
for (i = 1; i <= xVoiceProfileCount ; i++) { var RmvItem = new Object(); RmvItem = 'InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.' + i + '.'; var status = cpe.DeleteObject(RmvItem, "commandKey"); }
Download (commandKey, what_to_download, url, username, password, file_size, file_name) - Informs the CPE to download the file in the "what_to_download" field.
var response = cpe.Download ("daCommand", "3 Vendor Configuration File","http://192.168.1.1:8080/kkonf", "", "",000,"user.ini"); logger ("st="+response.StartTime+" ct="+response.CompleteTime+" status="+response.Status);
Reboot(commandKey) - Reboots the CPE if supported by the CPE.
cpe.Reboot("commandKey");
FactoryReset() - Resets CPE to factory default settings if supported by the CPE.
cpe.FactoryReset();
ScheduleInform(seconds_to_delay, commandKey) - Request the CPE to schedule a one-time Inform call which is separate from its periodic Inform frequency x seconds in the future if supported by the CPE.
cpe.ScheduleInform (3600, "commandKey"); // schedule inform in one hour
SyncParameterValues(parameters_array) - 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);
BackupCWMPTree() Backup the CPE's full CWMP Tree to the cpedb local database.
logger('Update complete. Performing CWMP tree backup'); cpe.BackupCWMPTree();
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(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 command var status = response.Status; // status - 0 if succes
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) }