curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Ubiquiti

From: Greg Stewart via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 19 Apr 2017 08:39:19 -0600

I do not cleanup until the end and I only init once. I'm still not able to
get it to work without having the cookie stored in a file. The code will
run, but it doesn't actually update the form. Below I have my current code.
I have commented out the SSL flags as that is causing a different issue. I
tried not setting CURLOPT_COOKIEJAR, but it didn't help. I think I am
close, but not quite there.

#include <curl/curl.h>
>
>
>> int main(int argc, char *argv[])
>
> {
>
> CURLcode ret;
>
> CURL *hnd;
>
>
>> hnd = curl_easy_init();
>
> curl_easy_setopt(hnd, CURLOPT_URL, "http://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);
>
>
>> ret = curl_easy_perform(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, "http://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);
>
>
>> ret = curl_easy_perform(hnd);
>
>
>> 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, "SSID 1",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "security",
>
> CURLFORM_COPYCONTENTS, "wpa2aes",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "wpa_key",
>
> CURLFORM_COPYCONTENTS, "password",
>
> 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, "http://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, "http://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);
>
>
>> 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;
>
> }
>
>
On Tue, Apr 18, 2017 at 4:56 PM, Ray Satiro via curl-library <
curl-library_at_cool.haxx.se> wrote:

> On 4/18/2017 4:08 PM, Greg Stewart via curl-library wrote:
>
> 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?
>
>
> Every e-mail reply on this topic that you've sent to the list is starting
> a separate thread in my e-mail clients (Thunderbird and Yahoo), I don't
> know why. It makes the conversation harder to follow.
>
> In addition to what Daniel said, all good points, if you are storing them
> in flash and that's why you need to output them to memory that is possible.
> The cookies would be imported individually by setting each cookie via
> CURLOPT_COOKIELIST [1] before curl_easy_perform, and then exported all at
> once as a linked list via CURLINFO_COOKIELIST [2].
>
> for(struct curl_slist *c = cookies; c; c = c->next) {
> res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, c->data);
> if(res != CURLE_OK) {
> /* bail out, cleanup, etc */
> }
> }
> res = curl_easy_perform(curl);
> if(res != CURLE_OK) {
> /* bail out, cleanup, etc */
> }
> curl_slist_free_all(cookies);
> cookies = NULL;
> res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
> if(res != CURLE_OK) {
> /* bail out, cleanup, etc */
> }
> for(struct curl_slist *c = cookies; c; c = c->next) {
> printf("%s\n",c->data);
> }
>
>
> [1]: https://curl.haxx.se/libcurl/c/CURLOPT_COOKIELIST.html
> [2]: https://curl.haxx.se/libcurl/c/CURLINFO_COOKIELIST.html
>
>
> -------------------------------------------------------------------
> Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette: https://curl.haxx.se/mail/etiquette.html
>

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-04-19