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",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -20,3 +20,5 @@ serde = "1.0.123"
|
|||
serde_json = "1.0.62"
|
||||
rand = "0.8.3"
|
||||
futures = "0.3.12"
|
||||
|
||||
sha1 = "0.6.0"
|
||||
|
|
@ -3,3 +3,4 @@
|
|||
# Lupt Chat
|
||||
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 static_path: String,
|
||||
pub bind_address: String,
|
||||
pub bind_address: String
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
|
@ -22,7 +22,7 @@ impl Config {
|
|||
.author(env!("CARGO_PKG_AUTHORS"))
|
||||
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||||
.arg(Arg::with_name("static_path")
|
||||
.short("s")
|
||||
.short("p")
|
||||
.long("static_path")
|
||||
.value_name("DIR")
|
||||
.help("Path of directory with index.html")
|
||||
|
|
@ -35,6 +35,13 @@ impl Config {
|
|||
.help("Address to bind for server")
|
||||
.required(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();
|
||||
|
||||
Config {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,12 @@ pub struct LeaveUser {
|
|||
}
|
||||
|
||||
//################################################## For WsSansad ##################################################
|
||||
// Request to send own kunjika hash
|
||||
#[derive(Clone, Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct WsKunjikaHash {
|
||||
pub kunjika: String
|
||||
}
|
||||
// Request to send transfer text
|
||||
#[derive(Clone, Message)]
|
||||
#[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
|
||||
impl Handler<ms::WsResponse> for WsSansad {
|
||||
type Result = ();
|
||||
|
|
@ -269,6 +281,12 @@ impl WsSansad {
|
|||
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") {
|
||||
Some(val ) => val.as_str().unwrap().to_owned(),
|
||||
None => {
|
||||
|
|
@ -308,13 +326,17 @@ impl WsSansad {
|
|||
|
||||
match result {
|
||||
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 => {
|
||||
self.addr.clone().unwrap().do_send(ms::WsResponse{
|
||||
result: "watch".to_owned() ,
|
||||
message: "Watchlist".to_owned()
|
||||
});
|
||||
self.isthiti = Isthiti::VraktigatWaitlist;
|
||||
self.addr.clone().unwrap().do_send(ms::WsKunjikaHash{ kunjika: kunjika.clone() });
|
||||
self.kunjika = kunjika
|
||||
}
|
||||
}
|
||||
|
|
@ -376,6 +398,12 @@ impl WsSansad {
|
|||
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") {
|
||||
Some(val ) => val.as_str().unwrap().to_owned(),
|
||||
None => {
|
||||
|
|
@ -425,6 +453,7 @@ impl WsSansad {
|
|||
Resp::Err(err) => self.send_err_response(&err),
|
||||
Resp::Ok => {
|
||||
self.isthiti = Isthiti::Kaksh(kaksh_kunjika);
|
||||
self.addr.clone().unwrap().do_send(ms::WsKunjikaHash{ kunjika: kunjika.clone() });
|
||||
self.kunjika = kunjika;
|
||||
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>
|
||||
</h4>
|
||||
</header>
|
||||
<div style="overflow-y: scroll; max-height: calc(100% - 40px);">
|
||||
<div style="overflow-y: scroll; height: calc(100% - 40px);">
|
||||
<table>
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
|
|
|
|||
|
|
@ -85,8 +85,7 @@ let Messages = class {
|
|||
})
|
||||
text = text.substr(0, text.length-1);
|
||||
text += ' is typing...'
|
||||
$('#status_area').append($('<div>', { id: 'typing',
|
||||
class:'siimple-label siimple--mx-2 siimple--my-0' }).append(text));
|
||||
$('#status_area').append($('<div>', { id: 'typing' }).append(text));
|
||||
|
||||
var scroll = $("#message_area_scroll");
|
||||
scroll.scrollTop(scroll[0].scrollHeight);
|
||||
|
|
@ -100,14 +99,12 @@ let Messages = class {
|
|||
if(sender == myinfo.kunjika)
|
||||
elm.append($('<div>', {class: 'message-by'}).append('me'))
|
||||
else
|
||||
elm.append($('<div>', {class: 'message-by'}).append(vayakti[sender]+'('+sender+')'))
|
||||
} else {
|
||||
elm.addClass('siimple--py-1');
|
||||
}
|
||||
elm.append($('<div>', {class: 'message-by'}).append(vayakti[sender]+'('+sender.substr(0, 8)+')'))
|
||||
}
|
||||
if(reply != null && reply.length > 0) {
|
||||
elm.append(
|
||||
$('<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));
|
||||
|
|
@ -295,6 +292,9 @@ socket.addEventListener('message', function (event) {
|
|||
actions.execute();
|
||||
}
|
||||
break;
|
||||
case 'kunjika':
|
||||
myinfo.kunjika = j.kunjika;
|
||||
break;
|
||||
case 'random':
|
||||
actions.execute();
|
||||
actions.clear_key('join');
|
||||
|
|
@ -318,12 +318,12 @@ socket.addEventListener('message', function (event) {
|
|||
case 'connected':
|
||||
vayakti[j.kunjika] = j.name;
|
||||
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;
|
||||
case 'disconnected':
|
||||
delete vayakti[j.kunjika];
|
||||
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;
|
||||
case 'left':
|
||||
myinfo.kunjika = '';
|
||||
|
|
@ -355,7 +355,6 @@ function connect(frm) {
|
|||
|
||||
actions.add('join', function() {
|
||||
Messages.cleanMessage();
|
||||
myinfo.kunjika = data.kunjika;
|
||||
myinfo.name = data.name;
|
||||
no_name_message = false;
|
||||
joining = false;
|
||||
|
|
@ -363,7 +362,7 @@ function connect(frm) {
|
|||
typing = [];
|
||||
State.chat();
|
||||
State.hideProgress();
|
||||
Messages.pushStatus('Connected at '+Messages.currentTime());
|
||||
Messages.pushStatus('Connected as '+data.name+' at '+Messages.currentTime());
|
||||
socket.send(JSON.stringify({cmd: 'list'}));
|
||||
})
|
||||
|
||||
|
|
@ -380,7 +379,7 @@ function connect_next() {
|
|||
vayakti = [];
|
||||
typing = [];
|
||||
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: 'randnext' }));
|
||||
|
|
@ -437,7 +436,7 @@ function refreshVayaktiList() {
|
|||
v.empty();
|
||||
Object.keys(vayakti).forEach((key) => {
|
||||
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