From e0ba0d8f1c630923568405f4ff96ba04311ec5fd Mon Sep 17 00:00:00 2001 From: "matt (tomatoj)" <53126325+mattprocoder@users.noreply.github.com> Date: Tue, 2 Jun 2020 15:29:58 +0200 Subject: [PATCH] Release --- README.md | 43 ++++++++++++- src/assets/css/style.css | 37 +++++++++++ src/assets/js/script.js | 92 +++++++++++++++++++++++++++ src/assets/php/check-email-prefix.php | 6 ++ src/assets/php/database-logging.php | 63 ++++++++++++++++++ src/assets/php/delete-old-emails.php | 27 ++++++++ src/assets/php/get-emails.php | 63 ++++++++++++++++++ src/assets/php/get-imap-details.php | 35 ++++++++++ src/index.php | 53 +++++++++++++++ src/message/index.php | 32 ++++++++++ src/templates/info.txt | 2 + src/templates/preview.html | 42 ++++++++++++ src/templates/template.php | 28 ++++++++ src/templates/template2.php | 14 ++++ src/templates/view.html | 32 ++++++++++ src/view/index.php | 74 +++++++++++++++++++++ 16 files changed, 641 insertions(+), 2 deletions(-) create mode 100644 src/assets/css/style.css create mode 100644 src/assets/js/script.js create mode 100644 src/assets/php/check-email-prefix.php create mode 100644 src/assets/php/database-logging.php create mode 100644 src/assets/php/delete-old-emails.php create mode 100644 src/assets/php/get-emails.php create mode 100644 src/assets/php/get-imap-details.php create mode 100644 src/index.php create mode 100644 src/message/index.php create mode 100644 src/templates/info.txt create mode 100644 src/templates/preview.html create mode 100644 src/templates/template.php create mode 100644 src/templates/template2.php create mode 100644 src/templates/view.html create mode 100644 src/view/index.php diff --git a/README.md b/README.md index 14982bb..3aed530 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,41 @@ -# PHP Temporary Email - Temporary email created with 99% of PHP(imap) and 1% of JS +# Temporary Email made with PHP + +You can check its live version at [billieiscute.xyz](https://billieiscute.xyz/temp/) +PHP-Temporary-Email is self-hosted temporary email library. You can use it on any website that has PHP IMAP + +## Installation + +Clone this repositary + +```bash +git clone https://github.com/xxx/xx +``` +Install IMAP for php (Linux) +```bash +sudo apt-get install php5-imap +sudo php5enmod imap +``` +Install IMAP for php (MacOS) +```bash +brew reinstall php56 --with-imap +``` + +Open 'assets/php/get-imap-details.php' +Set IMAP connection details in format +```php +imap_open("{address}", "username", "password"); +``` +Set other details such as delete timeframe and so on. + + +## Usage + +After this you can deploy the repo on your server. + +## Contributing +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. + +Please make sure to update tests as appropriate. + +## License +[GNU AGPLv3](https://choosealicense.com/licenses/agpl-3.0/) \ No newline at end of file diff --git a/src/assets/css/style.css b/src/assets/css/style.css new file mode 100644 index 0000000..5be7de3 --- /dev/null +++ b/src/assets/css/style.css @@ -0,0 +1,37 @@ +body{ + color: white; +} +.change-on-hover:hover{ + color: rgb(255, 0, 157); + font-weight: bolder; +} +.message-header{ + position: absolute; + top: 30%; + left: 22%; +} +.message-body{ + position: absolute; + top: 45%; + left:14vw; + padding:1rem 30%; + border-radius: 10px; + margin-bottom: 2rem; +} +.footer{ + position: fixed; + left: 0; + bottom: 0; + width: 100%; + background-color: #111111; + color: white; + text-align: center; +} +.footer a{ + font-weight: bolder; + color:rgb(255, 0, 157); + text-decoration: none; +} +.footer a:hover{ + color:blue; +} \ No newline at end of file diff --git a/src/assets/js/script.js b/src/assets/js/script.js new file mode 100644 index 0000000..a148b69 --- /dev/null +++ b/src/assets/js/script.js @@ -0,0 +1,92 @@ +function CheckEmailOnLoad(){ + if(GatherCookie('t_email_address_1').length != 0) + { + //If cookie already exist, get email address from it and set it as current email address + var current_address = GatherCookie('t_email_address_1'); + document.getElementById("mail-field").value = current_address; + document.cookie = "t_email_address_1="+current_address+"; expires=Jan, 1 Dec 2999 12:00:00 UTC"; + } + else{ + //If cookie doesn't exist, generate random address, and set it as current. + var current_address = GenerateRandomAddress(8).toLowerCase()+"@billieiscute.xyz"; + document.getElementById("mail-field").value = current_address; + document.cookie = "t_email_address_1="+current_address+"; expires=Jan, 1 Dec 2999 12:00:00 UTC"; + } + setTimeout(function() { location.reload(); }, 25000); +} +function CopyEmailAddress(){ + //Copy all informations into clipboard, basic js function. + var copyText = document.getElementById("mail-field"); + copyText.select(); + copyText.setSelectionRange(0, 99999); + copyText.select + document.execCommand("copy"); +} +function ChangeEmailAddress(){ + //Check if email address is blacklisted, if it is, use random address instead + if(CheckEmailAddress((document.getElementById("mail-field").value).split('@')[0])) + { + //Email address is blacklisted + var current_address = GenerateRandomAddress(8).toLowerCase()+"@billieiscute.xyz"; + document.getElementById("mail-field").value = current_address; + document.cookie = "t_email_address_1="+current_address+"; expires=Jan, 1 Dec 2999 12:00:00 UTC"; + location.reload(); + } + else + { + //Email address isn't blacklisted + document.getElementById("mail-field").value = document.getElementById("mail-field").value+"@billieiscute.xyz"; + var current_address = document.getElementById("mail-field").value; + document.cookie = "t_email_address_1="+current_address+"; expires=Jan, 1 Dec 2999 12:00:00 UTC"; + location.reload(); + } +} +//Gather the cookie, as cookies are not being saved as string value; +function GatherCookie(cname) { + var name = cname + "="; + var decodedCookie = decodeURIComponent(document.cookie); + var ca = decodedCookie.split(';'); + for(var i = 0; i \ No newline at end of file diff --git a/src/assets/php/database-logging.php b/src/assets/php/database-logging.php new file mode 100644 index 0000000..5337c7a --- /dev/null +++ b/src/assets/php/database-logging.php @@ -0,0 +1,63 @@ +connect_error) + { + //Error occured, do some action you want to do + //Redirect, log, or return some value here + } + + $sql = "INSERT INTO $table_name (email_address, accessed_by, unix_timestamp,date_time) + VALUES ('$email_adress','$accessed_by','$unix','$date_unix')"; //Get table, select fields and insert values into it + + if ($conn->query($sql) === TRUE) + { + //Record successfully saved into database + //You can continue in logging here, or eventually display message / return value + } + else + { + //Error occured when writing into databse, do some action here. + //You can put redirect, messages and so on here. + } + + $conn->close(); +} +function GetAccessedBy() +{ + //Get every single possible redirect, and get ip address from it (you can't get address behind VPN with this) + //I recommend encrypting the output. So in case of data breach nothing will be 'leaked' + //I'm not doing it here, as I wouldn't be able to debug on localhost then. + $ipaddress = ''; + if (isset($_SERVER['HTTP_CLIENT_IP'])) + $ipaddress = $_SERVER['HTTP_CLIENT_IP']; + else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) + $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; + else if(isset($_SERVER['HTTP_X_FORWARDED'])) + $ipaddress = $_SERVER['HTTP_X_FORWARDED']; + else if(isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) + $ipaddress = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; + else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) + $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; + else if(isset($_SERVER['HTTP_FORWARDED'])) + $ipaddress = $_SERVER['HTTP_FORWARDED']; + else if(isset($_SERVER['REMOTE_ADDR'])) + $ipaddress = $_SERVER['REMOTE_ADDR']; + else + $ipaddress = 'UNKNOWN'; + return $ipaddress; +} +?> \ No newline at end of file diff --git a/src/assets/php/delete-old-emails.php b/src/assets/php/delete-old-emails.php new file mode 100644 index 0000000..18ac62e --- /dev/null +++ b/src/assets/php/delete-old-emails.php @@ -0,0 +1,27 @@ +Nmsgs}",0); //Get overview of messages in catchall inbox. + foreach(array_reverse($imap_result) as $email) + { + //Delete the email only if it's not already deleted. + if($email->deleted !=1) + { + $email_timestamp = $email->udate; + if(time()-GetDeleteTime() > $email_timestamp) + { + imap_delete($imap, $email->msgno); + } + } + } + //Delete all messages marked for delete, you can command the line below and keep them in your 'trash bin' + imap_expunge($imap); + imap_close($imap); +} +?> \ No newline at end of file diff --git a/src/assets/php/get-emails.php b/src/assets/php/get-emails.php new file mode 100644 index 0000000..5a74244 --- /dev/null +++ b/src/assets/php/get-emails.php @@ -0,0 +1,63 @@ +Nmsgs}",0); + foreach(array_reverse($imap_result) as $email) + { + //Check if the email address isn't blacklisted, if it is, don't display anything. + if(!BlacklistedEmailAddresses(explode('@',$email_address)[0])) + { + if($email->deleted !=1) + { + //Go through all emails, but display only emails for the current email address + if($email->to == $email_address && $messages_displayed <= $max_messages_on_screen) + { + $messages_displayed += 1; + $message_id = $email->msgno; + $header = imap_header($imap, $message_id); + //The part of message we'll display as preview, you can change how many characters you want to display below. + $characters_to_display = 50; + $message_preview = substr(imap_fetchbody($imap, $message_id, 1), 0, $characters_to_display); + $sender_address = $header->from[0]->mailbox."@".$header->from[0]->host; + //Display all email as separate table raw. + //You can change this by chaning the echo below onto your own one + echo "$sender_address$email->subject$message_preview"; + } + $email_timestamp = $email->udate; + //Check for every email if it's older than 7 days. If it is, delete. + //This is only used when the page is loaded by someone, if you want to automate this in cron jobs please check 'delete-old-emails.php' + //You can change delete timeframe in 'get-imap-details.php' + if(time()-GetDeleteTime() > $email_timestamp) + { + imap_delete($imap, $email->msgno); //Mark message with specific id as 'for delete' + } + } + } + else + { + $email_in_blacklist = true; //Email is in blacklist, don't display anything. + } + } + //Display this content if there are no messages matching this email address + if($messages_displayed == 0 && !$email_in_blacklist){ + echo "This inbox is completely empty"; + } + //Display if current email address is in blacklist, thus user can't access its content + else if($email_in_blacklist){ + echo "You can't view this email address"; + } + //Delete all messages marked for delete, you can command the line below and keep them in your 'trash bin' + imap_expunge($imap); + imap_close($imap); +} +?> \ No newline at end of file diff --git a/src/assets/php/get-imap-details.php b/src/assets/php/get-imap-details.php new file mode 100644 index 0000000..eea1ad9 --- /dev/null +++ b/src/assets/php/get-imap-details.php @@ -0,0 +1,35 @@ + \ No newline at end of file diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..88cc7c6 --- /dev/null +++ b/src/index.php @@ -0,0 +1,53 @@ + + + + + + + + + Billie is cute || Temporary E-Mail + + +
+ +
+ BillieISCute +
+
+ Temporary E-mail +
+
+
+
+ E-mail address (click to copy) +
+ +
+
+
+ + + + + + + + + + + +
FromTitlePreview
+
+ + + + + \ No newline at end of file diff --git a/src/message/index.php b/src/message/index.php new file mode 100644 index 0000000..b9b51b4 --- /dev/null +++ b/src/message/index.php @@ -0,0 +1,32 @@ +"; + echo $message_body; + } + else{ + echo "Message with id $message_id doesn't exist"; + die(); + } +} +?> \ No newline at end of file diff --git a/src/templates/info.txt b/src/templates/info.txt new file mode 100644 index 0000000..a7dd2df --- /dev/null +++ b/src/templates/info.txt @@ -0,0 +1,2 @@ +All templates i've created and used later in this project. +You can use them as inspiration. \ No newline at end of file diff --git a/src/templates/preview.html b/src/templates/preview.html new file mode 100644 index 0000000..83c4ea2 --- /dev/null +++ b/src/templates/preview.html @@ -0,0 +1,42 @@ + + + + + + + + Billie is cute || Temporary E-Mail + + +
+
+ BillieISCute +
+
+ Temporary E-mail +
+
+
+ E-mail address (click to copy) +
+ +
+
+
+ + + + + + + + + + + +
FromTitlePreview
$sender_address$email->subject$message_preview
+
+ + + + \ No newline at end of file diff --git a/src/templates/template.php b/src/templates/template.php new file mode 100644 index 0000000..72ecaa4 --- /dev/null +++ b/src/templates/template.php @@ -0,0 +1,28 @@ +Mailboxes\n"; +$folders = imap_listmailbox($mbox, "{imap.example.org:143}", "*"); + +if ($folders == false) { + echo "Call failed
\n"; +} else { + foreach ($folders as $val) { + echo $val . "
\n"; + } +} + +echo "

Headers in INBOX

\n"; +$headers = imap_headers($mbox); + +if ($headers == false) { + echo "Call failed
\n"; +} else { + foreach ($headers as $val) { + print_r(imap_header($mbox,$val["number"])); + echo $val . "
\n"; + } +} + +imap_close($mbox); +?> \ No newline at end of file diff --git a/src/templates/template2.php b/src/templates/template2.php new file mode 100644 index 0000000..970641d --- /dev/null +++ b/src/templates/template2.php @@ -0,0 +1,14 @@ +Nmsgs}",0); +foreach ($result as $overview) { + echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from} + {$overview->subject} {$overview->to}\n"; +} +imap_close($mbox); +?> \ No newline at end of file diff --git a/src/templates/view.html b/src/templates/view.html new file mode 100644 index 0000000..458b282 --- /dev/null +++ b/src/templates/view.html @@ -0,0 +1,32 @@ + + + + + + + + Billie is cute || Temporary E-Mail || Viewing $message_id + + +
+
+ BillieISCute +
+
+ Temporary E-mail +
+
+
+
+ From : $address_from +
To : $address_to +
On : $message_date +
Message: +
+
+ this is test email +
+
+
+ + \ No newline at end of file diff --git a/src/view/index.php b/src/view/index.php new file mode 100644 index 0000000..a9ca5c6 --- /dev/null +++ b/src/view/index.php @@ -0,0 +1,74 @@ +Deleted == 'D') + { + header('Location: '.GetNotFoundPage()); + die(); + } + $from = $header->from[0]->personal; + $from_address = $header->from[0]->mailbox."@".$header->from[0]->host; + $to_address = $header->toaddress; + $title = $header->subject; + $date = $header->date; + $message_body = imap_fetchbody($imap, $message_id, 1); + //Convert all links in emails to simple href, so in case the link is really long it won't display the site in some weird way. + //It'll simply convert https://test.com into link + preg_match_all('/\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i', $message_body, $result, PREG_PATTERN_ORDER); + foreach($result as $links){ + foreach($links as $link){ + $message_body = str_replace($link,"link",$message_body); + } + } +} +else{ + //Redirect to error page in case email with specific id doesn't exist + header('Location: '.GetNotFoundPage()); + die(); +} +?> + + + + + + + + Billie is cute || Temporary E-Mail - Viewing <?php echo $message_id;?> + + +
+ +
+ BillieISCute +
+
+ Temporary E-mail +
+
+
+
+
+ From: +
From Address: +
To: +
On: +
Title: +
Message: +
+
+ +
+
+
+ + + \ No newline at end of file