oidc-registration-php/admin_delete.php

69 lines
1.7 KiB
PHP
Raw Normal View History

2024-09-06 20:00:02 +00:00
<?php
/*
* This is an adminstrative function, not exposed on the
* Menu, for debugging. It will remove all Client Registrations
* for a particular "Site Owner".
*
*/
error_reporting(E_ALL);
ini_set('display_errors', '1');
echo file_get_contents("html/header.html");
$ini_arr = parse_ini_file( "cacert.ini", true );
$dbUser = $ini_arr[ 'DB' ][ 'User' ];
$dbPass = $ini_arr[ 'DB' ][ 'Password' ];
$internalHydraEndpointURL = $ini_arr[ 'URLs' ][ 'InternalHydraEndpointURL' ];
$db = new PDO("pgsql:host=localhost;port=5432;dbname=oidc_db;user=$dbUser;password=$dbPass");
$sql = "select client_id from clients where site_owner like 'Brian %'";
foreach ( $db->query($sql) as $row) {
$clientID = $row['client_id'];
$retcode = exec("/srv/hydra/bin/hydra delete oauth2-client $clientID --endpoint $internalHydraEndpointURL ", $hydraArray);
$outArray = [];
foreach ($hydraArray as $hydra) {
$keyIDX = strpos($hydra,"\t");
if ( $keyIDX === false ) {
$outArray[ $hydra ] = "";
} else {
$valIDX = strrpos($hydra,"\t", -1);
$key = substr( $hydra, 0, $keyIDX );
$val = substr( $hydra, $valIDX + 1 );
$outArray[ $key ] = $val;
}
}
echo "Input: " . var_export($clientID,true) . "<br>";
echo "Hydra: " . var_export($outArray,true) . "<br>";
$stmt = $db->prepare("update clients set deleted_at = now() where client_id = :client_id");
$retcode = $stmt->execute( [ $clientID ]);
echo "<br><br>";
echo "DB Retcode: " . var_export($retcode,true). "<br>";
}
echo file_get_contents("html/footer.html");
echo "<br>";
echo '<p>Copyright © CAcert, Inc ';
echo date("Y");
echo "</p>";