WP-ContactForm eklentisine güvenlik kodu eklemek
26th Ocak 2010 · 0 Comments
WordPress ile daha önce birkaç site yapmıştım. Fakat kişisel sitemin kalıcı olması ve sürekliliğini sağlamak adına hem kolay kurulumu hem de kolay kullanımı olması için wordpress’ i tekrar tercih ettim. Eklentilerinin çeşitliliği sayesinde siteme acizane birkaç özellik kattım. Fakat “her yiğidin yoğurt yemesi farklıdır” derler ya, işte benimde istediğim bazı özellikler yoktu eklentilerde. İletişim linkinde gördüğünüz eklenti “WP-ContactForm Sürüm 1.5.1.1” olarak geçiyor. Fakat spam-botlara karşı henüz bir koruması yok (varsa da ben bilmiyorum). Bir dosya ve bazı eklemeler ile formu (bence) daha kullanışlı hale getirdim. WP kullanıp sitesinde bu eklentiyi kullanmak isteyen olur diye neler yaptığımı da açıklamak istedim.
İlk olarak WP-ContactForm un olduğu dizine ( /wp-content/plugins/wp-contact-form) aşağıdaki security.php dosyasını atıyoruz.
security.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | <?php function makePass($length=6) { $salt = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789"; $makepass = ''; mt_srand(10000000*(double)microtime()); for ($i = 0; $i < $length; $i++) $makepass .= $salt[mt_rand(0,33)]; return $makepass; } session_start('jdcode'); session_register('code'); $seccode = makePass(); $_SESSION['code'] = $seccode; function html2rgb( $color ) { if (substr($color,0,1)=="#") $color=substr($color,1,6); $tablo[0] = hexdec(substr($color, 0, 2)); $tablo[1] = hexdec(substr($color, 2, 2)); $tablo[2] = hexdec(substr($color, 4, 2)); return $tablo; } //background color $bgc=html2rgb( $_GET['bgc'] ); //fontcolor $fc=html2rgb( $_GET['fc'] ); //linecolor $lc=html2rgb( $_GET['lc'] ); //border color $bc=html2rgb( $_GET['bc'] ); header("Content-Type: image/png"); $im = imagecreate(100, 35) or die('Image create error!'); $bgcolor = imagecolorallocate($im, $bgc[0], $bgc[1], $bgc[2]); $fontcolor = imagecolorallocate($im, $fc[0], $fc[1], $fc[2]); $linecolor = imagecolorallocate($im, $lc[0], $lc[1], $lc[2]); $bordercolor = imagecolorallocate($im, $bc[0], $bc[1], $bc[2]); for($x=10; $x <= 100; $x+=10) imageline($im, $x, 0, $x, 50, $linecolor); imageline($im, 0, 5, 100, 5, $linecolor); imageline($im, 0, 15, 100, 15, $linecolor); imageline($im, 0, 25, 100, 25, $linecolor); imageline($im, 0, 0, 0, 50, $bordercolor); imageline($im, 0, 0, 100, 0, $bordercolor); imageline($im, 0, 34, 100, 34, $bordercolor); imageline($im, 99, 0, 99, 34, $bordercolor); imagestring($im, 10, 25, 10, $seccode, $fontcolor); imagepng($im); imagedestroy($im); session_destroy('jdcode'); ?> |
Daha sonra wp-contactform.php dosyasının içerisindeki kodları aşağıdakilerle değiştiriyoruz.
yeni wp-contactform.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | <?php /* Plugin Name: WP-ContactForm Plugin URI: http://blog.ftwr.co.uk/wordpress/ Description: WP Contact Form is a drop in form for users to contact you. It can be implemented on a page or a post. Author: Ryan Duff, Peter Westwood Author URI: http://blog.ftwr.co.uk Version: 1.5.1.1 */ load_plugin_textdomain('wpcf',$path = 'wp-content/plugins/wp-contact-form'); /* This shows the quicktag on the write pages Based off Buttonsnap Template http://redalt.com/downloads */ if(get_option('wpcf_show_quicktag') == true) { include( plugin_dir_path(__FILE__) . 'buttonsnap.php'); add_action('init', 'wpcf_button_init'); add_action('marker_css', 'wpcf_marker_css'); function wpcf_button_init() { $wpcf_button_url = buttonsnap_dirname(__FILE__) . '/wpcf_button.png'; buttonsnap_textbutton($wpcf_button_url, __('Insert Contact Form', 'wpcf'), '<!--contact form-->'); buttonsnap_register_marker('contact form', 'wpcf_marker'); } function wpcf_marker_css() { $wpcf_marker_url = buttonsnap_dirname(__FILE__) . '/wpcf_marker.gif'; echo " .wpcf_marker { display: block; height: 15px; width: 155px margin-top: 5px; background-image: url({$wpcf_marker_url}); background-repeat: no-repeat; background-position: center; } "; } } function wpcf_is_malicious($input) { $is_malicious = false; $bad_inputs = array("\r", "\n", "mime-version", "content-type", "cc:", "to:"); foreach($bad_inputs as $bad_input) { if(strpos(strtolower($input), strtolower($bad_input)) !== false) { $is_malicious = true; break; } } return $is_malicious; } /* This function checks for errors on input and changes $wpcf_strings if there are any errors. Shortcircuits if there has not been a submission */ function wpcf_check_input() { if(!(isset($_POST['wpcf_stage']))) {return false;} // Shortcircuit. $_POST['wpcf_your_name'] = htmlentities(stripslashes(trim($_POST['wpcf_your_name']))); $_POST['wpcf_email'] = htmlentities(stripslashes(trim($_POST['wpcf_email']))); $_POST['wpcf_website'] = htmlentities(stripslashes(trim($_POST['wpcf_website']))); $_POST['wpcf_msg'] = htmlentities(stripslashes(trim($_POST['wpcf_msg']))); $securitycode = htmlentities(stripslashes(strtoupper(trim(strtoupper($_POST['seccode']))))); global $wpcf_strings; $ok = true; if(empty($_POST['wpcf_your_name'])) { $ok = false; $reason = 'empty'; $wpcf_strings['name'] = '<div class="contactright"><input type="text" name="wpcf_your_name" id="wpcf_your_name" size="30" maxlength="50" value="' . $_POST['wpcf_your_name'] . '" class="contacterror" /> (' . __('required', 'wpcf') . ')</div>'; } if(!is_email($_POST['wpcf_email'])) { $ok = false; $reason = 'empty'; $wpcf_strings['email'] = '<div class="contactright"><input type="text" name="wpcf_email" id="wpcf_email" size="30" maxlength="50" value="' . $_POST['wpcf_email'] . '" class="contacterror" /> (' . __('required', 'wpcf') . ')</div>'; } if(empty($_POST['wpcf_msg'])) { $ok = false; $reason = 'empty'; $wpcf_strings['msg'] = '<div class="contactright"><textarea name="wpcf_msg" id="wpcf_message" cols="35" rows="8" class="contacterror">' . $_POST['wpcf_msg'] . '</textarea></div>'; } if(wpcf_is_malicious($_POST['wpcf_your_name']) || wpcf_is_malicious($_POST['wpcf_email'])) { $ok = false; $reason = 'malicious'; } session_start('jdcode'); $checkSecurity = false; if (isset($_SESSION['code']) && ($_SESSION['code'] != "") && ($_SESSION['code'] == $securitycode)) { $checkSecurity = true; } if ($checkSecurity == false) { $ok = false; $wpcf_strings['error'] = '<div style="font-weight: bold;">Güvenlik kodunu hatalı yazdınız. Tekrar deneyin</div>'; } if($ok == true) { return true; } else { if($reason == 'malicious') { $wpcf_strings['error'] = "<div style='font-weight: bold;'>You can not use any of the following in the Name or Email fields: a linebreak, or the phrases 'mime-version', 'content-type', 'cc:' or 'to:'.</div>"; } elseif($reason == 'empty') { $wpcf_strings['error'] = '<div style="font-weight: bold;">' . stripslashes(get_option('wpcf_error_msg')) . '</div>'; } return false; } } /*Wrapper function which calls the form.*/ function wpcf_callback( $content ) { global $wpcf_strings; /* Run the input check. */ if(false === strpos($content, '<!--contact form-->')) { return $content; } /* Declare strings that change depending on input. This also resets them so errors clear on resubmission. */ $wpcf_strings = array( 'name' => '<div class="contactright"><input type="text" name="wpcf_your_name" id="wpcf_your_name" size="30" maxlength="50" value="' . (isset($_POST['wpcf_your_name']) ? $_POST['wpcf_your_name'] :'') . '" /> (' . __('gerekli', 'wpcf') . ')</div>', 'email' => '<div class="contactright"><input type="text" name="wpcf_email" id="wpcf_email" size="30" maxlength="50" value="' . (isset($_POST['wpcf_email']) ? $_POST['wpcf_email'] : '') . '" /> (' . __('gerekli', 'wpcf') . ')</div>', 'msg' => '<div class="contactright"><textarea name="wpcf_msg" id="wpcf_msg" cols="35" rows="8" >' . (isset($_POST['wpcf_msg']) ? $_POST['wpcf_msg'] : '' ) . '</textarea></div>', 'error' => ''); if(wpcf_check_input()) // If the input check returns true (ie. there has been a submission & input is ok) { $recipient = get_option('wpcf_email'); $subject = get_option('wpcf_subject'); $success_msg = get_option('wpcf_success_msg'); $success_msg = stripslashes($success_msg); $name = $_POST['wpcf_your_name']; $email = $_POST['wpcf_email']; $website = $_POST['wpcf_website']; $msg = $_POST['wpcf_msg']; $headers = "MIME-Version: 1.0\n"; $headers .= "From: $name < $email>\n"; $headers .= "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; $fullmsg = "$name yazmış:\n"; $fullmsg .= wordwrap($msg, 80, "\n") . "\n\n"; $fullmsg .= "Web sitesi: " . $website . "\n"; $fullmsg .= "IP Adresi: " . getip(); mail($recipient, $subject, $fullmsg, $headers); $sonuc = '<div style="font-weight: bold;">' . $success_msg . '</div>'; echo $sonuc; } else // Else show the form. If there are errors the strings will have updated during running the inputcheck. { //security image by pisdoktor $securityimage = get_option('siteurl').'/wp-content/plugins/wp-contact-form/security.php?bgc=E5E5E5&fc=CACACA&lc=DFDFDF&bc=D2D2D2'; $securityimage = '<img src="'. $securityimage . '" alt="Güvenlik Kodu" />'; //end security image by pisdoktor $form = '<div class="contactform"> ' . $wpcf_strings['error'] . ' <form action="' . get_permalink() . '" method="post"> <div class="contactleft"><label for="wpcf_your_name">' . __('Adınız: ', 'wpcf') . '</label></div>' . $wpcf_strings['name'] . ' <div class="contactleft"><label for="wpcf_email">' . __('Eposta Adresiniz:', 'wpcf') . '</label></div>' . $wpcf_strings['email'] . ' <div class="contactleft"><label for="wpcf_website">' . __('Web siteniz:', 'wpcf') . '</label></div><div class="contactright"><input type="text" name="wpcf_website" id="wpcf_website" size="30" maxlength="100" value="' . (isset($_POST['wpcf_website']) ? $_POST['wpcf_website'] : '') . '" /></div> <div class="contactleft"><label for="wpcf_msg">' . __('Mesajınız: ', 'wpcf') . '</label></div>' . $wpcf_strings['msg'] . ' <div class="contactleft">' . $securityimage . '</div><div class="contactright"><input type="text" maxlength="6" name="seccode"/> <i>* Büyük-küçük harf duyarlı değildir</i></div> <div class="contactright"><input type="submit" name="Submit" value="' . __('Gönder', 'wpcf') . '" id="contactsubmit" /><input type="hidden" name="wpcf_stage" value="process" /></div> </form> </div> <div style="clear:both; height:1px;"> </div>'; return str_replace('<!--contact form-->', $form, $content); } } /*Can't use WP's function here, so lets use our own*/ function getip() { if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip_addr = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { $ip_addr = $_SERVER["HTTP_CLIENT_IP"]; } else { $ip_addr = $_SERVER["REMOTE_ADDR"]; } } else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $ip_addr = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) { $ip_addr = getenv( 'HTTP_CLIENT_IP' ); } else { $ip_addr = getenv( 'REMOTE_ADDR' ); } } return $ip_addr; } /*CSS Styling*/ function wpcf_css() { ?> <style type="text/css" media="screen"> /* Begin Contact Form CSS */ .contactform { position: static; overflow: hidden; width: 95%; } .contactleft { width: 25%; white-space: pre; text-align: right; clear: both; float: left; display: inline; padding: 4px; margin: 5px 0; } .contactright { width: 70%; text-align: left; float: right; display: inline; padding: 4px; margin: 5px 0; } .contacterror { border: 1px solid #ff0000; } .contactsubmit { } /* End Contact Form CSS */ </style> <?php } function wpcf_add_options_page() { add_options_page(__('Contact Form Options', 'wpcf'), __('Contact Form', 'wpcf'), 'manage_options', 'wp-contact-form/options-contactform.php'); } /* Action calls for all functions */ //if(get_option('wpcf_show_quicktag') == true) {add_action('admin_footer', 'wpcf_add_quicktag');} add_action('admin_menu', 'wpcf_add_options_page'); add_filter('wp_head', 'wpcf_css'); add_filter('the_content', 'wpcf_callback', 7); ?> |
İşte hepsi bu kadar. Hani belki sizler bu dosyaları paket olarak istersiniz diye de eklemeyi unutmadım. Buyrun buradan indirin.
Tags: güvenlik kodu, security, Wordpress, wp-contact-form
Readers Comments (0)
Comments are closed.