Changeset 122
- Timestamp:
- 11/12/07 20:27:28 (1 year ago)
- Files:
-
- branches/RB-0.9/wp-infocard/wp/admin.pw.php (modified) (7 diffs)
- branches/RB-0.9/wp-infocard/wp/db_upgrade.pw.php (added)
- branches/RB-0.9/wp-infocard/wp/processing.pw.php (modified) (1 diff)
- branches/RB-0.9/wp-infocard/wp/userdata.pw.php (modified) (2 diffs)
- branches/RB-0.9/wp-infocard/wp/utils.pw.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/RB-0.9/wp-infocard/wp/admin.pw.php
r110 r122 11 11 include_once( dirname(__FILE__) . '/../pwlib/admin.pwlib.php'); 12 12 include_once( dirname(__FILE__) . '/processing.pw.php'); 13 include_once( dirname(__FILE__) . '/utils.pw.php'); 13 14 //require_once( ABSPATH . WPINC . '/registration-functions.php'); 14 15 /* … … 62 63 63 64 $myTableAuditQuery = 64 "CREATE TABLE `$this->table_audit` (65 "CREATE TABLE IF NOT EXISTS `$this->table_audit` ( 65 66 `cardhash` text default '', 66 67 `accountid` bigint(20) unsigned, … … 168 169 foreach ( $wpdb->get_col("SHOW TABLES", 0) as $table ) 169 170 { 170 if ( $table == $this->table_ identity)171 if ( $table == $this->table_options ) 171 172 { 172 173 return true; … … 184 185 function setup() 185 186 { 187 pw_admin::createInfocardAuditTable(); 188 return; 186 189 global $wpdb; 187 190 … … 319 322 function getOption($attr_name) 320 323 { 321 return get_ settings($attr_name);324 return get_option($attr_name); 322 325 } //end function getOption 323 326 324 /*325 Function: createNewAccount326 Description: creates a new db record327 Input: account details328 Output: returns the user Id on success, FALSE on failure329 Side effect: none330 */331 function createNewAccount( $datamap )332 {333 require_once( ABSPATH . WPINC . '/registration-functions.php');334 335 $user_login = $datamap['user_login']->new_value;336 $user_firstname = $datamap['first_name']->new_value;337 $user_lastname = $datamap['last_name']->new_value;338 $user_email = $datamap['user_email']->new_value;339 $display_name = $datamap['display_name']->new_value;340 $user_nicename = $display_name;341 $user_pass = MD5($datamap['cardhash']->new_value);342 $user_url = $datamap['user_url']->new_value;343 344 InfocardUtils::printDebug("<br/>Action: createNewAccount<br>");345 InfocardUtils::printDebug("<br/>Nice Name: $user_nicename<br>");346 $userdata = compact('user_login', 'user_pass', 'user_email', 'user_nicename', 'user_url', 'display_name', 'user_firstname', 'user_lastname');347 $user_ID = wp_insert_user($userdata);348 349 if ($user_ID)350 {351 InfocardUtils::printDebug(" Inserted record # $user_ID<br>");352 return $user_ID;353 }354 else355 {356 InfocardUtils::printDebug(" Error - new user not created<br/>");357 return FALSE;358 }359 } // end function createNewAccount360 361 327 function createOption( $option_name, $option_value ) 362 { 363 // this function needs to be inside the pw_infocard class for WP to call it. This is just a 364 // placeholder 365 } 328 { 329 // this is duplicated in the case of the wordpress plugin. 330 $options = get_option($option_name); 331 if ( !$options ) 332 $options = $option_value; 333 334 update_option($option_name, $options); 335 } 336 337 function removeOption( $option_name ) 338 { 339 delete_option( $option_name ); 340 341 } 342 366 343 function pwAdminScreen() 367 344 { … … 369 346 $opts = pw_admin::updateAdminOptions(); 370 347 // write submitted changes if this page reload shows a submit 348 if (!pw_utils::databaseUpToDate()) 349 { 350 ?> 351 <form action="" method="post"> 352 <?php 353 echo "<div id='message' class='updated'>" . pw_admin::fixDatabase() . "</div>"; 354 ?> 355 <input type="submit" name="infocard_admin_upgrade" id="infocard_admin_upgrade" value="Continue" /> 356 </form> 357 <?php 358 return; 359 } 371 360 372 361 pw_admin::printSystemCheck($opts['pw_securesiteurl']); … … 491 480 return $option_val; 492 481 } 493 function checkDatabaseStructure() 494 { 495 // eventually this is where I will put my database upgrade code. 482 483 function createInfocardAuditTable() 484 { 485 global $wpdb; 486 $audittable = PW_TABLE_PREFIX . "infocard_audit"; 487 488 $myTableAuditQuery = 489 "CREATE TABLE IF NOT EXISTS `" . $audittable . "` ( 490 `cardhash` text default '', 491 `accountid` bigint(20) unsigned, 492 `email` varchar(128) NOT NULL default '', 493 `time` datetime NOT NULL default '0000-00-00 00:00:00', 494 `IP` varchar(16) NOT NULL default '', 495 `status` varchar(128) NOT NULL default '' 496 ) ENGINE = MYISAM"; 497 498 // Check if table is already there 499 foreach ($wpdb->get_col("SHOW TABLES", 0) as $table ) 500 { 501 if ($table == $audittable) 502 { 503 return false; 504 } 505 } 506 507 // Ok, let's proceed 508 if ( $wpdb->query( $myTableAuditQuery ) === false ) 509 { 510 return false; 511 } 512 513 // Just to be sure, we check that tables were actually created 514 foreach ( $wpdb->get_col("SHOW TABLES", 0) as $table ) 515 { 516 if ( $table == $audittable ) 517 { 518 return true; 519 } 520 } 521 return false; 522 } //end function createInfocardAuditTable 523 524 function createInfocardIdentityTable() 525 { 526 global $wpdb; 527 $identitytable = PW_TABLE_PREFIX . "infocard_identities"; 528 529 $myTableIdentityQuery = 530 "CREATE TABLE `" . $identitytable . "` ( 531 `cardhash` text default '', 532 `accountid` bigint(20) unsigned, 533 `cardhandle` varchar(128) NOT NULL default '', 534 `startdate` varchar(128) NOT NULL default '', 535 `lastused` varchar(128) NOT NULL default '' 536 ) ENGINE = MYISAM"; 537 538 // Check if table is already there 539 foreach ($wpdb->get_col("SHOW TABLES", 0) as $table ) 540 { 541 if ($table == $identitytable) 542 { 543 return false; 544 } 545 } 546 547 // Ok, let's proceed 548 if ( $wpdb->query( $myTableIdentityQuery ) === false ) 549 { 550 return false; 551 } 552 553 // Just to be sure, we check that tables were actually created 554 foreach ( $wpdb->get_col("SHOW TABLES", 0) as $table ) 555 { 556 if ( $table == $identitytable ) 557 { 558 return true; 559 } 560 } 561 return false; 562 } // end function createInfocardIdentityTable 563 564 /* 565 Function: fixDatabase 566 Description: updates/alters database depending on detection 567 of database version 568 Input: none 569 Output: status string 570 Side-Effect: may alter database structure 571 */ 572 function fixDatabase() 573 { 574 include_once('db_upgrade.pw.php'); 575 $output = "<h4>Upgrading PamelaWare to " . PW_VERSION . "</h4>"; 576 if (pw_admin::getOption('pw_db_version')) 577 return $output . "oops sorry, up to date</p>"; 578 579 if (pw_admin::getOption('pw_infocard_key')) 580 { 581 $output .= pw_db_upgrade::upgradeDBv2ToDBv3(); 582 return $output . "</p>"; 583 } 584 585 if (pw_admin::getOption('infocard_key')) 586 { 587 $output .= pw_db_upgrade::upgradeDBv1ToDBv3(); 588 return $output . "</p>"; 589 } 590 return $output . "ERROR: non-standard database state!"; 496 591 } 497 592 } // end class pw_admin branches/RB-0.9/wp-infocard/wp/processing.pw.php
r108 r122 51 51 } // end function showProcessingSummary 52 52 53 /* 54 Function: getDBv1CardHash 55 Description: Before we started storing card hash, we stored 56 the PPID and an MD5 hash of the base64-decoded 57 modulus. 58 This means that when we upgraded the database 59 from v1 to v3, we had to make a hash out of 60 the ppid and the md5 hash, not the ppid and the 61 modulus. 62 Input: none 63 Output: SHA256 card hash with ppid 64 & md5(base64_decode(modulus)) 65 */ 66 function getDBv1CardHash() 67 { 68 global $claimslist; 69 70 $mod = md5(base64_decode($claimslist['signerkeymodulus']->token_value)); 71 pw_utils::printDebug('<br/>Checking for DBv1 card hash<br/>'); 72 pw_utils::printDebug('Modulus: ' . $mod . '<br/>'); 73 74 $cardhash = pw_processing::calculateCardHash( 75 $claimslist['privatepersonalidentifier']->token_value, 76 $mod 77 ); 78 pw_utils::printDebug('CardHash: ' . $cardhash . '<br/>'); 79 return $cardhash; 80 } //end function getDBv1CardHash 81 53 82 } // end class pw_processing 54 83 ?> branches/RB-0.9/wp-infocard/wp/userdata.pw.php
r110 r122 527 527 . $cardhash . "'"; 528 528 $identity_info = $wpdb->get_results( $query, OBJECT ); 529 530 if ((count($identity_info) === 0) && (pw_admin::getOption('pw_dbv1_users'))) 531 { 532 $legacy_cardhash = pw_processing::getDBv1CardHash(); 533 $query = "SELECT * FROM `" . PW_TABLE_PREFIX 534 . "infocard_identities` WHERE cardhash = '" 535 . $legacy_cardhash . "'"; 536 $identity_info = $wpdb->get_results( $query, OBJECT ); 537 538 if (count($identity_info) == 1) 539 { 540 pw_userdata::updateLegacyCardHashFromToken($cardhash, $identity_info[0]->accountid); 541 542 $query = "SELECT * FROM `" . PW_TABLE_PREFIX 543 . "infocard_identities` WHERE cardhash = '" 544 . $cardhash . "'"; 545 $identity_info = $wpdb->get_results( $query, OBJECT ); 546 delete_usermeta($identity_info[0]->accountid, 'ppid'); 547 delete_usermeta($identity_info[0]->accountid, 'identity'); 548 } 549 } 550 529 551 switch (count($identity_info)) 530 552 { … … 715 737 }//end function userLoginIsUnique($user_login) 716 738 739 function updateLegacyCardHashFromToken($cardhash, $accountid) 740 { 741 if ((!$cardhash) | (!$accountid)) 742 { 743 pw_utils::printDebug('ERROR: missing parameter from updateLegacyCardHashFromToken<br/>'); 744 return; 745 } 746 global $claimslist, $wpdb; 747 $cardhandle = pw_processing::constructCardHandle( 748 $claimslist['privatepersonalidentifier']->token_value, 749 $claimslist['signerkeymodulus']->token_value 750 ); 751 $query = "UPDATE " . PW_TABLE_PREFIX . "infocard_identities " 752 . "SET cardhash = '" . $cardhash . "', cardhandle = '" 753 . $cardhandle . "' WHERE accountid = '" . $accountid . "'"; 754 755 $wpdb->query( $query ); 756 757 $total_cards = pw_admin::getOption('pw_dbv1_users'); 758 $total_cards = $total_cards - 1; 759 pw_admin::setOption('pw_dbv1_users', $total_cards); 760 pw_utils::printDebug('DBv1 users left: ' . $total_cards . '<br/>'); 761 } //end function updateLegacyCardHash 717 762 } // end class pw_userdata 718 763 ?> branches/RB-0.9/wp-infocard/wp/utils.pw.php
r121 r122 319 319 } 320 320 321 function databaseUpToDate() 322 { 323 // Current version: PW DB v3 324 // note that for this version anything older than the 325 // current version will not even have a pw_db_version 326 // option 327 return (bool)pw_admin::getOption('pw_db_version'); 328 } 329 321 330 } // end class pw_utils 322 331 ?>
