2020-08-08 03:32:08 +00:00
< ? php
2023-08-27 06:32:40 +00:00
$statementCreateTable = $RUNTIME [ 'PDO' ] -> prepare ( " CREATE TABLE IF NOT EXISTS `UserIdentitys` (`PrincipalID` CHAR(36) NOT NULL, `IdentityID` CHAR(36) NOT NULL, PRIMARY KEY (`PrincipalID`, `IdentityID`)) ENGINE=MyISAM CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci " );
2023-08-27 03:31:32 +00:00
$statementCreateTable -> execute ();
2023-08-27 06:32:40 +00:00
$statementCreateTrigger = $RUNTIME [ 'PDO' ] -> prepare ( " CREATE TRIGGER IF NOT EXISTS del_id_trig AFTER DELETE ON UserAccounts FOR EACH ROW DELETE FROM UserIdentitys WHERE UserIdentitys.PrincipalID = OLD.PrincipalID OR UserIdentitys.IdentityID = OLD.PrincipalID " );
$statementCreateTrigger -> execute ();
2020-08-08 03:32:08 +00:00
2023-08-27 03:31:32 +00:00
if ( $_SERVER [ 'REQUEST_METHOD' ] == 'POST' ) {
include_once 'app/FormValidator.php' ;
if ( isset ( $_POST [ 'enableIdent' ])) {
2023-08-23 16:16:35 +00:00
$validator = new FormValidator ( array (
2023-08-27 06:32:40 +00:00
'uuid' => array ( 'required' => true , 'regex' => '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/' )
2023-08-23 16:16:35 +00:00
));
2023-08-27 03:31:32 +00:00
if ( $validator -> isValid ( $_POST )) {
2023-08-23 16:16:35 +00:00
$statement = $RUNTIME [ 'PDO' ] -> prepare ( " SELECT 1 FROM UserIdentitys WHERE PrincipalID = :PrincipalID AND IdentityID = :IdentityID LIMIT 1 " );
2023-08-27 06:32:40 +00:00
$statement -> execute ([ 'PrincipalID' => $_SESSION [ 'UUID' ], 'IdentityID' => $_POST [ 'uuid' ]]);
2023-08-23 16:16:35 +00:00
$statementPresence = $RUNTIME [ 'PDO' ] -> prepare ( " SELECT 1 FROM Presence WHERE UserID = :PrincipalID LIMIT 1 " );
2023-08-27 03:31:32 +00:00
$statementPresence -> execute ([ 'PrincipalID' => $_SESSION [ 'UUID' ]]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
if ( $statementPresence -> rowCount () == 0 ) {
if ( $statement -> rowCount () == 1 ) {
$statementAuth = $RUNTIME [ 'PDO' ] -> prepare ( 'UPDATE auth SET UUID = :IdentityID WHERE UUID = :PrincipalID' );
2023-08-27 06:32:40 +00:00
$statementAuth -> execute ([ 'IdentityID' => $_POST [ 'uuid' ], 'PrincipalID' => $_SESSION [ 'UUID' ]]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
$statementUserIdentitys = $RUNTIME [ 'PDO' ] -> prepare ( 'UPDATE UserIdentitys SET PrincipalID = :IdentityID WHERE PrincipalID = :PrincipalID' );
2023-08-27 06:32:40 +00:00
$statementUserIdentitys -> execute ([ 'IdentityID' => $_POST [ 'uuid' ], 'PrincipalID' => $_SESSION [ 'UUID' ]]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
$statementFriends = $RUNTIME [ 'PDO' ] -> prepare ( 'UPDATE Friends SET PrincipalID = :IdentityID WHERE PrincipalID = :PrincipalID' );
2023-08-27 06:32:40 +00:00
$statementFriends -> execute ([ 'IdentityID' => $_POST [ 'uuid' ], 'PrincipalID' => $_SESSION [ 'UUID' ]]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
//$statementReFriends = $RUNTIME['PDO']->prepare('UPDATE Friends SET Friend = :IdentityID WHERE Friend = :PrincipalID');
2023-08-27 06:32:40 +00:00
//$statementReFriends->execute(['IdentityID' => $_POST['uuid'], 'PrincipalID' => $_SESSION['UUID']]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
$statementInventoryFolders = $RUNTIME [ 'PDO' ] -> prepare ( 'UPDATE inventoryfolders SET agentID = :IdentityID WHERE agentID = :PrincipalID AND type != :InventarTyp' );
2023-08-27 06:32:40 +00:00
$statementInventoryFolders -> execute ([ 'IdentityID' => $_POST [ 'uuid' ], 'PrincipalID' => $_SESSION [ 'UUID' ], 'InventarTyp' => 46 ]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
$statementInventoryItems = $RUNTIME [ 'PDO' ] -> prepare ( 'UPDATE inventoryitems SET avatarID = :IdentityID WHERE avatarID = :PrincipalID' );
2023-08-27 06:32:40 +00:00
$statementInventoryItems -> execute ([ 'IdentityID' => $_POST [ 'uuid' ], 'PrincipalID' => $_SESSION [ 'UUID' ]]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
$statementGroupMembership = $RUNTIME [ 'PDO' ] -> prepare ( 'UPDATE os_groups_membership SET PrincipalID = :IdentityID WHERE PrincipalID = :PrincipalID' );
2023-08-27 06:32:40 +00:00
$statementGroupMembership -> execute ([ 'IdentityID' => $_POST [ 'uuid' ], 'PrincipalID' => $_SESSION [ 'UUID' ]]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
$statementGroupRoles = $RUNTIME [ 'PDO' ] -> prepare ( 'UPDATE os_groups_rolemembership SET PrincipalID = :IdentityID WHERE PrincipalID = :PrincipalID' );
2023-08-27 06:32:40 +00:00
$statementGroupRoles -> execute ([ 'IdentityID' => $_POST [ 'uuid' ], 'PrincipalID' => $_SESSION [ 'UUID' ]]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
$statementGroupRoles = $RUNTIME [ 'PDO' ] -> prepare ( 'DELETE FROM Presence WHERE UserID = :PrincipalID' );
2023-08-23 16:16:35 +00:00
$statementGroupRoles -> execute ([ 'PrincipalID' => $_SESSION [ 'UUID' ]]);
$_SESSION [ 'LOGIN' ] = 'false' ;
session_destroy ();
}
} else {
$_SESSION [ 'identities_err' ] = 'Du kannst die Identität nicht ändern, während du angemeldet bist. Bitte schließe den Viewer.' ;
}
}
2023-08-27 06:32:40 +00:00
} elseif ( isset ( $_POST [ 'createIdent' ])) {
2023-08-23 16:16:35 +00:00
$validator = new FormValidator ( array (
2023-08-23 16:16:36 +00:00
'newName' => array ( 'required' => true , 'regex' => '/^[^\\/<>\s]{1,64} [^\\/<>\s]{1,64}$/' )
2023-08-23 16:16:35 +00:00
));
2023-08-27 03:31:32 +00:00
if ( $validator -> isValid ( $_POST )) {
2023-08-27 06:32:40 +00:00
$avatarNameParts = explode ( " " , trim ( $_POST [ 'newName' ]));
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
if ( count ( $avatarNameParts ) == 2 ) {
2023-08-23 16:16:35 +00:00
$statement = $RUNTIME [ 'PDO' ] -> prepare ( " SELECT 1 FROM UserAccounts WHERE FirstName = :FirstName AND LastName = :LastName LIMIT 1 " );
2023-08-27 03:31:32 +00:00
$statement -> execute ([ 'FirstName' => trim ( $avatarNameParts [ 0 ]), 'LastName' => trim ( $avatarNameParts [ 1 ])]);
2023-08-23 16:16:35 +00:00
2023-08-27 03:31:32 +00:00
if ( $statement -> rowCount () == 0 ) {
include_once 'app/OpenSim.php' ;
2023-08-23 16:16:35 +00:00
$avatarUUID = ( new OpenSim ()) -> gen_uuid ();
2023-08-27 03:31:32 +00:00
$statementAccounts = $RUNTIME [ 'PDO' ] -> prepare ( 'INSERT INTO UserAccounts (PrincipalID, ScopeID, FirstName, LastName, Email, ServiceURLs, Created, UserLevel, UserFlags, UserTitle, active) VALUES (:PrincipalID, :ScopeID, :FirstName, :LastName, :Email, :ServiceURLs, :Created, :UserLevel, :UserFlags, :UserTitle, :active )' );
2023-08-23 16:16:35 +00:00
$statementAccounts -> execute ([ 'PrincipalID' => $avatarUUID , 'ScopeID' => " 00000000-0000-0000-0000-000000000000 " , 'FirstName' => $avatarNameParts [ 0 ], 'LastName' => $avatarNameParts [ 1 ], 'Email' => $_SESSION [ 'EMAIL' ], 'ServiceURLs' => " HomeURI= GatekeeperURI= InventoryServerURI= AssetServerURI= " , 'Created' => time (), 'UserLevel' => 0 , 'UserFlags' => 0 , 'UserTitle' => " " , 'active' => 1 ]);
2023-08-27 03:31:32 +00:00
$statementUserIdentitys = $RUNTIME [ 'PDO' ] -> prepare ( 'INSERT INTO UserIdentitys (PrincipalID, IdentityID) VALUES (:PrincipalID, :IdentityID)' );
2023-08-23 16:16:35 +00:00
$statementUserIdentitys -> execute ([ 'PrincipalID' => $_SESSION [ 'UUID' ], 'IdentityID' => $avatarUUID ]);
2023-08-27 03:31:32 +00:00
} else {
2023-08-23 16:16:35 +00:00
$_SESSION [ 'identities_err' ] = 'Dieser Name ist schon in Benutzung.' ;
}
2023-08-27 03:31:32 +00:00
} else {
2023-08-23 16:16:35 +00:00
$_SESSION [ 'identities_err' ] = 'Der Name muss aus einem Vor und einem Nachnamen bestehen.' ;
}
}
}
2023-08-27 06:32:40 +00:00
elseif ( isset ( $_POST [ 'deleteIdent' ])) {
$validator = new FormValidator ( array (
'uuid' => array ( 'required' => true , 'regex' => '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/' )
));
if ( $validator -> isValid ( $_POST )) {
2023-08-27 10:17:33 +00:00
include_once 'app/OpenSim.php' ;
( new OpenSim ()) -> deleteIdentity ( $_SESSION [ 'UUID' ], $_POST [ 'uuid' ]);
2023-08-27 06:32:40 +00:00
}
}
2023-08-23 16:16:35 +00:00
header ( 'Location: index.php?page=identities' );
die ();
}
2023-08-27 03:31:32 +00:00
$HTML -> setHTMLTitle ( " Identitäten " );
$HTML -> importSeitenInhalt ( " identities.html " );
2023-08-23 16:16:35 +00:00
2023-08-23 16:16:34 +00:00
$statementCheckForEntry = $RUNTIME [ 'PDO' ] -> prepare ( " SELECT 1 FROM UserIdentitys WHERE PrincipalID = ? LIMIT 1 " );
2023-08-27 03:31:32 +00:00
$statementCheckForEntry -> execute ( array ( $_SESSION [ 'UUID' ]));
2020-08-08 03:32:08 +00:00
2023-08-27 03:31:32 +00:00
if ( $statementCheckForEntry -> rowCount () == 0 ) {
$statement = $RUNTIME [ 'PDO' ] -> prepare ( 'INSERT INTO `UserIdentitys` (PrincipalID, IdentityID) VALUES (:PrincipalID, :IdentityID)' );
2020-08-08 03:32:08 +00:00
$statement -> execute ([ 'PrincipalID' => $_SESSION [ 'UUID' ], 'IdentityID' => $_SESSION [ 'UUID' ]]);
}
$table = '<table class="table"><thead><tr><th scope="col">Name</th><th scope="col">Aktionen</th></thead><tbody>%%ENTRY%%</tbody></table>' ;
2023-08-23 16:16:34 +00:00
$statement = $RUNTIME [ 'PDO' ] -> prepare ( " SELECT IdentityID FROM UserIdentitys WHERE PrincipalID = ? ORDER BY IdentityID ASC " );
2023-08-27 03:31:32 +00:00
$statement -> execute ( array ( $_SESSION [ 'UUID' ]));
2020-08-08 03:32:08 +00:00
2023-08-27 03:31:32 +00:00
include_once 'app/OpenSim.php' ;
2023-08-23 16:16:35 +00:00
$opensim = new OpenSim ();
2023-08-27 03:31:32 +00:00
while ( $row = $statement -> fetch ()) {
if ( $row [ 'IdentityID' ] == $_SESSION [ 'UUID' ]) {
2023-08-23 16:16:35 +00:00
$entry = '<tr><td>' . htmlspecialchars ( trim ( $opensim -> getUserName ( $row [ 'IdentityID' ]))) . ' <span class="badge badge-info">Aktiv</span></td><td>-</td></tr>' ;
2023-08-27 03:31:32 +00:00
} else {
2023-08-27 06:32:40 +00:00
$entry = '<tr><td>' . htmlspecialchars ( trim ( $opensim -> getUserName ( $row [ 'IdentityID' ]))) . '</td><td><form action="index.php?page=identities" method="post">%%CSRF%%<input type="hidden" name="uuid" value="' . htmlspecialchars ( $row [ 'IdentityID' ]) . '"><button type="submit" name="enableIdent" class="btn btn-success btn-sm">Aktivieren</button> <button type="submit" name="deleteIdent" class="btn btn-danger btn-sm">Löschen</button></form></td></tr>' ;
2020-08-08 03:32:08 +00:00
}
$table = str_replace ( " %%ENTRY%% " , $entry . " %%ENTRY%% " , $table );
}
$table = str_replace ( " %%ENTRY%% " , " " , $table );
$HTML -> ReplaceSeitenInhalt ( " %%IDENT-LIST%% " , $table );
2023-08-23 16:16:35 +00:00
$HTML -> ReplaceSeitenInhalt ( " %%link%% " , ' ' );
$message = '' ;
2023-08-27 03:31:32 +00:00
if ( isset ( $_SESSION [ 'identities_err' ])) {
2023-08-23 16:16:35 +00:00
$message = '<div class="alert alert-danger" role="alert">' . $_SESSION [ 'identities_err' ] . '</div>' ;
unset ( $_SESSION [ 'identities_err' ]);
}
$HTML -> ReplaceSeitenInhalt ( " %%MESSAGE%% " , $message );
2020-08-08 03:32:08 +00:00
$HTML -> build ();
echo $HTML -> ausgabe ();