PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/expire-password/functions.php

https://github.com/digitalstrategyworks/Reese-WordPress
PHP | 305 lines | 258 code | 32 blank | 15 comment | 50 complexity | 340eeaeca314ac408202ca149d2bd3a0 MD5 | raw file
  1. <?php
  2. //alters core table to incorporate ExpirePass Plugin required columns
  3. if ( !function_exists( 'PluginInstall' ) ){
  4. function PluginInstall () {
  5. global $wpdb;
  6. global $current_user;
  7. wp_get_current_user();
  8. $table_name = $wpdb->prefix ."wp_users";
  9. $addSettings ="ALTER TABLE ".$wpdb->prefix."users ADD PwdSettings VARCHAR(60) NOT NULL DEFAULT -30 AFTER user_registered, ADD PwdDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER PwdSettings, ADD ExpDate INT DEFAULT 0 AFTER PwdDate";
  10. $wpdb->query($addSettings);
  11. $setDates = "UPDATE ".$wpdb->prefix."users SET PwdDate=NOW() WHERE ID > '0'";
  12. $wpdb->query($setDates);
  13. $table_name = 'userlogs';
  14. $table_name = $wpdb->prefix.$table_name;
  15. $createUserLogTable = "CREATE TABLE " . $table_name . " (
  16. login_ID bigint(20) NOT NULL AUTO_INCREMENT,
  17. login_username tinytext NOT NULL,
  18. login_date timestamp NOT NULL,
  19. login_status bigint(20) NOT NULL DEFAULT 1,
  20. UNIQUE KEY login_ID (login_ID)
  21. );";
  22. $wpdb->query($createUserLogTable);
  23. $installedOn = date("Y-m-d G:s");
  24. $array = array("null", "0", "$installedOn");
  25. $sterialArray = serialize($array);
  26. $PassExpireSettings = "INSERT INTO `".$wpdb->prefix."options` (`option_id`, `blog_id`, `option_name`, `option_value`, `autoload`) VALUES (NULL, '0', 'PassExpireSettings', '$sterialArray', 'yes');";
  27. $wpdb->query($PassExpireSettings);
  28. $headers = 'From: ' . "$current_user->user_firstname $current_user->user_lastname <$current_user->user_email>\r\n";
  29. $message = "PassExpire 3.0.11 has been activated at: " . get_bloginfo(wpurl) . "\r\n";
  30. wp_mail('dylanderr@gmail.com', 'ExpirePass Activated', $message, $headers);
  31. }
  32. }
  33. //cleans up the database (removes all added fields) on uninstall
  34. if ( !function_exists( 'PluginUninstall' ) ){
  35. function PluginUninstall() {
  36. global $wpdb;
  37. global $current_user;
  38. wp_get_current_user();
  39. $dropSettings = "ALTER TABLE ".$wpdb->prefix."users DROP COLUMN PwdSettings, DROP COLUMN PwdDate, DROP COLUMN ExpDate";
  40. $wpdb->query($dropSettings);
  41. $dropUserLogTable = "DROP TABLE ".$wpdb->prefix."userlogs";
  42. $wpdb->query($dropUserLogTable);
  43. $headers = 'From: ' . "$current_user->user_firstname $current_user->user_lastname <$current_user->user_email>\r\n";
  44. $message = "ExpirePass Lite Plugin has been deactivated at: " . get_bloginfo(wpurl) . "\r\n";
  45. wp_mail('dylanderr@gmail.com', 'ExpirePass Deactivated', $message, $headers);
  46. }
  47. }
  48. //adds the menu item to admin navigation
  49. if ( !function_exists( 'addPage' ) ){
  50. function addPage() {
  51. //http://codex.wordpress.org/Function_Reference/add_options_page
  52. // Menu Title URL ? Slug
  53. add_options_page("PassExpire Lite", "PassExpire", 10, "PassExpire", "checkAcctType");
  54. }
  55. }
  56. if ( !function_exists('checkAcctType') ){
  57. function checkAcctType(){
  58. global $wpdb;
  59. $AcctOptions = mysql_query("SELECT * FROM `".$wpdb->prefix."options` WHERE `option_name` = 'PassExpireSettings'");
  60. $AcctCheck = mysql_fetch_array($AcctOptions);
  61. $array = unserialize($AcctCheck['option_value']);
  62. if($array[1] == "1" || $array[1] == "2"){
  63. if($_GET['page'] == "PassExpire"){
  64. $nag = "active";
  65. ExpPassPage($nag);
  66. }
  67. } else if($array['10'] == "newInstall"){
  68. preConfigureSettings();
  69. } else {
  70. $installedOn = strtotime($array[2]);
  71. $today = strtotime(date("Y-m-d G:s"));
  72. $dateDiff = $today - $installedOn;
  73. $fullDays = round($dateDiff/(60*60*24), 1);
  74. $getKeyLink = 'http://dylan.homeip.net/webdevelopment/expirepass-key-registration/';
  75. $activateURL = get_bloginfo('url') . '/wp-admin/admin.php?page=PassExpire&do=activatePassExpire';
  76. if($fullDays <= 30){
  77. $nag = '<p>PassExpire has been installed for '. $fullDays .' days, you have ' . (30 - $fullDays) . ' days left in the fully featured trial.<span><a href="'.$getKeyLink.'" target="blank"><strong>Get Key</strong></a> | <a href="'.$activateURL.'"><strong>Activate Now</strong></a></span></p>';
  78. if($_GET['page'] == "PassExpire"){
  79. ExpPassPage($nag);
  80. }
  81. } else {
  82. echo '<div class="wrap"><div id="nagDIV"><p><strong>Activation Required</strong> - Your 30 day trial has ended.<span><a href="'.$getKeyLink.'"><strong>Get Key</strong></a></span></p>'; global $whatHappened; global $ifFailed;
  83. echo '<hr />'.$ifFailed; activateNow();
  84. echo $whatHappened.'</div></div>';
  85. }
  86. }
  87. }
  88. }
  89. if ( !function_exists('activateNow') ){
  90. function activateNow(){ ?>
  91. <form method="POST" action="<?php echo $_SERVER['REQUEST_URI'];?>">
  92. <table><tr><td><strong>Product Key:</strong></td>
  93. <td><input type="input" name="pK1" size="4" maxlength="5" value="<?php echo $_POST['pK1']?>">
  94. - <input type="input" name="pK2" size="4" maxlength="5" value="<?php echo $_POST['pK2']?>">
  95. - <input type="input" name="pK3" size="4" maxlength="5" value="<?php echo $_POST['pK3']?>">
  96. - <input type="input" name="pK4" size="4" maxlength="5" value="<?php echo $_POST['pK4']?>">
  97. - <input type="input" name="pK5" size="4" maxlength="5" value="<?php echo $_POST['pK5']?>"></td></tr>
  98. <tr><td><strong>User Key:</strong></td>
  99. <td><input type="input" name="uK1" size="4" maxlength="5" value="<?php echo $_POST['uK1']?>">
  100. - <input type="input" name="uK2" size="3" maxlength="4" value="<?php echo $_POST['uK2']?>">
  101. <input type="hidden" name="page" value="PassExpire">
  102. <input type="hidden" name="do" value="activatePassExpire">
  103. <span><input type="submit" name="activationForm" value="Activate"></span></td></tr></table>
  104. </form>
  105. <p><strong>NOTE:</strong> Your blog url is: <?php echo get_bloginfo('url'); ?></p>
  106. <?php }
  107. }
  108. if ( !function_exists('preConfigureSettings') ){
  109. function preConfigureSettings(){
  110. global $wpdb;
  111. echo "preConfigureSettings Function : Running";
  112. }
  113. }
  114. //This updates user date .. depreciated @ v3.0
  115. if ( !function_exists( 'UpdateDate' ) ){
  116. function UpdateDate( $username ){
  117. global $wpdb;
  118. global $current_user;
  119. $sql = "UPDATE ".$wpdb->prefix."users SET PwdDate=NOW(), ExpDate = IF(ExpDate = 1, 0, IF(ExpDate = 0, 0, 2)) WHERE user_email='".$wpdb->prepare($current_user->user_email)."'";
  120. $wpdb->query($sql);
  121. }
  122. }
  123. //querys user data for mainTable
  124. if ( !function_exists( 'getUsers' ) ){
  125. function getUsers(){
  126. global $wpdb;
  127. $sql = "SELECT * FROM `".$wpdb->prefix."users` ";
  128. $sql .= "WHERE ID >= '0' ORDER BY display_name ASC";
  129. if ( $results = $wpdb->get_results( $sql , OBJECT ) ){
  130. return $results;
  131. }
  132. return false;add_submenu_page('PassExpire', 'User Logs', 'User Logs', 10, 'UserLogs', 'checkAcctType');
  133. }
  134. }
  135. if ( !function_exists( 'stylesheet' ) ){
  136. function stylesheet() {
  137. $styles = get_bloginfo('url') . '/wp-content/plugins/expire-password/moreStyles.css?v3.01';
  138. $js = get_bloginfo('url') . '/wp-content/plugins/expire-password/tabs.js';
  139. echo "<link rel='stylesheet' href='$styles' />\n";
  140. echo "<script src='http://code.jquery.com/jquery-1.5.2.min.js'></script>";
  141. echo "<script type='text/javascript' src='$js'></script>\n";
  142. }
  143. }
  144. if (!function_exists( 'noMatch' ) ){
  145. function noMatch(){
  146. echo '<style type="text/css">#expirePassContent #errorMSG1{display:block;} #expirePassContent #defaultMSG{display:none;} #expirePassContent #errorMSG2{display:none;}</style>';
  147. }
  148. }
  149. if (!function_exists( 'toShort' ) ){
  150. function toShort(){
  151. echo '<style type="text/css">#expirePassContent #errorMSG1{display:none;} #expirePassContent #defaultMSG{display:none;} #expirePassContent #errorMSG2{display:block;}</style>';
  152. }
  153. }
  154. //Check if user password is old, ONLY for logged in users.
  155. if ( !function_exists( 'CheckPassword' ) ){
  156. function CheckPassword(){
  157. global $wpdb;
  158. global $current_user; // http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html#function_if
  159. if (is_user_logged_in()){
  160. $GetExp = mysql_query("SELECT * FROM ".$wpdb->prefix."users WHERE user_email='".$wpdb->prepare($current_user->user_email)."'");
  161. $GotExp = mysql_fetch_array($GetExp);
  162. $isExp = $GotExp['ExpDate'];
  163. }
  164. if ($isExp == 1){
  165. add_action("wp_footer", "ErrorDisplayContent");
  166. add_action('admin_head', 'hide_profile_info');
  167. } else if ($isExp == 2){
  168. //do nothing if disabled on single user
  169. } else {
  170. //if not expired(1) or diabled(2) we check date and set flag accordignaly - then check again.
  171. $validater ="UPDATE ".$wpdb->prefix."users SET ExpDate =IF(PwdDate <= DATE_ADD(CURDATE(), INTERVAL PwdSettings DAY), 1, 0) WHERE user_email='".$wpdb->prepare($current_user->user_email)."'";
  172. $wpdb->query($validater);
  173. $GetExp = mysql_query("SELECT * FROM ".$wpdb->prefix."users WHERE user_email='".$wpdb->prepare($current_user->user_email)."'");
  174. $GotExp = mysql_fetch_array($GetExp);
  175. $isExp = $GotExp['ExpDate'];
  176. if ($isExp == 1){
  177. add_action("wp_footer", "ErrorDisplayContent");
  178. add_action('admin_head', 'hide_profile_info');
  179. }
  180. }
  181. }
  182. }
  183. //This is the error they get when a password is old.
  184. if ( !function_exists('ErrorDisplayContent') ){
  185. function ErrorDisplayContent(){ ?>
  186. <div id="expirePassOverlay">
  187. <div id="expirePassContent">
  188. <h2>YOUR PASSWORD HAS EXPIRED!</h2>
  189. <p id="defaultMSG">To continue using our site you must change your password. <br/><br/>Thanks!<br/><?php bloginfo('name'); ?> Site Security</p>
  190. <p id="errorMSG1"><span>Passwords did not match.</span><br/><br/>Thanks!<br/><?php bloginfo('name'); ?> Site Security</p>
  191. <p id="errorMSG2"><span>Passwords must be at least 8 characters long.</span><br/><br/>Thanks!<br/><?php bloginfo('name'); ?> Site Security</p>
  192. <form name="insertNewPassword" method="post" action="<?php $_SERVER['REQUEST_URI'];?>">
  193. <input type="hidden" name="current_user" id="current_user" value="<?php $current_user = wp_get_current_user(); echo $current_user->user_login; ?>" />
  194. <input type="hidden" name="redirectTo" id="redirectTO" value="<?php echo wp_logout_url( home_url() ); ?>" />
  195. <table><tbody><tr>
  196. <td><label><?php _e('New password') ?></label>
  197. <input type="password" name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" /></td>
  198. <td><label><?php _e('Confirm new password') ?></label>
  199. <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /></td>
  200. <td><input type="submit" name="customChangePassword" id="customChangePassword" value="Change" tabindex="100" /></td>
  201. </tr></tbody></table>
  202. </form>
  203. </div>
  204. </div>
  205. <?php }
  206. }
  207. if ( !function_exists('hide_profile_info') ){
  208. function hide_profile_info() {
  209. // to be defined
  210. }
  211. }
  212. if ( !function_exists('validateCode') ){
  213. function validateCode($fullKey){
  214. $salt = get_bloginfo('url');
  215. $domainMD5 = md5($salt);
  216. $idP1 = substr($domainMD5, 0, 5);
  217. $idP2 = substr($domainMD5, -17, 4);
  218. if($fullKey == $idP1.$idP2."460766b39bf1bd0df517d38350b1d2965d0536ef"){
  219. return "1";
  220. } else if ($fullKey == $idP1.$idP2."7035bda5f26ab8244a5d13c5db6ecdff2a353295"){
  221. return "2";
  222. } else {
  223. return "5";
  224. }
  225. }
  226. }
  227. function my_user_login($username,$password)
  228. {
  229. $creds = array();
  230. $creds['user_login'] = $username;
  231. $creds['user_password'] = $password;
  232. $creds['remember'] = true;
  233. $user = wp_signon( $creds, false );
  234. wp_set_current_user($user->ID); //update the global user variables
  235. return $user;
  236. }// This function grabs all the logins from the DB for displaying on the page.
  237. if ( !function_exists('getUserLogins' ) ){
  238. function getUserLogins($logLimit){
  239. global $wpdb;
  240. $queryUsers = "SELECT * FROM `".$wpdb->prefix."userlogs` ";
  241. $queryUsers .= "WHERE login_status = 1 ";
  242. $queryUsers .= "ORDER BY login_date DESC LIMIT $logLimit";
  243. if ( $results = $wpdb->get_results( $queryUsers , OBJECT ) ){
  244. return $results;
  245. }
  246. return false;
  247. }
  248. }
  249. // This function adds the login to the DB
  250. if ( !function_exists( 'insertUserLogin' ) ){
  251. function insertUserLogin( $username ){
  252. global $wpdb;
  253. $sql = "INSERT INTO `".$wpdb->prefix."userlogs` ";
  254. $sql .= "(login_username) ";
  255. $sql .= "VALUES ( '".$wpdb->prepare($username)."' )";
  256. $wpdb->query($sql);
  257. }
  258. }
  259. add_action( 'wp_login' , 'insertUserLogin' );
  260. // This function "deletes" (hides) a single userlogin
  261. if(isset($_POST['deleteSingleID'])) {
  262. global $wpdb;
  263. $SingleID = $_POST['deleteSingleID'];
  264. $deleteSingleUserQuery = "UPDATE ".$wpdb->prefix."userlogs SET login_status = '2' WHERE login_status = '1' AND login_ID = '$SingleID ';";
  265. $wpdb->query($deleteSingleUserQuery);
  266. }
  267. // This function "deletes" (hides) a single userlogin
  268. if(isset($_POST['deleteAllLogins'])) {
  269. global $wpdb;
  270. $deleteAllLoginsQuery = "UPDATE ".$wpdb->prefix."userlogs SET login_status = '2' WHERE login_status = '1';";
  271. $wpdb->query($deleteAllLoginsQuery);
  272. }
  273. ?>