Skip to content

Commit 6cc7d13

Browse files
author
Jean-François Hivert
committed
Version 2.1.2
1 parent cf52067 commit 6cc7d13

17 files changed

Lines changed: 154 additions & 55 deletions

File tree

README.md

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# PHP-CLI SHELL for FIREWALL
1+
PHP-CLI SHELL for FIREWALL
2+
-------------------
23

34
This repository is the addon for PHP-CLI SHELL about FIREWALL (acl) service.
45
With this addon you can create ACLs (monosite, failover and fullmesh) and generate template for your firewall appliance.
56
It is possible to upload ACLs config file to firewall with SCP. For SCP, you can use an SSH bastion.
67

8+
![demo](documentation/readme/demo.gif)
9+
710
For the moment, there are 3 templates:
811
* Juniper JunOS
912
__there are 2 templates for Juniper JunOS: one formated with {} and one with set commands__
@@ -21,7 +24,8 @@ ACL failover:
2124
You have to use base PHP-CLI SHELL project that is here: https://github.com/cloudwatt/php-cli-shell_base
2225

2326

24-
# INSTALLATION
27+
INSTALLATION
28+
-------------------
2529

2630
#### APT PHP
2731
Ubuntu only, you can get last PHP version from this PPA:
@@ -40,35 +44,58 @@ pcre.jit=0
4044
```
4145
*To locate your php.ini, use this command: php -i | grep "Configuration File"*
4246

47+
48+
## USE PHAR
49+
50+
#### WIZARD
51+
52+
Download last PHAR release and its key from [releases](https://github.com/cloudwatt/php-cli-shell_firewall/releases)
53+
54+
![wizard](documentation/readme/wizard.gif)
55+
56+
Wizard help:
57+
`$ php php-cli-shell.phar --help`
58+
59+
Create firewall configuration with command:
60+
`$ php php-cli-shell.phar configuration:application:factory firewall`
61+
*For more informations about configuration file, see 'CONFIGURATION FILE' section*
62+
63+
Create firewall launcher with command:
64+
`$ php php-cli-shell.phar launcher:application:factory firewall`
65+
66+
__*The PHAR contains all PHP-CLI SHELL components (Base, DCIM, IPAM and Firewall)*__
67+
68+
69+
## USE SOURCE
70+
4371
#### REPOSITORIES
4472
* git clone https://github.com/cloudwatt/php-cli-shell_base
45-
* git checkout tags/v2.1.1
73+
* git checkout tags/v2.1.2
4674
* git clone https://github.com/cloudwatt/php-cli-shell_firewall
47-
* git checkout tags/v2.1.1
75+
* git checkout tags/v2.1.2
4876
* Merge these two repositories
4977

5078
#### PHPIPAM (Optionnal)
5179
If you have PHPIPAM and you want object name autocompletion, you have to perform these steps:
5280
* git clone https://github.com/cloudwatt/php-cli-shell_phpipam
53-
* git checkout tags/v2.1.1
81+
* git checkout tags/v2.1.2
5482
* Merge this repository with two previous repositories (base and firewall)
55-
* Install PHP-CLI SHELL for PHPIPAM with README helper
56-
https://github.com/cloudwatt/php-cli-shell_phpipam
83+
* Install PHP-CLI SHELL for PHPIPAM with [README](https://github.com/cloudwatt/php-cli-shell_phpipam) helper
5784

5885
#### CONFIGURATION FILE
5986
__[env] is not used by PHP-CLI, it is for user when he has many environments or sites to managed__
60-
* mv applications/firewall/configurations/firewall.envA.json.example configurations/firewall.[env].json
87+
* mv configurations/firewall.envA.json.example configurations/firewall.[env].json
6188
* vim configurations/firewall.[env].json
6289
* Adapt configuration to your network topology
6390
* Of course you can add more than two sites
6491
* Do not change topology attribute names: internet, onPremise, interSite, private
6592
* Optionnal
6693
* You can create user configuration files for base and firewall services to overwrite some configurations
6794
These files will be ignored for commits, so your user config files can not be overwrited by a futur release
68-
* mv applications/firewall/configurations/firewall.envA.user.json.example configurations/firewall.[env].user.json
95+
* mv configurations/firewall.envA.user.json.example configurations/firewall.[env].user.json
6996
* vim configurations/firewall.[env].user.json
7097
Change configuration like path or file
71-
* All *.user.json files are ignored by .gitignore
98+
* All \*.user.json files are ignored by .gitignore
7299
* Juniper JunOS
73100
* In firewall.json, you can change the configuration push method:
74101
```json
@@ -98,36 +125,26 @@ __[env] is not used by PHP-CLI, it is for user when he has many environments or
98125
* vim firewall.[env].php
99126
* Change [env] with the name of your environment
100127

128+
129+
EXECUTION
130+
-------------------
131+
101132
#### CREDENTIALS FILE
102133
__*Change informations which are between []*__
103134
* vim credentialsFile
104135
* read -sr USER_PASSWORD_INPUT
105-
* export SSH_SYS_LOGIN=[YourSystemLoginHere]
106-
* export SSH_NET_LOGIN=[YourNetworkLoginHere]
107-
* export SSH_NET_PASSWORD=$USER_PASSWORD_INPUT
108-
__Bastion authentication must be base on certificate__
109-
110-
__PHPIPAM__ (Only if you use PHPIPAM service/addon)
111-
/!\ For security reason, use a read only account!
112-
* export IPAM_[IPAM_SERVER_KEY]_LOGIN=[YourLoginHere]
136+
* export SSH_SYS_LOGIN=[YourSystemLoginHere]
137+
* export SSH_NET_LOGIN=[YourNetworkLoginHere]
138+
* export SSH_NET_PASSWORD=$USER_PASSWORD_INPUT
139+
__Bastion authentication must be base on certificate__
140+
141+
__PHPIPAM__ (Only if you use PHPIPAM service/addon)
142+
/!\ For security reason, use a read only account!
143+
* export IPAM_[IPAM_SERVER_KEY]_LOGIN=[YourLoginHere]
113144
* export IPAM_[IPAM_SERVER_KEY]_PASSWORD=$USER_PASSWORD_INPUT
114-
__Change [IPAM_SERVER_KEY] with the key of your PHPIPAM server in configuration file__
115-
116-
117-
# EXECUTION
145+
__Change [IPAM_SERVER_KEY] with the key of your PHPIPAM server in configuration file__
118146

119147
#### SHELL
120148
Launch PHP-CLI Shell for FIREWALL service
121149
* source credentialsFile
122150
* php firewall.[env].php
123-
124-
#### CLI
125-
Call commands directly from your OS shell.
126-
__*Informations between [] are optionnal*__
127-
* source credentialsFile
128-
* php firewall.php --site name|all --create_host "name;IPv4[;IPv6]" --create_subnet "name;IPv4/mask[;IPv6/mask]" --create_network "name;IPv4-IPv4[;IPv6-IPv6]"
129-
--create_rule monosite|failover [--fullmesh] --action permit|deny
130-
--source_host name --source_subnet name --source_network name
131-
--destination_host name --destination_subnet name --destination_network name
132-
--protocol protocol;number[-number] --description maDescription
133-
--save [name;[force]] --export_configuration "junos[;force]"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"FIREWALL": {
3+
"sites": {
4+
"datacenter_A": {
5+
"location": "Paris, FRANCE",
6+
"hostname": "firewall_dcA",
7+
"ip": false,
8+
"os": "juniper-junos",
9+
"gui": false,
10+
"scp": false,
11+
"scp_loginCredential": false,
12+
"scp_loginEnvVarName": false,
13+
"scp_passwordCredential": false,
14+
"scp_passwordEnvVarName": false,
15+
"scp_remoteFile": false,
16+
"ssh_remotePort": false,
17+
"ssh_bastionHost": false,
18+
"ssh_bastionPort": false,
19+
"ssh_portForwarding": false,
20+
"ssh_loginCredential": false,
21+
"ssh_loginEnvVarName": false,
22+
"ssh_passwordCredential": false,
23+
"ssh_passwordEnvVarName": false,
24+
"zones": {
25+
"WAN": {
26+
"ipv4": [ "0.0.0.0/0" ],
27+
"ipv6": [ "::/0" ]
28+
},
29+
"LOCAL": {
30+
"ipv4": [ "10.0.0.0/16" ],
31+
"ipv6": [ "2000::/64" ]
32+
},
33+
"__PRIVATE__": {
34+
"ipv4": [ "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16" ],
35+
"ipv6": [ ]
36+
}
37+
},
38+
"topology": {
39+
"onPremise": [ "LOCAL" ],
40+
"interSite": {
41+
},
42+
"private": [ "__PRIVATE__" ],
43+
"internet": [ "WAN" ]
44+
},
45+
"metadata": {
46+
},
47+
"options": {
48+
}
49+
}
50+
},
51+
"configuration": {
52+
"paths": {
53+
"objects": "backup/firewall/objects.json",
54+
"configs": "backup/firewall/configurations",
55+
"exports": "tmp/firewall",
56+
"autosave": "backup/firewall/autosave.json",
57+
"templates": "templates/firewall"
58+
},
59+
"autosave": {
60+
"status": false
61+
},
62+
"templates": {
63+
"juniper-junos_set": {
64+
"updateMode": "replace"
65+
}
66+
}
67+
}
68+
}
69+
}

applications/firewall/launchers/firewall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace App\Firewall;
33

4-
require_once(ROOT_DIR . '/launchers/abstract.php');
4+
require_once(PROJECT_ROOT_DIR . '/launchers/abstract.php');
55

66
class Launcher_Firewall extends \Launcher_Abstract
77
{

applications/firewall/shell/firewall.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,15 @@ class Shell_Firewall extends Cli\Shell\Shell
396396
protected $_sites = null;
397397

398398

399-
public function __construct($configFilename, array $servers, $autoInitialisation = true)
399+
/**
400+
* @param string|array|Core\Config $configuration
401+
* @param array $servers IPAM server keys
402+
* @param bool $autoInitialisation
403+
* @return $this
404+
*/
405+
public function __construct($configuration, array $servers = array(), $autoInitialisation = true)
400406
{
401-
parent::__construct($configFilename);
407+
parent::__construct($configuration);
402408

403409
if(!$this->isOneShotCall()) {
404410
$printInfoMessages = true;

applications/firewall/shell/program/firewall/config/extension/csv.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ protected function _save(array $configs, $filename)
123123

124124
$fileExists = file_exists($filename);
125125
$pathname = pathinfo($filename, PATHINFO_DIRNAME);
126+
$pathname = C\Tools::pathname($pathname, true, true); // Permet juste le mkdir
126127

127128
if((!$fileExists && is_writable($pathname)) || ($fileExists && is_writable($filename)))
128129
{

applications/firewall/shell/program/firewall/config/extension/json.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ protected function _save(array $configs, $filename)
197197

198198
$fileExists = file_exists($filename);
199199
$pathname = pathinfo($filename, PATHINFO_DIRNAME);
200+
$pathname = C\Tools::pathname($pathname, true, true); // Permet juste le mkdir
200201

201202
if((!$fileExists && is_writable($pathname)) || ($fileExists && is_writable($filename)))
202203
{

applications/firewall/shell/program/firewall/object/rule.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,8 @@ public function filterFlow($type, $filter, $strict = false)
874874
$flows[] = new ArrayObject(array(
875875
'ruleId' => $ruleId,
876876
'ruleName' => $Firewall_Api_Rule->name,
877+
'state' => $Firewall_Api_Rule->state,
878+
'action' => $Firewall_Api_Rule->action,
877879
'source' => $Core_Api_Address__src,
878880
'destination' => $Core_Api_Address__dst,
879881
'protocol' => $Core_Api_Protocol
@@ -885,7 +887,7 @@ public function filterFlow($type, $filter, $strict = false)
885887

886888
$time2 = microtime(true);
887889
$this->_TERMINAL->deleteMessage(1, true);
888-
$this->_SHELL->print("Inventaire des flows (".round($time2-$time1)."s) [OK]", 'green');
890+
$this->_SHELL->print("Inventaire des flows {".count($flows)."} (".round($time2-$time1)."s) [OK]", 'green');
889891
$this->_SHELL->print("Vérification doublons ...", 'orange');
890892

891893
foreach($flows as $index_a => $flow_a)
@@ -895,10 +897,10 @@ public function filterFlow($type, $filter, $strict = false)
895897

896898
foreach($flows as $index_b => $flow_b)
897899
{
898-
if($index_a === $index_b) {
900+
if($index_a >= $index_b) {
899901
continue;
900902
}
901-
else
903+
elseif($flow_a->action === $flow_b->action)
902904
{
903905
/**
904906
* /!\ A peut ne pas inclure B mais B peut inclure A

backup/.gitignore

Whitespace-only changes.

backup/firewall/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

backup/firewall/configurations/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)