()
| 371 | |
| 372 | # 自签证书 |
| 373 | def CreateSSL(): |
| 374 | import base64 |
| 375 | userInfo = public.get_user_info() |
| 376 | if not userInfo: |
| 377 | userInfo['uid'] = 0 |
| 378 | userInfo['access_key'] = 'B' * 32 |
| 379 | domains = get_host_all() |
| 380 | pdata = { |
| 381 | "action": "get_domain_cert", |
| 382 | "company": "宝塔面板", |
| 383 | "domain": ','.join(domains), |
| 384 | "uid": userInfo['uid'], |
| 385 | "access_key": userInfo['access_key'], |
| 386 | "panel": 1 |
| 387 | } |
| 388 | cert_api = 'https://api.bt.cn/bt_cert' |
| 389 | res = public.httpPost(cert_api, {'data': json.dumps(pdata)}) |
| 390 | try: |
| 391 | result = json.loads(res) |
| 392 | if 'status' in result: |
| 393 | if result['status']: |
| 394 | public.writeFile('ssl/certificate.pem', result['cert']) |
| 395 | public.writeFile('ssl/privateKey.pem', result['key']) |
| 396 | public.writeFile('ssl/baota_root.pfx', base64.b64decode(result['pfx']), 'wb+') |
| 397 | public.writeFile('ssl/root_password.pl', result['password']) |
| 398 | public.writeFile('data/ssl.pl', 'True') |
| 399 | public.ExecShell("/etc/init.d/bt reload") |
| 400 | print('1') |
| 401 | return True |
| 402 | except: |
| 403 | print('error:{}'.format(res)) |
| 404 | print('0') |
| 405 | return False |
| 406 | |
| 407 | |
| 408 | # 创建文件 |
no test coverage detected