| 117 | | } //end function populateUpdatedCardhash |
|---|
| 118 | | |
|---|
| | 117 | } //end function populateDBv1Cardhash |
|---|
| | 118 | |
|---|
| | 119 | |
|---|
| | 120 | /* |
|---|
| | 121 | Function: upgradeDBv2ToDBv3 |
|---|
| | 122 | Description: does all the work to get from version1 to version 3 |
|---|
| | 123 | Input: none |
|---|
| | 124 | Output: none |
|---|
| | 125 | Side-Effect: alters database structure |
|---|
| | 126 | */ |
|---|
| | 127 | final function upgradeDBv2ToDBv3() |
|---|
| | 128 | { |
|---|
| | 129 | global $wpdb; |
|---|
| | 130 | $output = '<ul>'; |
|---|
| | 131 | if (PW_PLUGIN !== "wp") |
|---|
| | 132 | return "ERROR: database option should not be needed for a PamelaWare Plugin other than Wordpress"; |
|---|
| | 133 | |
|---|
| | 134 | $options = get_alloptions(); |
|---|
| | 135 | $output .= "<li>adding NEW options</li>"; |
|---|
| | 136 | $output .= "<ul><li>New Trust settings for self-issued and managed cards</li></ul>"; |
|---|
| | 137 | $output .= "<li>By default, trust is set at most conservative level</li>"; |
|---|
| | 138 | $output .= "<ul><li>New Debug setting on console</li></ul>"; |
|---|
| | 139 | $output .= "<ul><li>Choose HTML or XHTML compatible selector trigger</li></ul>"; |
|---|
| | 140 | pw_admin::createOption('pw_selector_trigger', 'html'); |
|---|
| | 141 | pw_admin::createOption('pw_custom_data', 0); |
|---|
| | 142 | pw_admin::createOption('pw_time_validation', 1); |
|---|
| | 143 | if (isset($options->pw_trust_managed_cards)) |
|---|
| | 144 | { |
|---|
| | 145 | if ($options->pw_trust_managed_cards == 0) |
|---|
| | 146 | pw_admin::setOption('pw_trust_managed_cards','trustnone'); |
|---|
| | 147 | if ($option->pw_trust_managed_cards == 1) |
|---|
| | 148 | pw_admin::setOption('pw_trust_managed_cards','trustall'); |
|---|
| | 149 | } |
|---|
| | 150 | else |
|---|
| | 151 | { |
|---|
| | 152 | pw_admin::createOption('pw_trust_managed_cards', 'validate'); |
|---|
| | 153 | } |
|---|
| | 154 | |
|---|
| | 155 | if (isset($options->pw_trust_personal_cards)) |
|---|
| | 156 | { |
|---|
| | 157 | if ($options->pw_trust_personal_cards == 0) |
|---|
| | 158 | pw_admin::setOption('pw_trust_personal_cards','trustnone'); |
|---|
| | 159 | if ($option->pw_trust_personal_cards == 1) |
|---|
| | 160 | pw_admin::setOption('pw_trust_personal_cards','trustall'); |
|---|
| | 161 | } |
|---|
| | 162 | else |
|---|
| | 163 | { |
|---|
| | 164 | pw_admin::createOption('pw_trust_personal_cards', 'validate'); |
|---|
| | 165 | } |
|---|
| | 166 | pw_admin::createOption('pw_trusted_idp_list', ''); |
|---|
| | 167 | |
|---|
| | 168 | $output .= "<li>adding new columns to the identity table(" . PW_TABLE_PREFIX . "infocard_identities)</li>"; |
|---|
| | 169 | |
|---|
| | 170 | $query = "ALTER TABLE " . PW_TABLE_PREFIX |
|---|
| | 171 | . "infocard_identities" . " ADD cardhash text default '' FIRST"; |
|---|
| | 172 | |
|---|
| | 173 | if ( $wpdb->query( $query ) === false ) |
|---|
| | 174 | { |
|---|
| | 175 | $output .= "<li>Error adding cardhash column to Identity Table!</li>"; |
|---|
| | 176 | return $output . "</ul>"; |
|---|
| | 177 | } |
|---|
| | 178 | else |
|---|
| | 179 | $output .= "<ul><li>Added cardhash column</li>"; |
|---|
| | 180 | |
|---|
| | 181 | $query = "ALTER TABLE " . PW_TABLE_PREFIX |
|---|
| | 182 | . "infocard_identities" . " ADD cardhandle varchar(128) NOT NULL default ''"; |
|---|
| | 183 | |
|---|
| | 184 | if ( $wpdb->query( $query ) === false ) |
|---|
| | 185 | { |
|---|
| | 186 | $output .= "<li>Error adding cardhandle column to Identity Table!</li>"; |
|---|
| | 187 | return $output . "</ul></ul>"; |
|---|
| | 188 | } |
|---|
| | 189 | else |
|---|
| | 190 | $output .= "<li>Added cardhandle column</li>"; |
|---|
| | 191 | |
|---|
| | 192 | $query = "ALTER TABLE " . PW_TABLE_PREFIX |
|---|
| | 193 | . "infocard_identities" . " ADD startdate varchar(128) NOT NULL default ''"; |
|---|
| | 194 | |
|---|
| | 195 | if ( $wpdb->query( $query ) === false ) |
|---|
| | 196 | { |
|---|
| | 197 | $output .= "<li>Error adding startdate column to Identity Table!</li>"; |
|---|
| | 198 | return $output . "</ul></ul>"; |
|---|
| | 199 | } |
|---|
| | 200 | else |
|---|
| | 201 | $output .= "<li>Added startdate column</li>"; |
|---|
| | 202 | |
|---|
| | 203 | $query = "ALTER TABLE " . PW_TABLE_PREFIX . "infocard_identities" |
|---|
| | 204 | . " ADD lastused varchar(128) NOT NULL default ''"; |
|---|
| | 205 | |
|---|
| | 206 | if ( $wpdb->query( $query ) === false ) |
|---|
| | 207 | { |
|---|
| | 208 | $output .= "<li>Error adding lastused column to Identity Table!</li>"; |
|---|
| | 209 | return $output . "</ul></ul>"; |
|---|
| | 210 | } |
|---|
| | 211 | else |
|---|
| | 212 | $output .= "<li>Added lastused column</li></ul>"; |
|---|
| | 213 | |
|---|
| | 214 | $query = "ALTER TABLE " . PW_TABLE_PREFIX . "infocard_audit" |
|---|
| | 215 | . " ADD cardhash text default '' FIRST"; |
|---|
| | 216 | |
|---|
| | 217 | if ( $wpdb->query( $query ) === false ) |
|---|
| | 218 | { |
|---|
| | 219 | $output .= "<li>Error adding cardhash column to Audit Table!</li>"; |
|---|
| | 220 | return $output . "</ul></ul>"; |
|---|
| | 221 | } |
|---|
| | 222 | else |
|---|
| | 223 | $output .= "<li>Added cardhash column to Audit table</li></ul>"; |
|---|
| | 224 | $output .= "<li>upgrading existing users:</li>"; |
|---|
| | 225 | $output .= pw_db_upgrade::populateDBv2Cardhash(); |
|---|
| | 226 | pw_admin::createOption('pw_db_version', 'DB v3'); |
|---|
| | 227 | |
|---|
| | 228 | return $output . "</ul>"; |
|---|
| | 229 | |
|---|
| | 230 | } // end function upgradeDBv2ToDBv3 |
|---|
| | 231 | |
|---|
| | 232 | |
|---|
| | 233 | /* |
|---|
| | 234 | Function: populateDBv2Cardhash |
|---|
| | 235 | Description: loops through DB v2 identity table and |
|---|
| | 236 | populates the cardhash from the modulus and ppid |
|---|
| | 237 | Input: none |
|---|
| | 238 | Output: string with status |
|---|
| | 239 | */ |
|---|
| | 240 | function populateDBv2Cardhash() |
|---|
| | 241 | { |
|---|
| | 242 | if (PW_PLUGIN !== 'wp') |
|---|
| | 243 | return; |
|---|
| | 244 | global $wpdb; |
|---|
| | 245 | $output = ''; |
|---|
| | 246 | $today = date('Y-m-d H-i-s'); |
|---|
| | 247 | |
|---|
| | 248 | |
|---|
| | 249 | $query = "SELECT ppid, modulusHash as modulus, accountid FROM " |
|---|
| | 250 | . PW_TABLE_PREFIX . "infocard_identities"; |
|---|
| | 251 | |
|---|
| | 252 | $identity_info = $wpdb->get_results( $query, OBJECT ); |
|---|
| | 253 | |
|---|
| | 254 | $total_cards = count($identity_info); |
|---|
| | 255 | |
|---|
| | 256 | $output .= "<ul><li>Cardholders found: " . $total_cards . "</li></ul>"; |
|---|
| | 257 | pw_admin::createOption('pw_dbv2_users', $total_cards); |
|---|
| | 258 | foreach ($identity_info as $identity) |
|---|
| | 259 | { |
|---|
| | 260 | $cardhash = pw_processing::calculateCardHash( |
|---|
| | 261 | $identity->ppid, |
|---|
| | 262 | $identity->modulus |
|---|
| | 263 | ); |
|---|
| | 264 | $output .= "<li>cardhash: " . $cardhash . "from (" |
|---|
| | 265 | . $identity->ppid . ") and (" . $identity->modulus . ")</li>"; |
|---|
| | 266 | $query = "UPDATE " . PW_TABLE_PREFIX |
|---|
| | 267 | . "infocard_identities SET cardhash = '" . $cardhash |
|---|
| | 268 | . "', cardhandle = '" . $cardhandle . "', startdate = '" |
|---|
| | 269 | . $today . "', lastused = '" . $today . "' " |
|---|
| | 270 | . " WHERE accountid = '" . $identity->accountid . "'"; |
|---|
| | 271 | $output .= $query; |
|---|
| | 272 | $wpdb->query( $query ); |
|---|
| | 273 | } |
|---|
| | 274 | return $output; |
|---|
| | 275 | } //end function populateDBv2Cardhash |
|---|