Browse Source

fix: several issues

master
dnomd343 3 years ago
parent
commit
b52e051944
  1. 68
      encryption365.php
  2. 4
      install.sh

68
encryption365.php

@ -411,7 +411,7 @@ class Certificate {
} }
private static function waitIssued($vendorId) { // 等待证书签发 private static function waitIssued($vendorId) { // 等待证书签发
$maxTime = 20; $maxTime = 40;
$interval = 30; $interval = 30;
for ($i = 0; $i < 20; $i++) { for ($i = 0; $i < 20; $i++) {
Output::line('Let\'s wait ' . $interval . ' seconds and query certificate status...'); Output::line('Let\'s wait ' . $interval . ' seconds and query certificate status...');
@ -420,7 +420,7 @@ class Certificate {
if ($detail['result'] !== "success") { if ($detail['result'] !== "success") {
Output::str('Fail to get certificate details => '); Output::str('Fail to get certificate details => ');
Output::line($detail['message'], 'red'); Output::line($detail['message'], 'red');
continue; break;
} }
if ($detail['cert_status'] === 'issued_active') { if ($detail['cert_status'] === 'issued_active') {
Output::line('Certificate issue success', 'green'); Output::line('Certificate issue success', 'green');
@ -442,6 +442,12 @@ class Certificate {
Output::line('Issue certificate time out, you may validate again...', 'red'); Output::line('Issue certificate time out, you may validate again...', 'red');
return false; return false;
} }
self::saveCert($host, $certInfo);
return true;
}
public static function saveCert($host, $certInfo) {
$info = Storage::getInfo($host);
$cert = $certInfo['cert_code']; $cert = $certInfo['cert_code'];
$caCert = $certInfo['ca_code']; $caCert = $certInfo['ca_code'];
$startTime = $certInfo['created_at']; $startTime = $certInfo['created_at'];
@ -460,7 +466,6 @@ class Certificate {
Output::line($startTime, 'sky-blue'); Output::line($startTime, 'sky-blue');
Output::str('Expire time: '); Output::str('Expire time: ');
Output::line($endTime, 'sky-blue'); Output::line($endTime, 'sky-blue');
return true;
} }
public static function createCert($productId, $domains, $isEcc = false) { // 创建新的证书订单 public static function createCert($productId, $domains, $isEcc = false) { // 创建新的证书订单
@ -480,7 +485,8 @@ class Certificate {
} }
$vendorId = (string)$orderRlt['trustocean_id']; $vendorId = (string)$orderRlt['trustocean_id'];
foreach ($orderRlt['dcv_info'] as $domain => $dcvInfo) { foreach ($orderRlt['dcv_info'] as $domain => $dcvInfo) {
$verifyLink = $dcvInfo['http_verifylink']; preg_match('/^http:\/\/[\S]*?(\/[\S]+.txt)/', $dcvInfo['http_verifylink'], $match);
$verifyLink = 'http://{domain}' . $match[1];
$verifyContent = $dcvInfo['http_filecontent']; $verifyContent = $dcvInfo['http_filecontent'];
break; break;
} }
@ -546,7 +552,8 @@ class Certificate {
} }
$vendorId = (string)$orderRlt['trustocean_id']; $vendorId = (string)$orderRlt['trustocean_id'];
foreach ($orderRlt['dcv_info'] as $domain => $dcvInfo) { foreach ($orderRlt['dcv_info'] as $domain => $dcvInfo) {
$verifyLink = $dcvInfo['http_verifylink']; preg_match('/^http:\/\/[\S]*?(\/[\S]+.txt)/', $dcvInfo['http_verifylink'], $match);
$verifyLink = 'http://{domain}' . $match[1];
$verifyContent = $dcvInfo['http_filecontent']; $verifyContent = $dcvInfo['http_filecontent'];
break; break;
} }
@ -666,17 +673,17 @@ class LoginCtr {
$result = Encryption365::clientLogin($email, $passwd); $result = Encryption365::clientLogin($email, $passwd);
if ($result['result'] !== 'success') { if ($result['result'] !== 'success') {
Output::str('Fail to login: '); Output::str('Fail to login: ');
Output::str($result['message'], 'red'); Output::line($result['message'], 'red');
return; return;
} }
Output::str('Login success' . PHP_EOL, 'green'); Output::line('Login success', 'green');
Output::line('Account status: ' . $result['status']); Output::line('Account status: ' . $result['status']);
Output::line('Login time: ' . $result['created_at']); Output::line('Login time: ' . $result['created_at']);
Storage::setClientInfo($email, $result['client_id'], $result['access_token']); Storage::setClientInfo($email, $result['client_id'], $result['access_token']);
} }
} }
class listCtr { class ListCtr {
public static function list() { // 列出所有证书 public static function list() { // 列出所有证书
$list = Storage::getHostList(); $list = Storage::getHostList();
if (count($list) === 0) { if (count($list) === 0) {
@ -689,14 +696,22 @@ class listCtr {
Output::str($info['host'] . "\t", 'yellow'); Output::str($info['host'] . "\t", 'yellow');
Output::str($info['vendorId'] . "\t", 'sky-blue'); Output::str($info['vendorId'] . "\t", 'sky-blue');
Output::str(implode('/', $info['domains']) . "\t", 'purple'); Output::str(implode('/', $info['domains']) . "\t", 'purple');
Output::str($info['createTime'] . "\t", 'blue'); if (isset($info['createTime'])) {
Output::str($info['expireTime'] . "\t", 'blue'); Output::str($info['createTime'] . "\t", 'blue');
} else {
Output::str('-' . "\t\t", 'blue');
}
if (isset($info['expireTime'])) {
Output::str($info['expireTime'] . "\t", 'blue');
} else {
Output::str('-' . "\t\t", 'blue');
}
Output::line(''); Output::line('');
} }
} }
} }
class issueCtr { class IssueCtr {
public static function entry($params) { public static function entry($params) {
if (count($params) === 0) { if (count($params) === 0) {
Output::line('You must specify encryption method.', 'red'); Output::line('You must specify encryption method.', 'red');
@ -726,7 +741,8 @@ class issueCtr {
Output::line('Illegal product ID.', 'red'); Output::line('Illegal product ID.', 'red');
return; return;
} }
Certificate::createNewOrder($productId, $domains, $isEcc); Storage::addHost($domains[0]);
Certificate::createCert($productId, $domains, $isEcc);
} }
private function isHost($host) { // 判断host是否合法 private function isHost($host) { // 判断host是否合法
@ -775,6 +791,31 @@ class ReverifyCtr {
} }
} }
class FlashCtr {
public static function entry($params) {
if (count($params) === 0) {
Output::line('Host must be specified.', 'red');
return;
}
if (count($params) > 1) {
Output::line('Too many parameters to flash certificate.', 'red');
return;
}
$host = $params[0];
$info = Storage::getInfo($host);
$detail = Encryption365::certDetails($info['vendorId']);
if ($detail['result'] !== "success") {
Output::str('Fail to flash certificate => ');
Output::line($detail['message'], 'red');
}
Output::str('Certificate status: ');
Output::line($detail['cert_status'], 'sky-blue');
if ($detail['cert_status'] === 'issued_active') {
Certificate::saveCert($host, $detail);
}
}
}
class RenewCtr { class RenewCtr {
public static function entry($params) { public static function entry($params) {
if (count($params) === 0) { if (count($params) === 0) {
@ -921,6 +962,9 @@ function main($argv) { // 脚本入口
case 'reverify': case 'reverify':
ReverifyCtr::entry($params); ReverifyCtr::entry($params);
break; break;
case 'flash':
FlashCtr::entry($params);
break;
case 'renew': case 'renew':
RenewCtr::entry($params); RenewCtr::entry($params);
break; break;

4
install.sh

@ -28,7 +28,9 @@ echo -e "\033[32m OK\033[0m\n"
echo -e "\033[33mPlease ensure that the following modules are exist\033[0m" echo -e "\033[33mPlease ensure that the following modules are exist\033[0m"
echo -e "\033[36mphp / php-cli / php-fpm / php-json / php-openssl / php-mbstring\033[0m\n" echo -e "\033[36mphp / php-cli / php-fpm / php-json / php-openssl / php-mbstring\033[0m\n"
echo "0 * * * * encryption365 autorenew" >> /var/spool/cron/root if [ ! -n `crontab -l | grep -o encryption365` ]; then
echo "0 * * * * encryption365 autorenew" >> /var/spool/cron/root
fi
echo -e "\033[33mYou can use \"\033[0m\033[36mencryption365 help\033[0m\033[33m\" command for details.\033[0m\n" echo -e "\033[33mYou can use \"\033[0m\033[36mencryption365 help\033[0m\033[33m\" command for details.\033[0m\n"
echo -e "\033[32mInstall OK\033[0m" echo -e "\033[32mInstall OK\033[0m"

Loading…
Cancel
Save