-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertdir.py
executable file
·67 lines (52 loc) · 1.8 KB
/
convertdir.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/python
import M2Crypto
import re,os
import pysvn
path_repo = '/data/dispatch/configs/ssl/'
client = pysvn.Client()
client.update(path_repo)
def getdnsnames(crtstring):
dnsmatch = ""
dnsline = ""
dnsnames = ""
dnsline = list()
dnsnames = list()
match = re.search(r'DNS:(?P<domain>.*)',crtstring)
if(match):
dnsmatch = match.group('domain') #get the full line
dnsline = re.split(r'DNS:',dnsmatch)
for line in dnsline:
line = line.replace(',',"")
dnsnames.append(line)
dnsnames.append('Crt-File in dmz-crt Not Found')
return dnsnames[0]
def svncommit(file_path):
svnadd = list()
svnadd.append(file_path)
if not os.path.exists(file_path):
for line in svnadd:
client.add(line)
client.checkin(svnadd, "+ " + file_path + "\n ueber createcrt-bot")
for r, d, f in os.walk(os.getcwd()):
for filename in f:
# versteckte detein ueberspringen
match = re.search(r'^\.',filename)
if match:
continue
# wenn hinter crt. noch was kommt dann auch ueberspringen
match = re.search(r'pem\..*',filename)
if match:
continue
else:
if '.pem' in filename:
crt = M2Crypto.X509.load_cert(filename)
crtpem = crt.as_pem()
crtstring = crt.as_text()
common_name = getdnsnames(crtstring)
common_name = common_name.replace(' ','')
#e.sub('\s\n','',domainname)
with open(path_repo + '/' + common_name + '/' + common_name + '.cer','w+') as f:
f.write(crtstring+crtpem)
svncommit(path_repo + '/' + common_name + '/' + common_name + '.cer')
print(filename + " --> " + path_repo + '/' + common_name + '/' + common_name + '.cer')
os.remove(filename)