Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_sniffer.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3
4 # Copyright: (c) 2022 Fortinet
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
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_firewall_sniffer
23 short_description: Configure sniffer 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 firewall feature and sniffer 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 - We highly recommend using your own value as the id instead of 0, while '0' is a special placeholder that allows the backend to assign the latest
39 available number for the object, it does have limitations. Please find more details in Q&A.
40 - Legacy fortiosapi has been deprecated, httpapi is the preferred way to run playbooks
41
42 - The module supports check_mode.
43
44 requirements:
45 - ansible>=2.16
46 options:
47 access_token:
48 description:
49 - Token-based authentication.
50 Generated from GUI of Fortigate.
51 type: str
52 required: false
53 enable_log:
54 description:
55 - Enable/Disable logging for task.
56 type: bool
57 required: false
58 default: false
59 vdom:
60 description:
61 - Virtual domain, among those defined previously. A vdom is a
62 virtual instance of the FortiGate that can be configured and
63 used as a different unit.
64 type: str
65 default: root
66 member_path:
67 type: str
68 description:
69 - Member attribute path to operate on.
70 - Delimited by a slash character if there are more than one attribute.
71 - Parameter marked with member_path is legitimate for doing member operation.
72 member_state:
73 type: str
74 description:
75 - Add or delete a member under specified attribute path.
76 - When member_state is specified, the state option is ignored.
77 choices:
78 - 'present'
79 - 'absent'
80
81 state:
82 description:
83 - Indicates whether to create or remove the object.
84 type: str
85 required: true
86 choices:
87 - 'present'
88 - 'absent'
89 firewall_sniffer:
90 description:
91 - Configure sniffer.
92 default: null
93 type: dict
94 suboptions:
95 anomaly:
96 description:
97 - Configuration method to edit Denial of Service (DoS) anomaly settings.
98 type: list
99 elements: dict
100 suboptions:
101 action:
102 description:
103 - Action taken when the threshold is reached.
104 type: str
105 choices:
106 - 'pass'
107 - 'block'
108 - 'proxy'
109 log:
110 description:
111 - Enable/disable anomaly logging.
112 type: str
113 choices:
114 - 'enable'
115 - 'disable'
116 name:
117 description:
118 - Anomaly name.
119 required: true
120 type: str
121 quarantine:
122 description:
123 - Quarantine method.
124 type: str
125 choices:
126 - 'none'
127 - 'attacker'
128 quarantine_expiry:
129 description:
130 - Duration of quarantine. (Format ###d##h##m, minimum 1m, maximum 364d23h59m). Requires quarantine set to attacker.
131 type: str
132 quarantine_log:
133 description:
134 - Enable/disable quarantine logging.
135 type: str
136 choices:
137 - 'disable'
138 - 'enable'
139 status:
140 description:
141 - Enable/disable this anomaly.
142 type: str
143 choices:
144 - 'disable'
145 - 'enable'
146 synproxy_tcp_mss:
147 description:
148 - Determine TCP maximum segment size (MSS) value for packets replied by syn proxy module.
149 type: str
150 choices:
151 - '0'
152 - '256'
153 - '512'
154 - '1024'
155 - '1300'
156 - '1360'
157 - '1460'
158 - '1500'
159 synproxy_tcp_sack:
160 description:
161 - enable/disable TCP selective acknowledage (SACK) for packets replied by syn proxy module.
162 type: str
163 choices:
164 - 'enable'
165 - 'disable'
166 synproxy_tcp_timestamp:
167 description:
168 - enable/disable TCP timestamp option for packets replied by syn proxy module.
169 type: str
170 choices:
171 - 'enable'
172 - 'disable'
173 synproxy_tcp_window:
174 description:
175 - Determine TCP Window size for packets replied by syn proxy module.
176 type: str
177 choices:
178 - '4096'
179 - '8192'
180 - '16384'
181 - '32768'
182 synproxy_tcp_windowscale:
183 description:
184 - Determine TCP window scale option value for packets replied by syn proxy module.
185 type: str
186 choices:
187 - '0'
188 - '1'
189 - '2'
190 - '3'
191 - '4'
192 - '5'
193 - '6'
194 - '7'
195 - '8'
196 - '9'
197 - '10'
198 - '11'
199 - '12'
200 - '13'
201 - '14'
202 synproxy_tos:
203 description:
204 - Determine TCP differentiated services code point value (type of service).
205 type: str
206 choices:
207 - '0'
208 - '10'
209 - '12'
210 - '14'
211 - '18'
212 - '20'
213 - '22'
214 - '26'
215 - '28'
216 - '30'
217 - '34'
218 - '36'
219 - '38'
220 - '40'
221 - '46'
222 - '255'
223 synproxy_ttl:
224 description:
225 - Determine Time to live (TTL) value for packets replied by syn proxy module.
226 type: str
227 choices:
228 - '32'
229 - '64'
230 - '128'
231 - '255'
232 threshold:
233 description:
234 - Anomaly threshold. Number of detected instances (packets per second or concurrent session number) that triggers the anomaly
235 action.
236 type: int
237 threshold_default:
238 description:
239 - Number of detected instances per minute which triggers action (1 - 2147483647). Note that each anomaly has a different threshold
240 value assigned to it.
241 type: int
242 application_list:
243 description:
244 - Name of an existing application list. Source application.list.name.
245 type: str
246 application_list_status:
247 description:
248 - Enable/disable application control profile.
249 type: str
250 choices:
251 - 'enable'
252 - 'disable'
253 av_profile:
254 description:
255 - Name of an existing antivirus profile. Source antivirus.profile.name.
256 type: str
257 av_profile_status:
258 description:
259 - Enable/disable antivirus profile.
260 type: str
261 choices:
262 - 'enable'
263 - 'disable'
264 casb_profile:
265 description:
266 - Name of an existing CASB profile. Source casb.profile.name.
267 type: str
268 casb_profile_status:
269 description:
270 - Enable/disable CASB profile.
271 type: str
272 choices:
273 - 'enable'
274 - 'disable'
275 dlp_profile:
276 description:
277 - Name of an existing DLP profile. Source dlp.profile.name.
278 type: str
279 dlp_profile_status:
280 description:
281 - Enable/disable DLP profile.
282 type: str
283 choices:
284 - 'enable'
285 - 'disable'
286 dlp_sensor:
287 description:
288 - Name of an existing DLP sensor. Source dlp.sensor.name.
289 type: str
290 dlp_sensor_status:
291 description:
292 - Enable/disable DLP sensor.
293 type: str
294 choices:
295 - 'enable'
296 - 'disable'
297 dsri:
298 description:
299 - Enable/disable DSRI.
300 type: str
301 choices:
302 - 'enable'
303 - 'disable'
304 emailfilter_profile:
305 description:
306 - Name of an existing email filter profile. Source emailfilter.profile.name.
307 type: str
308 emailfilter_profile_status:
309 description:
310 - Enable/disable emailfilter.
311 type: str
312 choices:
313 - 'enable'
314 - 'disable'
315 file_filter_profile:
316 description:
317 - Name of an existing file-filter profile. Source file-filter.profile.name.
318 type: str
319 file_filter_profile_status:
320 description:
321 - Enable/disable file filter.
322 type: str
323 choices:
324 - 'enable'
325 - 'disable'
326 host:
327 description:
328 - 'Hosts to filter for in sniffer traffic (Format examples: 1.1.1.1, 2.2.2.0/24, 3.3.3.3/255.255.255.0, 4.4.4.0-4.4.4.240).'
329 type: str
330 id:
331 description:
332 - Sniffer ID (0 - 9999). see <a href='#notes'>Notes</a>.
333 required: true
334 type: int
335 interface:
336 description:
337 - Interface name that traffic sniffing will take place on. Source system.interface.name.
338 type: str
339 ip_threatfeed:
340 description:
341 - Name of an existing IP threat feed.
342 type: list
343 elements: dict
344 suboptions:
345 name:
346 description:
347 - Threat feed name. Source system.external-resource.name.
348 required: true
349 type: str
350 ip_threatfeed_status:
351 description:
352 - Enable/disable IP threat feed.
353 type: str
354 choices:
355 - 'enable'
356 - 'disable'
357 ips_dos_status:
358 description:
359 - Enable/disable IPS DoS anomaly detection.
360 type: str
361 choices:
362 - 'enable'
363 - 'disable'
364 ips_sensor:
365 description:
366 - Name of an existing IPS sensor. Source ips.sensor.name.
367 type: str
368 ips_sensor_status:
369 description:
370 - Enable/disable IPS sensor.
371 type: str
372 choices:
373 - 'enable'
374 - 'disable'
375 ipv6:
376 description:
377 - Enable/disable sniffing IPv6 packets.
378 type: str
379 choices:
380 - 'enable'
381 - 'disable'
382 logtraffic:
383 description:
384 - Either log all sessions, only sessions that have a security profile applied, or disable all logging for this policy.
385 type: str
386 choices:
387 - 'all'
388 - 'utm'
389 - 'disable'
390 max_packet_count:
391 description:
392 - Maximum packet count (1 - 1000000).
393 type: int
394 non_ip:
395 description:
396 - Enable/disable sniffing non-IP packets.
397 type: str
398 choices:
399 - 'enable'
400 - 'disable'
401 port:
402 description:
403 - 'Ports to sniff (Format examples: 10, :20, 30:40, 50-, 100-200).'
404 type: str
405 protocol:
406 description:
407 - Integer value for the protocol type as defined by IANA (0 - 255).
408 type: str
409 scan_botnet_connections:
410 description:
411 - Enable/disable scanning of connections to Botnet servers.
412 type: str
413 choices:
414 - 'disable'
415 - 'block'
416 - 'monitor'
417 spamfilter_profile:
418 description:
419 - Name of an existing spam filter profile. Source spamfilter.profile.name.
420 type: str
421 spamfilter_profile_status:
422 description:
423 - Enable/disable spam filter.
424 type: str
425 choices:
426 - 'enable'
427 - 'disable'
428 status:
429 description:
430 - Enable/disable the active status of the sniffer.
431 type: str
432 choices:
433 - 'enable'
434 - 'disable'
435 uuid:
436 description:
437 - Universally Unique Identifier (UUID; automatically assigned but can be manually reset).
438 type: str
439 vlan:
440 description:
441 - List of VLANs to sniff.
442 type: str
443 webfilter_profile:
444 description:
445 - Name of an existing web filter profile. Source webfilter.profile.name.
446 type: str
447 webfilter_profile_status:
448 description:
449 - Enable/disable web filter profile.
450 type: str
451 choices:
452 - 'enable'
453 - 'disable'
454 """
455
456 EXAMPLES = """
457 - name: Configure sniffer.
458 fortinet.fortios.fortios_firewall_sniffer:
459 vdom: "{{ vdom }}"
460 state: "present"
461 access_token: "<your_own_value>"
462 firewall_sniffer:
463 anomaly:
464 -
465 action: "pass"
466 log: "enable"
467 name: "default_name_6"
468 quarantine: "none"
469 quarantine_expiry: "<your_own_value>"
470 quarantine_log: "disable"
471 status: "disable"
472 synproxy_tcp_mss: "0"
473 synproxy_tcp_sack: "enable"
474 synproxy_tcp_timestamp: "enable"
475 synproxy_tcp_window: "4096"
476 synproxy_tcp_windowscale: "0"
477 synproxy_tos: "0"
478 synproxy_ttl: "32"
479 threshold: "0"
480 threshold_default: "0"
481 application_list: "<your_own_value> (source application.list.name)"
482 application_list_status: "enable"
483 av_profile: "<your_own_value> (source antivirus.profile.name)"
484 av_profile_status: "enable"
485 casb_profile: "<your_own_value> (source casb.profile.name)"
486 casb_profile_status: "enable"
487 dlp_profile: "<your_own_value> (source dlp.profile.name)"
488 dlp_profile_status: "enable"
489 dlp_sensor: "<your_own_value> (source dlp.sensor.name)"
490 dlp_sensor_status: "enable"
491 dsri: "enable"
492 emailfilter_profile: "<your_own_value> (source emailfilter.profile.name)"
493 emailfilter_profile_status: "enable"
494 file_filter_profile: "<your_own_value> (source file-filter.profile.name)"
495 file_filter_profile_status: "enable"
496 host: "myhostname"
497 id: "36"
498 interface: "<your_own_value> (source system.interface.name)"
499 ip_threatfeed:
500 -
501 name: "default_name_39 (source system.external-resource.name)"
502 ip_threatfeed_status: "enable"
503 ips_dos_status: "enable"
504 ips_sensor: "<your_own_value> (source ips.sensor.name)"
505 ips_sensor_status: "enable"
506 ipv6: "enable"
507 logtraffic: "all"
508 max_packet_count: "4000"
509 non_ip: "enable"
510 port: "<your_own_value>"
511 protocol: "<your_own_value>"
512 scan_botnet_connections: "disable"
513 spamfilter_profile: "<your_own_value> (source spamfilter.profile.name)"
514 spamfilter_profile_status: "enable"
515 status: "enable"
516 uuid: "<your_own_value>"
517 vlan: "<your_own_value>"
518 webfilter_profile: "<your_own_value> (source webfilter.profile.name)"
519 webfilter_profile_status: "enable"
520 """
521
522 RETURN = """
523 build:
524 description: Build number of the fortigate image
525 returned: always
526 type: str
527 sample: '1547'
528 http_method:
529 description: Last method used to provision the content into FortiGate
530 returned: always
531 type: str
532 sample: 'PUT'
533 http_status:
534 description: Last result given by FortiGate on last operation applied
535 returned: always
536 type: str
537 sample: "200"
538 mkey:
539 description: Master key (id) used in the last call to FortiGate
540 returned: success
541 type: str
542 sample: "id"
543 name:
544 description: Name of the table used to fulfill the request
545 returned: always
546 type: str
547 sample: "urlfilter"
548 path:
549 description: Path of the table used to fulfill the request
550 returned: always
551 type: str
552 sample: "webfilter"
553 revision:
554 description: Internal revision number
555 returned: always
556 type: str
557 sample: "17.0.2.10658"
558 serial:
559 description: Serial number of the unit
560 returned: always
561 type: str
562 sample: "FGVMEVYYQT3AB5352"
563 status:
564 description: Indication of the operation's result
565 returned: always
566 type: str
567 sample: "success"
568 vdom:
569 description: Virtual domain used
570 returned: always
571 type: str
572 sample: "root"
573 version:
574 description: Version of the FortiGate
575 returned: always
576 type: str
577 sample: "v5.6.3"
578 """
579 from ansible.module_utils.basic import AnsibleModule
580 from ansible.module_utils.connection import Connection
581 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
582 FortiOSHandler,
583 )
584 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
585 check_legacy_fortiosapi,
586 )
587 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
588 schema_to_module_spec,
589 )
590 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
591 check_schema_versioning,
592 )
593 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
594 FAIL_SOCKET_MSG,
595 )
596 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
597 remove_invalid_fields,
598 )
599 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
600 is_same_comparison,
601 )
602 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
603 serialize,
604 )
605 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
606 find_current_values,
607 )
608 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
609 unify_data_format,
610 )
611
612
613 def filter_firewall_sniffer_data(json):
614 option_list = [
615 "anomaly",
616 "application_list",
617 "application_list_status",
618 "av_profile",
619 "av_profile_status",
620 "casb_profile",
621 "casb_profile_status",
622 "dlp_profile",
623 "dlp_profile_status",
624 "dlp_sensor",
625 "dlp_sensor_status",
626 "dsri",
627 "emailfilter_profile",
628 "emailfilter_profile_status",
629 "file_filter_profile",
630 "file_filter_profile_status",
631 "host",
632 "id",
633 "interface",
634 "ip_threatfeed",
635 "ip_threatfeed_status",
636 "ips_dos_status",
637 "ips_sensor",
638 "ips_sensor_status",
639 "ipv6",
640 "logtraffic",
641 "max_packet_count",
642 "non_ip",
643 "port",
644 "protocol",
645 "scan_botnet_connections",
646 "spamfilter_profile",
647 "spamfilter_profile_status",
648 "status",
649 "uuid",
650 "vlan",
651 "webfilter_profile",
652 "webfilter_profile_status",
653 ]
654
655 json = remove_invalid_fields(json)
656 dictionary = {}
657
658 for attribute in option_list:
659 if attribute in json and json[attribute] is not None:
660 dictionary[attribute] = json[attribute]
661
662 return dictionary
663
664
665 def underscore_to_hyphen(data):
666 new_data = None
667 if isinstance(data, list):
668 new_data = []
669 for i, elem in enumerate(data):
670 new_data.append(underscore_to_hyphen(elem))
671 elif isinstance(data, dict):
672 new_data = {}
673 for k, v in data.items():
674 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
675 else:
676 return data
677 return new_data
678
679
680 def valid_attr_to_invalid_attr(data):
681 speciallist = {"threshold(default)": "threshold_default"}
682
683 for k, v in speciallist.items():
684 if v == data:
685 return k
686
687 return data
688
689
690 def valid_attr_to_invalid_attrs(data):
691 if isinstance(data, list):
692 new_data = []
693 for elem in data:
694 elem = valid_attr_to_invalid_attrs(elem)
695 new_data.append(elem)
696 data = new_data
697 elif isinstance(data, dict):
698 new_data = {}
699 for k, v in data.items():
700 new_data[valid_attr_to_invalid_attr(k)] = valid_attr_to_invalid_attrs(v)
701 data = new_data
702
703 return valid_attr_to_invalid_attr(data)
704
705
706 def firewall_sniffer(data, fos, check_mode=False):
707
708 state = None
709 vdom = data["vdom"]
710 parameters = None
711 state = data.get("state", None)
712 firewall_sniffer_data = data["firewall_sniffer"]
713
714 filtered_data = filter_firewall_sniffer_data(firewall_sniffer_data)
715 converted_data = underscore_to_hyphen(valid_attr_to_invalid_attrs(filtered_data))
716
717 # check_mode starts from here
718 if check_mode:
719 diff = {
720 "before": "",
721 "after": filtered_data,
722 }
723 mkeyname = fos.get_mkeyname(None, None)
724 mkey = fos.get_mkey("firewall", "sniffer", filtered_data, vdom=vdom)
725 current_data = fos.get(
726 "firewall", "sniffer", vdom=vdom, mkey=mkey, parameters=parameters
727 )
728 is_existed = (
729 current_data
730 and current_data.get("http_status") == 200
731 and (
732 mkeyname
733 and isinstance(current_data.get("results"), list)
734 and len(current_data["results"]) > 0
735 or not mkeyname
736 and current_data["results"] # global object response
737 )
738 )
739
740 # 2. if it exists and the state is 'present' then compare current settings with desired
741 if state == "present" or state is True or state is None:
742 # for non global modules, mkeyname must exist and it's a new module when mkey is None
743 if mkeyname is not None and mkey is None:
744 return False, True, filtered_data, diff
745
746 # if mkey exists then compare each other
747 # record exits and they're matched or not
748 copied_filtered_data = filtered_data.copy()
749 copied_filtered_data.pop(mkeyname, None)
750 unified_filtered_data = unify_data_format(copied_filtered_data)
751
752 current_data_results = current_data.get("results", {})
753 current_config = (
754 current_data_results[0]
755 if mkeyname
756 and isinstance(current_data_results, list)
757 and len(current_data_results) > 0
758 else current_data_results
759 )
760 if is_existed:
761 unified_current_values = find_current_values(
762 unified_filtered_data,
763 unify_data_format(current_config),
764 )
765
766 is_same = is_same_comparison(
767 serialize(unified_current_values), serialize(unified_filtered_data)
768 )
769
770 return (
771 False,
772 not is_same,
773 filtered_data,
774 {"before": unified_current_values, "after": unified_filtered_data},
775 )
776
777 # record does not exist
778 return False, True, filtered_data, diff
779
780 if state == "absent":
781 if mkey is None:
782 return (
783 False,
784 False,
785 filtered_data,
786 {"before": current_data["results"][0], "after": ""},
787 )
788
789 if is_existed:
790 return (
791 False,
792 True,
793 filtered_data,
794 {"before": current_data["results"][0], "after": ""},
795 )
796 return False, False, filtered_data, {}
797
798 return True, False, {"reason: ": "Must provide state parameter"}, {}
799 # pass post processed data to member operations
800 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
801 data_copy = data.copy()
802 data_copy["firewall_sniffer"] = filtered_data
803 fos.do_member_operation(
804 "firewall",
805 "sniffer",
806 data_copy,
807 )
808
809 if state == "present" or state is True:
810 return fos.set(
811 "firewall", "sniffer", data=converted_data, vdom=vdom, parameters=parameters
812 )
813
814 elif state == "absent":
815 return fos.delete(
816 "firewall",
817 "sniffer",
818 mkey=converted_data["id"],
819 vdom=vdom,
820 parameters=parameters,
821 )
822 else:
823 fos._module.fail_json(msg="state must be present or absent!")
824
825
826 def is_successful_status(resp):
827 return (
828 "status" in resp
829 and resp["status"] == "success"
830 or "http_status" in resp
831 and resp["http_status"] == 200
832 or "http_method" in resp
833 and resp["http_method"] == "DELETE"
834 and resp["http_status"] == 404
835 )
836
837
838 def fortios_firewall(data, fos, check_mode):
839
840 if data["firewall_sniffer"]:
841 resp = firewall_sniffer(data, fos, check_mode)
842 else:
843 fos._module.fail_json(msg="missing task body: %s" % ("firewall_sniffer"))
844 if isinstance(resp, tuple) and len(resp) == 4:
845 return resp
846 return (
847 not is_successful_status(resp),
848 is_successful_status(resp)
849 and (resp["revision_changed"] if "revision_changed" in resp else True),
850 resp,
851 {},
852 )
853
854
855 versioned_schema = {
856 "type": "list",
857 "elements": "dict",
858 "children": {
859 "id": {"v_range": [["v6.0.0", ""]], "type": "integer", "required": True},
860 "uuid": {"v_range": [["v7.4.2", ""]], "type": "string"},
861 "status": {
862 "v_range": [["v6.0.0", ""]],
863 "type": "string",
864 "options": [{"value": "enable"}, {"value": "disable"}],
865 },
866 "logtraffic": {
867 "v_range": [["v6.0.0", ""]],
868 "type": "string",
869 "options": [{"value": "all"}, {"value": "utm"}, {"value": "disable"}],
870 },
871 "ipv6": {
872 "v_range": [["v6.0.0", "v7.0.12"], ["v7.2.1", ""]],
873 "type": "string",
874 "options": [{"value": "enable"}, {"value": "disable"}],
875 },
876 "non_ip": {
877 "v_range": [["v6.0.0", "v7.0.12"], ["v7.2.1", ""]],
878 "type": "string",
879 "options": [{"value": "enable"}, {"value": "disable"}],
880 },
881 "interface": {"v_range": [["v6.0.0", ""]], "type": "string"},
882 "host": {"v_range": [["v6.0.0", "v7.0.12"], ["v7.2.1", ""]], "type": "string"},
883 "port": {"v_range": [["v6.0.0", "v7.0.12"], ["v7.2.1", ""]], "type": "string"},
884 "protocol": {
885 "v_range": [["v6.0.0", "v7.0.12"], ["v7.2.1", ""]],
886 "type": "string",
887 },
888 "vlan": {"v_range": [["v6.0.0", "v7.0.12"], ["v7.2.1", ""]], "type": "string"},
889 "application_list_status": {
890 "v_range": [["v6.0.0", ""]],
891 "type": "string",
892 "options": [{"value": "enable"}, {"value": "disable"}],
893 },
894 "application_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
895 "ips_sensor_status": {
896 "v_range": [["v6.0.0", ""]],
897 "type": "string",
898 "options": [{"value": "enable"}, {"value": "disable"}],
899 },
900 "ips_sensor": {"v_range": [["v6.0.0", ""]], "type": "string"},
901 "dsri": {
902 "v_range": [["v6.0.0", ""]],
903 "type": "string",
904 "options": [{"value": "enable"}, {"value": "disable"}],
905 },
906 "av_profile_status": {
907 "v_range": [["v6.0.0", ""]],
908 "type": "string",
909 "options": [{"value": "enable"}, {"value": "disable"}],
910 },
911 "av_profile": {"v_range": [["v6.0.0", ""]], "type": "string"},
912 "webfilter_profile_status": {
913 "v_range": [["v6.0.0", ""]],
914 "type": "string",
915 "options": [{"value": "enable"}, {"value": "disable"}],
916 },
917 "webfilter_profile": {"v_range": [["v6.0.0", ""]], "type": "string"},
918 "emailfilter_profile_status": {
919 "v_range": [["v6.2.0", ""]],
920 "type": "string",
921 "options": [{"value": "enable"}, {"value": "disable"}],
922 },
923 "emailfilter_profile": {"v_range": [["v6.2.0", ""]], "type": "string"},
924 "dlp_profile_status": {
925 "v_range": [["v7.2.0", ""]],
926 "type": "string",
927 "options": [{"value": "enable"}, {"value": "disable"}],
928 },
929 "dlp_profile": {"v_range": [["v7.2.0", ""]], "type": "string"},
930 "ip_threatfeed_status": {
931 "v_range": [["v7.0.0", ""]],
932 "type": "string",
933 "options": [{"value": "enable"}, {"value": "disable"}],
934 },
935 "ip_threatfeed": {
936 "type": "list",
937 "elements": "dict",
938 "children": {
939 "name": {
940 "v_range": [["v7.0.0", ""]],
941 "type": "string",
942 "required": True,
943 }
944 },
945 "v_range": [["v7.0.0", ""]],
946 },
947 "file_filter_profile_status": {
948 "v_range": [["v7.0.0", ""]],
949 "type": "string",
950 "options": [{"value": "enable"}, {"value": "disable"}],
951 },
952 "file_filter_profile": {"v_range": [["v7.0.0", ""]], "type": "string"},
953 "ips_dos_status": {
954 "v_range": [["v6.0.0", ""]],
955 "type": "string",
956 "options": [{"value": "enable"}, {"value": "disable"}],
957 },
958 "anomaly": {
959 "type": "list",
960 "elements": "dict",
961 "children": {
962 "name": {
963 "v_range": [["v6.0.0", ""]],
964 "type": "string",
965 "required": True,
966 },
967 "status": {
968 "v_range": [["v6.0.0", ""]],
969 "type": "string",
970 "options": [{"value": "disable"}, {"value": "enable"}],
971 },
972 "log": {
973 "v_range": [["v6.0.0", ""]],
974 "type": "string",
975 "options": [{"value": "enable"}, {"value": "disable"}],
976 },
977 "action": {
978 "v_range": [["v6.0.0", ""]],
979 "type": "string",
980 "options": [
981 {"value": "pass"},
982 {"value": "block"},
983 {"value": "proxy"},
984 ],
985 },
986 "quarantine": {
987 "v_range": [["v6.0.0", ""]],
988 "type": "string",
989 "options": [{"value": "none"}, {"value": "attacker"}],
990 },
991 "quarantine_expiry": {"v_range": [["v6.0.0", ""]], "type": "string"},
992 "quarantine_log": {
993 "v_range": [["v6.0.0", ""]],
994 "type": "string",
995 "options": [{"value": "disable"}, {"value": "enable"}],
996 },
997 "threshold": {"v_range": [["v6.0.0", ""]], "type": "integer"},
998 "synproxy_ttl": {
999 "v_range": [["v7.4.2", "v7.4.2"]],
1000 "type": "string",
1001 "options": [
1002 {"value": "32"},
1003 {"value": "64"},
1004 {"value": "128"},
1005 {"value": "255"},
1006 ],
1007 },
1008 "synproxy_tos": {
1009 "v_range": [["v7.4.2", "v7.4.2"]],
1010 "type": "string",
1011 "options": [
1012 {"value": "0"},
1013 {"value": "10"},
1014 {"value": "12"},
1015 {"value": "14"},
1016 {"value": "18"},
1017 {"value": "20"},
1018 {"value": "22"},
1019 {"value": "26"},
1020 {"value": "28"},
1021 {"value": "30"},
1022 {"value": "34"},
1023 {"value": "36"},
1024 {"value": "38"},
1025 {"value": "40"},
1026 {"value": "46"},
1027 {"value": "255"},
1028 ],
1029 },
1030 "synproxy_tcp_mss": {
1031 "v_range": [["v7.4.2", "v7.4.2"]],
1032 "type": "string",
1033 "options": [
1034 {"value": "0"},
1035 {"value": "256"},
1036 {"value": "512"},
1037 {"value": "1024"},
1038 {"value": "1300"},
1039 {"value": "1360"},
1040 {"value": "1460"},
1041 {"value": "1500"},
1042 ],
1043 },
1044 "synproxy_tcp_sack": {
1045 "v_range": [["v7.4.2", "v7.4.2"]],
1046 "type": "string",
1047 "options": [{"value": "enable"}, {"value": "disable"}],
1048 },
1049 "synproxy_tcp_timestamp": {
1050 "v_range": [["v7.4.2", "v7.4.2"]],
1051 "type": "string",
1052 "options": [{"value": "enable"}, {"value": "disable"}],
1053 },
1054 "synproxy_tcp_window": {
1055 "v_range": [["v7.4.2", "v7.4.2"]],
1056 "type": "string",
1057 "options": [
1058 {"value": "4096"},
1059 {"value": "8192"},
1060 {"value": "16384"},
1061 {"value": "32768"},
1062 ],
1063 },
1064 "synproxy_tcp_windowscale": {
1065 "v_range": [["v7.4.2", "v7.4.2"]],
1066 "type": "string",
1067 "options": [
1068 {"value": "0"},
1069 {"value": "1"},
1070 {"value": "2"},
1071 {"value": "3"},
1072 {"value": "4"},
1073 {"value": "5"},
1074 {"value": "6"},
1075 {"value": "7"},
1076 {"value": "8"},
1077 {"value": "9"},
1078 {"value": "10"},
1079 {"value": "11"},
1080 {"value": "12"},
1081 {"value": "13"},
1082 {"value": "14"},
1083 ],
1084 },
1085 "threshold_default": {
1086 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1087 "type": "integer",
1088 },
1089 },
1090 "v_range": [["v6.0.0", ""]],
1091 },
1092 "casb_profile_status": {
1093 "v_range": [["v7.4.1", "v7.4.1"]],
1094 "type": "string",
1095 "options": [{"value": "enable"}, {"value": "disable"}],
1096 },
1097 "casb_profile": {"v_range": [["v7.4.1", "v7.4.1"]], "type": "string"},
1098 "dlp_sensor_status": {
1099 "v_range": [["v6.0.0", "v7.0.12"]],
1100 "type": "string",
1101 "options": [{"value": "enable"}, {"value": "disable"}],
1102 },
1103 "dlp_sensor": {"v_range": [["v6.0.0", "v7.0.12"]], "type": "string"},
1104 "max_packet_count": {"v_range": [["v6.0.0", "v7.0.12"]], "type": "integer"},
1105 "spamfilter_profile_status": {
1106 "v_range": [["v6.0.0", "v6.0.11"]],
1107 "type": "string",
1108 "options": [{"value": "enable"}, {"value": "disable"}],
1109 },
1110 "spamfilter_profile": {"v_range": [["v6.0.0", "v6.0.11"]], "type": "string"},
1111 "scan_botnet_connections": {
1112 "v_range": [["v6.0.0", "v6.0.11"]],
1113 "type": "string",
1114 "options": [{"value": "disable"}, {"value": "block"}, {"value": "monitor"}],
1115 },
1116 },
1117 "v_range": [["v6.0.0", ""]],
1118 }
1119
1120
1121 def main():
1122 module_spec = schema_to_module_spec(versioned_schema)
1123 mkeyname = "id"
1124 fields = {
1125 "access_token": {"required": False, "type": "str", "no_log": True},
1126 "enable_log": {"required": False, "type": "bool", "default": False},
1127 "vdom": {"required": False, "type": "str", "default": "root"},
1128 "member_path": {"required": False, "type": "str"},
1129 "member_state": {
1130 "type": "str",
1131 "required": False,
1132 "choices": ["present", "absent"],
1133 },
1134 "state": {"required": True, "type": "str", "choices": ["present", "absent"]},
1135 "firewall_sniffer": {
1136 "required": False,
1137 "type": "dict",
1138 "default": None,
1139 "options": {},
1140 },
1141 }
1142 for attribute_name in module_spec["options"]:
1143 fields["firewall_sniffer"]["options"][attribute_name] = module_spec["options"][
1144 attribute_name
1145 ]
1146 if mkeyname and mkeyname == attribute_name:
1147 fields["firewall_sniffer"]["options"][attribute_name]["required"] = True
1148
1149 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
1150 check_legacy_fortiosapi(module)
1151
1152 is_error = False
1153 has_changed = False
1154 result = None
1155 diff = None
1156
1157 versions_check_result = None
1158 if module._socket_path:
1159 connection = Connection(module._socket_path)
1160 if "access_token" in module.params:
1161 connection.set_custom_option("access_token", module.params["access_token"])
1162
1163 if "enable_log" in module.params:
1164 connection.set_custom_option("enable_log", module.params["enable_log"])
1165 else:
1166 connection.set_custom_option("enable_log", False)
1167 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
1168 versions_check_result = check_schema_versioning(
1169 fos, versioned_schema, "firewall_sniffer"
1170 )
1171
1172 is_error, has_changed, result, diff = fortios_firewall(
1173 module.params, fos, module.check_mode
1174 )
1175
1176 else:
1177 module.fail_json(**FAIL_SOCKET_MSG)
1178
1179 if versions_check_result and versions_check_result["matched"] is False:
1180 module.warn(
1181 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
1182 )
1183
1184 if not is_error:
1185 if versions_check_result and versions_check_result["matched"] is False:
1186 module.exit_json(
1187 changed=has_changed,
1188 version_check_warning=versions_check_result,
1189 meta=result,
1190 diff=diff,
1191 )
1192 else:
1193 module.exit_json(changed=has_changed, meta=result, diff=diff)
1194 else:
1195 if versions_check_result and versions_check_result["matched"] is False:
1196 module.fail_json(
1197 msg="Error in repo",
1198 version_check_warning=versions_check_result,
1199 meta=result,
1200 )
1201 else:
1202 module.fail_json(msg="Error in repo", meta=result)
1203
1204
1205 if __name__ == "__main__":
1206 main()