{ "name": "Gestion certificat", "isActive": "1", "group": "Gestion infra domotique", "mode": "schedule", "schedule": "0 5 * * *", "trigger": [ "" ], "timeout": "0", "isVisible": "0", "display": { "name": "", "icon": "" }, "order": "9999", "description": "", "configuration": { "timeDependency": 0, "has_return": 0, "logmode": "default", "allowMultiInstance": "0", "syncmode": "0", "timeline::enable": "0", "timeline::folder": "" }, "elements": [ { "name": null, "type": "action", "options": [], "order": "0", "subElements": [ { "name": null, "type": "action", "subtype": "action", "options": { "collapse": "0", "enable": "1" }, "order": "0", "expressions": [ { "type": "action", "subtype": "", "expression": "tag", "options": { "enable": "1", "background": "0", "name": "domaine", "value": "monjeedom.mondomaine.fr" }, "order": "0" }, { "type": "action", "subtype": "", "expression": "tag", "options": { "enable": "1", "background": "0", "name": "expirationAlerte", "value": "10" }, "order": "1" }, { "type": "action", "subtype": "", "expression": "tag", "options": { "enable": "1", "background": "0", "name": "renewAuto", "value": "0" }, "order": "2" }, { "type": "action", "subtype": "", "expression": "tag", "options": { "enable": "1", "background": "0", "name": "renewDate", "value": "25" }, "order": "3" }, { "type": "action", "subtype": "", "expression": "tag", "options": { "enable": "1", "background": "0", "name": "cmdNotifOK", "value": "[Norbert][JC_Norbert][Notification]" }, "order": "4" }, { "type": "action", "subtype": "", "expression": "tag", "options": { "enable": "1", "background": "0", "name": "cmdNotifErreur", "value": "[Norbert][JC_Norbert][Notif_Erreur]" }, "order": "5" } ] } ] }, { "name": null, "type": "code", "options": [], "order": "0", "subElements": [ { "name": null, "type": "code", "subtype": "action", "options": { "collapse": "0", "enable": "1" }, "order": "0", "expressions": [ { "type": "code", "subtype": null, "expression": "$tags=$scenario->getTags(); \/\/ récupération des tag du scénario\n$domaine=$tags['#domaine#'];\n$alerte=$tags['#expirationAlerte#'];\n$renewAuto =$tags['#renewAuto#'];\n$renewDate =$tags['#renewDate#'];\n$cmdNotifOK = cmd::byString('#'.$tags['#cmdNotifOK#'].'#');\n$cmdNotifErreur = cmd::byString('#'.$tags['#cmdNotifErreur#'].'#');\n\n\/\/ Execution de commandes SSH pour determination de la date de renouvellement\n$expirationDate = date(\"d\/m\/Y\",strtotime(str_replace(CHR(10),\"\",shell_exec (\"sudo certbot certificates --cert-name \".$domaine.\" | grep 'Expiry Date'| awk '{print $3}'\"))));\n$expirationDay = str_replace(CHR(10),\"\",shell_exec (\"sudo certbot certificates --cert-name \".$domaine.\" | grep 'Expiry Date'| awk '{print $6}'\"));\n\n\nif ( $expirationDay <= $alerte || is_numeric($expirationDay) == 0 ) {\n $msgErreur = 'Erreur de renouvellement du certificat pour le domaine '.$domaine.', Pas de date d\\'expiration ou date d\\'expiration inferieure à '.$alerte.'
verifier la commande ci-dessous en ssh
sudo certbot certificates --cert-name '.$domaine ;\n $scenario->setlog($msgErreur);\n $cmdNotifErreur->execCmd($options = array('title' => 'title=Erreur renouvellement du certificat', 'message' => $msgErreur , $cache = 0));\n}\nelse {\n if ( $renewAuto == 1 ) {\n if ( $expirationDay <= $renewDate ) {\n \/\/ Renouvellement auto si necessaire\n \t $statutRenew = shell_exec (\"sudo certbot renew --cert-name \".$domaine.\" | grep -c 'Congratulations, all renewals succeeded'\");\n \t if ( $statutRenew == 1 ) { \n $expirationDate = date(\"d\/m\/Y\",strtotime(str_replace(CHR(10),\"\",shell_exec (\"sudo certbot certificates --cert-name \".$domaine.\" | grep 'Expiry Date'| awk '{print $3}'\"))));\n $expirationDay = str_replace(CHR(10),\"\",shell_exec (\"sudo certbot certificates --cert-name \".$domaine.\" | grep 'Expiry Date'| awk '{print $6}'\"));\n $msgOK='Renouvellement du certificat pour le domaine '.$domaine.', nouvelle expiration dans '.$expirationDay.' jours ('.$expirationDate.')';\n $scenario->setlog($msgOK);\n $cmdNotifOK->execCmd($options = array('title' => 'title=Renouvellement du certificat', 'message' => $msgOK , $cache = 0));\n }\n \t else {\n $msgErreur = 'Erreur de renouvellement du certificat pour le domaine '.$domaine.', expiration dans '.$expirationDay.' jours ('.$expirationDate.')
Essayer la commande ci-dessous en SSH
sudo certbot renew --cert-name '.$domaine;\n $scenario->setlog($msgErreur);\n $cmdNotifErreur->execCmd($options = array('title' => 'title=Erreur renouvellement du certificat', 'message' => $msgErreur , $cache = 0));\n }\n }\n else $scenario->setlog('Aucun renouvellement de certificat à réaliser pour le domaine '.$domaine.', expiration dans '.$expirationDay.' jours ('.$expirationDate.')');\n }\n else {\n $scenario->setlog('Renouvellement automatique desactivé pour le domaine '.$domaine.', Expiration dans '.$expirationDay.' jours ('.$expirationDate.')') ;\n if ( $expirationDay <= $renewDate ) {\n $msgRenew = 'Renouvellement nécessaire du certificat pour le domaine '.$domaine.', Expiration dans '.$expirationDay.' jours ('.$expirationDate.')' ;\n $scenario->setlog($msgRenew) ;\n $cmdNotifErreur->execCmd($options = array('title' => 'title=renouvellement nécessaire du certificat', 'message' => $msgRenew , $cache = 0));\n }\n }\n}\n ", "options": [], "order": "0" } ] } ] } ] }