AdminReport.php
changeset 0 cda2c95b368d
child 1 13ac3d9d47b2
equal deleted inserted replaced
-1:000000000000 0:cda2c95b368d
       
     1 <?php
       
     2 /**!info**
       
     3 {
       
     4   "Plugin Name"  : "Admin report generator",
       
     5   "Plugin URI"   : "http://enanocms.org/plugin/adminreport",
       
     6   "Description"  : "Allow users to report bugs with the site, including with automatic links that fill everything in.",
       
     7   "Author"       : "Dan Fuhry",
       
     8   "Version"      : "1.0",
       
     9   "Author URI"   : "http://enanocms.org/"
       
    10 }
       
    11 **!*/
       
    12 
       
    13 $plugins->attachHook('session_started', 'register_special_page(\'AdminReport\', \'Report site bug\', true);');
       
    14 
       
    15 function page_Special_AdminReport()
       
    16 {
       
    17 	global $db, $session, $paths, $template, $plugins; // Common objects
       
    18 	global $output;
       
    19 	
       
    20 	// parse parameters
       
    21 	$parms = str_replace('_', ' ', dirtify_page_id($paths->getAllParams()));
       
    22 	$replaces = array();
       
    23 	if ( preg_match_all('/<(.+?)>/', $parms, $matches) )
       
    24 	{
       
    25 		foreach ( $matches[0] as $i => $match )
       
    26 		{
       
    27 			$replaces[] = $matches[1][$i];
       
    28 			$parms = str_replace_once($match, "\${$i}\$", $parms);
       
    29 		}
       
    30 	}
       
    31 	
       
    32 	$parms = explode('/', $parms);
       
    33 	$info = array(
       
    34 			'page' => '',
       
    35 			'comment' => ''
       
    36 		);
       
    37 	foreach ( $parms as $parm )
       
    38 	{
       
    39 		list($name) = explode('=', $parm);
       
    40 		$info[$name] = substr($parm, strlen($name)+1);
       
    41 		foreach ( $replaces as $i => $val )
       
    42 		{
       
    43 			$info[$name] = str_replace_once("\${$i}\$", $val, $info[$name]);
       
    44 		}
       
    45 	}
       
    46 	
       
    47 	$output->header();
       
    48 	
       
    49 	$errors = array();
       
    50 	if ( isset($_POST['submit']) )
       
    51 	{
       
    52 		$page = $_POST['page'];
       
    53 		$comment = trim($_POST['comment']);
       
    54 		$captcha_input = $_POST['captcha_response'];
       
    55 		$captcha_id = $_POST['captcha_id'];
       
    56 		if ( strtolower($captcha_input) !== ($correct = strtolower($session->get_captcha($captcha_id))) )
       
    57 		{
       
    58 			$errors[] = 'The confirmation code you entered was incorrect. '; // . "($captcha_input vs. $correct)";
       
    59 		}
       
    60 		$session->kill_captcha();
       
    61 		if ( empty($comment) )
       
    62 		{
       
    63 			$errors[] = 'Please enter a description of the problem.';
       
    64 		}
       
    65 		else
       
    66 		{
       
    67 			$info['comment'] = $comment;
       
    68 		}
       
    69 		
       
    70 		if ( empty($errors) )
       
    71 		{
       
    72 			$email = getConfig('contact_email');
       
    73 			
       
    74 			if ( !is_array($result = arp_send_mail($email, "[{$_SERVER['HTTP_HOST']}] Website bug report", "Sent from IP: {$_SERVER['REMOTE_ADDR']}\n\n---------------------------\n$comment)")) )
       
    75 			{
       
    76 				redirect(makeUrl($page), 'Report sent', 'Thank you, your report has been sent. Redirecting you back to the page...', 5);
       
    77 			}
       
    78 			else
       
    79 			{
       
    80 				$errors = $result;
       
    81 			}
       
    82 		}
       
    83 		
       
    84 		$info['page'] = $_POST['page'];
       
    85 	}
       
    86 	
       
    87 	$captchacode = $session->make_captcha();
       
    88 	if ( !empty($errors) )
       
    89 	{
       
    90 		echo '<div class="error-box-mini"><ul><li>' .
       
    91 				implode('</li><li>', $errors) .
       
    92 				'</li></ul></div>';
       
    93 	}
       
    94 	?>
       
    95 	<form method="post" action="<?php echo makeUrl($paths->page); ?>">
       
    96 		<div class="tblholder">
       
    97 			<table border="0" cellspacing="1" cellpadding="4">
       
    98 				<tr>
       
    99 					<th colspan="2">Report a site bug</th>
       
   100 				</tr>
       
   101 				<tr>
       
   102 					<td class="row1">
       
   103 						URL of page:
       
   104 					</td>
       
   105 					<td class="row1">
       
   106 						http<?php if ( $GLOBALS['is_https'] ) echo 's'; ?>://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); 
       
   107 						echo contentPath; ?><input type="text" name="page" value="<?php echo htmlspecialchars($info['page']); ?>" />
       
   108 					</td>
       
   109 				</tr>
       
   110 				<tr>
       
   111 					<td class="row2">
       
   112 						The problem:
       
   113 					</td>
       
   114 					<td class="row2">
       
   115 						<textarea name="comment" rows="10" cols="40"><?php echo htmlspecialchars($info['comment']); ?></textarea>
       
   116 					</td>
       
   117 				</tr>
       
   118 				<tr>
       
   119 					<td class="row1">
       
   120 						Code from image:
       
   121 					</td>
       
   122 					<td class="row1">
       
   123 						<img alt="CAPTCHA" src="<?php echo makeUrlNS('Special', "Captcha/$captchacode"); ?>" style="cursor: pointer;" onclick="this.src = makeUrlNS('Special', 'Captcha/<?php echo $captchacode; ?>', String(Math.floor(Math.random() * 1000000)));" /><br />
       
   124 						<br />
       
   125 						Code: <input name="captcha_response" type="text" size="9" /><br />
       
   126 						<small>If you can't read it, click on the image to get a different one.</small>
       
   127 						<input type="hidden" name="captcha_id" value="<?php echo $captchacode; ?>" />
       
   128 					</td>
       
   129 				</tr>
       
   130 				<tr>
       
   131 					<th class="subhead" colspan="2">
       
   132 						<input type="submit" name="submit" value="Send report" />
       
   133 					</th>
       
   134 				</tr>
       
   135 			</table>
       
   136 		</div>
       
   137 	</form>
       
   138 	<?php
       
   139 	
       
   140 	$output->footer();
       
   141 }
       
   142 
       
   143 function arp_send_mail($to, $subject, $body)
       
   144 {
       
   145 	global $session;
       
   146 	global $lang, $enano_config;
       
   147 	
       
   148 	$use_smtp = getConfig('smtp_enabled') == '1';
       
   149 		
       
   150 	//
       
   151 	// Let's do some checking to make sure that mass mail functions
       
   152 	// are working in win32 versions of php. (copied from phpBB)
       
   153 	//
       
   154 	if ( preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$use_smtp)
       
   155 	{
       
   156 		$ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
       
   157 
       
   158 		// We are running on windows, force delivery to use our smtp functions
       
   159 		// since php's are broken by default
       
   160 		$use_smtp = true;
       
   161 		$enano_config['smtp_server'] = @$ini_val('SMTP');
       
   162 	}
       
   163 	
       
   164 	$mail = new emailer( !empty($use_smtp) );
       
   165 	
       
   166 	// Validate subject/message body
       
   167 	$subject = stripslashes(trim($subject));
       
   168 	$message = stripslashes(trim($body));
       
   169 	
       
   170 	if ( empty($subject) )
       
   171 		$errors[] = $lang->get('acpmm_err_need_subject');
       
   172 	if ( empty($message) )
       
   173 		$errors[] = $lang->get('acpmm_err_need_message');
       
   174 	
       
   175 	if ( sizeof($errors) < 1 )
       
   176 	{
       
   177 	
       
   178 		$mail->from(getConfig('contact_email'));
       
   179 		$mail->replyto(getConfig('contact_email'));
       
   180 		$mail->set_subject($subject);
       
   181 		$mail->email_address($to);
       
   182 		
       
   183 		// Copied/modified from phpBB
       
   184 		$email_headers = 'X-AntiAbuse: Website server name - ' . $_SERVER['SERVER_NAME'] . "\n";
       
   185 		$email_headers .= 'X-AntiAbuse: User_id - ' . $session->user_id . "\n";
       
   186 		$email_headers .= 'X-AntiAbuse: Username - ' . $session->username . "\n";
       
   187 		$email_headers .= 'X-AntiAbuse: User IP - ' . $_SERVER['REMOTE_ADDR'] . "\n";
       
   188 		
       
   189 		$mail->extra_headers($email_headers);
       
   190 		$mail->use_template($message);
       
   191 		
       
   192 		// All done
       
   193 		$mail->send();
       
   194 		$mail->reset();
       
   195 		
       
   196 		return true;
       
   197 	}
       
   198 	
       
   199 	return $errors;
       
   200 }