| 149 | }; |
| 150 | |
| 151 | static apr_status_t notify(md_job_t *job, const char *reason, |
| 152 | md_result_t *result, apr_pool_t *p, void *baton) |
| 153 | { |
| 154 | md_mod_conf_t *mc = baton; |
| 155 | const char * const *argv; |
| 156 | const char *cmdline; |
| 157 | int exit_code; |
| 158 | apr_status_t rv = APR_SUCCESS; |
| 159 | apr_time_t min_interim = 0; |
| 160 | md_timeperiod_t since_last; |
| 161 | const char *log_msg_reason; |
| 162 | int i; |
| 163 | |
| 164 | log_msg_reason = apr_psprintf(p, "message-%s", reason); |
| 165 | for (i = 0; i < (int)(sizeof(notify_rates)/sizeof(notify_rates[0])); ++i) { |
| 166 | if (!strcmp(reason, notify_rates[i].reason)) { |
| 167 | min_interim = notify_rates[i].min_interim; |
| 168 | } |
| 169 | } |
| 170 | if (min_interim > 0) { |
| 171 | since_last.start = md_job_log_get_time_of_latest(job, log_msg_reason); |
| 172 | since_last.end = apr_time_now(); |
| 173 | if (since_last.start > 0 && md_timeperiod_length(&since_last) < min_interim) { |
| 174 | /* not enough time has passed since we sent the last notification |
| 175 | * for this reason. */ |
| 176 | md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, 0, p, APLOGNO(10267) |
| 177 | "%s: rate limiting notification about '%s'", job->mdomain, reason); |
| 178 | return APR_SUCCESS; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if (!strcmp("renewed", reason)) { |
| 183 | if (mc->notify_cmd) { |
| 184 | cmdline = apr_psprintf(p, "%s %s", mc->notify_cmd, job->mdomain); |
| 185 | apr_tokenize_to_argv(cmdline, (char***)&argv, p); |
| 186 | rv = md_util_exec(p, argv[0], argv, &exit_code); |
| 187 | |
| 188 | if (APR_SUCCESS == rv && exit_code) rv = APR_EGENERAL; |
| 189 | if (APR_SUCCESS != rv) { |
| 190 | md_result_problem_printf(result, rv, MD_RESULT_LOG_ID(APLOGNO(10108)), |
| 191 | "MDNotifyCmd %s failed with exit code %d.", |
| 192 | mc->notify_cmd, exit_code); |
| 193 | md_result_log(result, MD_LOG_ERR); |
| 194 | md_job_log_append(job, "notify-error", result->problem, result->detail); |
| 195 | return rv; |
| 196 | } |
| 197 | } |
| 198 | md_log_perror(MD_LOG_MARK, MD_LOG_NOTICE, 0, p, APLOGNO(10059) |
| 199 | "The Managed Domain %s has been setup and changes " |
| 200 | "will be activated on next (graceful) server restart.", job->mdomain); |
| 201 | } |
| 202 | if (mc->message_cmd) { |
| 203 | cmdline = apr_psprintf(p, "%s %s %s", mc->message_cmd, reason, job->mdomain); |
| 204 | apr_tokenize_to_argv(cmdline, (char***)&argv, p); |
| 205 | rv = md_util_exec(p, argv[0], argv, &exit_code); |
| 206 | |
| 207 | if (APR_SUCCESS == rv && exit_code) rv = APR_EGENERAL; |
| 208 | if (APR_SUCCESS != rv) { |
no test coverage detected