fixed bug with websockets list; added <form autocomplete="on"> to pass/login

This commit is contained in:
Edward Emelianov 2020-10-30 16:03:05 +03:00
parent 6a8837f345
commit 366c1cd936
2 changed files with 7 additions and 3 deletions

View File

@ -98,17 +98,18 @@ void register_WS(onion_websocket *ws){
void send_all_WS(char *data){ void send_all_WS(char *data){
if(strlen(data) == 0) return; // zero length if(strlen(data) == 0) return; // zero length
WSlist *l = wslist; WSlist *l = wslist;
if(!l) return;
int cnt = 0; int cnt = 0;
unregister_WS(); // check for dead ws unregister_WS(); // check for dead ws
while(l){ while(l){
DBG("try to send"); //DBG("try to send");
if(onion_websocket_printf(l->ws, "%s", data) <= 0){ // dead websocket? remove it from list if(onion_websocket_printf(l->ws, "%s", data) <= 0){ // dead websocket? remove it from list
DBG("Error printing - check for dead"); DBG("Error printing - check for dead");
unregister_WS(); unregister_WS();
}else ++cnt; }else ++cnt;
l = l->next; l = l->next;
} }
DBG("Send message %s to %d clients", data, cnt); //DBG("Send message %s to %d clients", data, cnt);
} }
void unregister_WS(){ void unregister_WS(){
@ -128,6 +129,7 @@ void unregister_WS(){
wslist->last = l->prev; // we should delete last element wslist->last = l->prev; // we should delete last element
} }
WSlist *nxt = l->next; WSlist *nxt = l->next;
if(l == wslist) wslist = nxt; // delete the first element
FREE(l); FREE(l);
l = nxt; l = nxt;
continue; continue;

View File

@ -43,7 +43,9 @@ auth = function(){
s.type = 'text/css'; s.type = 'text/css';
s.innerHTML = '.shadow{position:absolute;text-align:center;vertical-align:center;top:0;display:none;left:0;width:100%;height:100%;background-color:lightGrey;opacity:0.9;}'; s.innerHTML = '.shadow{position:absolute;text-align:center;vertical-align:center;top:0;display:none;left:0;width:100%;height:100%;background-color:lightGrey;opacity:0.9;}';
document.body.appendChild(s); document.body.appendChild(s);
d.innerHTML = "<div>Login:</div><div><input type=text id='login'></div><div>Password:</div><div><input type=password id='passwd'></div><button onclick='auth.send();'>OK</button>"; d.innerHTML = "<form autocomplete='on'><div>Login:</div><div><input type='text' id='login' name='username'>" +
"</div><div>Password:</div><div><input type='password' id='passwd' name='password'>" +
"</div><button onclick='auth.send();'>OK</button></form>";
d.className = "shadow"; d.className = "shadow";
document.body.appendChild(d); document.body.appendChild(d);
} }