summaryrefslogtreecommitdiff
path: root/one.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-16 16:12:10 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-16 16:12:10 -0700
commit1f5700191f852f84fe211f0a881f03b40cd7d371 (patch)
tree35c6cd85ce5af4eaae6ba95386dd5c0ce80c7402 /one.cpp
parentc4c5fa63d152fc30463babf82bff3cf1dfdb2eda (diff)
downloadinfinitytier-1f5700191f852f84fe211f0a881f03b40cd7d371.tar.gz
infinitytier-1f5700191f852f84fe211f0a881f03b40cd7d371.zip
zerotier-cli suspiciously working... that didn't hurt *too* badly.
Diffstat (limited to 'one.cpp')
-rw-r--r--one.cpp60
1 files changed, 58 insertions, 2 deletions
diff --git a/one.cpp b/one.cpp
index 8ef09806..03f5e5fa 100644
--- a/one.cpp
+++ b/one.cpp
@@ -408,6 +408,59 @@ static int cli(int argc,char **argv)
printf("%s",cliFixJsonCRs(responseBody).c_str());
return 0;
} else {
+ printf("200 listnetworks <nwid> <name> <mac> <status> <type> <dev> <ZT assigned ips>"ZT_EOL_S);
+ json_value *j = json_parse(responseBody.c_str(),responseBody.length());
+ if (j) {
+ if (j->type == json_array) {
+ for(unsigned int p=0;p<j->u.array.length;++p) {
+ json_value *jn = j->u.array.values[p];
+ if (jn->type == json_object) {
+ const char *nwid = (const char *)0;
+ const char *name = "";
+ const char *mac = (const char *)0;
+ const char *status = (const char *)0;
+ const char *type = (const char *)0;
+ const char *portDeviceName = "";
+ std::string ips;
+ for(unsigned int k=0;k<jn->u.object.length;++k) {
+ if ((!strcmp(jn->u.object.values[k].name,"nwid"))&&(jn->u.object.values[k].value->type == json_string))
+ nwid = jn->u.object.values[k].value->u.string.ptr;
+ else if ((!strcmp(jn->u.object.values[k].name,"name"))&&(jn->u.object.values[k].value->type == json_string))
+ name = jn->u.object.values[k].value->u.string.ptr;
+ else if ((!strcmp(jn->u.object.values[k].name,"mac"))&&(jn->u.object.values[k].value->type == json_string))
+ mac = jn->u.object.values[k].value->u.string.ptr;
+ else if ((!strcmp(jn->u.object.values[k].name,"status"))&&(jn->u.object.values[k].value->type == json_string))
+ status = jn->u.object.values[k].value->u.string.ptr;
+ else if ((!strcmp(jn->u.object.values[k].name,"type"))&&(jn->u.object.values[k].value->type == json_string))
+ type = jn->u.object.values[k].value->u.string.ptr;
+ else if ((!strcmp(jn->u.object.values[k].name,"portDeviceName"))&&(jn->u.object.values[k].value->type == json_string))
+ portDeviceName = jn->u.object.values[k].value->u.string.ptr;
+ else if ((!strcmp(jn->u.object.values[k].name,"assignedAddresses"))&&(jn->u.object.values[k].value->type == json_array)) {
+ for(unsigned int a=0;a<jn->u.object.values[k].value->u.array.length;++a) {
+ json_value *aa = jn->u.object.values[k].value->u.array.values[a];
+ if (aa->type == json_string) {
+ if (ips.length())
+ ips.push_back(',');
+ ips.append(aa->u.string.ptr);
+ }
+ }
+ }
+ }
+ if ((nwid)&&(mac)&&(status)&&(type)) {
+ printf("200 listnetworks %s %s %s %s %s %s %s"ZT_EOL_S,
+ nwid,
+ (((name)&&(name[0])) ? name : "-"),
+ mac,
+ status,
+ type,
+ (((portDeviceName)&&(portDeviceName[0])) ? portDeviceName : "-"),
+ ((ips.length() > 0) ? ips.c_str() : "-"));
+ }
+ }
+ }
+ }
+ json_value_free(j);
+ }
}
} else {
printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
@@ -418,20 +471,23 @@ static int cli(int argc,char **argv)
cliPrintHelp(argv[0],stderr);
return 2;
}
+ requestHeaders["Content-Type"] = "application/json";
+ requestHeaders["Content-Length"] = "2";
unsigned int scode = Http::POST(
1024 * 1024 * 16,
60000,
(const struct sockaddr *)&addr,
(std::string("/network/") + arg1).c_str(),
requestHeaders,
- "",
- 0,
+ "{}",
+ 2,
responseHeaders,
responseBody);
if (scode == 200) {
if (json) {
printf("%s",cliFixJsonCRs(responseBody).c_str());
} else {
+ printf("200 join OK"ZT_EOL_S);
}
return 0;
} else {