| 1 |
|
| 2 |
from __future__ import absolute_import, division, print_function |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
ANSIBLE_METADATA = { |
| 15 |
"status": ["preview"], |
| 16 |
"supported_by": "community", |
| 17 |
"metadata_version": "1.1", |
| 18 |
} |
| 19 |
|
| 20 |
DOCUMENTATION = """ |
| 21 |
--- |
| 22 |
module: fortios_waf_profile |
| 23 |
short_description: Configure Web application firewall configuration in Fortinet's FortiOS and FortiGate. |
| 24 |
description: |
| 25 |
- This module is able to configure a FortiGate or FortiOS (FOS) device by allowing the |
| 26 |
user to set and modify waf feature and profile category. |
| 27 |
Examples include all parameters and values need to be adjusted to datasources before usage. |
| 28 |
Tested with FOS v6.0.0 |
| 29 |
version_added: "2.0.0" |
| 30 |
author: |
| 31 |
- Link Zheng (@chillancezen) |
| 32 |
- Jie Xue (@JieX19) |
| 33 |
- Hongbin Lu (@fgtdev-hblu) |
| 34 |
- Frank Shen (@frankshen01) |
| 35 |
- Miguel Angel Munoz (@mamunozgonzalez) |
| 36 |
- Nicolas Thomas (@thomnico) |
| 37 |
notes: |
| 38 |
- Legacy fortiosapi has been deprecated, httpapi is the preferred way to run playbooks |
| 39 |
|
| 40 |
- The module supports check_mode. |
| 41 |
|
| 42 |
requirements: |
| 43 |
- ansible>=2.16 |
| 44 |
options: |
| 45 |
access_token: |
| 46 |
description: |
| 47 |
- Token-based authentication. |
| 48 |
Generated from GUI of Fortigate. |
| 49 |
type: str |
| 50 |
required: false |
| 51 |
enable_log: |
| 52 |
description: |
| 53 |
- Enable/Disable logging for task. |
| 54 |
type: bool |
| 55 |
required: false |
| 56 |
default: false |
| 57 |
vdom: |
| 58 |
description: |
| 59 |
- Virtual domain, among those defined previously. A vdom is a |
| 60 |
virtual instance of the FortiGate that can be configured and |
| 61 |
used as a different unit. |
| 62 |
type: str |
| 63 |
default: root |
| 64 |
member_path: |
| 65 |
type: str |
| 66 |
description: |
| 67 |
- Member attribute path to operate on. |
| 68 |
- Delimited by a slash character if there are more than one attribute. |
| 69 |
- Parameter marked with member_path is legitimate for doing member operation. |
| 70 |
member_state: |
| 71 |
type: str |
| 72 |
description: |
| 73 |
- Add or delete a member under specified attribute path. |
| 74 |
- When member_state is specified, the state option is ignored. |
| 75 |
choices: |
| 76 |
- 'present' |
| 77 |
- 'absent' |
| 78 |
|
| 79 |
state: |
| 80 |
description: |
| 81 |
- Indicates whether to create or remove the object. |
| 82 |
type: str |
| 83 |
required: true |
| 84 |
choices: |
| 85 |
- 'present' |
| 86 |
- 'absent' |
| 87 |
waf_profile: |
| 88 |
description: |
| 89 |
- Configure Web application firewall configuration. |
| 90 |
default: null |
| 91 |
type: dict |
| 92 |
suboptions: |
| 93 |
address_list: |
| 94 |
description: |
| 95 |
- Address block and allow lists. |
| 96 |
type: dict |
| 97 |
suboptions: |
| 98 |
blocked_address: |
| 99 |
description: |
| 100 |
- Blocked address. |
| 101 |
type: list |
| 102 |
elements: dict |
| 103 |
suboptions: |
| 104 |
name: |
| 105 |
description: |
| 106 |
- Address name. Source firewall.address.name firewall.addrgrp.name. |
| 107 |
required: true |
| 108 |
type: str |
| 109 |
blocked_log: |
| 110 |
description: |
| 111 |
- Enable/disable logging on blocked addresses. |
| 112 |
type: str |
| 113 |
choices: |
| 114 |
- 'enable' |
| 115 |
- 'disable' |
| 116 |
severity: |
| 117 |
description: |
| 118 |
- Severity. |
| 119 |
type: str |
| 120 |
choices: |
| 121 |
- 'high' |
| 122 |
- 'medium' |
| 123 |
- 'low' |
| 124 |
status: |
| 125 |
description: |
| 126 |
- Status. |
| 127 |
type: str |
| 128 |
choices: |
| 129 |
- 'enable' |
| 130 |
- 'disable' |
| 131 |
trusted_address: |
| 132 |
description: |
| 133 |
- Trusted address. |
| 134 |
type: list |
| 135 |
elements: dict |
| 136 |
suboptions: |
| 137 |
name: |
| 138 |
description: |
| 139 |
- Address name. Source firewall.address.name firewall.addrgrp.name. |
| 140 |
required: true |
| 141 |
type: str |
| 142 |
comment: |
| 143 |
description: |
| 144 |
- Comment. |
| 145 |
type: str |
| 146 |
constraint: |
| 147 |
description: |
| 148 |
- WAF HTTP protocol restrictions. |
| 149 |
type: dict |
| 150 |
suboptions: |
| 151 |
content_length: |
| 152 |
description: |
| 153 |
- HTTP content length in request. |
| 154 |
type: dict |
| 155 |
suboptions: |
| 156 |
action: |
| 157 |
description: |
| 158 |
- Action. |
| 159 |
type: str |
| 160 |
choices: |
| 161 |
- 'allow' |
| 162 |
- 'block' |
| 163 |
length: |
| 164 |
description: |
| 165 |
- Length of HTTP content in bytes (0 to 2147483647). |
| 166 |
type: int |
| 167 |
log: |
| 168 |
description: |
| 169 |
- Enable/disable logging. |
| 170 |
type: str |
| 171 |
choices: |
| 172 |
- 'enable' |
| 173 |
- 'disable' |
| 174 |
severity: |
| 175 |
description: |
| 176 |
- Severity. |
| 177 |
type: str |
| 178 |
choices: |
| 179 |
- 'high' |
| 180 |
- 'medium' |
| 181 |
- 'low' |
| 182 |
status: |
| 183 |
description: |
| 184 |
- Enable/disable the constraint. |
| 185 |
type: str |
| 186 |
choices: |
| 187 |
- 'enable' |
| 188 |
- 'disable' |
| 189 |
exception: |
| 190 |
description: |
| 191 |
- HTTP constraint exception. |
| 192 |
type: list |
| 193 |
elements: dict |
| 194 |
suboptions: |
| 195 |
address: |
| 196 |
description: |
| 197 |
- Host address. Source firewall.address.name firewall.addrgrp.name. |
| 198 |
type: str |
| 199 |
content_length: |
| 200 |
description: |
| 201 |
- HTTP content length in request. |
| 202 |
type: str |
| 203 |
choices: |
| 204 |
- 'enable' |
| 205 |
- 'disable' |
| 206 |
header_length: |
| 207 |
description: |
| 208 |
- HTTP header length in request. |
| 209 |
type: str |
| 210 |
choices: |
| 211 |
- 'enable' |
| 212 |
- 'disable' |
| 213 |
hostname: |
| 214 |
description: |
| 215 |
- Enable/disable hostname check. |
| 216 |
type: str |
| 217 |
choices: |
| 218 |
- 'enable' |
| 219 |
- 'disable' |
| 220 |
id: |
| 221 |
description: |
| 222 |
- Exception ID. see <a href='#notes'>Notes</a>. |
| 223 |
required: true |
| 224 |
type: int |
| 225 |
line_length: |
| 226 |
description: |
| 227 |
- HTTP line length in request. |
| 228 |
type: str |
| 229 |
choices: |
| 230 |
- 'enable' |
| 231 |
- 'disable' |
| 232 |
malformed: |
| 233 |
description: |
| 234 |
- Enable/disable malformed HTTP request check. |
| 235 |
type: str |
| 236 |
choices: |
| 237 |
- 'enable' |
| 238 |
- 'disable' |
| 239 |
max_cookie: |
| 240 |
description: |
| 241 |
- Maximum number of cookies in HTTP request. |
| 242 |
type: str |
| 243 |
choices: |
| 244 |
- 'enable' |
| 245 |
- 'disable' |
| 246 |
max_header_line: |
| 247 |
description: |
| 248 |
- Maximum number of HTTP header line. |
| 249 |
type: str |
| 250 |
choices: |
| 251 |
- 'enable' |
| 252 |
- 'disable' |
| 253 |
max_range_segment: |
| 254 |
description: |
| 255 |
- Maximum number of range segments in HTTP range line. |
| 256 |
type: str |
| 257 |
choices: |
| 258 |
- 'enable' |
| 259 |
- 'disable' |
| 260 |
max_url_param: |
| 261 |
description: |
| 262 |
- Maximum number of parameters in URL. |
| 263 |
type: str |
| 264 |
choices: |
| 265 |
- 'enable' |
| 266 |
- 'disable' |
| 267 |
method: |
| 268 |
description: |
| 269 |
- Enable/disable HTTP method check. |
| 270 |
type: str |
| 271 |
choices: |
| 272 |
- 'enable' |
| 273 |
- 'disable' |
| 274 |
param_length: |
| 275 |
description: |
| 276 |
- Maximum length of parameter in URL, HTTP POST request or HTTP body. |
| 277 |
type: str |
| 278 |
choices: |
| 279 |
- 'enable' |
| 280 |
- 'disable' |
| 281 |
pattern: |
| 282 |
description: |
| 283 |
- URL pattern. |
| 284 |
type: str |
| 285 |
regex: |
| 286 |
description: |
| 287 |
- Enable/disable regular expression based pattern match. |
| 288 |
type: str |
| 289 |
choices: |
| 290 |
- 'enable' |
| 291 |
- 'disable' |
| 292 |
url_param_length: |
| 293 |
description: |
| 294 |
- Maximum length of parameter in URL. |
| 295 |
type: str |
| 296 |
choices: |
| 297 |
- 'enable' |
| 298 |
- 'disable' |
| 299 |
version: |
| 300 |
description: |
| 301 |
- Enable/disable HTTP version check. |
| 302 |
type: str |
| 303 |
choices: |
| 304 |
- 'enable' |
| 305 |
- 'disable' |
| 306 |
header_length: |
| 307 |
description: |
| 308 |
- HTTP header length in request. |
| 309 |
type: dict |
| 310 |
suboptions: |
| 311 |
action: |
| 312 |
description: |
| 313 |
- Action. |
| 314 |
type: str |
| 315 |
choices: |
| 316 |
- 'allow' |
| 317 |
- 'block' |
| 318 |
length: |
| 319 |
description: |
| 320 |
- Length of HTTP header in bytes (0 to 2147483647). |
| 321 |
type: int |
| 322 |
log: |
| 323 |
description: |
| 324 |
- Enable/disable logging. |
| 325 |
type: str |
| 326 |
choices: |
| 327 |
- 'enable' |
| 328 |
- 'disable' |
| 329 |
severity: |
| 330 |
description: |
| 331 |
- Severity. |
| 332 |
type: str |
| 333 |
choices: |
| 334 |
- 'high' |
| 335 |
- 'medium' |
| 336 |
- 'low' |
| 337 |
status: |
| 338 |
description: |
| 339 |
- Enable/disable the constraint. |
| 340 |
type: str |
| 341 |
choices: |
| 342 |
- 'enable' |
| 343 |
- 'disable' |
| 344 |
hostname: |
| 345 |
description: |
| 346 |
- Enable/disable hostname check. |
| 347 |
type: dict |
| 348 |
suboptions: |
| 349 |
action: |
| 350 |
description: |
| 351 |
- Action. |
| 352 |
type: str |
| 353 |
choices: |
| 354 |
- 'allow' |
| 355 |
- 'block' |
| 356 |
log: |
| 357 |
description: |
| 358 |
- Enable/disable logging. |
| 359 |
type: str |
| 360 |
choices: |
| 361 |
- 'enable' |
| 362 |
- 'disable' |
| 363 |
severity: |
| 364 |
description: |
| 365 |
- Severity. |
| 366 |
type: str |
| 367 |
choices: |
| 368 |
- 'high' |
| 369 |
- 'medium' |
| 370 |
- 'low' |
| 371 |
status: |
| 372 |
description: |
| 373 |
- Enable/disable the constraint. |
| 374 |
type: str |
| 375 |
choices: |
| 376 |
- 'enable' |
| 377 |
- 'disable' |
| 378 |
line_length: |
| 379 |
description: |
| 380 |
- HTTP line length in request. |
| 381 |
type: dict |
| 382 |
suboptions: |
| 383 |
action: |
| 384 |
description: |
| 385 |
- Action. |
| 386 |
type: str |
| 387 |
choices: |
| 388 |
- 'allow' |
| 389 |
- 'block' |
| 390 |
length: |
| 391 |
description: |
| 392 |
- Length of HTTP line in bytes (0 to 2147483647). |
| 393 |
type: int |
| 394 |
log: |
| 395 |
description: |
| 396 |
- Enable/disable logging. |
| 397 |
type: str |
| 398 |
choices: |
| 399 |
- 'enable' |
| 400 |
- 'disable' |
| 401 |
severity: |
| 402 |
description: |
| 403 |
- Severity. |
| 404 |
type: str |
| 405 |
choices: |
| 406 |
- 'high' |
| 407 |
- 'medium' |
| 408 |
- 'low' |
| 409 |
status: |
| 410 |
description: |
| 411 |
- Enable/disable the constraint. |
| 412 |
type: str |
| 413 |
choices: |
| 414 |
- 'enable' |
| 415 |
- 'disable' |
| 416 |
malformed: |
| 417 |
description: |
| 418 |
- Enable/disable malformed HTTP request check. |
| 419 |
type: dict |
| 420 |
suboptions: |
| 421 |
action: |
| 422 |
description: |
| 423 |
- Action. |
| 424 |
type: str |
| 425 |
choices: |
| 426 |
- 'allow' |
| 427 |
- 'block' |
| 428 |
log: |
| 429 |
description: |
| 430 |
- Enable/disable logging. |
| 431 |
type: str |
| 432 |
choices: |
| 433 |
- 'enable' |
| 434 |
- 'disable' |
| 435 |
severity: |
| 436 |
description: |
| 437 |
- Severity. |
| 438 |
type: str |
| 439 |
choices: |
| 440 |
- 'high' |
| 441 |
- 'medium' |
| 442 |
- 'low' |
| 443 |
status: |
| 444 |
description: |
| 445 |
- Enable/disable the constraint. |
| 446 |
type: str |
| 447 |
choices: |
| 448 |
- 'enable' |
| 449 |
- 'disable' |
| 450 |
max_cookie: |
| 451 |
description: |
| 452 |
- Maximum number of cookies in HTTP request. |
| 453 |
type: dict |
| 454 |
suboptions: |
| 455 |
action: |
| 456 |
description: |
| 457 |
- Action. |
| 458 |
type: str |
| 459 |
choices: |
| 460 |
- 'allow' |
| 461 |
- 'block' |
| 462 |
log: |
| 463 |
description: |
| 464 |
- Enable/disable logging. |
| 465 |
type: str |
| 466 |
choices: |
| 467 |
- 'enable' |
| 468 |
- 'disable' |
| 469 |
max_cookie: |
| 470 |
description: |
| 471 |
- Maximum number of cookies in HTTP request (0 to 2147483647). |
| 472 |
type: int |
| 473 |
severity: |
| 474 |
description: |
| 475 |
- Severity. |
| 476 |
type: str |
| 477 |
choices: |
| 478 |
- 'high' |
| 479 |
- 'medium' |
| 480 |
- 'low' |
| 481 |
status: |
| 482 |
description: |
| 483 |
- Enable/disable the constraint. |
| 484 |
type: str |
| 485 |
choices: |
| 486 |
- 'enable' |
| 487 |
- 'disable' |
| 488 |
max_header_line: |
| 489 |
description: |
| 490 |
- Maximum number of HTTP header line. |
| 491 |
type: dict |
| 492 |
suboptions: |
| 493 |
action: |
| 494 |
description: |
| 495 |
- Action. |
| 496 |
type: str |
| 497 |
choices: |
| 498 |
- 'allow' |
| 499 |
- 'block' |
| 500 |
log: |
| 501 |
description: |
| 502 |
- Enable/disable logging. |
| 503 |
type: str |
| 504 |
choices: |
| 505 |
- 'enable' |
| 506 |
- 'disable' |
| 507 |
max_header_line: |
| 508 |
description: |
| 509 |
- Maximum number HTTP header lines (0 to 2147483647). |
| 510 |
type: int |
| 511 |
severity: |
| 512 |
description: |
| 513 |
- Severity. |
| 514 |
type: str |
| 515 |
choices: |
| 516 |
- 'high' |
| 517 |
- 'medium' |
| 518 |
- 'low' |
| 519 |
status: |
| 520 |
description: |
| 521 |
- Enable/disable the constraint. |
| 522 |
type: str |
| 523 |
choices: |
| 524 |
- 'enable' |
| 525 |
- 'disable' |
| 526 |
max_range_segment: |
| 527 |
description: |
| 528 |
- Maximum number of range segments in HTTP range line. |
| 529 |
type: dict |
| 530 |
suboptions: |
| 531 |
action: |
| 532 |
description: |
| 533 |
- Action. |
| 534 |
type: str |
| 535 |
choices: |
| 536 |
- 'allow' |
| 537 |
- 'block' |
| 538 |
log: |
| 539 |
description: |
| 540 |
- Enable/disable logging. |
| 541 |
type: str |
| 542 |
choices: |
| 543 |
- 'enable' |
| 544 |
- 'disable' |
| 545 |
max_range_segment: |
| 546 |
description: |
| 547 |
- Maximum number of range segments in HTTP range line (0 to 2147483647). |
| 548 |
type: int |
| 549 |
severity: |
| 550 |
description: |
| 551 |
- Severity. |
| 552 |
type: str |
| 553 |
choices: |
| 554 |
- 'high' |
| 555 |
- 'medium' |
| 556 |
- 'low' |
| 557 |
status: |
| 558 |
description: |
| 559 |
- Enable/disable the constraint. |
| 560 |
type: str |
| 561 |
choices: |
| 562 |
- 'enable' |
| 563 |
- 'disable' |
| 564 |
max_url_param: |
| 565 |
description: |
| 566 |
- Maximum number of parameters in URL. |
| 567 |
type: dict |
| 568 |
suboptions: |
| 569 |
action: |
| 570 |
description: |
| 571 |
- Action. |
| 572 |
type: str |
| 573 |
choices: |
| 574 |
- 'allow' |
| 575 |
- 'block' |
| 576 |
log: |
| 577 |
description: |
| 578 |
- Enable/disable logging. |
| 579 |
type: str |
| 580 |
choices: |
| 581 |
- 'enable' |
| 582 |
- 'disable' |
| 583 |
max_url_param: |
| 584 |
description: |
| 585 |
- Maximum number of parameters in URL (0 to 2147483647). |
| 586 |
type: int |
| 587 |
severity: |
| 588 |
description: |
| 589 |
- Severity. |
| 590 |
type: str |
| 591 |
choices: |
| 592 |
- 'high' |
| 593 |
- 'medium' |
| 594 |
- 'low' |
| 595 |
status: |
| 596 |
description: |
| 597 |
- Enable/disable the constraint. |
| 598 |
type: str |
| 599 |
choices: |
| 600 |
- 'enable' |
| 601 |
- 'disable' |
| 602 |
method: |
| 603 |
description: |
| 604 |
- Enable/disable HTTP method check. |
| 605 |
type: dict |
| 606 |
suboptions: |
| 607 |
action: |
| 608 |
description: |
| 609 |
- Action. |
| 610 |
type: str |
| 611 |
choices: |
| 612 |
- 'allow' |
| 613 |
- 'block' |
| 614 |
log: |
| 615 |
description: |
| 616 |
- Enable/disable logging. |
| 617 |
type: str |
| 618 |
choices: |
| 619 |
- 'enable' |
| 620 |
- 'disable' |
| 621 |
severity: |
| 622 |
description: |
| 623 |
- Severity. |
| 624 |
type: str |
| 625 |
choices: |
| 626 |
- 'high' |
| 627 |
- 'medium' |
| 628 |
- 'low' |
| 629 |
status: |
| 630 |
description: |
| 631 |
- Enable/disable the constraint. |
| 632 |
type: str |
| 633 |
choices: |
| 634 |
- 'enable' |
| 635 |
- 'disable' |
| 636 |
param_length: |
| 637 |
description: |
| 638 |
- Maximum length of parameter in URL, HTTP POST request or HTTP body. |
| 639 |
type: dict |
| 640 |
suboptions: |
| 641 |
action: |
| 642 |
description: |
| 643 |
- Action. |
| 644 |
type: str |
| 645 |
choices: |
| 646 |
- 'allow' |
| 647 |
- 'block' |
| 648 |
length: |
| 649 |
description: |
| 650 |
- Maximum length of parameter in URL, HTTP POST request or HTTP body in bytes (0 to 2147483647). |
| 651 |
type: int |
| 652 |
log: |
| 653 |
description: |
| 654 |
- Enable/disable logging. |
| 655 |
type: str |
| 656 |
choices: |
| 657 |
- 'enable' |
| 658 |
- 'disable' |
| 659 |
severity: |
| 660 |
description: |
| 661 |
- Severity. |
| 662 |
type: str |
| 663 |
choices: |
| 664 |
- 'high' |
| 665 |
- 'medium' |
| 666 |
- 'low' |
| 667 |
status: |
| 668 |
description: |
| 669 |
- Enable/disable the constraint. |
| 670 |
type: str |
| 671 |
choices: |
| 672 |
- 'enable' |
| 673 |
- 'disable' |
| 674 |
url_param_length: |
| 675 |
description: |
| 676 |
- Maximum length of parameter in URL. |
| 677 |
type: dict |
| 678 |
suboptions: |
| 679 |
action: |
| 680 |
description: |
| 681 |
- Action. |
| 682 |
type: str |
| 683 |
choices: |
| 684 |
- 'allow' |
| 685 |
- 'block' |
| 686 |
length: |
| 687 |
description: |
| 688 |
- Maximum length of URL parameter in bytes (0 to 2147483647). |
| 689 |
type: int |
| 690 |
log: |
| 691 |
description: |
| 692 |
- Enable/disable logging. |
| 693 |
type: str |
| 694 |
choices: |
| 695 |
- 'enable' |
| 696 |
- 'disable' |
| 697 |
severity: |
| 698 |
description: |
| 699 |
- Severity. |
| 700 |
type: str |
| 701 |
choices: |
| 702 |
- 'high' |
| 703 |
- 'medium' |
| 704 |
- 'low' |
| 705 |
status: |
| 706 |
description: |
| 707 |
- Enable/disable the constraint. |
| 708 |
type: str |
| 709 |
choices: |
| 710 |
- 'enable' |
| 711 |
- 'disable' |
| 712 |
version: |
| 713 |
description: |
| 714 |
- Enable/disable HTTP version check. |
| 715 |
type: dict |
| 716 |
suboptions: |
| 717 |
action: |
| 718 |
description: |
| 719 |
- Action. |
| 720 |
type: str |
| 721 |
choices: |
| 722 |
- 'allow' |
| 723 |
- 'block' |
| 724 |
log: |
| 725 |
description: |
| 726 |
- Enable/disable logging. |
| 727 |
type: str |
| 728 |
choices: |
| 729 |
- 'enable' |
| 730 |
- 'disable' |
| 731 |
severity: |
| 732 |
description: |
| 733 |
- Severity. |
| 734 |
type: str |
| 735 |
choices: |
| 736 |
- 'high' |
| 737 |
- 'medium' |
| 738 |
- 'low' |
| 739 |
status: |
| 740 |
description: |
| 741 |
- Enable/disable the constraint. |
| 742 |
type: str |
| 743 |
choices: |
| 744 |
- 'enable' |
| 745 |
- 'disable' |
| 746 |
extended_log: |
| 747 |
description: |
| 748 |
- Enable/disable extended logging. |
| 749 |
type: str |
| 750 |
choices: |
| 751 |
- 'enable' |
| 752 |
- 'disable' |
| 753 |
external: |
| 754 |
description: |
| 755 |
- Disable/Enable external HTTP Inspection. |
| 756 |
type: str |
| 757 |
choices: |
| 758 |
- 'disable' |
| 759 |
- 'enable' |
| 760 |
method: |
| 761 |
description: |
| 762 |
- Method restriction. |
| 763 |
type: dict |
| 764 |
suboptions: |
| 765 |
default_allowed_methods: |
| 766 |
description: |
| 767 |
- Methods. |
| 768 |
type: list |
| 769 |
elements: str |
| 770 |
choices: |
| 771 |
- 'get' |
| 772 |
- 'post' |
| 773 |
- 'put' |
| 774 |
- 'head' |
| 775 |
- 'connect' |
| 776 |
- 'trace' |
| 777 |
- 'options' |
| 778 |
- 'delete' |
| 779 |
- 'others' |
| 780 |
log: |
| 781 |
description: |
| 782 |
- Enable/disable logging. |
| 783 |
type: str |
| 784 |
choices: |
| 785 |
- 'enable' |
| 786 |
- 'disable' |
| 787 |
method_policy: |
| 788 |
description: |
| 789 |
- HTTP method policy. |
| 790 |
type: list |
| 791 |
elements: dict |
| 792 |
suboptions: |
| 793 |
address: |
| 794 |
description: |
| 795 |
- Host address. Source firewall.address.name firewall.addrgrp.name. |
| 796 |
type: str |
| 797 |
allowed_methods: |
| 798 |
description: |
| 799 |
- Allowed Methods. |
| 800 |
type: list |
| 801 |
elements: str |
| 802 |
choices: |
| 803 |
- 'get' |
| 804 |
- 'post' |
| 805 |
- 'put' |
| 806 |
- 'head' |
| 807 |
- 'connect' |
| 808 |
- 'trace' |
| 809 |
- 'options' |
| 810 |
- 'delete' |
| 811 |
- 'others' |
| 812 |
id: |
| 813 |
description: |
| 814 |
- HTTP method policy ID. see <a href='#notes'>Notes</a>. |
| 815 |
required: true |
| 816 |
type: int |
| 817 |
pattern: |
| 818 |
description: |
| 819 |
- URL pattern. |
| 820 |
type: str |
| 821 |
regex: |
| 822 |
description: |
| 823 |
- Enable/disable regular expression based pattern match. |
| 824 |
type: str |
| 825 |
choices: |
| 826 |
- 'enable' |
| 827 |
- 'disable' |
| 828 |
severity: |
| 829 |
description: |
| 830 |
- Severity. |
| 831 |
type: str |
| 832 |
choices: |
| 833 |
- 'high' |
| 834 |
- 'medium' |
| 835 |
- 'low' |
| 836 |
status: |
| 837 |
description: |
| 838 |
- Status. |
| 839 |
type: str |
| 840 |
choices: |
| 841 |
- 'enable' |
| 842 |
- 'disable' |
| 843 |
name: |
| 844 |
description: |
| 845 |
- WAF Profile name. |
| 846 |
required: true |
| 847 |
type: str |
| 848 |
signature: |
| 849 |
description: |
| 850 |
- WAF signatures. |
| 851 |
type: dict |
| 852 |
suboptions: |
| 853 |
credit_card_detection_threshold: |
| 854 |
description: |
| 855 |
- The minimum number of Credit cards to detect violation. |
| 856 |
type: int |
| 857 |
custom_signature: |
| 858 |
description: |
| 859 |
- Custom signature. |
| 860 |
type: list |
| 861 |
elements: dict |
| 862 |
suboptions: |
| 863 |
action: |
| 864 |
description: |
| 865 |
- Action. |
| 866 |
type: str |
| 867 |
choices: |
| 868 |
- 'allow' |
| 869 |
- 'block' |
| 870 |
- 'erase' |
| 871 |
case_sensitivity: |
| 872 |
description: |
| 873 |
- Case sensitivity in pattern. |
| 874 |
type: str |
| 875 |
choices: |
| 876 |
- 'disable' |
| 877 |
- 'enable' |
| 878 |
direction: |
| 879 |
description: |
| 880 |
- Traffic direction. |
| 881 |
type: str |
| 882 |
choices: |
| 883 |
- 'request' |
| 884 |
- 'response' |
| 885 |
log: |
| 886 |
description: |
| 887 |
- Enable/disable logging. |
| 888 |
type: str |
| 889 |
choices: |
| 890 |
- 'enable' |
| 891 |
- 'disable' |
| 892 |
name: |
| 893 |
description: |
| 894 |
- Signature name. |
| 895 |
required: true |
| 896 |
type: str |
| 897 |
pattern: |
| 898 |
description: |
| 899 |
- Match pattern. |
| 900 |
type: str |
| 901 |
severity: |
| 902 |
description: |
| 903 |
- Severity. |
| 904 |
type: str |
| 905 |
choices: |
| 906 |
- 'high' |
| 907 |
- 'medium' |
| 908 |
- 'low' |
| 909 |
status: |
| 910 |
description: |
| 911 |
- Status. |
| 912 |
type: str |
| 913 |
choices: |
| 914 |
- 'enable' |
| 915 |
- 'disable' |
| 916 |
target: |
| 917 |
description: |
| 918 |
- Match HTTP target. |
| 919 |
type: list |
| 920 |
elements: str |
| 921 |
choices: |
| 922 |
- 'arg' |
| 923 |
- 'arg-name' |
| 924 |
- 'req-body' |
| 925 |
- 'req-cookie' |
| 926 |
- 'req-cookie-name' |
| 927 |
- 'req-filename' |
| 928 |
- 'req-header' |
| 929 |
- 'req-header-name' |
| 930 |
- 'req-raw-uri' |
| 931 |
- 'req-uri' |
| 932 |
- 'resp-body' |
| 933 |
- 'resp-hdr' |
| 934 |
- 'resp-status' |
| 935 |
disabled_signature: |
| 936 |
description: |
| 937 |
- Disabled signatures. |
| 938 |
type: list |
| 939 |
elements: dict |
| 940 |
suboptions: |
| 941 |
id: |
| 942 |
description: |
| 943 |
- Signature ID. see <a href='#notes'>Notes</a>. Source waf.signature.id. |
| 944 |
required: true |
| 945 |
type: int |
| 946 |
disabled_sub_class: |
| 947 |
description: |
| 948 |
- Disabled signature subclasses. |
| 949 |
type: list |
| 950 |
elements: dict |
| 951 |
suboptions: |
| 952 |
id: |
| 953 |
description: |
| 954 |
- Signature subclass ID. see <a href='#notes'>Notes</a>. Source waf.sub-class.id. |
| 955 |
required: true |
| 956 |
type: int |
| 957 |
main_class: |
| 958 |
description: |
| 959 |
- Main signature class. |
| 960 |
type: list |
| 961 |
elements: dict |
| 962 |
suboptions: |
| 963 |
action: |
| 964 |
description: |
| 965 |
- Action. |
| 966 |
type: str |
| 967 |
choices: |
| 968 |
- 'allow' |
| 969 |
- 'block' |
| 970 |
- 'erase' |
| 971 |
id: |
| 972 |
description: |
| 973 |
- Main signature class ID. see <a href='#notes'>Notes</a>. Source waf.main-class.id. |
| 974 |
required: true |
| 975 |
type: int |
| 976 |
log: |
| 977 |
description: |
| 978 |
- Enable/disable logging. |
| 979 |
type: str |
| 980 |
choices: |
| 981 |
- 'enable' |
| 982 |
- 'disable' |
| 983 |
severity: |
| 984 |
description: |
| 985 |
- Severity. |
| 986 |
type: str |
| 987 |
choices: |
| 988 |
- 'high' |
| 989 |
- 'medium' |
| 990 |
- 'low' |
| 991 |
status: |
| 992 |
description: |
| 993 |
- Status. |
| 994 |
type: str |
| 995 |
choices: |
| 996 |
- 'enable' |
| 997 |
- 'disable' |
| 998 |
url_access: |
| 999 |
description: |
| 1000 |
- URL access list. |
| 1001 |
type: list |
| 1002 |
elements: dict |
| 1003 |
suboptions: |
| 1004 |
access_pattern: |
| 1005 |
description: |
| 1006 |
- URL access pattern. |
| 1007 |
type: list |
| 1008 |
elements: dict |
| 1009 |
suboptions: |
| 1010 |
id: |
| 1011 |
description: |
| 1012 |
- URL access pattern ID. see <a href='#notes'>Notes</a>. |
| 1013 |
required: true |
| 1014 |
type: int |
| 1015 |
negate: |
| 1016 |
description: |
| 1017 |
- Enable/disable match negation. |
| 1018 |
type: str |
| 1019 |
choices: |
| 1020 |
- 'enable' |
| 1021 |
- 'disable' |
| 1022 |
pattern: |
| 1023 |
description: |
| 1024 |
- URL pattern. |
| 1025 |
type: str |
| 1026 |
regex: |
| 1027 |
description: |
| 1028 |
- Enable/disable regular expression based pattern match. |
| 1029 |
type: str |
| 1030 |
choices: |
| 1031 |
- 'enable' |
| 1032 |
- 'disable' |
| 1033 |
srcaddr: |
| 1034 |
description: |
| 1035 |
- Source address. Source firewall.address.name firewall.addrgrp.name. |
| 1036 |
type: str |
| 1037 |
action: |
| 1038 |
description: |
| 1039 |
- Action. |
| 1040 |
type: str |
| 1041 |
choices: |
| 1042 |
- 'bypass' |
| 1043 |
- 'permit' |
| 1044 |
- 'block' |
| 1045 |
address: |
| 1046 |
description: |
| 1047 |
- Host address. Source firewall.address.name firewall.addrgrp.name. |
| 1048 |
type: str |
| 1049 |
id: |
| 1050 |
description: |
| 1051 |
- URL access ID. see <a href='#notes'>Notes</a>. |
| 1052 |
required: true |
| 1053 |
type: int |
| 1054 |
log: |
| 1055 |
description: |
| 1056 |
- Enable/disable logging. |
| 1057 |
type: str |
| 1058 |
choices: |
| 1059 |
- 'enable' |
| 1060 |
- 'disable' |
| 1061 |
severity: |
| 1062 |
description: |
| 1063 |
- Severity. |
| 1064 |
type: str |
| 1065 |
choices: |
| 1066 |
- 'high' |
| 1067 |
- 'medium' |
| 1068 |
- 'low' |
| 1069 |
""" |
| 1070 |
|
| 1071 |
EXAMPLES = """ |
| 1072 |
- name: Configure Web application firewall configuration. |
| 1073 |
fortinet.fortios.fortios_waf_profile: |
| 1074 |
vdom: "{{ vdom }}" |
| 1075 |
state: "present" |
| 1076 |
access_token: "<your_own_value>" |
| 1077 |
waf_profile: |
| 1078 |
address_list: |
| 1079 |
blocked_address: |
| 1080 |
- |
| 1081 |
name: "default_name_5 (source firewall.address.name firewall.addrgrp.name)" |
| 1082 |
blocked_log: "enable" |
| 1083 |
severity: "high" |
| 1084 |
status: "enable" |
| 1085 |
trusted_address: |
| 1086 |
- |
| 1087 |
name: "default_name_10 (source firewall.address.name firewall.addrgrp.name)" |
| 1088 |
comment: "Comment." |
| 1089 |
constraint: |
| 1090 |
content_length: |
| 1091 |
action: "allow" |
| 1092 |
length: "67108864" |
| 1093 |
log: "enable" |
| 1094 |
severity: "high" |
| 1095 |
status: "enable" |
| 1096 |
exception: |
| 1097 |
- |
| 1098 |
address: "<your_own_value> (source firewall.address.name firewall.addrgrp.name)" |
| 1099 |
content_length: "enable" |
| 1100 |
header_length: "enable" |
| 1101 |
hostname: "enable" |
| 1102 |
id: "24" |
| 1103 |
line_length: "enable" |
| 1104 |
malformed: "enable" |
| 1105 |
max_cookie: "enable" |
| 1106 |
max_header_line: "enable" |
| 1107 |
max_range_segment: "enable" |
| 1108 |
max_url_param: "enable" |
| 1109 |
method: "enable" |
| 1110 |
param_length: "enable" |
| 1111 |
pattern: "<your_own_value>" |
| 1112 |
regex: "enable" |
| 1113 |
url_param_length: "enable" |
| 1114 |
version: "enable" |
| 1115 |
header_length: |
| 1116 |
action: "allow" |
| 1117 |
length: "8192" |
| 1118 |
log: "enable" |
| 1119 |
severity: "high" |
| 1120 |
status: "enable" |
| 1121 |
hostname: |
| 1122 |
action: "allow" |
| 1123 |
log: "enable" |
| 1124 |
severity: "high" |
| 1125 |
status: "enable" |
| 1126 |
line_length: |
| 1127 |
action: "allow" |
| 1128 |
length: "1024" |
| 1129 |
log: "enable" |
| 1130 |
severity: "high" |
| 1131 |
status: "enable" |
| 1132 |
malformed: |
| 1133 |
action: "allow" |
| 1134 |
log: "enable" |
| 1135 |
severity: "high" |
| 1136 |
status: "enable" |
| 1137 |
max_cookie: |
| 1138 |
action: "allow" |
| 1139 |
log: "enable" |
| 1140 |
max_cookie: "16" |
| 1141 |
severity: "high" |
| 1142 |
status: "enable" |
| 1143 |
max_header_line: |
| 1144 |
action: "allow" |
| 1145 |
log: "enable" |
| 1146 |
max_header_line: "32" |
| 1147 |
severity: "high" |
| 1148 |
status: "enable" |
| 1149 |
max_range_segment: |
| 1150 |
action: "allow" |
| 1151 |
log: "enable" |
| 1152 |
max_range_segment: "5" |
| 1153 |
severity: "high" |
| 1154 |
status: "enable" |
| 1155 |
max_url_param: |
| 1156 |
action: "allow" |
| 1157 |
log: "enable" |
| 1158 |
max_url_param: "16" |
| 1159 |
severity: "high" |
| 1160 |
status: "enable" |
| 1161 |
method: |
| 1162 |
action: "allow" |
| 1163 |
log: "enable" |
| 1164 |
severity: "high" |
| 1165 |
status: "enable" |
| 1166 |
param_length: |
| 1167 |
action: "allow" |
| 1168 |
length: "8192" |
| 1169 |
log: "enable" |
| 1170 |
severity: "high" |
| 1171 |
status: "enable" |
| 1172 |
url_param_length: |
| 1173 |
action: "allow" |
| 1174 |
length: "8192" |
| 1175 |
log: "enable" |
| 1176 |
severity: "high" |
| 1177 |
status: "enable" |
| 1178 |
version: |
| 1179 |
action: "allow" |
| 1180 |
log: "enable" |
| 1181 |
severity: "high" |
| 1182 |
status: "enable" |
| 1183 |
extended_log: "enable" |
| 1184 |
external: "disable" |
| 1185 |
method: |
| 1186 |
default_allowed_methods: "get" |
| 1187 |
log: "enable" |
| 1188 |
method_policy: |
| 1189 |
- |
| 1190 |
address: "<your_own_value> (source firewall.address.name firewall.addrgrp.name)" |
| 1191 |
allowed_methods: "get" |
| 1192 |
id: "113" |
| 1193 |
pattern: "<your_own_value>" |
| 1194 |
regex: "enable" |
| 1195 |
severity: "high" |
| 1196 |
status: "enable" |
| 1197 |
name: "default_name_118" |
| 1198 |
signature: |
| 1199 |
credit_card_detection_threshold: "3" |
| 1200 |
custom_signature: |
| 1201 |
- |
| 1202 |
action: "allow" |
| 1203 |
case_sensitivity: "disable" |
| 1204 |
direction: "request" |
| 1205 |
log: "enable" |
| 1206 |
name: "default_name_126" |
| 1207 |
pattern: "<your_own_value>" |
| 1208 |
severity: "high" |
| 1209 |
status: "enable" |
| 1210 |
target: "arg" |
| 1211 |
disabled_signature: |
| 1212 |
- |
| 1213 |
id: "132 (source waf.signature.id)" |
| 1214 |
disabled_sub_class: |
| 1215 |
- |
| 1216 |
id: "134 (source waf.sub-class.id)" |
| 1217 |
main_class: |
| 1218 |
- |
| 1219 |
action: "allow" |
| 1220 |
id: "137 (source waf.main-class.id)" |
| 1221 |
log: "enable" |
| 1222 |
severity: "high" |
| 1223 |
status: "enable" |
| 1224 |
url_access: |
| 1225 |
- |
| 1226 |
access_pattern: |
| 1227 |
- |
| 1228 |
id: "143" |
| 1229 |
negate: "enable" |
| 1230 |
pattern: "<your_own_value>" |
| 1231 |
regex: "enable" |
| 1232 |
srcaddr: "<your_own_value> (source firewall.address.name firewall.addrgrp.name)" |
| 1233 |
action: "bypass" |
| 1234 |
address: "<your_own_value> (source firewall.address.name firewall.addrgrp.name)" |
| 1235 |
id: "150" |
| 1236 |
log: "enable" |
| 1237 |
severity: "high" |
| 1238 |
""" |
| 1239 |
|
| 1240 |
RETURN = """ |
| 1241 |
build: |
| 1242 |
description: Build number of the fortigate image |
| 1243 |
returned: always |
| 1244 |
type: str |
| 1245 |
sample: '1547' |
| 1246 |
http_method: |
| 1247 |
description: Last method used to provision the content into FortiGate |
| 1248 |
returned: always |
| 1249 |
type: str |
| 1250 |
sample: 'PUT' |
| 1251 |
http_status: |
| 1252 |
description: Last result given by FortiGate on last operation applied |
| 1253 |
returned: always |
| 1254 |
type: str |
| 1255 |
sample: "200" |
| 1256 |
mkey: |
| 1257 |
description: Master key (id) used in the last call to FortiGate |
| 1258 |
returned: success |
| 1259 |
type: str |
| 1260 |
sample: "id" |
| 1261 |
name: |
| 1262 |
description: Name of the table used to fulfill the request |
| 1263 |
returned: always |
| 1264 |
type: str |
| 1265 |
sample: "urlfilter" |
| 1266 |
path: |
| 1267 |
description: Path of the table used to fulfill the request |
| 1268 |
returned: always |
| 1269 |
type: str |
| 1270 |
sample: "webfilter" |
| 1271 |
revision: |
| 1272 |
description: Internal revision number |
| 1273 |
returned: always |
| 1274 |
type: str |
| 1275 |
sample: "17.0.2.10658" |
| 1276 |
serial: |
| 1277 |
description: Serial number of the unit |
| 1278 |
returned: always |
| 1279 |
type: str |
| 1280 |
sample: "FGVMEVYYQT3AB5352" |
| 1281 |
status: |
| 1282 |
description: Indication of the operation's result |
| 1283 |
returned: always |
| 1284 |
type: str |
| 1285 |
sample: "success" |
| 1286 |
vdom: |
| 1287 |
description: Virtual domain used |
| 1288 |
returned: always |
| 1289 |
type: str |
| 1290 |
sample: "root" |
| 1291 |
version: |
| 1292 |
description: Version of the FortiGate |
| 1293 |
returned: always |
| 1294 |
type: str |
| 1295 |
sample: "v5.6.3" |
| 1296 |
""" |
| 1297 |
from ansible.module_utils.basic import AnsibleModule |
| 1298 |
from ansible.module_utils.connection import Connection |
| 1299 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import ( |
| 1300 |
FortiOSHandler, |
| 1301 |
) |
| 1302 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import ( |
| 1303 |
check_legacy_fortiosapi, |
| 1304 |
) |
| 1305 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import ( |
| 1306 |
schema_to_module_spec, |
| 1307 |
) |
| 1308 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import ( |
| 1309 |
check_schema_versioning, |
| 1310 |
) |
| 1311 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import ( |
| 1312 |
FAIL_SOCKET_MSG, |
| 1313 |
) |
| 1314 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import ( |
| 1315 |
remove_invalid_fields, |
| 1316 |
) |
| 1317 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import ( |
| 1318 |
is_same_comparison, |
| 1319 |
) |
| 1320 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import ( |
| 1321 |
serialize, |
| 1322 |
) |
| 1323 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import ( |
| 1324 |
find_current_values, |
| 1325 |
) |
| 1326 |
from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import ( |
| 1327 |
unify_data_format, |
| 1328 |
) |
| 1329 |
|
| 1330 |
|
| 1331 |
def filter_waf_profile_data(json): |
| 1332 |
option_list = [ |
| 1333 |
"address_list", |
| 1334 |
"comment", |
| 1335 |
"constraint", |
| 1336 |
"extended_log", |
| 1337 |
"external", |
| 1338 |
"method", |
| 1339 |
"name", |
| 1340 |
"signature", |
| 1341 |
"url_access", |
| 1342 |
] |
| 1343 |
|
| 1344 |
json = remove_invalid_fields(json) |
| 1345 |
dictionary = {} |
| 1346 |
|
| 1347 |
for attribute in option_list: |
| 1348 |
if attribute in json and json[attribute] is not None: |
| 1349 |
dictionary[attribute] = json[attribute] |
| 1350 |
|
| 1351 |
return dictionary |
| 1352 |
|
| 1353 |
|
| 1354 |
def flatten_single_path(data, path, index): |
| 1355 |
if ( |
| 1356 |
not data |
| 1357 |
or index == len(path) |
| 1358 |
or path[index] not in data |
| 1359 |
or (not data[path[index]] and not isinstance(data[path[index]], list)) |
| 1360 |
): |
| 1361 |
return |
| 1362 |
|
| 1363 |
if index == len(path) - 1: |
| 1364 |
data[path[index]] = " ".join(str(elem) for elem in data[path[index]]) |
| 1365 |
if len(data[path[index]]) == 0: |
| 1366 |
data[path[index]] = None |
| 1367 |
elif isinstance(data[path[index]], list): |
| 1368 |
for value in data[path[index]]: |
| 1369 |
flatten_single_path(value, path, index + 1) |
| 1370 |
else: |
| 1371 |
flatten_single_path(data[path[index]], path, index + 1) |
| 1372 |
|
| 1373 |
|
| 1374 |
def flatten_multilists_attributes(data): |
| 1375 |
multilist_attrs = [ |
| 1376 |
["signature", "custom_signature", "target"], |
| 1377 |
["method", "default_allowed_methods"], |
| 1378 |
["method", "method_policy", "allowed_methods"], |
| 1379 |
] |
| 1380 |
|
| 1381 |
for attr in multilist_attrs: |
| 1382 |
flatten_single_path(data, attr, 0) |
| 1383 |
|
| 1384 |
return data |
| 1385 |
|
| 1386 |
|
| 1387 |
def underscore_to_hyphen(data): |
| 1388 |
new_data = None |
| 1389 |
if isinstance(data, list): |
| 1390 |
new_data = [] |
| 1391 |
for i, elem in enumerate(data): |
| 1392 |
new_data.append(underscore_to_hyphen(elem)) |
| 1393 |
elif isinstance(data, dict): |
| 1394 |
new_data = {} |
| 1395 |
for k, v in data.items(): |
| 1396 |
new_data[k.replace("_", "-")] = underscore_to_hyphen(v) |
| 1397 |
else: |
| 1398 |
return data |
| 1399 |
return new_data |
| 1400 |
|
| 1401 |
|
| 1402 |
def waf_profile(data, fos, check_mode=False): |
| 1403 |
|
| 1404 |
state = None |
| 1405 |
vdom = data["vdom"] |
| 1406 |
parameters = None |
| 1407 |
state = data.get("state", None) |
| 1408 |
waf_profile_data = data["waf_profile"] |
| 1409 |
|
| 1410 |
filtered_data = filter_waf_profile_data(waf_profile_data) |
| 1411 |
filtered_data = flatten_multilists_attributes(filtered_data) |
| 1412 |
converted_data = underscore_to_hyphen(filtered_data) |
| 1413 |
|
| 1414 |
|
| 1415 |
if check_mode: |
| 1416 |
diff = { |
| 1417 |
"before": "", |
| 1418 |
"after": filtered_data, |
| 1419 |
} |
| 1420 |
mkeyname = fos.get_mkeyname(None, None) |
| 1421 |
mkey = fos.get_mkey("waf", "profile", filtered_data, vdom=vdom) |
| 1422 |
current_data = fos.get( |
| 1423 |
"waf", "profile", vdom=vdom, mkey=mkey, parameters=parameters |
| 1424 |
) |
| 1425 |
is_existed = ( |
| 1426 |
current_data |
| 1427 |
and current_data.get("http_status") == 200 |
| 1428 |
and ( |
| 1429 |
mkeyname |
| 1430 |
and isinstance(current_data.get("results"), list) |
| 1431 |
and len(current_data["results"]) > 0 |
| 1432 |
or not mkeyname |
| 1433 |
and current_data["results"] |
| 1434 |
) |
| 1435 |
) |
| 1436 |
|
| 1437 |
|
| 1438 |
if state == "present" or state is True or state is None: |
| 1439 |
|
| 1440 |
if mkeyname is not None and mkey is None: |
| 1441 |
return False, True, filtered_data, diff |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
copied_filtered_data = filtered_data.copy() |
| 1446 |
copied_filtered_data.pop(mkeyname, None) |
| 1447 |
unified_filtered_data = unify_data_format(copied_filtered_data) |
| 1448 |
|
| 1449 |
current_data_results = current_data.get("results", {}) |
| 1450 |
current_config = ( |
| 1451 |
current_data_results[0] |
| 1452 |
if mkeyname |
| 1453 |
and isinstance(current_data_results, list) |
| 1454 |
and len(current_data_results) > 0 |
| 1455 |
else current_data_results |
| 1456 |
) |
| 1457 |
if is_existed: |
| 1458 |
unified_current_values = find_current_values( |
| 1459 |
unified_filtered_data, |
| 1460 |
unify_data_format(current_config), |
| 1461 |
) |
| 1462 |
|
| 1463 |
is_same = is_same_comparison( |
| 1464 |
serialize(unified_current_values), serialize(unified_filtered_data) |
| 1465 |
) |
| 1466 |
|
| 1467 |
return ( |
| 1468 |
False, |
| 1469 |
not is_same, |
| 1470 |
filtered_data, |
| 1471 |
{"before": unified_current_values, "after": unified_filtered_data}, |
| 1472 |
) |
| 1473 |
|
| 1474 |
|
| 1475 |
return False, True, filtered_data, diff |
| 1476 |
|
| 1477 |
if state == "absent": |
| 1478 |
if mkey is None: |
| 1479 |
return ( |
| 1480 |
False, |
| 1481 |
False, |
| 1482 |
filtered_data, |
| 1483 |
{"before": current_data["results"][0], "after": ""}, |
| 1484 |
) |
| 1485 |
|
| 1486 |
if is_existed: |
| 1487 |
return ( |
| 1488 |
False, |
| 1489 |
True, |
| 1490 |
filtered_data, |
| 1491 |
{"before": current_data["results"][0], "after": ""}, |
| 1492 |
) |
| 1493 |
return False, False, filtered_data, {} |
| 1494 |
|
| 1495 |
return True, False, {"reason: ": "Must provide state parameter"}, {} |
| 1496 |
|
| 1497 |
|
| 1498 |
data_copy = data.copy() |
| 1499 |
data_copy["waf_profile"] = filtered_data |
| 1500 |
fos.do_member_operation( |
| 1501 |
"waf", |
| 1502 |
"profile", |
| 1503 |
data_copy, |
| 1504 |
) |
| 1505 |
|
| 1506 |
if state == "present" or state is True: |
| 1507 |
return fos.set( |
| 1508 |
"waf", "profile", data=converted_data, vdom=vdom, parameters=parameters |
| 1509 |
) |
| 1510 |
|
| 1511 |
elif state == "absent": |
| 1512 |
return fos.delete( |
| 1513 |
"waf", |
| 1514 |
"profile", |
| 1515 |
mkey=converted_data["name"], |
| 1516 |
vdom=vdom, |
| 1517 |
parameters=parameters, |
| 1518 |
) |
| 1519 |
else: |
| 1520 |
fos._module.fail_json(msg="state must be present or absent!") |
| 1521 |
|
| 1522 |
|
| 1523 |
def is_successful_status(resp): |
| 1524 |
return ( |
| 1525 |
"status" in resp |
| 1526 |
and resp["status"] == "success" |
| 1527 |
or "http_status" in resp |
| 1528 |
and resp["http_status"] == 200 |
| 1529 |
or "http_method" in resp |
| 1530 |
and resp["http_method"] == "DELETE" |
| 1531 |
and resp["http_status"] == 404 |
| 1532 |
) |
| 1533 |
|
| 1534 |
|
| 1535 |
def fortios_waf(data, fos, check_mode): |
| 1536 |
|
| 1537 |
if data["waf_profile"]: |
| 1538 |
resp = waf_profile(data, fos, check_mode) |
| 1539 |
else: |
| 1540 |
fos._module.fail_json(msg="missing task body: %s" % ("waf_profile")) |
| 1541 |
if isinstance(resp, tuple) and len(resp) == 4: |
| 1542 |
return resp |
| 1543 |
return ( |
| 1544 |
not is_successful_status(resp), |
| 1545 |
is_successful_status(resp) |
| 1546 |
and (resp["revision_changed"] if "revision_changed" in resp else True), |
| 1547 |
resp, |
| 1548 |
{}, |
| 1549 |
) |
| 1550 |
|
| 1551 |
|
| 1552 |
versioned_schema = { |
| 1553 |
"type": "list", |
| 1554 |
"elements": "dict", |
| 1555 |
"children": { |
| 1556 |
"name": {"v_range": [["v6.0.0", ""]], "type": "string", "required": True}, |
| 1557 |
"external": { |
| 1558 |
"v_range": [["v6.0.0", ""]], |
| 1559 |
"type": "string", |
| 1560 |
"options": [{"value": "disable"}, {"value": "enable"}], |
| 1561 |
}, |
| 1562 |
"extended_log": { |
| 1563 |
"v_range": [["v6.0.0", ""]], |
| 1564 |
"type": "string", |
| 1565 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1566 |
}, |
| 1567 |
"signature": { |
| 1568 |
"v_range": [["v6.0.0", ""]], |
| 1569 |
"type": "dict", |
| 1570 |
"children": { |
| 1571 |
"disabled_sub_class": { |
| 1572 |
"type": "list", |
| 1573 |
"elements": "dict", |
| 1574 |
"children": { |
| 1575 |
"id": { |
| 1576 |
"v_range": [["v6.0.0", ""]], |
| 1577 |
"type": "integer", |
| 1578 |
"required": True, |
| 1579 |
} |
| 1580 |
}, |
| 1581 |
"v_range": [["v6.0.0", ""]], |
| 1582 |
}, |
| 1583 |
"disabled_signature": { |
| 1584 |
"type": "list", |
| 1585 |
"elements": "dict", |
| 1586 |
"children": { |
| 1587 |
"id": { |
| 1588 |
"v_range": [["v6.0.0", ""]], |
| 1589 |
"type": "integer", |
| 1590 |
"required": True, |
| 1591 |
} |
| 1592 |
}, |
| 1593 |
"v_range": [["v6.0.0", ""]], |
| 1594 |
}, |
| 1595 |
"credit_card_detection_threshold": { |
| 1596 |
"v_range": [["v6.0.0", ""]], |
| 1597 |
"type": "integer", |
| 1598 |
}, |
| 1599 |
"custom_signature": { |
| 1600 |
"type": "list", |
| 1601 |
"elements": "dict", |
| 1602 |
"children": { |
| 1603 |
"name": { |
| 1604 |
"v_range": [["v6.0.0", ""]], |
| 1605 |
"type": "string", |
| 1606 |
"required": True, |
| 1607 |
}, |
| 1608 |
"status": { |
| 1609 |
"v_range": [["v6.0.0", ""]], |
| 1610 |
"type": "string", |
| 1611 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1612 |
}, |
| 1613 |
"action": { |
| 1614 |
"v_range": [["v6.0.0", ""]], |
| 1615 |
"type": "string", |
| 1616 |
"options": [ |
| 1617 |
{"value": "allow"}, |
| 1618 |
{"value": "block"}, |
| 1619 |
{"value": "erase"}, |
| 1620 |
], |
| 1621 |
}, |
| 1622 |
"log": { |
| 1623 |
"v_range": [["v6.0.0", ""]], |
| 1624 |
"type": "string", |
| 1625 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1626 |
}, |
| 1627 |
"severity": { |
| 1628 |
"v_range": [["v6.0.0", ""]], |
| 1629 |
"type": "string", |
| 1630 |
"options": [ |
| 1631 |
{"value": "high"}, |
| 1632 |
{"value": "medium"}, |
| 1633 |
{"value": "low"}, |
| 1634 |
], |
| 1635 |
}, |
| 1636 |
"direction": { |
| 1637 |
"v_range": [["v6.0.0", ""]], |
| 1638 |
"type": "string", |
| 1639 |
"options": [{"value": "request"}, {"value": "response"}], |
| 1640 |
}, |
| 1641 |
"case_sensitivity": { |
| 1642 |
"v_range": [["v6.0.0", ""]], |
| 1643 |
"type": "string", |
| 1644 |
"options": [{"value": "disable"}, {"value": "enable"}], |
| 1645 |
}, |
| 1646 |
"pattern": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 1647 |
"target": { |
| 1648 |
"v_range": [["v6.0.0", ""]], |
| 1649 |
"type": "list", |
| 1650 |
"options": [ |
| 1651 |
{"value": "arg"}, |
| 1652 |
{"value": "arg-name"}, |
| 1653 |
{"value": "req-body"}, |
| 1654 |
{"value": "req-cookie"}, |
| 1655 |
{"value": "req-cookie-name"}, |
| 1656 |
{"value": "req-filename"}, |
| 1657 |
{"value": "req-header"}, |
| 1658 |
{"value": "req-header-name"}, |
| 1659 |
{"value": "req-raw-uri"}, |
| 1660 |
{"value": "req-uri"}, |
| 1661 |
{"value": "resp-body"}, |
| 1662 |
{"value": "resp-hdr"}, |
| 1663 |
{"value": "resp-status"}, |
| 1664 |
], |
| 1665 |
"multiple_values": True, |
| 1666 |
"elements": "str", |
| 1667 |
}, |
| 1668 |
}, |
| 1669 |
"v_range": [["v6.0.0", ""]], |
| 1670 |
}, |
| 1671 |
"main_class": { |
| 1672 |
"type": "list", |
| 1673 |
"elements": "dict", |
| 1674 |
"children": { |
| 1675 |
"id": { |
| 1676 |
"v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]], |
| 1677 |
"type": "integer", |
| 1678 |
"required": True, |
| 1679 |
}, |
| 1680 |
"status": { |
| 1681 |
"v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]], |
| 1682 |
"type": "string", |
| 1683 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1684 |
}, |
| 1685 |
"action": { |
| 1686 |
"v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]], |
| 1687 |
"type": "string", |
| 1688 |
"options": [ |
| 1689 |
{"value": "allow"}, |
| 1690 |
{"value": "block"}, |
| 1691 |
{"value": "erase"}, |
| 1692 |
], |
| 1693 |
}, |
| 1694 |
"log": { |
| 1695 |
"v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]], |
| 1696 |
"type": "string", |
| 1697 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1698 |
}, |
| 1699 |
"severity": { |
| 1700 |
"v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]], |
| 1701 |
"type": "string", |
| 1702 |
"options": [ |
| 1703 |
{"value": "high"}, |
| 1704 |
{"value": "medium"}, |
| 1705 |
{"value": "low"}, |
| 1706 |
], |
| 1707 |
}, |
| 1708 |
}, |
| 1709 |
"v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]], |
| 1710 |
}, |
| 1711 |
}, |
| 1712 |
}, |
| 1713 |
"constraint": { |
| 1714 |
"v_range": [["v6.0.0", ""]], |
| 1715 |
"type": "dict", |
| 1716 |
"children": { |
| 1717 |
"header_length": { |
| 1718 |
"v_range": [["v6.0.0", ""]], |
| 1719 |
"type": "dict", |
| 1720 |
"children": { |
| 1721 |
"status": { |
| 1722 |
"v_range": [["v6.0.0", ""]], |
| 1723 |
"type": "string", |
| 1724 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1725 |
}, |
| 1726 |
"length": {"v_range": [["v6.0.0", ""]], "type": "integer"}, |
| 1727 |
"action": { |
| 1728 |
"v_range": [["v6.0.0", ""]], |
| 1729 |
"type": "string", |
| 1730 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1731 |
}, |
| 1732 |
"log": { |
| 1733 |
"v_range": [["v6.0.0", ""]], |
| 1734 |
"type": "string", |
| 1735 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1736 |
}, |
| 1737 |
"severity": { |
| 1738 |
"v_range": [["v6.0.0", ""]], |
| 1739 |
"type": "string", |
| 1740 |
"options": [ |
| 1741 |
{"value": "high"}, |
| 1742 |
{"value": "medium"}, |
| 1743 |
{"value": "low"}, |
| 1744 |
], |
| 1745 |
}, |
| 1746 |
}, |
| 1747 |
}, |
| 1748 |
"content_length": { |
| 1749 |
"v_range": [["v6.0.0", ""]], |
| 1750 |
"type": "dict", |
| 1751 |
"children": { |
| 1752 |
"status": { |
| 1753 |
"v_range": [["v6.0.0", ""]], |
| 1754 |
"type": "string", |
| 1755 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1756 |
}, |
| 1757 |
"length": {"v_range": [["v6.0.0", ""]], "type": "integer"}, |
| 1758 |
"action": { |
| 1759 |
"v_range": [["v6.0.0", ""]], |
| 1760 |
"type": "string", |
| 1761 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1762 |
}, |
| 1763 |
"log": { |
| 1764 |
"v_range": [["v6.0.0", ""]], |
| 1765 |
"type": "string", |
| 1766 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1767 |
}, |
| 1768 |
"severity": { |
| 1769 |
"v_range": [["v6.0.0", ""]], |
| 1770 |
"type": "string", |
| 1771 |
"options": [ |
| 1772 |
{"value": "high"}, |
| 1773 |
{"value": "medium"}, |
| 1774 |
{"value": "low"}, |
| 1775 |
], |
| 1776 |
}, |
| 1777 |
}, |
| 1778 |
}, |
| 1779 |
"param_length": { |
| 1780 |
"v_range": [["v6.0.0", ""]], |
| 1781 |
"type": "dict", |
| 1782 |
"children": { |
| 1783 |
"status": { |
| 1784 |
"v_range": [["v6.0.0", ""]], |
| 1785 |
"type": "string", |
| 1786 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1787 |
}, |
| 1788 |
"length": {"v_range": [["v6.0.0", ""]], "type": "integer"}, |
| 1789 |
"action": { |
| 1790 |
"v_range": [["v6.0.0", ""]], |
| 1791 |
"type": "string", |
| 1792 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1793 |
}, |
| 1794 |
"log": { |
| 1795 |
"v_range": [["v6.0.0", ""]], |
| 1796 |
"type": "string", |
| 1797 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1798 |
}, |
| 1799 |
"severity": { |
| 1800 |
"v_range": [["v6.0.0", ""]], |
| 1801 |
"type": "string", |
| 1802 |
"options": [ |
| 1803 |
{"value": "high"}, |
| 1804 |
{"value": "medium"}, |
| 1805 |
{"value": "low"}, |
| 1806 |
], |
| 1807 |
}, |
| 1808 |
}, |
| 1809 |
}, |
| 1810 |
"line_length": { |
| 1811 |
"v_range": [["v6.0.0", ""]], |
| 1812 |
"type": "dict", |
| 1813 |
"children": { |
| 1814 |
"status": { |
| 1815 |
"v_range": [["v6.0.0", ""]], |
| 1816 |
"type": "string", |
| 1817 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1818 |
}, |
| 1819 |
"length": {"v_range": [["v6.0.0", ""]], "type": "integer"}, |
| 1820 |
"action": { |
| 1821 |
"v_range": [["v6.0.0", ""]], |
| 1822 |
"type": "string", |
| 1823 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1824 |
}, |
| 1825 |
"log": { |
| 1826 |
"v_range": [["v6.0.0", ""]], |
| 1827 |
"type": "string", |
| 1828 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1829 |
}, |
| 1830 |
"severity": { |
| 1831 |
"v_range": [["v6.0.0", ""]], |
| 1832 |
"type": "string", |
| 1833 |
"options": [ |
| 1834 |
{"value": "high"}, |
| 1835 |
{"value": "medium"}, |
| 1836 |
{"value": "low"}, |
| 1837 |
], |
| 1838 |
}, |
| 1839 |
}, |
| 1840 |
}, |
| 1841 |
"url_param_length": { |
| 1842 |
"v_range": [["v6.0.0", ""]], |
| 1843 |
"type": "dict", |
| 1844 |
"children": { |
| 1845 |
"status": { |
| 1846 |
"v_range": [["v6.0.0", ""]], |
| 1847 |
"type": "string", |
| 1848 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1849 |
}, |
| 1850 |
"length": {"v_range": [["v6.0.0", ""]], "type": "integer"}, |
| 1851 |
"action": { |
| 1852 |
"v_range": [["v6.0.0", ""]], |
| 1853 |
"type": "string", |
| 1854 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1855 |
}, |
| 1856 |
"log": { |
| 1857 |
"v_range": [["v6.0.0", ""]], |
| 1858 |
"type": "string", |
| 1859 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1860 |
}, |
| 1861 |
"severity": { |
| 1862 |
"v_range": [["v6.0.0", ""]], |
| 1863 |
"type": "string", |
| 1864 |
"options": [ |
| 1865 |
{"value": "high"}, |
| 1866 |
{"value": "medium"}, |
| 1867 |
{"value": "low"}, |
| 1868 |
], |
| 1869 |
}, |
| 1870 |
}, |
| 1871 |
}, |
| 1872 |
"version": { |
| 1873 |
"v_range": [["v6.0.0", ""]], |
| 1874 |
"type": "dict", |
| 1875 |
"children": { |
| 1876 |
"status": { |
| 1877 |
"v_range": [["v6.0.0", ""]], |
| 1878 |
"type": "string", |
| 1879 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1880 |
}, |
| 1881 |
"action": { |
| 1882 |
"v_range": [["v6.0.0", ""]], |
| 1883 |
"type": "string", |
| 1884 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1885 |
}, |
| 1886 |
"log": { |
| 1887 |
"v_range": [["v6.0.0", ""]], |
| 1888 |
"type": "string", |
| 1889 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1890 |
}, |
| 1891 |
"severity": { |
| 1892 |
"v_range": [["v6.0.0", ""]], |
| 1893 |
"type": "string", |
| 1894 |
"options": [ |
| 1895 |
{"value": "high"}, |
| 1896 |
{"value": "medium"}, |
| 1897 |
{"value": "low"}, |
| 1898 |
], |
| 1899 |
}, |
| 1900 |
}, |
| 1901 |
}, |
| 1902 |
"method": { |
| 1903 |
"v_range": [["v6.0.0", ""]], |
| 1904 |
"type": "dict", |
| 1905 |
"children": { |
| 1906 |
"status": { |
| 1907 |
"v_range": [["v6.0.0", ""]], |
| 1908 |
"type": "string", |
| 1909 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1910 |
}, |
| 1911 |
"action": { |
| 1912 |
"v_range": [["v6.0.0", ""]], |
| 1913 |
"type": "string", |
| 1914 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1915 |
}, |
| 1916 |
"log": { |
| 1917 |
"v_range": [["v6.0.0", ""]], |
| 1918 |
"type": "string", |
| 1919 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1920 |
}, |
| 1921 |
"severity": { |
| 1922 |
"v_range": [["v6.0.0", ""]], |
| 1923 |
"type": "string", |
| 1924 |
"options": [ |
| 1925 |
{"value": "high"}, |
| 1926 |
{"value": "medium"}, |
| 1927 |
{"value": "low"}, |
| 1928 |
], |
| 1929 |
}, |
| 1930 |
}, |
| 1931 |
}, |
| 1932 |
"hostname": { |
| 1933 |
"v_range": [["v6.0.0", ""]], |
| 1934 |
"type": "dict", |
| 1935 |
"children": { |
| 1936 |
"status": { |
| 1937 |
"v_range": [["v6.0.0", ""]], |
| 1938 |
"type": "string", |
| 1939 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1940 |
}, |
| 1941 |
"action": { |
| 1942 |
"v_range": [["v6.0.0", ""]], |
| 1943 |
"type": "string", |
| 1944 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1945 |
}, |
| 1946 |
"log": { |
| 1947 |
"v_range": [["v6.0.0", ""]], |
| 1948 |
"type": "string", |
| 1949 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1950 |
}, |
| 1951 |
"severity": { |
| 1952 |
"v_range": [["v6.0.0", ""]], |
| 1953 |
"type": "string", |
| 1954 |
"options": [ |
| 1955 |
{"value": "high"}, |
| 1956 |
{"value": "medium"}, |
| 1957 |
{"value": "low"}, |
| 1958 |
], |
| 1959 |
}, |
| 1960 |
}, |
| 1961 |
}, |
| 1962 |
"malformed": { |
| 1963 |
"v_range": [["v6.0.0", ""]], |
| 1964 |
"type": "dict", |
| 1965 |
"children": { |
| 1966 |
"status": { |
| 1967 |
"v_range": [["v6.0.0", ""]], |
| 1968 |
"type": "string", |
| 1969 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1970 |
}, |
| 1971 |
"action": { |
| 1972 |
"v_range": [["v6.0.0", ""]], |
| 1973 |
"type": "string", |
| 1974 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 1975 |
}, |
| 1976 |
"log": { |
| 1977 |
"v_range": [["v6.0.0", ""]], |
| 1978 |
"type": "string", |
| 1979 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 1980 |
}, |
| 1981 |
"severity": { |
| 1982 |
"v_range": [["v6.0.0", ""]], |
| 1983 |
"type": "string", |
| 1984 |
"options": [ |
| 1985 |
{"value": "high"}, |
| 1986 |
{"value": "medium"}, |
| 1987 |
{"value": "low"}, |
| 1988 |
], |
| 1989 |
}, |
| 1990 |
}, |
| 1991 |
}, |
| 1992 |
"max_cookie": { |
| 1993 |
"v_range": [["v6.0.0", ""]], |
| 1994 |
"type": "dict", |
| 1995 |
"children": { |
| 1996 |
"status": { |
| 1997 |
"v_range": [["v6.0.0", ""]], |
| 1998 |
"type": "string", |
| 1999 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2000 |
}, |
| 2001 |
"max_cookie": {"v_range": [["v6.0.0", ""]], "type": "integer"}, |
| 2002 |
"action": { |
| 2003 |
"v_range": [["v6.0.0", ""]], |
| 2004 |
"type": "string", |
| 2005 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 2006 |
}, |
| 2007 |
"log": { |
| 2008 |
"v_range": [["v6.0.0", ""]], |
| 2009 |
"type": "string", |
| 2010 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2011 |
}, |
| 2012 |
"severity": { |
| 2013 |
"v_range": [["v6.0.0", ""]], |
| 2014 |
"type": "string", |
| 2015 |
"options": [ |
| 2016 |
{"value": "high"}, |
| 2017 |
{"value": "medium"}, |
| 2018 |
{"value": "low"}, |
| 2019 |
], |
| 2020 |
}, |
| 2021 |
}, |
| 2022 |
}, |
| 2023 |
"max_header_line": { |
| 2024 |
"v_range": [["v6.0.0", ""]], |
| 2025 |
"type": "dict", |
| 2026 |
"children": { |
| 2027 |
"status": { |
| 2028 |
"v_range": [["v6.0.0", ""]], |
| 2029 |
"type": "string", |
| 2030 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2031 |
}, |
| 2032 |
"max_header_line": { |
| 2033 |
"v_range": [["v6.0.0", ""]], |
| 2034 |
"type": "integer", |
| 2035 |
}, |
| 2036 |
"action": { |
| 2037 |
"v_range": [["v6.0.0", ""]], |
| 2038 |
"type": "string", |
| 2039 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 2040 |
}, |
| 2041 |
"log": { |
| 2042 |
"v_range": [["v6.0.0", ""]], |
| 2043 |
"type": "string", |
| 2044 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2045 |
}, |
| 2046 |
"severity": { |
| 2047 |
"v_range": [["v6.0.0", ""]], |
| 2048 |
"type": "string", |
| 2049 |
"options": [ |
| 2050 |
{"value": "high"}, |
| 2051 |
{"value": "medium"}, |
| 2052 |
{"value": "low"}, |
| 2053 |
], |
| 2054 |
}, |
| 2055 |
}, |
| 2056 |
}, |
| 2057 |
"max_url_param": { |
| 2058 |
"v_range": [["v6.0.0", ""]], |
| 2059 |
"type": "dict", |
| 2060 |
"children": { |
| 2061 |
"status": { |
| 2062 |
"v_range": [["v6.0.0", ""]], |
| 2063 |
"type": "string", |
| 2064 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2065 |
}, |
| 2066 |
"max_url_param": { |
| 2067 |
"v_range": [["v6.0.0", ""]], |
| 2068 |
"type": "integer", |
| 2069 |
}, |
| 2070 |
"action": { |
| 2071 |
"v_range": [["v6.0.0", ""]], |
| 2072 |
"type": "string", |
| 2073 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 2074 |
}, |
| 2075 |
"log": { |
| 2076 |
"v_range": [["v6.0.0", ""]], |
| 2077 |
"type": "string", |
| 2078 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2079 |
}, |
| 2080 |
"severity": { |
| 2081 |
"v_range": [["v6.0.0", ""]], |
| 2082 |
"type": "string", |
| 2083 |
"options": [ |
| 2084 |
{"value": "high"}, |
| 2085 |
{"value": "medium"}, |
| 2086 |
{"value": "low"}, |
| 2087 |
], |
| 2088 |
}, |
| 2089 |
}, |
| 2090 |
}, |
| 2091 |
"max_range_segment": { |
| 2092 |
"v_range": [["v6.0.0", ""]], |
| 2093 |
"type": "dict", |
| 2094 |
"children": { |
| 2095 |
"status": { |
| 2096 |
"v_range": [["v6.0.0", ""]], |
| 2097 |
"type": "string", |
| 2098 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2099 |
}, |
| 2100 |
"max_range_segment": { |
| 2101 |
"v_range": [["v6.0.0", ""]], |
| 2102 |
"type": "integer", |
| 2103 |
}, |
| 2104 |
"action": { |
| 2105 |
"v_range": [["v6.0.0", ""]], |
| 2106 |
"type": "string", |
| 2107 |
"options": [{"value": "allow"}, {"value": "block"}], |
| 2108 |
}, |
| 2109 |
"log": { |
| 2110 |
"v_range": [["v6.0.0", ""]], |
| 2111 |
"type": "string", |
| 2112 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2113 |
}, |
| 2114 |
"severity": { |
| 2115 |
"v_range": [["v6.0.0", ""]], |
| 2116 |
"type": "string", |
| 2117 |
"options": [ |
| 2118 |
{"value": "high"}, |
| 2119 |
{"value": "medium"}, |
| 2120 |
{"value": "low"}, |
| 2121 |
], |
| 2122 |
}, |
| 2123 |
}, |
| 2124 |
}, |
| 2125 |
"exception": { |
| 2126 |
"type": "list", |
| 2127 |
"elements": "dict", |
| 2128 |
"children": { |
| 2129 |
"id": { |
| 2130 |
"v_range": [["v6.0.0", ""]], |
| 2131 |
"type": "integer", |
| 2132 |
"required": True, |
| 2133 |
}, |
| 2134 |
"pattern": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 2135 |
"regex": { |
| 2136 |
"v_range": [["v6.0.0", ""]], |
| 2137 |
"type": "string", |
| 2138 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2139 |
}, |
| 2140 |
"address": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 2141 |
"header_length": { |
| 2142 |
"v_range": [["v6.0.0", ""]], |
| 2143 |
"type": "string", |
| 2144 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2145 |
}, |
| 2146 |
"content_length": { |
| 2147 |
"v_range": [["v6.0.0", ""]], |
| 2148 |
"type": "string", |
| 2149 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2150 |
}, |
| 2151 |
"param_length": { |
| 2152 |
"v_range": [["v6.0.0", ""]], |
| 2153 |
"type": "string", |
| 2154 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2155 |
}, |
| 2156 |
"line_length": { |
| 2157 |
"v_range": [["v6.0.0", ""]], |
| 2158 |
"type": "string", |
| 2159 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2160 |
}, |
| 2161 |
"url_param_length": { |
| 2162 |
"v_range": [["v6.0.0", ""]], |
| 2163 |
"type": "string", |
| 2164 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2165 |
}, |
| 2166 |
"version": { |
| 2167 |
"v_range": [["v6.0.0", ""]], |
| 2168 |
"type": "string", |
| 2169 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2170 |
}, |
| 2171 |
"method": { |
| 2172 |
"v_range": [["v6.0.0", ""]], |
| 2173 |
"type": "string", |
| 2174 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2175 |
}, |
| 2176 |
"hostname": { |
| 2177 |
"v_range": [["v6.0.0", ""]], |
| 2178 |
"type": "string", |
| 2179 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2180 |
}, |
| 2181 |
"malformed": { |
| 2182 |
"v_range": [["v6.0.0", ""]], |
| 2183 |
"type": "string", |
| 2184 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2185 |
}, |
| 2186 |
"max_cookie": { |
| 2187 |
"v_range": [["v6.0.0", ""]], |
| 2188 |
"type": "string", |
| 2189 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2190 |
}, |
| 2191 |
"max_header_line": { |
| 2192 |
"v_range": [["v6.0.0", ""]], |
| 2193 |
"type": "string", |
| 2194 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2195 |
}, |
| 2196 |
"max_url_param": { |
| 2197 |
"v_range": [["v6.0.0", ""]], |
| 2198 |
"type": "string", |
| 2199 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2200 |
}, |
| 2201 |
"max_range_segment": { |
| 2202 |
"v_range": [["v6.0.0", ""]], |
| 2203 |
"type": "string", |
| 2204 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2205 |
}, |
| 2206 |
}, |
| 2207 |
"v_range": [["v6.0.0", ""]], |
| 2208 |
}, |
| 2209 |
}, |
| 2210 |
}, |
| 2211 |
"method": { |
| 2212 |
"v_range": [["v6.0.0", ""]], |
| 2213 |
"type": "dict", |
| 2214 |
"children": { |
| 2215 |
"status": { |
| 2216 |
"v_range": [["v6.0.0", ""]], |
| 2217 |
"type": "string", |
| 2218 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2219 |
}, |
| 2220 |
"log": { |
| 2221 |
"v_range": [["v6.0.0", ""]], |
| 2222 |
"type": "string", |
| 2223 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2224 |
}, |
| 2225 |
"severity": { |
| 2226 |
"v_range": [["v6.0.0", ""]], |
| 2227 |
"type": "string", |
| 2228 |
"options": [ |
| 2229 |
{"value": "high"}, |
| 2230 |
{"value": "medium"}, |
| 2231 |
{"value": "low"}, |
| 2232 |
], |
| 2233 |
}, |
| 2234 |
"default_allowed_methods": { |
| 2235 |
"v_range": [["v6.0.0", ""]], |
| 2236 |
"type": "list", |
| 2237 |
"options": [ |
| 2238 |
{"value": "get"}, |
| 2239 |
{"value": "post"}, |
| 2240 |
{"value": "put"}, |
| 2241 |
{"value": "head"}, |
| 2242 |
{"value": "connect"}, |
| 2243 |
{"value": "trace"}, |
| 2244 |
{"value": "options"}, |
| 2245 |
{"value": "delete"}, |
| 2246 |
{"value": "others"}, |
| 2247 |
], |
| 2248 |
"multiple_values": True, |
| 2249 |
"elements": "str", |
| 2250 |
}, |
| 2251 |
"method_policy": { |
| 2252 |
"type": "list", |
| 2253 |
"elements": "dict", |
| 2254 |
"children": { |
| 2255 |
"id": { |
| 2256 |
"v_range": [["v6.0.0", ""]], |
| 2257 |
"type": "integer", |
| 2258 |
"required": True, |
| 2259 |
}, |
| 2260 |
"pattern": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 2261 |
"regex": { |
| 2262 |
"v_range": [["v6.0.0", ""]], |
| 2263 |
"type": "string", |
| 2264 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2265 |
}, |
| 2266 |
"address": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 2267 |
"allowed_methods": { |
| 2268 |
"v_range": [["v6.0.0", ""]], |
| 2269 |
"type": "list", |
| 2270 |
"options": [ |
| 2271 |
{"value": "get"}, |
| 2272 |
{"value": "post"}, |
| 2273 |
{"value": "put"}, |
| 2274 |
{"value": "head"}, |
| 2275 |
{"value": "connect"}, |
| 2276 |
{"value": "trace"}, |
| 2277 |
{"value": "options"}, |
| 2278 |
{"value": "delete"}, |
| 2279 |
{"value": "others"}, |
| 2280 |
], |
| 2281 |
"multiple_values": True, |
| 2282 |
"elements": "str", |
| 2283 |
}, |
| 2284 |
}, |
| 2285 |
"v_range": [["v6.0.0", ""]], |
| 2286 |
}, |
| 2287 |
}, |
| 2288 |
}, |
| 2289 |
"address_list": { |
| 2290 |
"v_range": [["v6.0.0", ""]], |
| 2291 |
"type": "dict", |
| 2292 |
"children": { |
| 2293 |
"status": { |
| 2294 |
"v_range": [["v6.0.0", ""]], |
| 2295 |
"type": "string", |
| 2296 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2297 |
}, |
| 2298 |
"blocked_log": { |
| 2299 |
"v_range": [["v6.0.0", ""]], |
| 2300 |
"type": "string", |
| 2301 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2302 |
}, |
| 2303 |
"severity": { |
| 2304 |
"v_range": [["v6.0.0", ""]], |
| 2305 |
"type": "string", |
| 2306 |
"options": [ |
| 2307 |
{"value": "high"}, |
| 2308 |
{"value": "medium"}, |
| 2309 |
{"value": "low"}, |
| 2310 |
], |
| 2311 |
}, |
| 2312 |
"trusted_address": { |
| 2313 |
"type": "list", |
| 2314 |
"elements": "dict", |
| 2315 |
"children": { |
| 2316 |
"name": { |
| 2317 |
"v_range": [["v6.0.0", ""]], |
| 2318 |
"type": "string", |
| 2319 |
"required": True, |
| 2320 |
} |
| 2321 |
}, |
| 2322 |
"v_range": [["v6.0.0", ""]], |
| 2323 |
}, |
| 2324 |
"blocked_address": { |
| 2325 |
"type": "list", |
| 2326 |
"elements": "dict", |
| 2327 |
"children": { |
| 2328 |
"name": { |
| 2329 |
"v_range": [["v6.0.0", ""]], |
| 2330 |
"type": "string", |
| 2331 |
"required": True, |
| 2332 |
} |
| 2333 |
}, |
| 2334 |
"v_range": [["v6.0.0", ""]], |
| 2335 |
}, |
| 2336 |
}, |
| 2337 |
}, |
| 2338 |
"url_access": { |
| 2339 |
"type": "list", |
| 2340 |
"elements": "dict", |
| 2341 |
"children": { |
| 2342 |
"id": { |
| 2343 |
"v_range": [["v6.0.0", ""]], |
| 2344 |
"type": "integer", |
| 2345 |
"required": True, |
| 2346 |
}, |
| 2347 |
"address": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 2348 |
"action": { |
| 2349 |
"v_range": [["v6.0.0", ""]], |
| 2350 |
"type": "string", |
| 2351 |
"options": [ |
| 2352 |
{"value": "bypass"}, |
| 2353 |
{"value": "permit"}, |
| 2354 |
{"value": "block"}, |
| 2355 |
], |
| 2356 |
}, |
| 2357 |
"log": { |
| 2358 |
"v_range": [["v6.0.0", ""]], |
| 2359 |
"type": "string", |
| 2360 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2361 |
}, |
| 2362 |
"severity": { |
| 2363 |
"v_range": [["v6.0.0", ""]], |
| 2364 |
"type": "string", |
| 2365 |
"options": [ |
| 2366 |
{"value": "high"}, |
| 2367 |
{"value": "medium"}, |
| 2368 |
{"value": "low"}, |
| 2369 |
], |
| 2370 |
}, |
| 2371 |
"access_pattern": { |
| 2372 |
"type": "list", |
| 2373 |
"elements": "dict", |
| 2374 |
"children": { |
| 2375 |
"id": { |
| 2376 |
"v_range": [["v6.0.0", ""]], |
| 2377 |
"type": "integer", |
| 2378 |
"required": True, |
| 2379 |
}, |
| 2380 |
"srcaddr": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 2381 |
"pattern": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 2382 |
"regex": { |
| 2383 |
"v_range": [["v6.0.0", ""]], |
| 2384 |
"type": "string", |
| 2385 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2386 |
}, |
| 2387 |
"negate": { |
| 2388 |
"v_range": [["v6.0.0", ""]], |
| 2389 |
"type": "string", |
| 2390 |
"options": [{"value": "enable"}, {"value": "disable"}], |
| 2391 |
}, |
| 2392 |
}, |
| 2393 |
"v_range": [["v6.0.0", ""]], |
| 2394 |
}, |
| 2395 |
}, |
| 2396 |
"v_range": [["v6.0.0", ""]], |
| 2397 |
}, |
| 2398 |
"comment": {"v_range": [["v6.0.0", ""]], "type": "string"}, |
| 2399 |
}, |
| 2400 |
"v_range": [["v6.0.0", ""]], |
| 2401 |
} |
| 2402 |
|
| 2403 |
|
| 2404 |
def main(): |
| 2405 |
module_spec = schema_to_module_spec(versioned_schema) |
| 2406 |
mkeyname = "name" |
| 2407 |
fields = { |
| 2408 |
"access_token": {"required": False, "type": "str", "no_log": True}, |
| 2409 |
"enable_log": {"required": False, "type": "bool", "default": False}, |
| 2410 |
"vdom": {"required": False, "type": "str", "default": "root"}, |
| 2411 |
"member_path": {"required": False, "type": "str"}, |
| 2412 |
"member_state": { |
| 2413 |
"type": "str", |
| 2414 |
"required": False, |
| 2415 |
"choices": ["present", "absent"], |
| 2416 |
}, |
| 2417 |
"state": {"required": True, "type": "str", "choices": ["present", "absent"]}, |
| 2418 |
"waf_profile": { |
| 2419 |
"required": False, |
| 2420 |
"type": "dict", |
| 2421 |
"default": None, |
| 2422 |
"options": {}, |
| 2423 |
}, |
| 2424 |
} |
| 2425 |
for attribute_name in module_spec["options"]: |
| 2426 |
fields["waf_profile"]["options"][attribute_name] = module_spec["options"][ |
| 2427 |
attribute_name |
| 2428 |
] |
| 2429 |
if mkeyname and mkeyname == attribute_name: |
| 2430 |
fields["waf_profile"]["options"][attribute_name]["required"] = True |
| 2431 |
|
| 2432 |
module = AnsibleModule(argument_spec=fields, supports_check_mode=True) |
| 2433 |
check_legacy_fortiosapi(module) |
| 2434 |
|
| 2435 |
is_error = False |
| 2436 |
has_changed = False |
| 2437 |
result = None |
| 2438 |
diff = None |
| 2439 |
|
| 2440 |
versions_check_result = None |
| 2441 |
if module._socket_path: |
| 2442 |
connection = Connection(module._socket_path) |
| 2443 |
if "access_token" in module.params: |
| 2444 |
connection.set_custom_option("access_token", module.params["access_token"]) |
| 2445 |
|
| 2446 |
if "enable_log" in module.params: |
| 2447 |
connection.set_custom_option("enable_log", module.params["enable_log"]) |
| 2448 |
else: |
| 2449 |
connection.set_custom_option("enable_log", False) |
| 2450 |
fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False) |
| 2451 |
versions_check_result = check_schema_versioning( |
| 2452 |
fos, versioned_schema, "waf_profile" |
| 2453 |
) |
| 2454 |
|
| 2455 |
is_error, has_changed, result, diff = fortios_waf( |
| 2456 |
module.params, fos, module.check_mode |
| 2457 |
) |
| 2458 |
|
| 2459 |
else: |
| 2460 |
module.fail_json(**FAIL_SOCKET_MSG) |
| 2461 |
|
| 2462 |
if versions_check_result and versions_check_result["matched"] is False: |
| 2463 |
module.warn( |
| 2464 |
"Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv" |
| 2465 |
) |
| 2466 |
|
| 2467 |
if not is_error: |
| 2468 |
if versions_check_result and versions_check_result["matched"] is False: |
| 2469 |
module.exit_json( |
| 2470 |
changed=has_changed, |
| 2471 |
version_check_warning=versions_check_result, |
| 2472 |
meta=result, |
| 2473 |
diff=diff, |
| 2474 |
) |
| 2475 |
else: |
| 2476 |
module.exit_json(changed=has_changed, meta=result, diff=diff) |
| 2477 |
else: |
| 2478 |
if versions_check_result and versions_check_result["matched"] is False: |
| 2479 |
module.fail_json( |
| 2480 |
msg="Error in repo", |
| 2481 |
version_check_warning=versions_check_result, |
| 2482 |
meta=result, |
| 2483 |
) |
| 2484 |
else: |
| 2485 |
module.fail_json(msg="Error in repo", meta=result) |
| 2486 |
|
| 2487 |
|
| 2488 |
if __name__ == "__main__": |
| 2489 |
main() |