Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.

Beschreibung:

Dieses Skript zeigt, wie man mit Listen von Werten in Variablen umgeht.

Liste der verwendeten Variablen:

Add-in Code:

/**
 * @param {Config} config
 * @param {Context} context
 * Do not edit this comment or parameter types. Required for code suggestions
*/
exports.main = function (config, context) {

    // Variables
    // Store lists as comma (,) separated values:
    // REMOTE_SERIALS  = 001,002,003,004,...
    // REMOTE_NAMES = name001,name002,name003,name004,...
    // HINT: no spaces in the above!
    // HINT: make sure both lists have the same length!
    // HINT: both lists need to be ordered, such that each entry at position 'index' corresponds to the other (001 -> name001, ...)
    // split the lists into javascript arrays:
    var serials = context.vars.REMOTE_SERIALS.split(",");
    var names = context.vars.REMOTE_NAMES.split(",");
    // iterate over one list
    serials.forEach(function (serial, index) {
        // Exmaple: Set add a table row for each serial:
        // /Setup/VPN/Certificates-and-Keys/IKE-Keys -> 1.2.19.5.3
        var ikeKeysTable = config.getTableByOid("1.2.19.5.3");
        var ikeKeysTableRow = ikeKeysTable.createNewRow();
        ikeKeysTableRow.setByOids({
            // access the other list via index:
            1: names[index],                // Name            : 16 chars from ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()+-,/:;<=>?[\]^_.0123456789
            6: "9",                         // Local-ID-Type   : No-Identity (0), IPv4-Address (1), IPv6-Address (5), Domain-Name (2), Email-Address (3), Distinguished-Name (9), Key-ID (11)
            7: "VPN3",                      // Local-Identity  : 254 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!"$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `
            5: "9",                         // Remote-ID-Type  : No-Identity (0), IPv4-Address (1), IPv6-Address (5), Domain-Name (2), Email-Address (3), Distinguished-Name (9), Key-ID (11)
            2: "serialNumber=" + serial,     // Remote-Identity : 254 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!"$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `
            3: "",                          // Shared-Sec      : 64 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `
            4: ""                           // Shared-Sec-File : 20 chars from ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz`
        });
        ikeKeysTable.addOrMerge(ikeKeysTableRow);
    });
};

Add-in als JSON-Datei:

Seiteneigenschaften
Deutsch
VariableBeschreibung
View file
namevariable_as_list.json
pageListen von Werten innerhalb von Variablen behandeln
spaceLMCADEN
height150

 

...


Description:

This script shows a way to handle lists of values inside variables.

List of used variables:

VariableDescription




Add-in code:


/**
 * @param {Config} config
 * @param {Context} context
 * Do not edit this comment or parameter types. Required for code suggestions
*/
exports.main = function (config, context) {



 

...

 

...

//

...

Variables
 

...

 

...

//

...

Store

...

lists

...

as

...

comma

...

(,)

...

separated

...

values:
 

...

 

...

//

...

REMOTE_SERIALS

...

 =

...

001,002,003,004,...
 

...

 

...

//

...

REMOTE_NAMES

...

=

...

name001,name002,name003,name004,...
 

...

 

...

//

...

HINT:

...

no

...

spaces

...

in

...

the

...

above!
 

...

 

...

//

...

HINT:

...

make

...

sure

...

both

...

lists

...

have

...

the

...

same

...

length!
 

...

 

...

//

...

HINT:

...

both

...

lists

...

need

...

to

...

be

...

ordered,

...

such

...

that

...

each

...

entry

...

at

...

position

...

'index'

...

corresponds

...

to

...

the

...

other

...

(001

...

->

...

name001,

...

...)

 

...

 

...

//

...

split

...

the

...

lists

...

into

...

javascript

...

arrays:
 

...

 

...

var

...

serials

...

=

...

context.vars.REMOTE_SERIALS.split(",");
 

...

 

...

var

...

names

...

=

...

context.vars.REMOTE_NAMES.split(",");

 

...

 

...

//

...

iterate

...

over

...

one

...

list
 

...

 

...

serials.forEach(function

...

(serial,

...

index)

...

{

 

...

 

...

 

...

 

...

//

...

Exmaple:

...

Set

...

add

...

a

...

table

...

row

...

for

...

each

...

serial:
 

...

 

...

 

...

 

...

//

...

/Setup/VPN/Certificates-and-Keys/IKE-Keys

...

->

...

1.2.19.5.3
 

...

 

...

 

...

 

...

var

...

ikeKeysTable

...

=

...

config.getTableByOid("1.2.19.5.3");
 

...

 

...

 

...

 

...

var

...

ikeKeysTableRow

...

=

...

ikeKeysTable.createNewRow();
 

...

 

...

 

...

 

...

ikeKeysTableRow.setByOids({
 

...

 

...

 

...

 

...

 

...

 

...

//

...

access

...

the

...

other

...

list

...

via

...

index:
 

...

 

...

 

...

 

...

 

...

 

...

1:

...

names[index],

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 //

...

Name

...

 

...

 

...

 

...

 

...

 

...

 :

...

16

...

chars

...

from

...

ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()+-,/:;<=>?[\]^_.0123456789
 

...

 

...

 

...

 

...

 

...

 

...

6:

...

"9",

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

//

...

Local-ID-Type

...

 

...

:

...

No-Identity

...

(0),

...

IPv4-Address

...

(1),

...

IPv6-Address

...

(5),

...

Domain-Name

...

(2),

...

Email-Address

...

(3),

...

Distinguished-Name

...

(9),

...

Key-ID

...

(11)
 

...

 

...

 

...

 

...

 

...

 

...

7:

...

"VPN3",

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 //

...

Local-Identity

...

 :

...

254

...

chars

...

from

...

#ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!"$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz

...

`
 

...

 

...

 

...

 

...

 

...

 

...

5:

...

"9",

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

//

...

Remote-ID-Type

...

 :

...

No-Identity

...

(0),

...

IPv4-Address

...

(1),

...

IPv6-Address

...

(5),

...

Domain-Name

...

(2),

...

Email-Address

...

(3),

...

Distinguished-Name

...

(9),

...

Key-ID

...

(11)
 

...

 

...

 

...

 

...

 

...

 

...

2:

...

"serialNumber="

...

+

...

serial,

...

 

...

 

...

//

...

Remote-Identity

...

:

...

254

...

chars

...

from

...

#ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!"$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz

...

`
 

...

 

...

 

...

 

...

 

...

 

...

3:

...

"",

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 //

...

Shared-Sec

...

 

...

 

...

 :

...

64

...

chars

...

from

...

#ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz

...

`
 

...

 

...

 

...

 

...

 

...

 

...

4:

...

""

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

 

...

//

...

Shared-Sec-File

...

:

...

20

...

chars

...

from

...

ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz`
 

...

 

...

 

...

 

...

});
 

...

 

...

 

...

 

...

ikeKeysTable.addOrMerge(ikeKeysTableRow);
 

...

 

...

});

};

Add-in as JSON file:

View file
namevariable_as_list.json

...

height150