author | Dan Fuhry <dan@enanocms.org> |
Sat, 31 Jul 2010 00:29:56 -0400 | |
changeset 2 | e4a8a8e1a50d |
parent 1 | 13ac3d9d47b2 |
permissions | -rw-r--r-- |
0 | 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 |
||
2
e4a8a8e1a50d
Maybe I could include the page id in the report too
Dan Fuhry <dan@enanocms.org>
parents:
1
diff
changeset
|
74 |
list($pid, $ns) = RenderMan::strToPageID($page); |
e4a8a8e1a50d
Maybe I could include the page id in the report too
Dan Fuhry <dan@enanocms.org>
parents:
1
diff
changeset
|
75 |
$pageurl = makeUrlComplete($ns, $pid); |
e4a8a8e1a50d
Maybe I could include the page id in the report too
Dan Fuhry <dan@enanocms.org>
parents:
1
diff
changeset
|
76 |
if ( !is_array($result = arp_send_mail($email, "[{$_SERVER['HTTP_HOST']}] Website bug report", "Sent from IP: {$_SERVER['REMOTE_ADDR']}\nPage: $pageurl\n\n---------------------------\n$comment")) ) |
0 | 77 |
{ |
78 |
redirect(makeUrl($page), 'Report sent', 'Thank you, your report has been sent. Redirecting you back to the page...', 5); |
|
79 |
} |
|
80 |
else |
|
81 |
{ |
|
82 |
$errors = $result; |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
$info['page'] = $_POST['page']; |
|
87 |
} |
|
88 |
||
89 |
$captchacode = $session->make_captcha(); |
|
90 |
if ( !empty($errors) ) |
|
91 |
{ |
|
92 |
echo '<div class="error-box-mini"><ul><li>' . |
|
93 |
implode('</li><li>', $errors) . |
|
94 |
'</li></ul></div>'; |
|
95 |
} |
|
96 |
?> |
|
97 |
<form method="post" action="<?php echo makeUrl($paths->page); ?>"> |
|
98 |
<div class="tblholder"> |
|
99 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
100 |
<tr> |
|
101 |
<th colspan="2">Report a site bug</th> |
|
102 |
</tr> |
|
103 |
<tr> |
|
104 |
<td class="row1"> |
|
105 |
URL of page: |
|
106 |
</td> |
|
107 |
<td class="row1"> |
|
108 |
http<?php if ( $GLOBALS['is_https'] ) echo 's'; ?>://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); |
|
109 |
echo contentPath; ?><input type="text" name="page" value="<?php echo htmlspecialchars($info['page']); ?>" /> |
|
110 |
</td> |
|
111 |
</tr> |
|
112 |
<tr> |
|
113 |
<td class="row2"> |
|
114 |
The problem: |
|
115 |
</td> |
|
116 |
<td class="row2"> |
|
117 |
<textarea name="comment" rows="10" cols="40"><?php echo htmlspecialchars($info['comment']); ?></textarea> |
|
118 |
</td> |
|
119 |
</tr> |
|
120 |
<tr> |
|
121 |
<td class="row1"> |
|
122 |
Code from image: |
|
123 |
</td> |
|
124 |
<td class="row1"> |
|
125 |
<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 /> |
|
126 |
<br /> |
|
127 |
Code: <input name="captcha_response" type="text" size="9" /><br /> |
|
128 |
<small>If you can't read it, click on the image to get a different one.</small> |
|
129 |
<input type="hidden" name="captcha_id" value="<?php echo $captchacode; ?>" /> |
|
130 |
</td> |
|
131 |
</tr> |
|
132 |
<tr> |
|
133 |
<th class="subhead" colspan="2"> |
|
134 |
<input type="submit" name="submit" value="Send report" /> |
|
135 |
</th> |
|
136 |
</tr> |
|
137 |
</table> |
|
138 |
</div> |
|
139 |
</form> |
|
140 |
<?php |
|
141 |
||
142 |
$output->footer(); |
|
143 |
} |
|
144 |
||
145 |
function arp_send_mail($to, $subject, $body) |
|
146 |
{ |
|
147 |
global $session; |
|
148 |
global $lang, $enano_config; |
|
149 |
||
150 |
$use_smtp = getConfig('smtp_enabled') == '1'; |
|
151 |
||
152 |
// |
|
153 |
// Let's do some checking to make sure that mass mail functions |
|
154 |
// are working in win32 versions of php. (copied from phpBB) |
|
155 |
// |
|
156 |
if ( preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$use_smtp) |
|
157 |
{ |
|
158 |
$ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var'; |
|
159 |
||
160 |
// We are running on windows, force delivery to use our smtp functions |
|
161 |
// since php's are broken by default |
|
162 |
$use_smtp = true; |
|
163 |
$enano_config['smtp_server'] = @$ini_val('SMTP'); |
|
164 |
} |
|
165 |
||
166 |
$mail = new emailer( !empty($use_smtp) ); |
|
167 |
||
168 |
// Validate subject/message body |
|
169 |
$subject = stripslashes(trim($subject)); |
|
170 |
$message = stripslashes(trim($body)); |
|
171 |
||
172 |
if ( empty($subject) ) |
|
173 |
$errors[] = $lang->get('acpmm_err_need_subject'); |
|
174 |
if ( empty($message) ) |
|
175 |
$errors[] = $lang->get('acpmm_err_need_message'); |
|
176 |
||
177 |
if ( sizeof($errors) < 1 ) |
|
178 |
{ |
|
179 |
||
180 |
$mail->from(getConfig('contact_email')); |
|
181 |
$mail->replyto(getConfig('contact_email')); |
|
182 |
$mail->set_subject($subject); |
|
183 |
$mail->email_address($to); |
|
184 |
||
185 |
// Copied/modified from phpBB |
|
186 |
$email_headers = 'X-AntiAbuse: Website server name - ' . $_SERVER['SERVER_NAME'] . "\n"; |
|
187 |
$email_headers .= 'X-AntiAbuse: User_id - ' . $session->user_id . "\n"; |
|
188 |
$email_headers .= 'X-AntiAbuse: Username - ' . $session->username . "\n"; |
|
189 |
$email_headers .= 'X-AntiAbuse: User IP - ' . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
190 |
||
191 |
$mail->extra_headers($email_headers); |
|
192 |
$mail->use_template($message); |
|
193 |
||
194 |
// All done |
|
195 |
$mail->send(); |
|
196 |
$mail->reset(); |
|
197 |
||
198 |
return true; |
|
199 |
} |
|
200 |
||
201 |
return $errors; |
|
202 |
} |