Created module for sending telegram.org messages

This commit is contained in:
Luca Deri 2018-06-05 00:01:48 +02:00
parent b22e083da6
commit c7ae3e3956
4 changed files with 129 additions and 1 deletions

View file

@ -1067,6 +1067,57 @@ static void readCurlStats(CURL *curl, HTTPTranferStats *stats, lua_State* vm) {
/* **************************************** */
/* form_data is in format param=value&param1=&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;