summaryrefslogtreecommitdiff
path: root/04-CustomLibrary/Custometest/cmd_cer.py
blob: 02e782c23c4117a063ce4335eb5b9e30f7ff65dd (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
import subprocess
from time import sleep


class Order:
    def CMD(self,data):
        result = os.popen(data)
        # res = result.read().encoding('GBK')
        res = result.read()
        result.close()
        # res = res.decode("unicode-escape")
        return res
    def Linux(self):
        pass
    # 根据证书颁发者名字判断证书是否替换
    def Cert_Verification(self,data):
        c = []
        print(1)
        #with open(r'C:\Users\iiesoft\AppData\Local\Programs\Python\Python36\Lib\site-packages\custometest\certificate.yaml', 'r') as foo:
        with open(r'certificate.yaml', 'r') as foo:
            print(2)
            for line in foo.readlines():
                if data in line:
                    print(line)
                    c.append('证书已替换')
                else:
                    pass
            if '证书已替换' in c:
                # print('证书已替换')
                foo.close()
                return '证书已替换'
            else:
                # print('证书未替换')
                foo.close()
                return '证书未替换'

    def Content_Type(self,data):
        d = []
        with open('certificate.yaml', 'r') as foo:
            for line in foo.readlines():
                if data in line:
                    # print(line)
                    d.append('Content_Type已替换')
                else:
                    pass
            if 'Content_Type已替换' in d:
                # print('证书已替换')
                foo.close()
                return 'Content_Type已替换'
            else:
                # print('证书未替换')
                foo.close()
                return 'Content_Type未替换'
    # curl路由内容设置
    def curl_name(self,data):
        #curl_name = 'curl -kv -m 10 -1 --trace C:/Users/iiesoft/AppData/Local/Programs/Python/Python36/Lib/site-packages/custometest/certificate.yaml '+data+'| iconv -f utf-8 -t gbk'
        curl_name = 'curl -kv -m 10 -1 --trace certificate.yaml '+data+'| iconv -f utf-8 -t gbk'
        return curl_name
    # 控制器
    def manu(self,url,Certificate):
        # print(data['url'])
        n = 0
        while n != len(url):
            b = self.curl_name(url[n])
            d = self.CMD(b)
            # print(d)
            sleep(1)
            if Certificate != "":
                c =self.Cert_Verification(Certificate)
                # f = self.Content_Type(data["Content_Type"])
                sleep(1)
                assert_cer = url[n]+c
                # assert_Content_Type = data['Content_Type']+f
            n+=1
        return d,assert_cer
    
    def FTP(self, ftp_type):
        windows_path = os.getcwd()
        linux_path = os.getcwd().replace('\\', '/')
        # 判断FTP执行类型:(下载/登录)
        if ftp_type == "下载":
            # 调用cmd执行FTP下载文件
            data = 'curl -m 20 ftp://202.38.97.230/pub/iso/linux/knoppix/KNOPPIX_V7.7.1DVD-2016-10-22-EN/dpkg-l-dvd-771.txt -u"anonymous:[email protected]" -o zmmtext123.txt'
            d = self.CMD(data)
            sleep(5)
            fsize = os.path.getsize(linux_path + "/zmmtext123.txt")  # 435814
            if fsize == 435814:
                return "Success"
            else:
                return "Fail"
        elif ftp_type == "登录":
            data = 'curl -m 10 ftp://202.38.97.230/pub/iso/linux/knoppix/KNOPPIX_V7.7.1DVD-2016-10-22-EN/dpkg-l-dvd-771.txt -u"anonymous:[email protected]" | iconv -f utf-8 -t gbk'
            d = self.CMD(data)
            # print(d)
            if "Graphical (Xorg) program starter for ADRIANE" in d:
                return "Success"
            else:
                return "Fail"
    # FTP  下载
    def FTP_down(self, ftp_url,file_size,fiel_name):
        windows_path = os.getcwd()
        linux_path = os.getcwd().replace('\\', '/')
        # 判断FTP执行类型:(下载/登录)
        # 调用cmd执行FTP下载文件
        data = 'curl -m 20 '+ftp_url+ '-o '+ fiel_name + " ' "
        print(data)
        d = self.CMD(data)
        sleep(5)
        fsize = os.path.getsize(linux_path + "/"+fiel_name)  # 435814
        print(fsize)
        if fsize == file_size:
            return "ftp_success"
        else:
            return "ftp_fail"

    # FTP 登录
    def FTP_login(self, ftp_url,file_content):
        data = 'curl -m 10 '+ftp_url+' | iconv -f utf-8 -t gbk'
        d = self.CMD(data)
        # print(d)
        if file_content in d:
            return "ftp_success"
        else:
            return "ftp_fail"

if __name__ == '__main__':
    datas = {"url":['https://www.baidu.com'],
"Certificate":"Tango Secure Gateway CA",
# "Content_Type":"text/html",
'log':'Security Event Logs',
"sni":['baidu'],
"intercept_code":"200",
"log_code":"200",
"certifucate":"1",
"log_content":"true"
}
#     data= {"url":['https://www.baidu.com'],
# "Certificate":"Tango Secure Gateway CA"
#     }
    # url = ['https://www.baidu.com']
    # url = ['https://www.baidu.com']
    # url = ['https://www.baidu.com']
    # # Certificate1 = "Tango Secure Gateway CA"
    # Certificate = "baidu"
    # a='Tango Secure Gateway CA'
    # s = Order()
    # b = s.manu(url,Certificate)
    # print(b[1])
    # FTP下载 传入ftp的路径和文件大小
    ftp_url = 'ftp://202.38.97.230/pub/iso/linux/knoppix/KNOPPIX_V7.7.1DVD-2016-10-22-EN/dpkg-l-dvd-771.txt -u"anonymous:[email protected]" '
    ftp_size = 435814
    ftp_issue = s.FTP_down(ftp_url,ftp_size)
    # FTP登录 传入ftp的路径和文件内容
    ftp_url ='ftp://202.38.97.230/pub/iso/linux/knoppix/KNOPPIX_V7.7.1DVD-2016-10-22-EN/dpkg-l-dvd-771.txt -u"anonymous:[email protected]" '
    file_content = "Graphical (Xorg) program starter for ADRIANE"
    ftp_issue = s.FTP_login(ftp_url,file_content)
    # for i in b:
    #     print(i)
    # dd = s.CMD('curl -I https://www.baidu.com')
    # print(dd)
    # if "private, no-cache, no-store, proxy-revalidate, no-transform"in dd:
    #     print("ok")
    # a ='curl -kv -1 --trace certificate.yaml https://www.baidu.com | iconv -f utf-8 -t gbk'