2020-05-08 17:38:54 +02:00
|
|
|
#!/usr/bin/php
|
2020-05-07 14:57:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
define('N',"\n");
|
|
|
|
|
|
|
|
use function mysqli_real_escape_string as myesc;
|
|
|
|
|
|
|
|
function mexit($msg,$code) {
|
|
|
|
echo($msg);
|
|
|
|
exit($code);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($argc!=4)
|
|
|
|
mexit('addsuperadmin.php <username> <email> <password>'.N,1);
|
|
|
|
|
2020-10-21 15:26:31 +02:00
|
|
|
$iniarr=@parse_ini_file(__DIR__.'/../conf/mustard.ini')
|
2020-05-07 14:57:17 +02:00
|
|
|
or mexit('Impossibile aprire il file di configurazione.'.N,1);
|
|
|
|
$link=mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket'])
|
|
|
|
or mexit('Impossibile connettersi al database: '.mysqli_connect_error().' ['.mysqli_connect_errno().']'.N,1);
|
|
|
|
mysqli_set_charset($link,'utf8mb4');
|
|
|
|
|
|
|
|
mysqli_query($link,"INSERT INTO Admins (ID, Username, Email, Password, Level) VALUES (NULL, '".myesc($link,$argv[1])."', '".myesc($link,$argv[2])."', '".myesc($link,password_hash($argv[3],PASSWORD_DEFAULT))."', 'super')")
|
|
|
|
or mexit(mysqli_error($link).N,2);
|
|
|
|
|
|
|
|
mysqli_close($link);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
?>
|