mirror of https://github.com/PiyushXCoder/lupt.git
hashes
This commit is contained in:
parent
900d45b540
commit
cf35411bc4
|
|
@ -1087,6 +1087,7 @@ dependencies = [
|
||||||
"rand 0.8.3",
|
"rand 0.8.3",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"sha1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,5 @@ serde = "1.0.123"
|
||||||
serde_json = "1.0.62"
|
serde_json = "1.0.62"
|
||||||
rand = "0.8.3"
|
rand = "0.8.3"
|
||||||
futures = "0.3.12"
|
futures = "0.3.12"
|
||||||
|
|
||||||
|
sha1 = "0.6.0"
|
||||||
|
|
@ -3,3 +3,4 @@
|
||||||
# Lupt Chat
|
# Lupt Chat
|
||||||
Chat app to talk in group or to strangers
|
Chat app to talk in group or to strangers
|
||||||
|
|
||||||
|
export SALT as environment variable to use as salt for hashing.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use clap::{App, Arg};
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub static_path: String,
|
pub static_path: String,
|
||||||
pub bind_address: String,
|
pub bind_address: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
@ -22,7 +22,7 @@ impl Config {
|
||||||
.author(env!("CARGO_PKG_AUTHORS"))
|
.author(env!("CARGO_PKG_AUTHORS"))
|
||||||
.about(env!("CARGO_PKG_DESCRIPTION"))
|
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||||||
.arg(Arg::with_name("static_path")
|
.arg(Arg::with_name("static_path")
|
||||||
.short("s")
|
.short("p")
|
||||||
.long("static_path")
|
.long("static_path")
|
||||||
.value_name("DIR")
|
.value_name("DIR")
|
||||||
.help("Path of directory with index.html")
|
.help("Path of directory with index.html")
|
||||||
|
|
@ -35,6 +35,13 @@ impl Config {
|
||||||
.help("Address to bind for server")
|
.help("Address to bind for server")
|
||||||
.required(true)
|
.required(true)
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
|
.arg(Arg::with_name("salt")
|
||||||
|
.short("s")
|
||||||
|
.long("salt")
|
||||||
|
.value_name("SALT")
|
||||||
|
.help("Salt for hashing")
|
||||||
|
.required(false)
|
||||||
|
.takes_value(true))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,12 @@ pub struct LeaveUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
//################################################## For WsSansad ##################################################
|
//################################################## For WsSansad ##################################################
|
||||||
|
// Request to send own kunjika hash
|
||||||
|
#[derive(Clone, Message)]
|
||||||
|
#[rtype(result = "()")]
|
||||||
|
pub struct WsKunjikaHash {
|
||||||
|
pub kunjika: String
|
||||||
|
}
|
||||||
// Request to send transfer text
|
// Request to send transfer text
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,18 @@ impl Handler<ms::WsList> for WsSansad {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Own Kunjika hash
|
||||||
|
impl Handler<ms::WsKunjikaHash> for WsSansad {
|
||||||
|
type Result = ();
|
||||||
|
fn handle(&mut self, msg: ms::WsKunjikaHash, ctx: &mut Self::Context) -> Self::Result {
|
||||||
|
let json = json!({
|
||||||
|
"cmd": "kunjika",
|
||||||
|
"kunjika": msg.kunjika
|
||||||
|
});
|
||||||
|
ctx.text(json.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// send response ok, error
|
/// send response ok, error
|
||||||
impl Handler<ms::WsResponse> for WsSansad {
|
impl Handler<ms::WsResponse> for WsSansad {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
|
|
@ -269,6 +281,12 @@ impl WsSansad {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// kunjika to hash
|
||||||
|
let mut m = sha1::Sha1::new();
|
||||||
|
m.update(format!("{}{}",kunjika,
|
||||||
|
std::env::var("SALT").unwrap_or("".to_owned())).as_bytes());
|
||||||
|
let kunjika = m.digest().to_string();
|
||||||
|
|
||||||
let name = match val.get("name") {
|
let name = match val.get("name") {
|
||||||
Some(val ) => val.as_str().unwrap().to_owned(),
|
Some(val ) => val.as_str().unwrap().to_owned(),
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -308,13 +326,17 @@ impl WsSansad {
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Resp::Err(err) => self.send_err_response(&err),
|
Resp::Err(err) => self.send_err_response(&err),
|
||||||
Resp::Ok => self.kunjika = kunjika,
|
Resp::Ok => {
|
||||||
|
self.addr.clone().unwrap().do_send(ms::WsKunjikaHash{ kunjika: kunjika.clone() });
|
||||||
|
self.kunjika = kunjika;
|
||||||
|
},
|
||||||
Resp::None => {
|
Resp::None => {
|
||||||
self.addr.clone().unwrap().do_send(ms::WsResponse{
|
self.addr.clone().unwrap().do_send(ms::WsResponse{
|
||||||
result: "watch".to_owned() ,
|
result: "watch".to_owned() ,
|
||||||
message: "Watchlist".to_owned()
|
message: "Watchlist".to_owned()
|
||||||
});
|
});
|
||||||
self.isthiti = Isthiti::VraktigatWaitlist;
|
self.isthiti = Isthiti::VraktigatWaitlist;
|
||||||
|
self.addr.clone().unwrap().do_send(ms::WsKunjikaHash{ kunjika: kunjika.clone() });
|
||||||
self.kunjika = kunjika
|
self.kunjika = kunjika
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -376,6 +398,12 @@ impl WsSansad {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// kunjika to hash
|
||||||
|
let mut m = sha1::Sha1::new();
|
||||||
|
m.update(format!("{}{}",kunjika,
|
||||||
|
std::env::var("SALT").unwrap_or("".to_owned())).as_bytes());
|
||||||
|
let kunjika = m.digest().to_string();
|
||||||
|
|
||||||
let name = match val.get("name") {
|
let name = match val.get("name") {
|
||||||
Some(val ) => val.as_str().unwrap().to_owned(),
|
Some(val ) => val.as_str().unwrap().to_owned(),
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -425,6 +453,7 @@ impl WsSansad {
|
||||||
Resp::Err(err) => self.send_err_response(&err),
|
Resp::Err(err) => self.send_err_response(&err),
|
||||||
Resp::Ok => {
|
Resp::Ok => {
|
||||||
self.isthiti = Isthiti::Kaksh(kaksh_kunjika);
|
self.isthiti = Isthiti::Kaksh(kaksh_kunjika);
|
||||||
|
self.addr.clone().unwrap().do_send(ms::WsKunjikaHash{ kunjika: kunjika.clone() });
|
||||||
self.kunjika = kunjika;
|
self.kunjika = kunjika;
|
||||||
self.send_ok_response("joined")
|
self.send_ok_response("joined")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -179,7 +179,7 @@
|
||||||
<button onclick="$('#vayakti_model').addClass('is-hidden'); $('#vayakti_list').empty()" class="button bg-red" style="float: right;"><img src="img/close.svg" alt="X" style="height: 1.8rem; width: auto; cursor: pointer;"></button>
|
<button onclick="$('#vayakti_model').addClass('is-hidden'); $('#vayakti_list').empty()" class="button bg-red" style="float: right;"><img src="img/close.svg" alt="X" style="height: 1.8rem; width: auto; cursor: pointer;"></button>
|
||||||
</h4>
|
</h4>
|
||||||
</header>
|
</header>
|
||||||
<div style="overflow-y: scroll; max-height: calc(100% - 40px);">
|
<div style="overflow-y: scroll; height: calc(100% - 40px);">
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,7 @@ let Messages = class {
|
||||||
})
|
})
|
||||||
text = text.substr(0, text.length-1);
|
text = text.substr(0, text.length-1);
|
||||||
text += ' is typing...'
|
text += ' is typing...'
|
||||||
$('#status_area').append($('<div>', { id: 'typing',
|
$('#status_area').append($('<div>', { id: 'typing' }).append(text));
|
||||||
class:'siimple-label siimple--mx-2 siimple--my-0' }).append(text));
|
|
||||||
|
|
||||||
var scroll = $("#message_area_scroll");
|
var scroll = $("#message_area_scroll");
|
||||||
scroll.scrollTop(scroll[0].scrollHeight);
|
scroll.scrollTop(scroll[0].scrollHeight);
|
||||||
|
|
@ -100,14 +99,12 @@ let Messages = class {
|
||||||
if(sender == myinfo.kunjika)
|
if(sender == myinfo.kunjika)
|
||||||
elm.append($('<div>', {class: 'message-by'}).append('me'))
|
elm.append($('<div>', {class: 'message-by'}).append('me'))
|
||||||
else
|
else
|
||||||
elm.append($('<div>', {class: 'message-by'}).append(vayakti[sender]+'('+sender+')'))
|
elm.append($('<div>', {class: 'message-by'}).append(vayakti[sender]+'('+sender.substr(0, 8)+')'))
|
||||||
} else {
|
|
||||||
elm.addClass('siimple--py-1');
|
|
||||||
}
|
}
|
||||||
if(reply != null && reply.length > 0) {
|
if(reply != null && reply.length > 0) {
|
||||||
elm.append(
|
elm.append(
|
||||||
$('<div>', {class: 'message message-reply'})
|
$('<div>', {class: 'message message-reply'})
|
||||||
.append($('<pre>', {class: 'siimple--my-0 siimple--pt-1'}).append(reply))
|
.append($('<pre>').append(reply))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
elm.append($('<pre>').append(text));
|
elm.append($('<pre>').append(text));
|
||||||
|
|
@ -295,6 +292,9 @@ socket.addEventListener('message', function (event) {
|
||||||
actions.execute();
|
actions.execute();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'kunjika':
|
||||||
|
myinfo.kunjika = j.kunjika;
|
||||||
|
break;
|
||||||
case 'random':
|
case 'random':
|
||||||
actions.execute();
|
actions.execute();
|
||||||
actions.clear_key('join');
|
actions.clear_key('join');
|
||||||
|
|
@ -318,12 +318,12 @@ socket.addEventListener('message', function (event) {
|
||||||
case 'connected':
|
case 'connected':
|
||||||
vayakti[j.kunjika] = j.name;
|
vayakti[j.kunjika] = j.name;
|
||||||
if(!$('#vayakti_model').hasClass('.is-hidden')) refreshVayaktiList();
|
if(!$('#vayakti_model').hasClass('.is-hidden')) refreshVayaktiList();
|
||||||
Messages.pushStatus('Vyakti '+j.name+' connected as '+j.kunjika+' at '+Messages.currentTime());
|
Messages.pushStatus('Vyakti '+j.name+' connected as '+j.kunjika.substr(0,8)+' at '+Messages.currentTime());
|
||||||
break;
|
break;
|
||||||
case 'disconnected':
|
case 'disconnected':
|
||||||
delete vayakti[j.kunjika];
|
delete vayakti[j.kunjika];
|
||||||
if(!$('#vayakti_model').hasClass('.is-hidden')) refreshVayaktiList();
|
if(!$('#vayakti_model').hasClass('.is-hidden')) refreshVayaktiList();
|
||||||
Messages.pushStatus('Vyakti '+j.name+' disconnected as '+j.kunjika+' at '+Messages.currentTime());
|
Messages.pushStatus('Vyakti '+j.name+' disconnected as '+j.kunjika.substr(0,8)+' at '+Messages.currentTime());
|
||||||
break;
|
break;
|
||||||
case 'left':
|
case 'left':
|
||||||
myinfo.kunjika = '';
|
myinfo.kunjika = '';
|
||||||
|
|
@ -355,7 +355,6 @@ function connect(frm) {
|
||||||
|
|
||||||
actions.add('join', function() {
|
actions.add('join', function() {
|
||||||
Messages.cleanMessage();
|
Messages.cleanMessage();
|
||||||
myinfo.kunjika = data.kunjika;
|
|
||||||
myinfo.name = data.name;
|
myinfo.name = data.name;
|
||||||
no_name_message = false;
|
no_name_message = false;
|
||||||
joining = false;
|
joining = false;
|
||||||
|
|
@ -363,7 +362,7 @@ function connect(frm) {
|
||||||
typing = [];
|
typing = [];
|
||||||
State.chat();
|
State.chat();
|
||||||
State.hideProgress();
|
State.hideProgress();
|
||||||
Messages.pushStatus('Connected at '+Messages.currentTime());
|
Messages.pushStatus('Connected as '+data.name+' at '+Messages.currentTime());
|
||||||
socket.send(JSON.stringify({cmd: 'list'}));
|
socket.send(JSON.stringify({cmd: 'list'}));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -380,7 +379,7 @@ function connect_next() {
|
||||||
vayakti = [];
|
vayakti = [];
|
||||||
typing = [];
|
typing = [];
|
||||||
State.hideProgress();
|
State.hideProgress();
|
||||||
Messages.pushStatus('Connected at '+Messages.currentTime());
|
Messages.pushStatus('Connectedas '+data.name+' at '+Messages.currentTime());
|
||||||
socket.send(JSON.stringify({cmd: 'list'}));
|
socket.send(JSON.stringify({cmd: 'list'}));
|
||||||
});
|
});
|
||||||
socket.send(JSON.stringify({ cmd: 'randnext' }));
|
socket.send(JSON.stringify({ cmd: 'randnext' }));
|
||||||
|
|
@ -437,7 +436,7 @@ function refreshVayaktiList() {
|
||||||
v.empty();
|
v.empty();
|
||||||
Object.keys(vayakti).forEach((key) => {
|
Object.keys(vayakti).forEach((key) => {
|
||||||
v.append($('<tr>')
|
v.append($('<tr>')
|
||||||
.append($('<td>').append(key))
|
.append($('<td>').append(vayakti[key]))
|
||||||
.append($('<td>').append(vayakti[key])));
|
.append($('<td>').append(key)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
/*!
|
|
||||||
autosize 4.0.2
|
|
||||||
license: MIT
|
|
||||||
http://www.jacklmoore.com/autosize
|
|
||||||
*/
|
|
||||||
!function(e,t){if("function"==typeof define&&define.amd)define(["module","exports"],t);else if("undefined"!=typeof exports)t(module,exports);else{var n={exports:{}};t(n,n.exports),e.autosize=n.exports}}(this,function(e,t){"use strict";var n,o,p="function"==typeof Map?new Map:(n=[],o=[],{has:function(e){return-1<n.indexOf(e)},get:function(e){return o[n.indexOf(e)]},set:function(e,t){-1===n.indexOf(e)&&(n.push(e),o.push(t))},delete:function(e){var t=n.indexOf(e);-1<t&&(n.splice(t,1),o.splice(t,1))}}),c=function(e){return new Event(e,{bubbles:!0})};try{new Event("test")}catch(e){c=function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!1),t}}function r(r){if(r&&r.nodeName&&"TEXTAREA"===r.nodeName&&!p.has(r)){var e,n=null,o=null,i=null,d=function(){r.clientWidth!==o&&a()},l=function(t){window.removeEventListener("resize",d,!1),r.removeEventListener("input",a,!1),r.removeEventListener("keyup",a,!1),r.removeEventListener("autosize:destroy",l,!1),r.removeEventListener("autosize:update",a,!1),Object.keys(t).forEach(function(e){r.style[e]=t[e]}),p.delete(r)}.bind(r,{height:r.style.height,resize:r.style.resize,overflowY:r.style.overflowY,overflowX:r.style.overflowX,wordWrap:r.style.wordWrap});r.addEventListener("autosize:destroy",l,!1),"onpropertychange"in r&&"oninput"in r&&r.addEventListener("keyup",a,!1),window.addEventListener("resize",d,!1),r.addEventListener("input",a,!1),r.addEventListener("autosize:update",a,!1),r.style.overflowX="hidden",r.style.wordWrap="break-word",p.set(r,{destroy:l,update:a}),"vertical"===(e=window.getComputedStyle(r,null)).resize?r.style.resize="none":"both"===e.resize&&(r.style.resize="horizontal"),n="content-box"===e.boxSizing?-(parseFloat(e.paddingTop)+parseFloat(e.paddingBottom)):parseFloat(e.borderTopWidth)+parseFloat(e.borderBottomWidth),isNaN(n)&&(n=0),a()}function s(e){var t=r.style.width;r.style.width="0px",r.offsetWidth,r.style.width=t,r.style.overflowY=e}function u(){if(0!==r.scrollHeight){var e=function(e){for(var t=[];e&&e.parentNode&&e.parentNode instanceof Element;)e.parentNode.scrollTop&&t.push({node:e.parentNode,scrollTop:e.parentNode.scrollTop}),e=e.parentNode;return t}(r),t=document.documentElement&&document.documentElement.scrollTop;r.style.height="",r.style.height=r.scrollHeight+n+"px",o=r.clientWidth,e.forEach(function(e){e.node.scrollTop=e.scrollTop}),t&&(document.documentElement.scrollTop=t)}}function a(){u();var e=Math.round(parseFloat(r.style.height)),t=window.getComputedStyle(r,null),n="content-box"===t.boxSizing?Math.round(parseFloat(t.height)):r.offsetHeight;if(n<e?"hidden"===t.overflowY&&(s("scroll"),u(),n="content-box"===t.boxSizing?Math.round(parseFloat(window.getComputedStyle(r,null).height)):r.offsetHeight):"hidden"!==t.overflowY&&(s("hidden"),u(),n="content-box"===t.boxSizing?Math.round(parseFloat(window.getComputedStyle(r,null).height)):r.offsetHeight),i!==n){i=n;var o=c("autosize:resized");try{r.dispatchEvent(o)}catch(e){}}}}function i(e){var t=p.get(e);t&&t.destroy()}function d(e){var t=p.get(e);t&&t.update()}var l=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?((l=function(e){return e}).destroy=function(e){return e},l.update=function(e){return e}):((l=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],function(e){return r(e)}),e}).destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],i),e},l.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],d),e}),t.default=l,e.exports=t.default});
|
|
||||||
Loading…
Reference in New Issue