示例#1
0
文件: lib.php 项目: rboyatt/mahara
 public static function save_instance_config_options($values, Pieform $form)
 {
     if (false === strpos($values['wwwroot'], '://')) {
         $values['wwwroot'] = 'http://' . $values['wwwroot'];
     }
     db_begin();
     $authinstance = new stdClass();
     $peer = new Peer();
     if ($values['instance'] > 0) {
         $values['create'] = false;
         $current = get_records_assoc('auth_instance_config', 'instance', $values['instance'], '', 'field, value');
         $authinstance->id = $values['instance'];
     } else {
         $values['create'] = true;
         // Get the auth instance with the highest priority number (which is
         // the instance with the lowest priority).
         // TODO: rethink 'priority' as a fieldname... it's backwards!!
         $lastinstance = get_records_array('auth_instance', 'institution', $values['institution'], 'priority DESC', '*', '0', '1');
         if ($lastinstance == false) {
             $authinstance->priority = 0;
         } else {
             $authinstance->priority = $lastinstance[0]->priority + 1;
         }
     }
     if (false == $peer->findByWwwroot($values['wwwroot'])) {
         try {
             $peer->bootstrap($values['wwwroot'], null, $values['appname'], $values['institution']);
         } catch (RemoteServerException $e) {
             $form->set_error('wwwroot', get_string('cantretrievekey', 'auth'));
             throw new RemoteServerException($e->getMessage(), $e->getCode());
         }
     }
     $peer->wwwroot = preg_replace("|\\/+\$|", "", $values['wwwroot']);
     $peer->name = $values['name'];
     $peer->deleted = $values['deleted'];
     $peer->appname = $values['appname'];
     $peer->institution = $values['institution'];
     if (isset($values['publickey'])) {
         $peer->publickey = new PublicKey($values['publickey'], $peer->wwwroot);
         $peer->publickeyexpires = $peer->publickey->expires;
     }
     /**
     * The following properties are not user-updatable
             $peer->lastconnecttime      = $values['lastconnecttime'];
     */
     $peer->commit();
     $authinstance->instancename = $values['instancename'];
     $authinstance->institution = $values['institution'];
     $authinstance->authname = $values['authname'];
     if ($values['create']) {
         $values['instance'] = insert_record('auth_instance', $authinstance, 'id', true);
     } else {
         update_record('auth_instance', $authinstance, array('id' => $values['instance']));
     }
     if (empty($current)) {
         $current = array();
     }
     self::$default_config = array('wwwroot' => $values['wwwroot'], 'parent' => $values['parent'], 'authloginmsg' => $values['authloginmsg'], 'wessoout' => 0, 'theyssoin' => 0, 'theyautocreateusers' => 0, 'weautocreateusers' => 0, 'updateuserinfoonlogin' => 0, 'weimportcontent' => 0);
     if ($values['ssodirection'] == 'wessoout') {
         self::$default_config['wessoout'] = 1;
         self::$default_config['theyautocreateusers'] = $values['theyautocreateusers'];
     } else {
         if ($values['ssodirection'] == 'theyssoin') {
             self::$default_config['theyssoin'] = 1;
             self::$default_config['updateuserinfoonlogin'] = $values['updateuserinfoonlogin'];
             self::$default_config['weautocreateusers'] = $values['weautocreateusers'];
             self::$default_config['weimportcontent'] = $values['weimportcontent'];
         }
     }
     foreach (self::$default_config as $field => $value) {
         $record = new stdClass();
         $record->instance = $values['instance'];
         $record->field = $field;
         $record->value = $value;
         if ($field == 'wwwroot') {
             $record->value = dropslash($value);
         }
         if (empty($value)) {
             delete_records('auth_instance_config', 'field', $field, 'instance', $values['instance']);
         } elseif ($values['create'] || !array_key_exists($field, $current)) {
             insert_record('auth_instance_config', $record);
         } else {
             update_record('auth_instance_config', $record, array('instance' => $values['instance'], 'field' => $field));
         }
     }
     db_commit();
     return $values;
 }
 function keyswap($function, $params)
 {
     require_once get_config('libroot') . 'peer.php';
     //TODO: Verify params
     empty($params[0]) ? $wwwroot = null : ($wwwroot = $params[0]);
     empty($params[1]) ? $pubkey = null : ($pubkey = $params[1]);
     empty($params[2]) ? $application = null : ($application = $params[2]);
     if (get_config('promiscuousmode')) {
         try {
             $peer = new Peer();
             if ($peer->bootstrap($wwwroot, $pubkey, $application)) {
                 $peer->commit();
             }
         } catch (Exception $e) {
             throw new SystemException($e->getMessage(), $e->getCode());
         }
     }
     $openssl = OpenSslRepo::singleton();
     return $openssl->certificate;
 }