Exemplo n.º 1
0
/**
* this function hooks cases of keyswap being called with forced mode.    
* Forced mode can only be used from hosts we trust untill now.
* 
* @see api/xmlrpc/dispatcher.php::keyswap()
* 
* Add : 
*		// PATCH add force mode
*        if (!empty($params[3])){ // requiring force mode
*        	$mnetlocallib = get_config('docroot').'/local/mnet/lib.php';
*        	if (file_exists($mnetlocallib)){
*	        	return local_xmlrpc_key_forced_keyswap($wwwroot, $pubkey, $application);
*	        }
*	        return false;
*        }
*        // /PATCH
*
* after $params decoding for enabling forced mode.
*/
function local_xmlrpc_key_forced_keyswap($wwwroot, $pubkey, $application)
{
    $now = time();
    // reinforced security : only known host with still valid key can force us renewal
    if ($exists = get_records_select_array('host', " wwwroot = '{$wwwroot}' AND deleted = 0 AND publickeyexpires >= {$now} ")) {
        try {
            $peer = new Peer();
            if ($peer->findByWwwroot($wwwroot)) {
                $pk = new PublicKey($pubkey, $wwwroot);
                $peer->publickey = $pk;
                $peer->commit();
            }
            // Mahara return his own key
            $openssl = OpenSslRepo::singleton();
            return $openssl->certificate;
        } catch (Exception $e) {
            throw new SystemException($e->getMessage(), $e->getCode());
        }
    } else {
        throw new SystemException("Fails exists known {$wwwroot} as wwwroot", 6100);
    }
}
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
function get_peer($wwwroot, $cache = true)
{
    $wwwroot = (string) $wwwroot;
    static $peers = array();
    if ($cache) {
        if (isset($peers[$wwwroot])) {
            return $peers[$wwwroot];
        }
    }
    require_once get_config('libroot') . 'peer.php';
    $peer = new Peer();
    if (!$peer->findByWwwroot($wwwroot)) {
        // Bootstrap unknown hosts?
        throw new MaharaException("We don't have a record for your webserver ({$wwwroot}) in our database", 6003);
    }
    $peers[$wwwroot] = $peer;
    return $peers[$wwwroot];
}
Exemplo n.º 4
0
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details:
 *
 *             http://www.gnu.org/copyleft/gpl.html
 */
define('INTERNAL', 1);
require dirname(dirname(dirname(__FILE__))) . '/init.php';
require_once get_config('docroot') . 'api/xmlrpc/client.php';
require_once get_config('docroot') . 'auth/xmlrpc/lib.php';
require_once get_config('libroot') . 'institution.php';
$remotewwwroot = param_variable('wr');
$instanceid = param_variable('ins');
$wantsurl = param_variable('wantsurl', '');
if (!get_config('enablenetworking')) {
    throw new AccessTotallyDeniedException(get_string('networkingdisabledonthissite', 'auth.xmlrpc'));
}
$peer = new Peer();
$peer->findByWwwroot($remotewwwroot);
$url = $remotewwwroot . $peer->application->ssolandurl;
$providers = get_service_providers($USER->authinstance);
$approved = false;
$url = start_jump_session($peer, $instanceid, $wantsurl);
if (empty($url)) {
    throw new XmlrpcClientException('DEBUG: Jump session was not started correctly or blank URL returned.');
    // TODO: errors
}
redirect($url);