diff options
author | grant-kun <[email protected]> | 2022-10-19 08:42:39 -0500 |
---|---|---|
committer | grant-kun <[email protected]> | 2022-10-19 08:42:39 -0500 |
commit | 1f82c948ac210dc03dadf243d5441139cd50ab03 (patch) | |
tree | 236abd3f6686f9d9a4ef5932af1043033055e728 | |
parent | 11bfeb2d410acf5e5faca67215341289fdaf8462 (diff) |
email reg
-rw-r--r-- | html/mail.html | 43 | ||||
-rw-r--r-- | index.ts | 18 |
2 files changed, 50 insertions, 11 deletions
diff --git a/html/mail.html b/html/mail.html index 7dc9951..857dc1b 100644 --- a/html/mail.html +++ b/html/mail.html @@ -312,21 +312,46 @@ let emails = [] let bod let html = false + function reg() { + console.log(document.getElementById('email').value) + sendenc('/reg', { 'address': document.getElementById('email').value, 'host': document.getElementById('host').value, 'port': document.getElementById('port').value, 'creds': document.getElementById('auth').value }).then(() => { + update() + }) + } function update() { //console.log('hi') let promie = new Promise((resolve, reject) => { sendenc('/get/update', { 'user': 'root', 'requested': 0, 'login_key': getCookie('login_key') }).then(res => { res = JSON.parse(res) console.log('parsed') - emails = res.messages.reverse() - //console.log(res) - console.log(res) - bod = res.bod - if (res.bod == 'body[2]') { - html = true + if (res.messages == 'reg') { + document.body.style.backgroundColor = '#444444' + document.body.innerHTML = ` + <h1>welcome! please add an email:)</h1> + + email: <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;'id="email"></input> + </br> + auth/password: <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;'type="password" id="auth"></input> + </br> + host: <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;'id="host"></input> + </br> + port: <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;'value='993' id="port"></input> + </br> + <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;' type='button' value='submit' onclick='reg()'> + `; + } else { + + + emails = res.messages.reverse() + //console.log(res) + console.log(res) + bod = res.bod + if (res.bod == 'body[2]') { + html = true + } + umail() + resolve(res) } - umail() - resolve(res) }) }) return promie @@ -436,7 +461,7 @@ if (getCookie('login_key') == null) { window.location.href = '/' } - await init() + await update() //return //document.getElementsByClassName('loading')[0].style.display = 'none' let xx = document.getElementsByClassName('card')[0] @@ -123,6 +123,13 @@ app.post('/mail/get/update',async(req:any,res:any)=>{ mail =JSON.parse(decrypt(user.mail,logkey)).emails[parseInt(dec.data.requested)] } } + if(mail==''){ + const skey = new NodeRSA() + let mail; + skey.importKey(keyring[req.body.sid].theirpub,'pkcs8-public') + res.send(JSON.stringify({data:skey.encrypt(JSON.stringify({messages:'reg'}),'base64'),enc:true,html:true})) + return + } var client = new ImapClient(mail.host, parseInt(mail.port), { auth: { user: mail.address, @@ -181,7 +188,7 @@ app.post('/mail/del',async(req:any,res:any)=>{ key.importKey(keyring[req.body.sid].mypriv,'pkcs1-private') let dec:any = JSON.parse((atob(key.decrypt(req.body.data,'base64','base64')))) const users:any = await User.findAll(); - let logkey:any,mail:any + let logkey:any,mail:any; for(let user of users){ //console.log(user,dec) if(user.name==dec.data.user){ @@ -254,6 +261,13 @@ app.post('/mail/get/storage',async(req:any,res:any)=>{ mail =JSON.parse(decrypt(user.mail,logkey)) } } + if(mail==''){ + const skey = new NodeRSA() + let mail; + skey.importKey(keyring[req.body.sid].theirpub,'pkcs8-public') + res.send(JSON.stringify({data:skey.encrypt(JSON.stringify({messages:'reg'}),'base64'),enc:true,html:true})) + return + } let d = skey.encrypt((mail.emails[parseInt(dec.data.requested)].storage),'base64') res.send(JSON.stringify({data:d,enc:true,html:true})) }) @@ -361,4 +375,4 @@ httpsServer.listen(443, function https() { /* todo: -*/
\ No newline at end of file +*/ |