Skip to content

Commit

Permalink
all messages configured in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPaglusch committed Jul 24, 2020
1 parent abcb219 commit 93c7ed6
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 45 deletions.
4 changes: 2 additions & 2 deletions html/confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<fieldset style="text-align: center">
<div class="form-group row float-middle">
<div class="col">
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 15px; font-size: 30px; font-weight: bold; padding-bottom: 1%">View this secret?</label>
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 15px; font-size: 30px; font-weight: bold; padding-bottom: 1%"><?php echo $settings['messages']['confirm_view_secret_header'] ?></label>
<br />
<form method="post" action="./">
<input type="hidden" name="k" value="<?php echo $_GET['k'] ?>">
<button type="submit" onclick="this.disabled=true;this.form.submit();" class="btn btn-primary w-20 mx-auto">View Secret</button>
<button type="submit" onclick="this.disabled=true;this.form.submit();" class="btn btn-primary w-20 mx-auto"><?php echo $settings['messages']['confirm_view_secret_button'] ?></button>
</form>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions html/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<form class="form-horizontal" action="" method="POST">
<fieldset>
<div>
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 30px; font-weight: bold;"><?php echo $message_title; ?></label>
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 30px; font-weight: bold;"><?php echo $settings['messages']['submit_secret_header']; ?></label>
<div style="font-style: italic">
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 15px; font-weight: bold;"><?php echo $message_subtitle; ?></label>
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 15px; font-weight: bold;"><?php echo $settings['messages']['submit_secret_subheader'] ?></label>
</div>
<div style="margin-top:10px">
<textarea class="form-control" id="secret" name="secret" rows="8" maxlength="<?php echo constant('MAX_INPUT_LENGTH') ?>" style="resize: vertical;" placeholder="Secret text..."><?php echo $template_text ?></textarea>
Expand All @@ -29,7 +29,7 @@
</div>
<div class="form-group row float-left" style='padding-top: 3%'>
<div class="col">
<button name="submit" type="submit" class="btn btn-primary">Encrypt Message</button>
<button name="submit" type="submit" class="btn btn-primary"><?php echo $settings['messages']['submit_secret_button'] ?></button>
</div>
</div>
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion html/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# https://raw.githubusercontent.com/AndrewPaglusch/FlashPaper/master/LICENSE #
######################################################################################
-->
<title><?php echo env('SITE_TITLE') ?></title>
<title><?php echo $settings['site_title'] ?></title>
<!-- Meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
Expand Down
4 changes: 2 additions & 2 deletions html/message.php → html/view_code.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<div id="form-div">
<fieldset>
<div>
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 30px; font-weight: bold;"><?php echo $message_title; ?></label>
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 30px; font-weight: bold;"><?php echo $settings['messages']['view_code_header'] ?></label>
<div style="font-style: italic">
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 15px; font-weight: bold;"><?php echo $message_subtitle; ?></label>
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 15px; font-weight: bold;"><?php echo $settings['messages']['view_code_subheader'] ?></label>
</div>
<div style="margin-top:10px">
<textarea readonly class="form-control" name="secret" rows="8" style="resize: vertical;"><?php echo $message ?></textarea>
Expand Down
14 changes: 14 additions & 0 deletions html/view_secret.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php defined('_DIRECT_ACCESS_CHECK') or exit(); ?>
<div id="form-div">
<fieldset>
<div>
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 30px; font-weight: bold;"><?php echo $settings['messages']['view_secret_header'] ?></label>
<div style="font-style: italic">
<label style="font-family: 'Enriqueta', arial, serif; line-height: 1.25; margin: 0 0 10px; font-size: 15px; font-weight: bold;"><?php echo $settings['messages']['view_secret_subheader'] ?></label>
</div>
<div style="margin-top:10px">
<textarea readonly class="form-control" name="secret" rows="8" style="resize: vertical;"><?php echo $message ?></textarea>
</div>
</div>
</fieldset>
</div>
43 changes: 14 additions & 29 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
<?php
#Settings
define('RETURN_FULL_URL', true);
define('MAX_INPUT_LENGTH', 3000);
define('DATA_DIR', 'data');

define('_DIRECT_ACCESS_CHECK', 1);

# check everything before we proceed
require_once("includes/sanitycheck.php");

require_once("settings.php");

require_once("includes/functions.php");

require_once('html/header.php');

if (isset($_GET['k'])) {
#**User is trying to view a secret**
require_once('html/confirm.php');

} elseif (isset($_POST['k'])) {
#**User confirmed viewing the secret**
try {
$secret = retrieve_secret($_POST['k']);
$message = htmlentities($secret);
$message_title = "Self-Destructing Message";
$message_subtitle = "This message has been destroyed";

require_once('html/message.php');
require_once('html/view_secret.php');
} catch (Exception $e) {
$error_message = $e->getMessage();
require_once('html/error.php');
}

} elseif (isset($_POST['submit'])) {
#**User just submitted a secret. Show them the generated URL**
try {
$incoming_text = $_POST['secret'];

if ( strlen($incoming_text) > constant('MAX_INPUT_LENGTH') ) {
if ( strlen($incoming_text) > $settings['max_secret_length'] ) {
throw new exception("Input length too long");
}

$k = store_secret($incoming_text);

if (constant('RETURN_FULL_URL') == true) {
if ($settings['return_full_url'] == true) {
# construct retrieval url
if ( isset($_SERVER['REQUEST_SCHEME']) ) {
$scheme = $_SERVER['REQUEST_SCHEME'] . '://'; # https://
Expand All @@ -56,39 +52,28 @@

# display URL to user
$message = "${scheme}${hostname}${path}${args}";
$message_title = "Self-Destructing URL";
$message_subtitle = "Share this URL via email, chat, or another messaging service. It will self-destruct after being viewed once.";
require_once('html/message.php');
require_once('html/view_code.php');
} else {
# display 'k' value of URL to user
$message = $k;
$message_title = "Self-Destructing Message Code";
$message_subtitle = "Share this code with the person who requested it. Your message will self-destruct after being viewed once.";
require_once('html/message.php');
require_once('html/view_code.php');
}
} catch (Exception $e) {
$error_message = $e->getMessage();
require_once('html/error.php');
}

} else {
#**User is loading the main page**

#Get template from URL (if any)
$template_text = "";

try {
if (isset($_GET['t']) && $_GET['t'] != "") {
$template_text = file_get_contents('templates/' . basename($_GET['t'] . '.txt'));
}

$message_title = "Create A Self-Destructing Message";
$message_subtitle = "";
if (isset($_GET['t']) && $_GET['t'] != "") {
$template_text = file_get_contents('templates/' . basename($_GET['t'] . '.txt'));
}

require_once('html/form.php');
} catch (Exception $e) {
$error_message = "Template can not be found!";
require_once('html/error.php');
}
require_once('html/form.php');
}

require_once('html/footer.php');
Expand Down
29 changes: 21 additions & 8 deletions settings.example.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
<?php
defined('_DIRECT_ACCESS_CHECK') or exit();

defined('_DIRECT_ACCESS_CHECK') or exit();
$settings = [
'site_title' => 'FlashPaper :: Self-Destructing Message',
'return_full_url' => true,
'max_secret_length' => 3000,
'messages' => [
'error_secret_too_long' => 'Input length too long',

$variables = [
'SITE_TITLE' => 'FlashPaper :: Self-Destructing Message',
];
'submit_secret_header' => 'Create A Self-Destructing Message',
'submit_secret_subheader' => '',
'submit_secret_button' => 'Encrypt Message',

foreach ($variables as $key => $value) {
putenv("$key=$value");
}
?>
'view_code_header' => 'Self-Destructing URL',
'view_code_subheader' => 'Share this URL via email, chat, or another messaging service. It will self-destruct after being viewed once.',

'confirm_view_secret_header' => 'View this secret?',
'confirm_view_secret_button' => 'View Secret',

'view_secret_header' => 'Self-Destructing Message',
'view_secret_subheader' => 'This message has been destroyed',
]
];
?>

0 comments on commit 93c7ed6

Please sign in to comment.