mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-13 05:51:46 +00:00
Created module for sending telegram.org messages
This commit is contained in:
parent
b22e083da6
commit
c7ae3e3956
4 changed files with 129 additions and 1 deletions
|
|
@ -1067,6 +1067,57 @@ static void readCurlStats(CURL *curl, HTTPTranferStats *stats, lua_State* vm) {
|
|||
|
||||
/* **************************************** */
|
||||
|
||||
/* form_data is in format param=value¶m1=&value1... */
|
||||
bool Utils::postHTTPForm(char *username, char *password, char *url, char *form_data) {
|
||||
CURL *curl;
|
||||
bool ret = true;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
|
||||
if((username && (username[0] != '\0'))
|
||||
|| (password && (password[0] != '\0'))) {
|
||||
char auth[64];
|
||||
|
||||
snprintf(auth, sizeof(auth), "%s:%s",
|
||||
username ? username : "",
|
||||
password ? password : "");
|
||||
curl_easy_setopt(curl, CURLOPT_USERPWD, auth);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
|
||||
}
|
||||
|
||||
if(!strncmp(url, "https", 5)) {
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, form_data);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(form_data));
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(res != CURLE_OK) {
|
||||
ntop->getTrace()->traceEvent(TRACE_WARNING,
|
||||
"Unable to post data to (%s): %s",
|
||||
url, curl_easy_strerror(res));
|
||||
ret = false;
|
||||
} else {
|
||||
ntop->getTrace()->traceEvent(TRACE_INFO, "Posted data to %s", url);
|
||||
}
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/* **************************************** */
|
||||
|
||||
bool Utils::postHTTPJsonData(char *username, char *password, char *url,
|
||||
char *json, HTTPTranferStats *stats) {
|
||||
CURL *curl;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue