registry completed, including impersonate
Costa Tsaousis committed
May 13, 2016 at 02:52 UTC
b1f03e0d4b33c7d25b047d7d2e1d7ff9972192d4
5 files changed
+275
-75
src/registry.c
+74
-9
@@ -540,9 +540,7 @@ static inline PERSON *registry_person_allocate(const char *person_guid, time_t w
540
if(!person_guid) {
541
for (; ;) {
542
uuid_t uuid;
543
- if (uuid_generate_time_safe(uuid) == -1)
544
- info("Registry: uuid_generate_time_safe() reports UUID generation is not safe for uniqueness.");
545
-
543
+ uuid_generate(uuid);
544
uuid_unparse_lower(uuid, p->guid);
545
546
debug(D_REGISTRY, "Registry: Checking if the generated person guid '%s' is unique", p->guid);
@@ -923,7 +921,7 @@ PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *url
921
922
// make sure the user is not deleting the url it uses
923
if(!strcmp(delete_url, pu->url->url)) {
926
- info("Registry Delete Request: delete URL is the one currently accessing, person: '%s', machine '%s', url '%s', delete url '%s'", p->guid, m->guid, pu->url->url, delete_url);
924
+ info("Registry Delete Request: delete URL is the one currently accessed, person: '%s', machine '%s', url '%s', delete url '%s'", p->guid, m->guid, pu->url->url, delete_url);
925
return NULL;
926
}
927
@@ -931,7 +929,7 @@ PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *url
929
930
PERSON_URL *dpu = dictionary_get(p->urls, delete_url);
931
if(!dpu) {
934
- info("Registry Delete Request: URL not found for person, person: '%s', machine '%s', url '%s', delete url '%s'", p->guid, m->guid, pu->url->url, delete_url);
932
+ info("Registry Delete Request: URL not found for person: '%s', machine '%s', url '%s', delete url '%s'", p->guid, m->guid, pu->url->url, delete_url);
933
registry_person_urls_unlock(p);
934
return NULL;
935
}
@@ -1110,7 +1108,7 @@ int registry_request_access_json(struct web_client *w, char *person_guid, char *
1108
if(!p) {
1109
registry_json_header(w, "access", REGISTRY_STATUS_FAILED);
1110
registry_json_footer(w);
1113
- return 400;
1111
+ return 412;
1112
}
1113
1114
// set the cookie
@@ -1119,7 +1117,7 @@ int registry_request_access_json(struct web_client *w, char *person_guid, char *
1117
// generate the response
1118
registry_json_header(w, "access", REGISTRY_STATUS_OK);
1119
1122
- buffer_strcat(w->response.data, ",\n\t\"urls\": [");
1120
+ buffer_sprintf(w->response.data, ",\n\t\"person_guid\": \"%s\",\n\t\"urls\": [", p->guid);
1121
struct registry_json_walk_person_urls_callback c = { p, NULL, w, 0 };
1122
dictionary_get_all(p->urls, registry_json_person_url_callback, &c);
1123
buffer_strcat(w->response.data, "\n\t]\n");
@@ -1137,7 +1135,7 @@ int registry_request_delete_json(struct web_client *w, char *person_guid, char *
1135
if(!p) {
1136
registry_json_header(w, "delete", REGISTRY_STATUS_FAILED);
1137
registry_json_footer(w);
1140
- return 400;
1138
+ return 412;
1139
}
1140
1141
// generate the response
@@ -1155,7 +1153,7 @@ int registry_request_search_json(struct web_client *w, char *person_guid, char *
1153
if(!m) {
1154
registry_json_header(w, "search", REGISTRY_STATUS_FAILED);
1155
registry_json_footer(w);
1158
- return 400;
1156
+ return 404;
1157
}
1158
1159
registry_json_header(w, "search", REGISTRY_STATUS_OK);
@@ -1170,6 +1168,73 @@ int registry_request_search_json(struct web_client *w, char *person_guid, char *
1168
}
1169
1170
1171
+int registry_person_url_callback_verify_machine_exists(void *entry, void *machine) {
1172
+ PERSON_URL *pu = (PERSON_URL *)entry;
1173
+ MACHINE *m = (MACHINE *)machine;
1174
+
1175
+ if(pu->machine == m)
1176
+ return 1;
1177
+ else
1178
+ return 0;
1179
+}
1180
+
1181
+// the main method for switching user identity
1182
+int registry_request_switch_json(struct web_client *w, char *person_guid, char *machine_guid, char *url, char *new_person_guid, time_t when) {
1183
+ (void)url;
1184
+ (void)when;
1185
+
1186
+ if(!registry.enabled)
1187
+ return registry_json_disabled(w, "switch");
1188
+
1189
+ PERSON *op = registry_person_find(person_guid);
1190
+ if(!op) {
1191
+ registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1192
+ registry_json_footer(w);
1193
+ return 430;
1194
+ }
1195
+
1196
+ PERSON *np = registry_person_find(new_person_guid);
1197
+ if(!np) {
1198
+ registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1199
+ registry_json_footer(w);
1200
+ return 431;
1201
+ }
1202
+
1203
+ MACHINE *m = registry_machine_find(machine_guid);
1204
+ if(!m) {
1205
+ registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1206
+ registry_json_footer(w);
1207
+ return 432;
1208
+ }
1209
+
1210
+ // verify the old person has access to this machine
1211
+ int count = dictionary_get_all(op->urls, registry_person_url_callback_verify_machine_exists, m);
1212
+ if(!count) {
1213
+ registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1214
+ registry_json_footer(w);
1215
+ return 433;
1216
+ }
1217
+
1218
+ // verify the new person has access to this machine
1219
+ count = dictionary_get_all(np->urls, registry_person_url_callback_verify_machine_exists, m);
1220
+ if(!count) {
1221
+ registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1222
+ registry_json_footer(w);
1223
+ return 434;
1224
+ }
1225
+
1226
+ // set the cookie of the new person
1227
+ // the user just switched identity
1228
+ registry_set_person_cookie(w, np);
1229
+
1230
+ // generate the response
1231
+ registry_json_header(w, "switch", REGISTRY_STATUS_OK);
1232
+ buffer_sprintf(w->response.data, ",\n\t\"person_guid\": \"%s\"", np->guid);
1233
+ registry_json_footer(w);
1234
+ return 200;
1235
+}
1236
+
1237
+
1238
// ----------------------------------------------------------------------------
1239
// REGISTRY THIS MACHINE UNIQUE ID
1240
src/registry.h
+1
@@ -8,6 +8,7 @@
8
extern int registry_request_access_json(struct web_client *w, char *person_guid, char *machine_guid, char *url, char *name, time_t when);
9
extern int registry_request_delete_json(struct web_client *w, char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when);
10
extern int registry_request_search_json(struct web_client *w, char *person_guid, char *machine_guid, char *url, char *request_machine, time_t when);
11
+extern int registry_request_switch_json(struct web_client *w, char *person_guid, char *machine_guid, char *url, char *new_person_guid, time_t when);
12
extern int registry_request_hello_json(struct web_client *w);
13
14
extern int registry_init(void);
src/web_client.c
+17
-7
@@ -812,7 +812,8 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
812
*machine_url = NULL,
813
*url_name = NULL,
814
*search_machine_guid = NULL,
815
- *delete_url = NULL;
815
+ *delete_url = NULL,
816
+ *to_person_guid = NULL;
817
818
while(url) {
819
char *value = mystrsep(&url, "?&[]");
@@ -829,6 +830,7 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
830
else if(!strcmp(value, "hello")) action = 'H';
831
else if(!strcmp(value, "delete")) action = 'D';
832
else if(!strcmp(value, "search")) action = 'S';
833
+ else if(!strcmp(value, "switch")) action = 'W';
834
}
835
else if(!strcmp(name, "machine"))
836
machine_guid = value;
@@ -848,6 +850,10 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
850
if(!strcmp(name, "for"))
851
search_machine_guid = value;
852
}
853
+ else if(action == 'W') {
854
+ if(!strcmp(name, "to"))
855
+ to_person_guid = value;
856
+ }
857
}
858
859
if(action == 'A' && (!machine_guid || !machine_url || !url_name)) {
@@ -868,15 +874,12 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
874
machine_guid?machine_guid:"UNSET", machine_url?machine_url:"UNSET", search_machine_guid?search_machine_guid:"UNSET");
875
return 400;
876
}
871
-
872
- /*
873
- * No, this is not right
874
- if(action != 'H' && !person_guid[0]) {
877
+ else if(action == 'W' && (!machine_guid || !machine_url || !to_person_guid)) {
878
buffer_flush(w->response.data);
876
- buffer_sprintf(w->response.data, "Invalid registry request - you need to send your cookie for this action.");
879
+ buffer_sprintf(w->response.data, "Invalid registry request - switching identity requires these parameters: machine ('%s'), url ('%s'), to ('%s')",
880
+ machine_guid?machine_guid:"UNSET", machine_url?machine_url:"UNSET", to_person_guid?to_person_guid:"UNSET");
881
return 400;
882
}
879
- */
883
884
switch(action) {
885
case 'A':
@@ -888,6 +891,9 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
891
case 'S':
892
return registry_request_search_json(w, person_guid, machine_guid, machine_url, search_machine_guid, time(NULL));
893
894
+ case 'W':
895
+ return registry_request_switch_json(w, person_guid, machine_guid, machine_url, to_person_guid, time(NULL));
896
+
897
case 'H':
898
return registry_request_hello_json(w);
899
@@ -1632,6 +1638,10 @@ void web_client_process(struct web_client *w) {
1638
code_msg = "Not Found";
1639
break;
1640
1641
+ case 412:
1642
+ code_msg = "Preconditions Failed";
1643
+ break;
1644
+
1645
default:
1646
code_msg = "Internal Server Error";
1647
break;
web/dashboard.js
+89
-31
@@ -496,7 +496,11 @@
496
407: { message: "Cannot HELLO netdata server", alert: false },
497
408: { message: "Netdata servers sent invalid response to HELLO", alert: false },
498
409: { message: "Cannot ACCESS netdata registry", alert: false },
499
- 410: { message: "Netdata registry ACCESS failed", alert: false }
499
+ 410: { message: "Netdata registry ACCESS failed", alert: false },
500
+ 411: { message: "Netdata registry server send invalid response to DELETE ", alert: false },
501
+ 412: { message: "Netdata registry DELETE failed", alert: false },
502
+ 413: { message: "Netdata registry server send invalid response to SWITCH ", alert: false },
503
+ 414: { message: "Netdata registry SWITCH failed", alert: false }
504
};
505
NETDATA.errorLast = {
506
code: 0,
@@ -5487,28 +5491,11 @@
5491
// Registry of netdata hosts
5492
5493
NETDATA.registry = {
5490
- server: null,
5491
- machine_guid: null,
5492
- hostname: null,
5493
- urls: null,
5494
-
5495
- init: function() {
5496
- if(typeof netdataNoRegistry !== 'undefined' && netdataNoRegistry)
5497
- return;
5498
-
5499
- NETDATA.registry.hello(NETDATA.serverDefault, function(data) {
5500
- if(data) {
5501
- NETDATA.registry.server = data.registry;
5502
- NETDATA.registry.machine_guid = data.machine_guid;
5503
- NETDATA.registry.hostname = data.hostname;
5504
-
5505
- NETDATA.registry.access(10, function (person_urls) {
5506
- NETDATA.registry.parsePersonUrls(person_urls);
5507
-
5508
- });
5509
- }
5510
- });
5511
- },
5494
+ server: null, // the netdata registry server
5495
+ person_guid: null, // the unique ID of this browser / user
5496
+ machine_guid: null, // the unique ID the netdata server that served dashboard.js
5497
+ hostname: null, // the hostname of the netdata server that served dashboard.js
5498
+ urls: null, // the user's other URLs
5499
5500
parsePersonUrls: function(person_urls) {
5501
if(person_urls) {
@@ -5543,6 +5530,24 @@
5530
netdataRegistryCallback(NETDATA.registry.urls);
5531
},
5532
5533
+ init: function() {
5534
+ if(typeof netdataNoRegistry !== 'undefined' && netdataNoRegistry)
5535
+ return;
5536
+
5537
+ NETDATA.registry.hello(NETDATA.serverDefault, function(data) {
5538
+ if(data) {
5539
+ NETDATA.registry.server = data.registry;
5540
+ NETDATA.registry.machine_guid = data.machine_guid;
5541
+ NETDATA.registry.hostname = data.hostname;
5542
+
5543
+ NETDATA.registry.access(10, function (person_urls) {
5544
+ NETDATA.registry.parsePersonUrls(person_urls);
5545
+
5546
+ });
5547
+ }
5548
+ });
5549
+ },
5550
+
5551
hello: function(host, callback) {
5552
// send HELLO to a netdata server:
5553
// 1. verifies the server is reachable
@@ -5572,11 +5577,12 @@
5577
5578
access: function(max_redirects, callback) {
5579
// send ACCESS to a netdata registry:
5575
- // 1. it let it know we are accessing a netdata server (in the URL)
5580
+ // 1. it lets it know we are accessing a netdata server (its machine GUID and its URL)
5581
// 2. it responds with a list of netdata servers we know
5582
// the registry identifies us using a cookie it sets the first time we access it
5583
+ // the registry may respond with a redirect URL to send us to another registry
5584
$.ajax({
5579
- url: NETDATA.registry.server + '/api/v1/registry?action=access&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&visible_url=' + encodeURIComponent(document.location),
5585
+ url: NETDATA.registry.server + '/api/v1/registry?action=access&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault), // + '&visible_url=' + encodeURIComponent(document.location),
5586
async: true,
5587
cache: false,
5588
xhrFields: { withCredentials: true } // required for the cookie
@@ -5586,24 +5592,76 @@
5592
if(typeof data.registry === 'string')
5593
redirect = data.registry;
5594
5589
- if(typeof data.status !== 'string' || data.status !== 'ok')
5595
+ if(typeof data.status !== 'string' || data.status !== 'ok') {
5596
+ NETDATA.error(409, NETDATA.registry.server + ' responded with: ' + JSON.stringify(data));
5597
data = null;
5598
+ }
5599
5600
if(data === null && redirect !== null && max_redirects > 0) {
5601
+ NETDATA.registry.server = redirect;
5602
NETDATA.registry.access(max_redirects - 1, callback);
5603
}
5595
- else if(data === null) {
5596
- NETDATA.error(409, NETDATA.registry.server + ' response: ' + JSON.stringify(data));
5597
- if(typeof callback === 'function')
5598
- callback(null);
5599
- }
5604
else {
5605
+ if(typeof data.person_guid === 'string')
5606
+ NETDATA.registry.person_guid = data.person_guid;
5607
+
5608
if(typeof callback === 'function')
5609
callback(data.urls);
5610
}
5611
})
5612
.fail(function() {
5613
NETDATA.error(410, NETDATA.registry.server);
5614
+
5615
+ if(typeof callback === 'function')
5616
+ callback(null);
5617
+ });
5618
+ },
5619
+
5620
+ delete: function(delete_url, callback) {
5621
+ // send DELETE to a netdata registry:
5622
+ $.ajax({
5623
+ url: NETDATA.registry.server + '/api/v1/registry?action=delete&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&delete_url=' + encodeURIComponent(delete_url),
5624
+ async: true,
5625
+ cache: false,
5626
+ xhrFields: { withCredentials: true } // required for the cookie
5627
+ })
5628
+ .done(function(data) {
5629
+ if(typeof data.status !== 'string' || data.status !== 'ok') {
5630
+ NETDATA.error(411, NETDATA.registry.server + ' responded with: ' + JSON.stringify(data));
5631
+ data = null;
5632
+ }
5633
+
5634
+ if(typeof callback === 'function')
5635
+ callback(data);
5636
+ })
5637
+ .fail(function() {
5638
+ NETDATA.error(412, NETDATA.registry.server);
5639
+
5640
+ if(typeof callback === 'function')
5641
+ callback(null);
5642
+ });
5643
+ },
5644
+
5645
+ switch: function(new_person_guid, callback) {
5646
+ // impersonate
5647
+ $.ajax({
5648
+ url: NETDATA.registry.server + '/api/v1/registry?action=switch&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&to=' + new_person_guid,
5649
+ async: true,
5650
+ cache: false,
5651
+ xhrFields: { withCredentials: true } // required for the cookie
5652
+ })
5653
+ .done(function(data) {
5654
+ if(typeof data.status !== 'string' || data.status !== 'ok') {
5655
+ NETDATA.error(413, NETDATA.registry.server + ' responded with: ' + JSON.stringify(data));
5656
+ data = null;
5657
+ }
5658
+
5659
+ if(typeof callback === 'function')
5660
+ callback(data);
5661
+ })
5662
+ .fail(function() {
5663
+ NETDATA.error(414, NETDATA.registry.server);
5664
+
5665
if(typeof callback === 'function')
5666
callback(null);
5667
});
web/index.html
+94
-28
@@ -362,23 +362,37 @@
362
363
var netdataRegistryCallback = function(urls) {
364
if(urls) {
365
+ var found = 0;
366
var el = '';
367
var a1 = '';
368
369
$.each(urls, function(i, u) {
369
- if(u.guid === NETDATA.registry.machine_guid)
370
- el += '<li id="registry_server_' + u.guid + '" class="active"><a href="' + u.url + '">' + u.name + '</a></li>';
371
- else
370
+ if(u.guid !== NETDATA.registry.machine_guid) {
371
+ found++;
372
el += '<li id="registry_server_' + u.guid + '"><a href="' + u.url + '">' + u.name + '</a></li>';
373
-
374
- a1 += '<li id="registry_action_' + u.guid + '"><a href="#" onclick="deleteRegistryModalHandler(\'' + u.guid + '\',\'' + u.name + '\',\'' + u.url + '\'); return false;"><i class="fa fa-trash-o" aria-hidden="true" style="color: #999;"></i></a></li>';
373
+ a1 += '<li id="registry_action_' + u.guid + '"><a href="#" onclick="deleteRegistryModalHandler(\'' + u.guid + '\',\'' + u.name + '\',\'' + u.url + '\'); return false;"><i class="fa fa-trash-o" aria-hidden="true" style="color: #999;"></i></a></li>';
374
+ }
375
});
376
+
377
+ if(!found) {
378
+ el += '<li><a href="https://github.com/firehol/netdata/wiki/mynetdata-menu-item" style="color: #666;" target="_blank">your netdata server list is empty...</a></li>';
379
+ a1 += '<li><a href="#"> </a></li>';
380
+
381
+ el += '<li role="separator" class="divider"></li>' +
382
+ '<li><a href="//london.netdata.rocks/default.html">EU - London (DigitalOcean.com)</a></li>' +
383
+ '<li><a href="//atlanta.netdata.rocks/default.html">US - Atlanta (CDN77.com)</a></li>' +
384
+ '<li><a href="//athens.netdata.rocks/default.html">EU - Athens</a></li>';
385
+ a1 += '<li role="separator" class="divider"></li>' +
386
+ '<li><a href="#"> </a></li>' +
387
+ '<li><a href="#"> </a></li>'+
388
+ '<li><a href="#"> </a></li>';
389
+ }
390
391
el += '<li role="separator" class="divider"></li>';
392
a1 += '<li role="separator" class="divider"></li>';
393
394
el += '<li><a href="https://github.com/firehol/netdata/wiki/mynetdata-menu-item" style="color: #999;" target="_blank">What is this?</a></li>';
381
- a1 += '<li><a href="https://github.com/firehol/netdata/wiki/mynetdata-menu-item" style="color: #999;" target="_blank"><i class="fa fa-question" aria-hidden="true" style="color: #999;"></i></a></li>'
395
+ a1 += '<li><a href="#" style="color: #999;" onclick="switchRegistryModalHandler(); return false;"><i class="fa fa-cog" aria-hidden="true" style="color: #999;"></i></a></li>'
396
397
document.getElementById('mynetdata_servers').innerHTML = el;
398
document.getElementById('mynetdata_actions1').innerHTML = a1;
@@ -404,12 +418,6 @@
418
<div class="row">
419
<div class="col-sm-6" style="width: 85%; padding-right: 0;">
420
<ul id="mynetdata_servers" class="multi-column-dropdown">
407
- <li><a href="//london.netdata.rocks/default.html">EU - London (DigitalOcean.com)</a></li>
408
- <li><a href="//atlanda.netdata.rocks/default.html">US - Atlanta (CDN77.com)</a></li>
409
- <li><a href="//athens.netdata.rocks/default.html">EU - Greece</a></li>
410
- <li role="separator" class="divider"></li>
411
- <li><a href="tv.html">TV Dashboard for 2 servers</a></li>
412
- <li><a href="demosites.html">Dashboard for monitoring netdata demo sites</a></li>
421
</ul>
422
</div>
423
<div class="col-sm-3 hidden-xs" style="width: 15%; padding-left: 0;">
@@ -447,12 +455,6 @@
455
<li class="dropdown hidden-sm hidden-md hidden-lg">
456
<a href="#" class="dropdown-toggle" data-toggle="dropdown" id="current_view">my-netdata <strong class="caret"></strong></a>
457
<ul id="mynetdata_servers2" class="dropdown-menu scrollable-menu inpagemenu" role="menu">
450
- <li><a href="//london.netdata.rocks/default.html">EU - London (DigitalOcean.com)</a></li>
451
- <li><a href="//atlanda.netdata.rocks/default.html">US - Atlanta (CDN77.com)</a></li>
452
- <li><a href="//athens.netdata.rocks/default.html">EU - Greece</a></li>
453
- <li role="separator" class="divider"></li>
454
- <li><a href="tv.html">TV Dashboard for 2 servers</a></li>
455
- <li><a href="demosites.html">Dashboard for monitoring netdata demo sites</a></li>
458
</ul>
459
</li>
460
</ul>
@@ -892,6 +894,8 @@
894
<br/>
895
<div style="padding: 10px;"></div>
896
<small>Keep in mind, this server will be added back if and when you visit it again.</small>
897
+ <br/>
898
+ <div id="deleteRegistryResponse" style="display: block; width: 100%; text-align: center; padding-top: 20px; color: #fff;"></div>
899
</div>
900
<div class="modal-footer">
901
<button type="button" class="btn btn-success" data-dismiss="modal">keep it</button>
@@ -901,6 +905,42 @@
905
</div>
906
</div>
907
908
+ <div class="modal fade" id="switchRegistryModal" tabindex="-1" role="dialog" aria-labelledby="switchRegistryModalLabel">
909
+ <div class="modal-dialog" role="document">
910
+ <div class="modal-content">
911
+ <div class="modal-header">
912
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
913
+ <h4 class="modal-title" id="switchRegistryModalLabel">Switch Netdata Registry Identity</h4>
914
+ </div>
915
+ <div class="modal-body">
916
+ You can copy and paste the following ID to all your browsers (e.g. work and home).
917
+ <br/>
918
+ All the browsers with the same ID will identify <b>you</b>, so please don't share this with others.
919
+ <p style="text-align: center; padding-top: 10px; padding-bottom: 10px; line-height: 2;">
920
+ <form action="#">
921
+ <input type="text" class="form-control" id="switchRegistryPersonGUID" placeholder="your personal ID" maxlength="36" autocomplete="off" style="text-align: center; font-size: 1.4em;">
922
+ </form>
923
+ </p>
924
+ Either copy this ID and paste it to another browser, or paste here the ID you have taken from another browser.
925
+ <p style="padding-top: 10px;"><small>
926
+ Keep in mind that:
927
+ <ul>
928
+ <li>when you switch ID, your previous ID will be lost forever - this is irreversible.</li>
929
+ <li>both IDs (your old and the new) must list this netdata at their personal lists.</li>
930
+ <li>both IDs have to be known by the registry: <b><span id="switchRegistryURL"></span></b>.</li>
931
+ <li>to get a new ID, just clear your browser cookies.</li>
932
+ </ul>
933
+ </small></p>
934
+ <div id="switchRegistryResponse" style="display: block; width: 100%; text-align: center; padding-top: 20px; color: #fff;"></div>
935
+ </div>
936
+ <div class="modal-footer">
937
+ <button type="button" class="btn btn-success" data-dismiss="modal">cancel</button>
938
+ <a href="#" onclick="notifyForSwitchRegistry(true);" type="button" class="btn btn-danger">impersonate</a>
939
+ </div>
940
+ </div>
941
+ </div>
942
+ </div>
943
+
944
<script>
945
var this_is_demo = null;
946
function isdemo() {
@@ -928,9 +968,33 @@ if(isdemo()) {
968
document.getElementById('masthead').style.display = 'block';
969
}
970
931
-var deleteRegistryGuid = null;
971
+function switchRegistryModalHandler() {
972
+ document.getElementById('switchRegistryPersonGUID').value = NETDATA.registry.person_guid;
973
+ document.getElementById('switchRegistryURL').innerHTML = NETDATA.registry.server;
974
+ $('#switchRegistryModal').modal('show');
975
+}
976
+
977
+function notifyForSwitchRegistry() {
978
+ var n = document.getElementById('switchRegistryPersonGUID').value;
979
+
980
+ if(n !== '' && n.length === 36) {
981
+ NETDATA.registry.switch(n, function(result) {
982
+ if(result !== null) {
983
+ $('#switchRegistryModal').modal('hide');
984
+ NETDATA.registry.init();
985
+ }
986
+ else {
987
+ document.getElementById('switchRegistryResponse').innerHTML = "<b>Sorry! The registry rejected your request.</b>";
988
+ }
989
+ });
990
+ }
991
+ else
992
+ document.getElementById('switchRegistryResponse').innerHTML = "<b>The ID you have entered is not a GUID.</b>";
993
+}
994
+
995
+var deleteRegistryUrl = null;
996
function deleteRegistryModalHandler(guid, name, url) {
933
- deleteRegistryGuid = guid;
997
+ deleteRegistryUrl = url;
998
document.getElementById('deleteRegistryServerName').innerHTML = name;
999
document.getElementById('deleteRegistryServerName2').innerHTML = name;
1000
document.getElementById('deleteRegistryServerURL').innerHTML = url;
@@ -938,16 +1002,18 @@ function deleteRegistryModalHandler(guid, name, url) {
1002
}
1003
1004
function notifyForDeleteRegistry() {
941
-/* if(deleteRegistryGuid) {
942
- NETDATA.registry.delete(deleteRegistryGuid, function() {
943
- console.log('delete called callback');
944
- NETDATA.registry.init();
1005
+ if(deleteRegistryUrl) {
1006
+ NETDATA.registry.delete(deleteRegistryUrl, function(result) {
1007
+ if(result !== null) {
1008
+ deleteRegistryUrl = null;
1009
+ $('#deleteRegistryModal').modal('hide');
1010
+ NETDATA.registry.init();
1011
+ }
1012
+ else {
1013
+ document.getElementById('deleteRegistryResponse').innerHTML = "<b>Sorry! this command was rejected by the registry server.</b>";
1014
+ }
1015
});
1016
}
947
-
948
- deleteRegistryGuid = null;
949
- $('#deleteRegistryModal').modal('hide');
950
-*/
1017
}
1018
1019
var options = {