From 02d1a5977daa650290004a6cd2b4b591ca75b59e Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 18 Aug 2019 21:02:04 +0200 Subject: [PATCH] added admin email account that can see all emails on all acounts --- docker/rootfs/start.sh | 5 +++++ example.config.ini | 4 ++++ web/api.php | 28 ++++++++++++++++++++++++++-- web/inc/core.php | 15 +++++++++++++++ web/js/opentrashmail.js | 24 +++++++++++++++++++----- 5 files changed, 69 insertions(+), 7 deletions(-) diff --git a/docker/rootfs/start.sh b/docker/rootfs/start.sh index edc154d..9bfc2fc 100644 --- a/docker/rootfs/start.sh +++ b/docker/rootfs/start.sh @@ -28,6 +28,11 @@ if [ "$DOMAINS" != "" ]; then echo " [i] Active Domain(s): $DOMAINS" fi +if [ "$ADMIN" != "" ]; then + echo "ADMIN=$ADMIN" >> /var/www/opentrashmail/config.ini + echo " [i] Set admin to: $ADMIN" +fi + echo "[MAILSERVER]" >> /var/www/opentrashmail/config.ini echo "PORT=25" >> /var/www/opentrashmail/config.ini diff --git a/example.config.ini b/example.config.ini index c179743..24f67ba 100644 --- a/example.config.ini +++ b/example.config.ini @@ -4,6 +4,10 @@ ; Enter your domains here. Comma separated if multiple DOMAINS=yourdomain,sub.yourdomain +; Enter the admin email address. If you choose this email on the website you will see all emails from all users +; The email doesn't really have to exist or have mail but must look like an email address +;ADMIN=some@random.email + [MAILSERVER] ; Port that the Mailserver will run on (default 25 but that needs root) MAILPORT=25 \ No newline at end of file diff --git a/web/api.php b/web/api.php index e62be31..d37e95b 100644 --- a/web/api.php +++ b/web/api.php @@ -53,14 +53,38 @@ switch($action) break; case 'list': + $settings = loadSettings(); if(!filter_var($email, FILTER_VALIDATE_EMAIL)) $o = array('status'=>'err','reason'=>'Invalid Email address'); + else if($settings['ADMIN'] && $settings['ADMIN']==$email) + { + $o['status'] = 'ok'; + $o['type'] = 'admin'; + $emails = listEmailAdresses(); + $emaillist = array(); + + if(count($emails)) + { + foreach($emails as $email) + { + $emaildata = getEmailsOfEmail($email); + foreach($emaildata as $time=>$d) + { + $emaillist[$time.'-'.$email]=$d; + } + } + if(is_array($emaillist)) + ksort($emaillist); + $data = (count($emaillist)?$emaillist:array()); + } + + $o['emails']=$data; + } else if(!is_dir(ROOT.DS.'..'.DS.'data'.DS.$email)) $o = array('status'=>'ok','emails'=>[]); else { $data = getEmailsOfEmail($email); - $lastid = $_REQUEST['lastid']; if($lastid && is_numeric($lastid)) { @@ -72,7 +96,7 @@ switch($action) $data = (is_array($emails)?$emails:array()); } - $o = array('status'=>'ok','emails'=>$data); + $o = array('status'=>'ok','emails'=>$data); } break; } diff --git a/web/inc/core.php b/web/inc/core.php index 3cb6dae..e6593ea 100644 --- a/web/inc/core.php +++ b/web/inc/core.php @@ -46,6 +46,21 @@ function getEmailsOfEmail($email) return $o; } +function listEmailAdresses() +{ + $o = array(); + $o = false; + if ($handle = opendir(ROOT.DS.'..'.DS.'data'.DS)) { + while (false !== ($entry = readdir($handle))) { + if(filter_var($entry, FILTER_VALIDATE_EMAIL)) + $o[] = $entry; + } + closedir($handle); + } + + return $o; +} + function loadSettings() { if(file_exists(ROOT.DS.'..'.DS.'config.ini')) diff --git a/web/js/opentrashmail.js b/web/js/opentrashmail.js index e726001..4694fdc 100644 --- a/web/js/opentrashmail.js +++ b/web/js/opentrashmail.js @@ -37,7 +37,7 @@ function renderEmail(email,id,data) btns+=''+filename+'' } $("#main").html('

'+email+'

\ - \ + \ '+(data.parsed.body?'
'+data.parsed.body+'
':'')+' \ '+(data.parsed.htmlbody?'
'+data.parsed.htmlbody+'':'')+' \ '+(btns!==''?'

Attachments

'+btns:'')+'\ @@ -56,7 +56,7 @@ function loadAccount(email) \ \ \ - \ + \ \ \ \ @@ -84,22 +84,36 @@ function updateEmailTable() console.log("Checking mail for "+email) $.get("api.php?a=list&email="+email+"&lastid="+lastid,function(data){ - if(data.status=="ok") { + var admin=false; + if(data.type=="admin") + { + clearInterval(timer); + admin = true; + $('#tableheader').children(':eq(1)').after(''); + } + if(Object.keys(data.emails).length>0) for(em in data.emails) { if($("#nomailyet").length != 0) $("#nomailyet").remove(); + if(admin===true) + { + dateofemail=em.split("-")[0]; + email = em.substring(em.indexOf('-') + 1); + } + else dateofemail = em; if(em>lastid) lastid = em; - var date = new Date(parseInt(em)) + var date = new Date(parseInt(dateofemail)) var datestring = date.getDate()+"."+date.getMonth()+"."+date.getFullYear()+" "+date.getHours()+":"+date.getMinutes(); var ed = data.emails[em] $("#emailtable").append('\ - \ + \ \ \ + '+(admin===true?'':'')+'\ \ \ ');
#DateFromTo
'+(index++)+''+datestring+''+email+''+ed.from.toHtmlEntities()+''+ed.subject.toHtmlEntities()+'