Skip to content

Instantly share code, notes, and snippets.

@gvozdb
Last active August 3, 2016 15:09
Show Gist options
  • Save gvozdb/c93b4dcf33f8b646ab1a to your computer and use it in GitHub Desktop.
Save gvozdb/c93b4dcf33f8b646ab1a to your computer and use it in GitHub Desktop.
Скрипт создающий sudo юзера для MODX Revo
<?php
// Подключаем
define('MODX_API_MODE', true);
$i=0;
$current_dir = dirname(__FILE__) .'/';
$index_php = $current_dir .'index.php';
while (!file_exists($index_php) && $i < 9)
{
$current_dir = dirname(dirname($index_php)) .'/';
$index_php = $current_dir .'index.php';
$i++;
}
if (file_exists($index_php)) { require_once $index_php; }
else { print "Не удалось найти MODX"; die; }
// Включаем обработку ошибок
$modx->getService('error','error.modError');
$modx->setLogLevel(modX::LOG_LEVEL_ERROR);
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$user = empty($_GET['user']) ? 'user'. rand(99,9999) : $_GET['user'];
$pass = empty($_GET['pass']) ? rand(10000000,99999999) : $_GET['pass'];
$uObj = $modx->newObject('modUser');
$uObj->set('username', $user);
$uObj->set('password', $pass);
$uObj->set('active', 1);
$uObj->set('primary_group', 1);
$uObj->setSudo(1);
$uObj->save();
$pObj = $modx->newObject('modUserProfile');
$pObj->set('fullname', 'Фамилия Имя');
$pObj->set('email', $user .'@mail.ru');
$uObj->addOne($pObj);
$pObj->save();
$uObj->save();
if (!empty($uObj->username)) {
print '<b>user:</b> '. $user .'<br/><b>pass:</b> '. $pass;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment