curl-library
Ubiquiti
Date: Tue, 18 Apr 2017 14:08:12 -0600
On Tue, Apr 18, 2017 at 07:52:35AM -0600, Greg Stewart via curl-library
wrote:
> I am working with Ubiquiti airMax products. I'm trying to get logged in
and
> change the device configuration.
I actually had to do exactly that a few weeks ago. What I ended up doing is:
I got everything working. Below I have my code which needs to be cleaned
up. I used the --libcurl flag to produce the libcurl c code, and it worked
great. That is an awesome feature.
Since I can't save the cookie file to the ESP32 in a file format, how do I
store the cookie and reuse it? Can I put it in a buffer?
/********* Sample code generated by the curl command line tool **********
> * All curl_easy_setopt() options are documented at:
> * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
> ************************************************************************/
> #include <curl/curl.h>
> int main(int argc, char *argv[])
> {
> CURLcode ret;
> CURL *hnd;
> hnd = curl_easy_init();
> curl_easy_setopt(hnd, CURLOPT_URL, "https://192.168.1.20/");
> curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
> curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.50.3");
> curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
> curl_easy_setopt(hnd, CURLOPT_COOKIEFILE, "cookie.txt");
> curl_easy_setopt(hnd, CURLOPT_COOKIEJAR, "cookie.txt");
> curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
> /* Here is a list of options the curl code used that cannot get generated
> as source easily. You may select to either not use them or implement
> them yourself.
> CURLOPT_WRITEDATA set to a objectpointer
> CURLOPT_WRITEFUNCTION set to a functionpointer
> CURLOPT_READDATA set to a objectpointer
> CURLOPT_READFUNCTION set to a functionpointer
> CURLOPT_SEEKDATA set to a objectpointer
> CURLOPT_SEEKFUNCTION set to a functionpointer
> CURLOPT_ERRORBUFFER set to a objectpointer
> CURLOPT_STDERR set to a objectpointer
> CURLOPT_HEADERFUNCTION set to a functionpointer
> CURLOPT_HEADERDATA set to a objectpointer
> */
> ret = curl_easy_perform(hnd);
> curl_easy_cleanup(hnd);
> hnd = NULL;
>
>
>
> // CURLcode ret;
> // CURL *hnd;
> struct curl_httppost *post1;
> struct curl_httppost *postend;
> struct curl_slist *slist1;
> post1 = NULL;
> postend = NULL;
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "uri",
> CURLFORM_COPYCONTENTS, "/",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "username",
> CURLFORM_COPYCONTENTS, "ubnt",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "password",
> CURLFORM_COPYCONTENTS, "ubnt",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "country",
> CURLFORM_COPYCONTENTS, "56",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "ui_language",
> CURLFORM_COPYCONTENTS, "en_US",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "lang_changed",
> CURLFORM_COPYCONTENTS, "no",
> CURLFORM_END);
> slist1 = NULL;
> slist1 = curl_slist_append(slist1, "Expect:");
> hnd = curl_easy_init();
> curl_easy_setopt(hnd, CURLOPT_URL, "https://192.168.1.20/login.cgi");
> curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
> curl_easy_setopt(hnd, CURLOPT_HTTPPOST, post1);
> curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.50.3");
> curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
> curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
> curl_easy_setopt(hnd, CURLOPT_COOKIEFILE, "cookie.txt");
> curl_easy_setopt(hnd, CURLOPT_COOKIEJAR, "cookie.txt");
> curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
> /* Here is a list of options the curl code used that cannot get generated
> as source easily. You may select to either not use them or implement
> them yourself.
> CURLOPT_WRITEDATA set to a objectpointer
> CURLOPT_WRITEFUNCTION set to a functionpointer
> CURLOPT_READDATA set to a objectpointer
> CURLOPT_READFUNCTION set to a functionpointer
> CURLOPT_SEEKDATA set to a objectpointer
> CURLOPT_SEEKFUNCTION set to a functionpointer
> CURLOPT_ERRORBUFFER set to a objectpointer
> CURLOPT_STDERR set to a objectpointer
> CURLOPT_HEADERFUNCTION set to a functionpointer
> CURLOPT_HEADERDATA set to a objectpointer
> */
> ret = curl_easy_perform(hnd);
> curl_easy_cleanup(hnd);
> hnd = NULL;
> curl_formfree(post1);
> post1 = NULL;
> curl_slist_free_all(slist1);
> slist1 = NULL;
>
>
>
> post1 = NULL;
> postend = NULL;
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "essid",
> CURLFORM_COPYCONTENTS, "Stewarts 2012",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "security",
> CURLFORM_COPYCONTENTS, "wpa2aes",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "wpa_key",
> CURLFORM_COPYCONTENTS, "stephanie",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "change",
> CURLFORM_COPYCONTENTS, "Change",
> CURLFORM_END);
> curl_formadd(&post1, &postend,
> CURLFORM_COPYNAME, "action",
> CURLFORM_COPYCONTENTS, "change",
> CURLFORM_END);
> slist1 = NULL;
> slist1 = curl_slist_append(slist1, "Expect:");
> hnd = curl_easy_init();
> curl_easy_setopt(hnd, CURLOPT_URL, "https://192.168.1.20/link.cgi");
> curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
> curl_easy_setopt(hnd, CURLOPT_HTTPPOST, post1);
> curl_easy_setopt(hnd, CURLOPT_REFERER, "https://192.168.1.20/link.cgi");
> curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.50.3");
> curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
> curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
> curl_easy_setopt(hnd, CURLOPT_COOKIEFILE, "cookie.txt");
> curl_easy_setopt(hnd, CURLOPT_COOKIEJAR, "cookie.txt");
> curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
> /* Here is a list of options the curl code used that cannot get generated
> as source easily. You may select to either not use them or implement
> them yourself.
> CURLOPT_WRITEDATA set to a objectpointer
> CURLOPT_WRITEFUNCTION set to a functionpointer
> CURLOPT_READDATA set to a objectpointer
> CURLOPT_READFUNCTION set to a functionpointer
> CURLOPT_SEEKDATA set to a objectpointer
> CURLOPT_SEEKFUNCTION set to a functionpointer
> CURLOPT_ERRORBUFFER set to a objectpointer
> CURLOPT_STDERR set to a objectpointer
> CURLOPT_HEADERFUNCTION set to a functionpointer
> CURLOPT_HEADERDATA set to a objectpointer
> */
> ret = curl_easy_perform(hnd);
> curl_easy_cleanup(hnd);
> hnd = NULL;
> curl_formfree(post1);
> post1 = NULL;
> curl_slist_free_all(slist1);
> slist1 = NULL;
>
> return (int)ret;
> }
> /**** End of sample code ****/
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-04-18