Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!empty($_POST)) {
- $errors = array();
- $sieveScript = $_POST['script'];
- $emailBody = $_POST['body'];
- if (empty($sieveScript)) {
- $errors[] = 'The script contents cannot be empty.';
- }
- if (empty($emailBody)) {
- $errors[] = 'The email body cannot be empty.';
- }
- if (count($errors) === 0) {
- $tmpScript = tempnam(sys_get_temp_dir(), '');
- $tmpBody = tempnam(sys_get_temp_dir(), '');
- $handle = fopen($tmpScript, 'w');
- fwrite($handle, $sieveScript);
- fclose($handle);
- $handle = fopen($tmpBody, 'w');
- fwrite($handle, $emailBody);
- fclose($handle);
- $cmd = 'sieve-test "' . $tmpScript . '" "' . $tmpBody . '" 2>&1 1> /dev/null';
- $output = shell_exec($cmd);
- unlink($tmpScript);
- unlink($tmpBody);
- }
- }
- ?>
- <html>
- <head>
- <style type="text/css">
- .fullWidth {
- width:100%;
- }
- .quarterHeight {
- height:25%;
- }
- .error {
- color:red;
- }
- </style>
- </head>
- <form method="post" name="form" action="">
- <h2>Sieve Script</h2>
- <div>
- <textarea name="script" class="fullWidth quarterHeight"><?php if (isset($sieveScript)) { echo $sieveScript; } ?></textarea>
- </div>
- <h2>Email Body</h2>
- </div>
- <div>
- <textarea name="body" class="fullWidth quarterHeight"><?php if (isset($emailBody)) { echo $emailBody; } ?></textarea>
- </div>
- <input type="submit" value="Test Script" />
- <?php
- echo '<h2>Output</h2>';
- if (isset($errors) && count($errors) > 0) {
- foreach ($errors as $error) {
- echo '<div class="error">' . $error . '</div>';
- }
- }
- if (isset($output)) {
- echo '<pre>' . $output . '</pre>';
- }
- elseif (!isset($errors)) {
- echo '[No input provided]';
- }
- echo '</div>';
- ?>
- </form>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement