Package platformids :: Package net :: Module pfsense

Source Code for Module platformids.net.pfsense

 1  # -*- coding: utf-8 -*- 
 2  """pfSense releases. 
 3  """ 
 4  from __future__ import absolute_import 
 5   
 6  import re 
 7   
 8  from pythonids import PYV35Plus 
 9  from platformids import rte2num, num2rte, num2pretty, custom_dist, \ 
10      decode_version_str_to_segments, RTE_BSD, PlatformIDsFileCheck 
11   
12  __author__ = 'Arno-Can Uestuensoez' 
13  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
14  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
15                  " @Ingenieurbuero Arno-Can Uestuensoez" 
16  __version__ = '0.1.2' 
17  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
18   
19   
20   
21  RTE_PFSENSE      = RTE_BSD   + custom_dist.add_enum()   #: Registration of the *dist* value 
22  RTE_PFSENSE244   = RTE_PFSENSE            + 0x00006181  #: pfSense-2.4.4  
23       
24       
25  #: mapping of the rte string and numeric representation to the numeric value 
26  rte2num.update( 
27      { 
28          'pfsense':   RTE_PFSENSE, 
29          RTE_PFSENSE: RTE_PFSENSE, 
30      } 
31  ) 
32   
33   
34  #: mapping of the rte numeric representation to the string value 
35  num2rte.update( 
36      { 
37          RTE_PFSENSE: 'pfsense', 
38     } 
39  ) 
40   
41   
42  #: mapping of the rte numeric representation to the pretty string value 
43  num2pretty.update( 
44      { 
45          RTE_PFSENSE: 'pfsense', 
46     } 
47  ) 
48   
49   
50  dist = ['', '', '', 'pfSense', '', ''] 
51   
52  try: 
53      # same as defaults: 
54      with open("/etc/platform", 'r') as f: 
55          for l in f:  # one entry only 
56              dist[2] = dist[3] = l 
57              dist[5] = l.lower() 
58       
59      if dist[5] == 'pfsense': 
60          with open("/etc/version", 'r') as f: 
61              for l in f:  # one entry only 
62                  dist[1] = re.sub(r'^\([0-9.]+).*', r'\1', l) 
63                  dist[2] += 'pfSense-' + dist[1] 
64                  dist[4] = decode_version_str_to_segments(dist[1]) 
65                  dist[0] = 'pfsense%d%d%d' % (dist[4][0], dist[4][1], dist[4][2], )  
66   
67  except PlatformIDsFileCheck: 
68      # not on pfSense platform, so scan will fail 
69      pass     
70   
71  if dist[5] != 'pfsense': 
72      # does not actually match pfSense 
73      dist = ['pfsense', '0.0.0', 'pfSense-0.0.0', 'pfSense', (0, 0, 0,), 'pfsense'] 
74