(self)
| 1478 | |
| 1479 | # 自签证书 |
| 1480 | def CreateSSL(self): |
| 1481 | userInfo = public.get_user_info() |
| 1482 | if userInfo: |
| 1483 | domains = [] |
| 1484 | req_host = public.GetHost() |
| 1485 | server_ip = public.get_ip() |
| 1486 | domains.append(req_host) |
| 1487 | if server_ip != req_host and not server_ip in ['127.0.0.1', '::1', 'localhost']: |
| 1488 | domains.append(server_ip) |
| 1489 | pdata = { |
| 1490 | "action": "get_domain_cert", |
| 1491 | "company": "宝塔面板", |
| 1492 | "domain": ','.join(domains), |
| 1493 | "uid": userInfo['uid'], |
| 1494 | "access_key": userInfo['access_key'], |
| 1495 | "panel": 1 |
| 1496 | } |
| 1497 | cert_api = 'https://api.bt.cn/bt_cert' |
| 1498 | http_data = public.httpPost(cert_api, {'data': json.dumps(pdata)}) |
| 1499 | if http_data is not False: |
| 1500 | try: |
| 1501 | result = json.loads(http_data) |
| 1502 | except: |
| 1503 | result = {} |
| 1504 | if 'status' in result: |
| 1505 | if result['status']: |
| 1506 | public.writeFile('ssl/certificate.pem', result['cert']) |
| 1507 | public.writeFile('ssl/privateKey.pem', result['key']) |
| 1508 | public.writeFile('ssl/baota_root.pfx', base64.b64decode(result['pfx']), 'wb+') |
| 1509 | public.writeFile('ssl/root_password.pl', result['password']) |
| 1510 | return True |
| 1511 | |
| 1512 | if os.path.exists('ssl/input.pl'): return True |
| 1513 | import OpenSSL |
| 1514 | key = OpenSSL.crypto.PKey() |
| 1515 | key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048) |
| 1516 | cert = OpenSSL.crypto.X509() |
| 1517 | cert.set_serial_number(0) |
| 1518 | cert.get_subject().CN = public.GetLocalIp() |
| 1519 | cert.set_issuer(cert.get_subject()) |
| 1520 | cert.gmtime_adj_notBefore(0) |
| 1521 | cert.gmtime_adj_notAfter(86400 * 3650) |
| 1522 | cert.set_pubkey(key) |
| 1523 | cert.sign(key, 'md5') |
| 1524 | cert_ca = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert) |
| 1525 | private_key = OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key) |
| 1526 | |
| 1527 | if len(cert_ca) > 100 and len(private_key) > 100: |
| 1528 | public.writeFile('ssl/certificate.pem', cert_ca, 'wb+') |
| 1529 | public.writeFile('ssl/privateKey.pem', private_key, 'wb+') |
| 1530 | return True |
| 1531 | return False |
| 1532 | |
| 1533 | # 生成Token |
| 1534 | def SetToken(self, get): |
no test coverage detected