#!/usr/bin/php
<?php
// Change password for any user
error_reporting(E_ALL);
ini_set("track_errors", "On");
set_time_limit(0);
$_s = microtime(TRUE);
require_once("/etc/rocketgit/config.php");
$INC = $rg_scripts . '/inc';
require_once($INC . "/init.inc.php");
require_once($INC . "/log.inc.php");
require_once($INC . "/sql.inc.php");
require_once($INC . "/struct.inc.php");
require_once($INC . "/cache.inc.php");
require_once($INC . "/repo.inc.php");
require_once($INC . "/prof.inc.php");
require_once($INC . "/mr.inc.php");
require_once($INC . "/keys.inc.php");
require_once($INC . "/user.inc.php");
require_once($INC . "/bug.inc.php");
require_once($INC . "/fixes.inc.php");
$uid = posix_getuid();
if ($uid !== 0) {
echo 'This script must be run with root rights!' . "\n";
exit(1);
}
rg_sql_app("rg_change_pass");
$db = rg_sql_open($rg_sql);
if ($db === FALSE) {
echo 'Cannot connect to db: ' . $rg_sql_error() . "!\n";
exit(1);
}
$stdin = fopen('php://stdin', 'r');
if ($stdin === FALSE) {
echo 'Cannot open stdin!' . "\n";
exit(1);
}
if ($_SERVER['argc'] < 2)
$user = 'admin';
else
$user = trim($_SERVER['argv'][1]);
echo 'Changing password for user ' . $user . "\n";
echo "New password (will show on the screen, watch your back!): ";
$pass = fread($stdin, 128);
$pass = trim($pass);
$ui = rg_user_info($db, 0, $user, '');
if ($ui['exists'] != 1) {
echo 'User not found!' . "\n";
exit(1);
}
$r = rg_user_set_pass($db, $ui['uid'], $pass);
if ($r !== TRUE) {
echo 'Could not change pass: ' . rg_user_error() . "!\n";
exit(1);
}
echo 'Password changed with success!' . "\n";
if (rg_totp_enrolled($db, $ui['uid'])) {
echo 'Please note that user ' . $user . ' is enrolled in 2fa.' . "\n";
echo 'Do you want to remove any enrollment (yes/no) [no]: ';
$a = trim(fread($stdin, 128));
if (strcasecmp($a, 'yes') == 0) {
$r = rg_totp_unenroll($db, $ui['uid']);
if ($r !== TRUE) {
echo 'Cannot unenroll: ' . rg_totp_error() . '!' . "\n";
exit(1);
}
echo 'Done unenrolling!' . "\n";
}
}
?>
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master