-
Notifications
You must be signed in to change notification settings - Fork 3
/
pfsense-updateCRL.py
executable file
·48 lines (36 loc) · 1.24 KB
/
pfsense-updateCRL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import sys
from pfsense_api import PfSenseAPI
from datetime import datetime
from pfsense_cmdline import PfSenseOptionParser
parser = PfSenseOptionParser()
parser.add_option("--id", dest="crlID", help="ID of the CRL to update")
parser.add_option("--name", dest="name", help="Descriptive name of the CRL", default="Imported CRL")
parser.add_option("--crl", dest="crl", help="File containing CRL in PEM format" )
(options, args) = parser.parse_args()
parser.checkOptions( options )
if options.crlID is None or options.crl is None:
print 'pfsense-updateCRL: options --id and --crl are required (see help: pfsense-updateCRL --help)'
sys.exit( 1 )
crlFile = open( options.crl, 'rU' )
crl = crlFile.read()
crlFile.close()
api = PfSenseAPI.fromConfig( options.config )
(rc, data, contentType) = api.call( '/system_crlmanager.php', 'POST',
apiData = {
'method': 'existing',
'descr': '%s (last refresh: %s)' % (options.name, datetime.now().isoformat()),
'crltext': crl,
'submit': 'Save'
},
itemData = {
'id': options.crlID,
'act': 'editimported'
})
api.logout()
if rc == 302:
print 'CRL Update successful'
sys.exit( 0 )
else:
print 'CRL Update failed'
sys.exit( -1 )