function wpses_options() { global $wpdb, $wpses_options; global $current_user; get_currentuserinfo(); if (!in_array('administrator', $current_user->roles)) { //die('Pas admin'); } $autorized = ''; if ($wpses_options['access_key'] != '' and $wpses_options['secret_key'] != '') { $autorized = wpses_getverified(); } $senders = (array) get_option('wpses_senders'); // ajouter dans senders les verified absents $updated = false; if ('' != $autorized) { if (!is_array($autorized)) { $authorized = array($autorized); } foreach ($autorized as $email) { if (!array_key_exists($email, $senders)) { $senders[$email] = array(-1, TRUE); $updated = true; } else { if (!$senders[$email][1]) { // activer ceux qu'on a reçu depuis $senders[$email][1] = true; $updated = true; } } } // remove old senders foreach ($senders as $email => $info) { if ($info[1] and !in_array($email, $autorized)) { $senders[$email][1] = false; // echo 'remove '.$email.' '; $updated = true; } } } if ($updated) { update_option('wpses_senders', $senders); } if ($wpses_options['sender_ok'] != 1 or $wpses_options['credentials_ok'] != 1) { $wpses_options['active'] = 0; update_option('wpses_options', $wpses_options); } if ($wpses_options['from_email'] != '') { if (!isset($senders[$wpses_options['from_email']])) { $senders[$wpses_options['from_email']] = array(-1, false); } if ($senders[$wpses_options['from_email']][1] === TRUE) { // // email exp enregistré non vide et listé, on peut donc supposer que credentials ok et exp ok. if ($wpses_options['credentials_ok'] == 0) { $wpses_options['credentials_ok'] = 1; update_option('wpses_options', $wpses_options); } if ($wpses_options['sender_ok'] == 0) { $wpses_options['sender_ok'] = 1; update_option('wpses_options', $wpses_options); } } else { //if ($senders[$wpses_options['from_email']][1] !== TRUE) { // $wpses_options['sender_ok'] = 0; update_option('wpses_options', $wpses_options); } } if (!empty($_POST['activate'])) { if ($wpses_options['sender_ok'] == 1 and $wpses_options['credentials_ok'] == 1) { $wpses_options['active'] = 1; update_option('wpses_options', $wpses_options); echo '<div id="message" class="updated fade"> <p>' . __('Plugin is activated and functionnal', 'wpses') . '</p> </div>' . "\n"; } } if (!empty($_POST['deactivate'])) { $wpses_options['active'] = 0; update_option('wpses_options', $wpses_options); echo '<div id="message" class="updated fade"> <p>' . __('Plugin de-activated', 'wpses') . '</p> </div>' . "\n"; } if (!empty($_POST['save'])) { //check_admin_referer(); //$wpses_options['active'] = trim($_POST['active']); if ($wpses_options['from_email'] != trim($_POST['from_email'])) { $wpses_options['sender_ok'] = 0; $wpses_options['active'] = 0; } if (!defined('WP_SES_FROM')) { $wpses_options['from_email'] = trim($_POST['from_email']); } if (!defined('WP_SES_RETURNPATH')) { $wpses_options['return_path'] = trim($_POST['return_path']); } if ($wpses_options['return_path'] == '') { $wpses_options['return_path'] = $wpses_options['from_email']; } if (!defined('WP_SES_REPLYTO')) { $wpses_options['reply_to'] = trim($_POST['reply_to']); if ($wpses_options['reply_to'] == '') { $wpses_options['reply_to'] = $wpses_options['from_email']; } } $wpses_options['from_name'] = trim($_POST['from_name']); // $wpses_options['endpoint'] = trim($_POST['endpoint']); // // TODO si mail diff�re, relancer proc�dure check => resetter sender_ok si besoin if ($wpses_options['access_key'] != trim($_POST['access_key']) or $wpses_options['secret_key'] != trim($_POST['secret_key'])) { $wpses_options['credentials_ok'] = 0; $wpses_options['sender_ok'] = 0; $wpses_options['active'] = 0; } if (!WP_SES_RESTRICTED) { $wpses_options['access_key'] = trim($_POST['access_key']); // $wpses_options['secret_key'] = trim($_POST['secret_key']); // } // TODO si credentials different, resetter credentials_ok update_option('wpses_options', $wpses_options); echo '<div id="message" class="updated fade"><p>' . __('Settings updated', 'wpses') . '</p></div>' . "\n"; } wpses_getoptions(); //$wpses_options = get_option('wpses_options'); // validation cle amazon if (!WP_SES_RESTRICTED) { // server side check. // validation email envoi if (!empty($_POST['addemail'])) { wpses_verify_sender_step1($wpses_options['from_email']); } // remove verified email if (!empty($_POST['removeemail'])) { wpses_remove_sender($_POST['email']); } // envoi mail test if (!empty($_POST['testemail'])) { wpses_test_email($wpses_options['from_email']); } // envoi mail test prod if (!empty($_POST['prodemail'])) { wpses_prod_email($_POST['prod_email_to'], $_POST['prod_email_subject'], $_POST['prod_email_content']); } } include 'admin.tmpl.php'; }
function wpses_options() { global $wpdb, $wpses_options; global $current_user; get_currentuserinfo(); if (!in_array('administrator', $current_user->roles)) { //die('Pas admin'); } $authorized = ''; if ($wpses_options['access_key'] != '' and $wpses_options['secret_key'] != '') { $authorized = wpses_getverified(); } $senders = (array) get_option('wpses_senders'); // ajouter dans senders les verified absents $updated = false; if ('' != $authorized) { if (!is_array($authorized)) { $authorized = array($authorized); } foreach ($authorized as $email) { // if (false !==strpos($email, '@')) { // identity if full email if (!array_key_exists($email, $senders)) { $senders[$email] = array(-1, TRUE); $updated = true; } else { if (!$senders[$email][1]) { // activate the new emails $senders[$email][1] = true; $updated = true; } } /* } else { // identity is domain only // Must check with all senders // No request id here, just tag as valid foreach($senders as $email=>$detail) { } } */ } // remove old senders foreach ($senders as $email => $info) { if ($info[1] and !in_array($email, $authorized)) { $senders[$email][1] = false; // echo 'remove '.$email.' '; $updated = true; } } } if ($updated) { update_option('wpses_senders', $senders); } $wpses_options['sender_ok'] = 0; if ($wpses_options['from_email'] != '') { if ($senders[$wpses_options['from_email']][1] === TRUE) { // // email exp enregistré non vide et listé, on peut donc supposer que credentials ok et exp ok. if ($wpses_options['credentials_ok'] == 0) { $wpses_options['credentials_ok'] = 1; wpses_log('Credentials ok'); update_option('wpses_options', $wpses_options); } if ($wpses_options['sender_ok'] == 0) { $wpses_options['sender_ok'] = 1; wpses_log('Sender Ok'); update_option('wpses_options', $wpses_options); } } else { //if ($senders[$wpses_options['from_email']][1] !== TRUE) { // //$wpses_options['sender_ok'] = 0; //wpses_log('Sender not OK'); //update_option('wpses_options', $wpses_options); } //if (!isset($senders[$wpses_options['from_email']])) { if (0 == $wpses_options['sender_ok']) { // email is not known, but domain could be listed list($user, $domain) = explode('@', $wpses_options['from_email']); if ($senders[$domain][1] === TRUE) { // domain is validated //$senders[$wpses_options['from_email']] = array(-1, true); $wpses_options['sender_ok'] = 1; wpses_log('Sender domain ok'); $wpses_options['credentials_ok'] = 1; update_option('wpses_options', $wpses_options); } else { //$senders[$wpses_options['from_email']] = array(-1, false); } } } if ($wpses_options['sender_ok'] != 1 and $wpses_options['force'] != 1 or $wpses_options['credentials_ok'] != 1) { $wpses_options['active'] = 0; wpses_log('Deactivate sender_ok=' . $wpses_options['sender_ok'] . ' Force=' . $wpses_options['force'] . ' credentials_ok=' . $wpses_options['credentials_ok']); update_option('wpses_options', $wpses_options); } if (!empty($_POST['activate'])) { $wpses_options['force'] = 0; if ($wpses_options['sender_ok'] == 1 and $wpses_options['credentials_ok'] == 1) { $wpses_options['active'] = 1; wpses_log('Normal activation'); update_option('wpses_options', $wpses_options); echo '<div id="message" class="updated fade"> <p>' . __('Plugin is activated and functionnal', 'wpses') . '</p> </div>' . "\n"; } if (isset($_POST['force']) and 1 == $_POST['force']) { // bad hack to force plugin activation with IAM credentials $wpses_options['sender_ok'] = 1; $wpses_options['credentials_ok'] = 1; $wpses_options['active'] = 1; $wpses_options['force'] = 1; wpses_log('Forced activation'); update_option('wpses_options', $wpses_options); } } if (!empty($_POST['deactivate'])) { $wpses_options['active'] = 0; wpses_log('Manual deactivation'); update_option('wpses_options', $wpses_options); echo '<div id="message" class="updated fade"> <p>' . __('Plugin de-activated', 'wpses') . '</p> </div>' . "\n"; } if (!empty($_POST['activatelogs'])) { @mkdir(WP_PLUGIN_DIR . '/wp-ses/log/'); @touch(WP_PLUGIN_DIR . '/wp-ses/log/wpses.log'); if (!file_exists(WP_PLUGIN_DIR . '/wp-ses/log/wpses.log')) { echo '<div id="message" class="updated"> <p>' . __('Unable to create dir ', 'wpses') . WP_PLUGIN_DIR . '/wp-ses/log/' . __(' Please create it and give WP proper rights ', 'wpses') . '</p> </div>' . "\n"; } else { @unlink(WP_PLUGIN_DIR . '/wp-ses/log/wpses.log'); echo '<div id="message" class="updated fade"> <p>' . __('Logs activated', 'wpses') . '</p> </div>' . "\n"; $wpses_options['log'] = 1; update_option('wpses_options', $wpses_options); wpses_log('Start Logging'); } } if (!empty($_POST['deactivatelogs'])) { $wpses_options['log'] = 0; update_option('wpses_options', $wpses_options); @unlink(WP_PLUGIN_DIR . '/wp-ses/log/wpses.log'); echo '<div id="message" class="updated fade"> <p>' . __('Logs deactivated and cleared', 'wpses') . '</p> </div>' . "\n"; } if (!empty($_POST['viewlogs'])) { if (file_exists(WP_PLUGIN_DIR . '/wp-ses/log/wpses.log')) { echo nl2br(file_get_contents(WP_PLUGIN_DIR . '/wp-ses/log/wpses.log')); die; } else { echo '<div id="message" class="updated fade"> <p>' . __('No log file', 'wpses') . '</p> </div>' . "\n"; } } if (!empty($_POST['save'])) { //check_admin_referer(); //$wpses_options['active'] = trim($_POST['active']); if ($wpses_options['from_email'] != trim($_POST['from_email'])) { wpses_log('From Email changed, reset state'); $wpses_options['sender_ok'] = 0; $wpses_options['active'] = 0; } if (!defined('WP_SES_FROM')) { $wpses_options['from_email'] = trim($_POST['from_email']); } if (!defined('WP_SES_RETURNPATH')) { $wpses_options['return_path'] = trim($_POST['return_path']); } if ($wpses_options['return_path'] == '') { $wpses_options['return_path'] = $wpses_options['from_email']; } if (!defined('WP_SES_REPLYTO')) { $wpses_options['reply_to'] = trim($_POST['reply_to']); if ($wpses_options['reply_to'] == '') { $wpses_options['reply_to'] = $wpses_options['from_email']; } } $wpses_options['from_name'] = trim($_POST['from_name']); // $wpses_options['endpoint'] = trim($_POST['endpoint']); // // TODO si mail diff�re, relancer proc�dure check => resetter sender_ok si besoin if ($wpses_options['access_key'] != trim($_POST['access_key']) or $wpses_options['secret_key'] != trim($_POST['secret_key'])) { wpses_log('API Keys changed, reset state and deactivate'); $wpses_options['credentials_ok'] = 0; $wpses_options['sender_ok'] = 0; $wpses_options['active'] = 0; } if (!WP_SES_RESTRICTED) { $wpses_options['access_key'] = trim($_POST['access_key']); // $wpses_options['secret_key'] = trim($_POST['secret_key']); // } // TODO si credentials different, resetter credentials_ok update_option('wpses_options', $wpses_options); echo '<div id="message" class="updated fade"><p>' . __('Settings updated', 'wpses') . '</p></div>' . "\n"; } wpses_getoptions(); //$wpses_options = get_option('wpses_options'); // validation cle amazon if (!WP_SES_RESTRICTED) { // server side check. // validation email envoi if (!empty($_POST['addemail'])) { wpses_verify_sender_step1($wpses_options['from_email']); } // remove verified email if (!empty($_POST['removeemail'])) { wpses_remove_sender($_POST['email']); } // envoi mail test if (!empty($_POST['testemail'])) { wpses_log('Test email request'); wpses_test_email($wpses_options['from_email']); } // envoi mail test prod if (!empty($_POST['prodemail'])) { wpses_log('Prod email request'); wpses_prod_email($_POST['prod_email_to'], $_POST['prod_email_subject'], $_POST['prod_email_content']); } } include 'admin.tmpl.php'; }