21 lines
1.4 KiB
PHP
21 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
$root=$argv[1]??'';
|
|
try {
|
|
require $root.'/vendor/autoload.php';
|
|
$app=new class($root.DIRECTORY_SEPARATOR) extends think\App {
|
|
public function loadEnv(string $name=''):void { parent::loadEnv($name); $this->env->set('APP_DEBUG',false); }
|
|
};
|
|
$app->initialize();
|
|
$cfg=(array)$app->config->get('database.connections.mysql');
|
|
$db=think\facade\Db::connect();
|
|
$db->execute('SET SESSION TRANSACTION READ ONLY');
|
|
$db->startTrans();
|
|
$rows=$db->name('admin')->field('id,account,root,delete_time')->order('id')->select()->toArray();
|
|
$canonical=[];$roots=[];$identities=[];
|
|
foreach($rows as $row){$canonical[]=(int)$row['id'].'|'.$row['account'].'|'.(int)$row['root'].'|'.(string)$row['delete_time']; $identities[(string)$row['id']]=hash('sha256',(int)$row['id'].'|'.$row['account']); if((int)$row['root']===1 && !$row['delete_time'])$roots[]=(int)$row['id'];}
|
|
$db->rollback();
|
|
if(isset($argv[2])) {file_put_contents($argv[2],json_encode($identities,JSON_THROW_ON_ERROR));chmod($argv[2],0600);}
|
|
echo json_encode(['ok'=>true,'database'=>$cfg['database']??'','prefix'=>$cfg['prefix']??'','admin_count'=>count($rows),'identity_sha256'=>hash('sha256',implode("\n",$canonical)),'root_ids'=>$roots],JSON_UNESCAPED_UNICODE).PHP_EOL;
|
|
}catch(Throwable $e){echo json_encode(['ok'=>false,'error'=>get_class($e)]).PHP_EOL;exit(1);}
|