Skip to content

Commit eef0114

Browse files
abr-ubiqubefambon
authored andcommitted
Merge pull request #17 from abr-ubiqube/master
code from OpenMSA devday Tokyo 2018
2 parents 44bdc6b + f229235 commit eef0114

File tree

21 files changed

+1172
-97
lines changed

21 files changed

+1172
-97
lines changed

WORKFLOWS/.meta_Samples

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<metadata>
3+
<map>
4+
<entry>
5+
<key>MODEL</key>
6+
</entry>
7+
<entry>
8+
<key>DATE_MODIFICATION</key>
9+
<value>1513269379142</value>
10+
</entry>
11+
<entry>
12+
<key>COMMENT</key>
13+
<value></value>
14+
</entry>
15+
<entry>
16+
<key>REPOSITORY</key>
17+
<value>CommandDefinition</value>
18+
</entry>
19+
<entry>
20+
<key>DATE_CREATION</key>
21+
<value>1513269379130</value>
22+
</entry>
23+
<entry>
24+
<key>MANUFACTURER</key>
25+
</entry>
26+
<entry>
27+
<key>CONFIGURATION_FILTER</key>
28+
<value></value>
29+
</entry>
30+
<entry>
31+
<key>TYPE</key>
32+
<value>DIRECTORY</value>
33+
</entry>
34+
<entry>
35+
<key>TAG</key>
36+
<value></value>
37+
</entry>
38+
</map>
39+
</metadata>

WORKFLOWS/.meta_Utils

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<metadata>
3+
<map>
4+
<entry>
5+
<key>MODEL</key>
6+
</entry>
7+
<entry>
8+
<key>DATE_MODIFICATION</key>
9+
<value>1453798968685</value>
10+
</entry>
11+
<entry>
12+
<key>COMMENT</key>
13+
<value></value>
14+
</entry>
15+
<entry>
16+
<key>REPOSITORY</key>
17+
<value>CommandDefinition</value>
18+
</entry>
19+
<entry>
20+
<key>DATE_CREATION</key>
21+
<value>1453798968671</value>
22+
</entry>
23+
<entry>
24+
<key>MANUFACTURER</key>
25+
</entry>
26+
<entry>
27+
<key>CONFIGURATION_FILTER</key>
28+
<value></value>
29+
</entry>
30+
<entry>
31+
<key>TYPE</key>
32+
<value>DIRECTORY</value>
33+
</entry>
34+
<entry>
35+
<key>TAG</key>
36+
<value></value>
37+
</entry>
38+
</map>
39+
</metadata>

WORKFLOWS/Tutorials/Simple_Firewall/Process_Add_deny_rule/Tasks/Task_add_rule.php

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,69 @@
66
require_once '/opt/fmc_repository/Process/Reference/Common/common.php';
77

88
/**
9-
* List all the parameters required by the task
9+
* list all the parameters required by the task
1010
*/
11-
function list_args()
12-
{
13-
create_var_def('id', 'String');
14-
create_var_def('src_ip', 'String');
15-
create_var_def('dst_port', 'String');
11+
function list_args() {
12+
create_var_def ( 'id', 'String' );
13+
create_var_def ( 'src_ip', 'String' );
14+
create_var_def ( 'dst_port', 'String' );
1615
}
17-
18-
foreach ($context['devices'] as $deviceidRow) {
19-
20-
$devicelongid = substr($deviceidRow['id'], 3);
21-
logToFile("***************************");
22-
logToFile("update device $devicelongid");
23-
24-
/**
25-
* build the Microservice JSON params for the CREATE
26-
*/
27-
$micro_service_vars_array = array();
28-
$micro_service_vars_array['object_id'] = $context['id'];
29-
$micro_service_vars_array['src_ip'] = $context['src_ip'];
30-
$micro_service_vars_array['dst_port'] = $context['dst_port'];
31-
32-
$object_id = $context['id'];
33-
34-
$simple_firewall = array('simple_firewall' => array($object_id => $micro_service_vars_array));
35-
36-
3716
/**
38-
* call the CREATE for simple_firewall MS for each device
17+
* iterate through the array of devices in order to apply the policy for each device
3918
*/
40-
$response = execute_command_and_verify_response($devicelongid, CMD_CREATE, $simple_firewall, "CREATE simple_firewall");
41-
$response = json_decode($response, true);
42-
if ($response['wo_status'] === ENDED) {
43-
if (isset($context['rules'])) {
44-
$index = count($context['rules']);
45-
} else {
46-
$index = 0;
47-
}
48-
49-
$context['rules'][$index]['delete'] = false;
50-
$context['rules'][$index]['id'] = $context['id'];
51-
$context['rules'][$index]['src_ip'] = $context['src_ip'];
52-
$context['rules'][$index]['dst_port'] = $context['dst_port'];
53-
54-
$response = prepare_json_response($response['wo_status'], $response['wo_comment'], $context, true);
55-
echo $response;
56-
} else {
57-
task_exit(FAILED, "Task FAILED");
58-
}
19+
foreach ( $context ['devices'] as $deviceidRow ) {
20+
/**
21+
* extract the device database identifier from the device ID
22+
*/
23+
$devicelongid = substr ( $deviceidRow ['id'], 3 );
24+
logToFile ( "***************************" );
25+
logToFile ( "update device $devicelongid" );
26+
27+
/**
28+
* build the Microservice JSON params for the CREATE operation of the microservice
29+
*/
30+
$micro_service_vars_array = array ();
31+
$micro_service_vars_array ['object_id'] = $context ['id'];
32+
$micro_service_vars_array ['src_ip'] = $context ['src_ip'];
33+
$micro_service_vars_array ['dst_port'] = $context ['dst_port'];
34+
35+
$object_id = $context ['id'];
36+
37+
$simple_firewall = array (
38+
'simple_firewall' => array (
39+
$object_id => $micro_service_vars_array
40+
)
41+
);
42+
43+
/**
44+
* call the CREATE for simple_firewall MS for each device
45+
*/
46+
$response = execute_command_and_verify_response ( $devicelongid, CMD_CREATE, $simple_firewall, "CREATE simple_firewall" );
47+
$response = json_decode ( $response, true );
48+
if ($response ['wo_status'] === ENDED) {
49+
if (isset ( $context ['rules'] )) {
50+
$index = count ( $context ['rules'] );
51+
} else {
52+
$index = 0;
53+
}
54+
/**
55+
* add the firewall policy rule to the array of rules applied on the devices
56+
*/
57+
$context ['rules'] [$index] ['delete'] = false;
58+
$context ['rules'] [$index] ['id'] = $context ['id'];
59+
$context ['rules'] [$index] ['src_ip'] = $context ['src_ip'];
60+
$context ['rules'] [$index] ['dst_port'] = $context ['dst_port'];
61+
62+
$response = prepare_json_response ( $response ['wo_status'], $response ['wo_comment'], $context, true );
63+
echo $response;
64+
} else {
65+
task_exit ( FAILED, "Task FAILED" );
66+
}
5967
}
6068

6169
/**
6270
* End of the task do not modify after this point
6371
*/
64-
task_exit(ENDED, "Task OK");
72+
task_exit ( ENDED, "Task OK" );
6573

6674
?>

WORKFLOWS/Tutorials/Simple_Firewall/Process_Create_Firewall/Tasks/Task_Select_Devices.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
/**
99
* List all the parameters required by the task
1010
*/
11-
function list_args()
12-
{
13-
create_var_def('devices.0.id', 'String');
11+
function list_args() {
12+
create_var_def ( 'devices.0.id', 'String' );
1413
}
1514

16-
1715
/**
1816
* End of the task do not modify after this point
1917
*/
20-
task_exit(ENDED, "Task OK");
18+
task_exit ( ENDED, "Task OK" );
2119

2220
?>

WORKFLOWS/Tutorials/Simple_Firewall/Process_Delete_Firewall_Service/Tasks/Task_Delete_Service.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
/**
99
* List all the parameters required by the task
1010
*/
11-
function list_args()
12-
{
11+
function list_args() {
1312
}
1413

15-
1614
/**
1715
* End of the task do not modify after this point
1816
*/
19-
task_exit(ENDED, "Task OK");
17+
task_exit ( ENDED, "Task OK" );
2018

2119
?>

WORKFLOWS/Tutorials/Simple_Firewall/Process_Remove_deny_rule/Tasks/Task_remove_rule.php

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,56 @@
88
/**
99
* List all the parameters required by the task
1010
*/
11-
function list_args()
12-
{
13-
create_var_def('rules.0.delete', 'String');
14-
create_var_def('rules.0.id', 'String');
15-
create_var_def('rules.0.src_ip', 'String');
16-
create_var_def('rules.0.dst_port', 'String');
11+
function list_args() {
12+
create_var_def ( 'rules.0.delete', 'String' );
13+
create_var_def ( 'rules.0.id', 'String' );
14+
create_var_def ( 'rules.0.src_ip', 'String' );
15+
create_var_def ( 'rules.0.dst_port', 'String' );
1716
}
18-
19-
foreach ($context['devices'] as $deviceidRow) {
20-
21-
$device_id = substr($deviceidRow['id'], 3);
22-
23-
$index = 0;
24-
foreach ($context['rules'] as $rulesRow) {
25-
26-
$delete = $rulesRow['delete'];
27-
$rule_id = $rulesRow['id'];
28-
$rule_src_ip = $rulesRow['src_ip'];
29-
$rule_dst_port = $rulesRow['dst_port'];
30-
logToFile("************************************************");
31-
logToFile("$delete : $rule_id - $rule_src_ip:$rule_dst_port");
32-
33-
if ($delete === "true") {
34-
35-
$object_id = $rule_id;
36-
$simple_firewall = array('simple_firewall' => $object_id);
37-
38-
$response = execute_command_and_verify_response($device_id, CMD_DELETE, $simple_firewall, "DELETE simple_firewall");
39-
$response = json_decode($response, true);
40-
if ($response['wo_status'] !== ENDED) {
41-
$response = prepare_json_response($response['wo_status'], $response['wo_comment'], $context, true);
42-
echo $response;
43-
44-
}
45-
unset($context['rules'][$index]);
46-
47-
48-
}
49-
$index++;
50-
}
17+
/**
18+
* iterate through the array of devices in order to remove the policy for each device
19+
*/
20+
foreach ( $context ['devices'] as $deviceidRow ) {
21+
/**
22+
* extract the device database identifier from the device ID
23+
*/
24+
$device_id = substr ( $deviceidRow ['id'], 3 );
25+
26+
/**
27+
* loop through each rule stored in the array "rules" and call the microservice DELETE when the flag "delete" is set to true
28+
*/
29+
$index = 0;
30+
foreach ( $context ['rules'] as $rulesRow ) {
31+
32+
$delete = $rulesRow ['delete'];
33+
$rule_id = $rulesRow ['id'];
34+
$rule_src_ip = $rulesRow ['src_ip'];
35+
$rule_dst_port = $rulesRow ['dst_port'];
36+
logToFile ( "************************************************" );
37+
logToFile ( "$delete : $rule_id - $rule_src_ip:$rule_dst_port" );
38+
39+
if ($delete === "true") {
40+
41+
$object_id = $rule_id;
42+
$simple_firewall = array (
43+
'simple_firewall' => $object_id
44+
);
45+
46+
$response = execute_command_and_verify_response ( $device_id, CMD_DELETE, $simple_firewall, "DELETE simple_firewall" );
47+
$response = json_decode ( $response, true );
48+
if ($response ['wo_status'] !== ENDED) {
49+
$response = prepare_json_response ( $response ['wo_status'], $response ['wo_comment'], $context, true );
50+
echo $response;
51+
}
52+
unset ( $context ['rules'] [$index] );
53+
}
54+
$index ++;
55+
}
5156
}
5257

53-
5458
/**
5559
* End of the task do not modify after this point
5660
*/
57-
task_exit(ENDED, "Task OK");
61+
task_exit ( ENDED, "Task OK" );
5862

5963
?>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<metadata>
3+
<map>
4+
<entry>
5+
<key>MODEL</key>
6+
</entry>
7+
<entry>
8+
<key>DATE_MODIFICATION</key>
9+
<value>1532003127892</value>
10+
</entry>
11+
<entry>
12+
<key>COMMENT</key>
13+
<value></value>
14+
</entry>
15+
<entry>
16+
<key>REPOSITORY</key>
17+
<value>CommandDefinition</value>
18+
</entry>
19+
<entry>
20+
<key>DATE_CREATION</key>
21+
<value>1532003127575</value>
22+
</entry>
23+
<entry>
24+
<key>MANUFACTURER</key>
25+
</entry>
26+
<entry>
27+
<key>CONFIGURATION_FILTER</key>
28+
<value></value>
29+
</entry>
30+
<entry>
31+
<key>TYPE</key>
32+
<value>DIRECTORY</value>
33+
</entry>
34+
<entry>
35+
<key>TAG</key>
36+
<value></value>
37+
</entry>
38+
</map>
39+
</metadata>

0 commit comments

Comments
 (0)