Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param to show database password #26

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chash.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
new Chash\Command\User\ResetLoginCommand(),
new Chash\Command\User\SetLanguageCommand(),
new Chash\Command\User\UsersPerUrlAccessCommand(),

new Chash\Command\Email\SendEmailCommand(),
)
);
$application->run();
43 changes: 43 additions & 0 deletions src/Chash/Command/Email/CommonChamiloEmailCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Chash\Command\Email;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use Symfony\Component\Console\Formatter\OutputFormatterStyle;

/**
* Class CommonChamiloUserCommand
* @package Chash\Command\User
*/
class CommonChamiloEmailCommand extends Command
{
/**
*
*/
protected function configure()
{
$this
->addOption(
'conf',
null,
InputOption::VALUE_NONE,
'Set a configuration file'
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$configuration = $input->getOption('conf');
$this->getHelper('configuration')->readConfigurationFile($configuration);
}
}
134 changes: 134 additions & 0 deletions src/Chash/Command/Email/SendEmailCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace Chash\Command\Email;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Chash\Command\Email\CommonChamiloEmailCommand;

/**
* Command functions meant to deal with what the user of this script is calling
* it for.
*/
/**
* Class SendEmailCommand
* Changes a user password to the one given
* @package Chash\Command\User
*/
class SendEmailCommand extends CommonChamiloEmailCommand
{
protected function configure()
{
parent::configure();

$this
->setName('email:send_email')
->setDescription('Sends email using Chamilo e-mail system')
->addArgument(
'recipient-name',
InputArgument::REQUIRED,
'Recipient name'
)
->addArgument(
'recipient-email',
InputArgument::REQUIRED,
'Recipient e-mail'
)
->addArgument(
'subject',
InputArgument::REQUIRED,
'Email subject'
)
->addArgument(
'message',
InputArgument::REQUIRED,
'Message'
)
->addArgument(
'sender-name',
InputArgument::OPTIONAL,
'Sender name',
''
)
->addArgument(
'sender-email',
InputArgument::OPTIONAL,
'Sender mail',
''
)
->addArgument(
'extra-headers',
InputArgument::OPTIONAL,
'Extra headers',
''
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$mailLib = $this->getHelper('configuration')->getLibFile('mail.lib.inc.php');
$mainApiLib = $this->getHelper('configuration')->getLibFile('main_api.lib.php');
$cnfFiles = $this->getHelper('configuration')->getConfFile('mail.conf.php');

if (empty($mailLib)) {
$output->writeln('We could not find the mail.lib.inc.php file');
} else {
global $_configuration, $platform_email;
$_configuration = $this->getHelper('configuration')->getConfiguration();

$this->getHelper('configuration')->getConnection();
$userTable = $_configuration['main_database'].'.user';
$adminTable = $_configuration['main_database'].'.admin';

require_once "{$mainApiLib->getRealPath()}";
require_once "{$cnfFiles->getRealPath()}";
require_once "{$mailLib->getRealPath()}";

$recipient_name = $input->getArgument('recipient-name');
$recipient_email = $input->getArgument('recipient-email');
$subject = $input->getArgument('subject');
$message = $input->getArgument('message');
$sender_name = $input->getArgument('sender-name');
$sender_email = $input->getArgument('sender-email');
$extra_headers = $input->getArgument('extra-headers');

$sql = "SELECT email, CONCAT(lastname, firstname) as name FROM $userTable u "
. "LEFT JOIN $adminTable a ON a.user_id = u.user_id "
. "ORDER BY u.user_id LIMIT 1";
$res = mysql_query($sql);
if ($res != false) {
$row = mysql_fetch_assoc($res);
if (empty($sender_name)) {
$sender_name = $row['name'];
}
if (empty($sender_email)) {
$sender_email = $row['email'];
}
}

try {
$output->writeln('Your message is going to be sent ...');
$rsp = api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name, $sender_email, $extra_headers);
if ($rsp) {
$output->writeln('Your message has been sent correctly');
} else {
$output->writeln('Your message could NOT be sent correctly');
$output->writeln('Check the recipient email or your chamilo configuration');
}
} catch (Exception $e) {
$output->writeln('We have detected some problems');
$output->writeln($e->getMessage());
}
}
return null;
}
}
37 changes: 24 additions & 13 deletions src/Chash/Command/Installation/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected function configure()
$this
->setName('chamilo:status')
->setDescription('Show the information of the current Chamilo installation')
->addOption('show-pass', null, InputOption::VALUE_OPTIONAL, 'Set a value to show the chamilo database password')
->addOption('path', null, InputOption::VALUE_OPTIONAL, 'The path to the Chamilo folder');
}

Expand All @@ -32,22 +33,32 @@ protected function configure()
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$path = $input->getOption('path');

$showPass = $input->getOption('show-pass');

$_configuration = $this->getConfigurationHelper()->getConfiguration($path);

if (empty($_configuration)) {
$output->writeln("<comment>Chamilo is not installed here! You may add a path as an option:</comment>");
$output->writeln("<comment>For example: </comment><info>chamilo:status --path=/var/www/chamilo</info>");
return 0;
}

$databaseSettings = array(
'driver' => 'pdo_mysql',
'host' => $_configuration['db_host'],
'dbname' => $_configuration['main_database'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password']
);

$dbPassword = $databaseSettings['password'];
if (empty($showPass)) {
$dbPassLen = strlen($dbPassword);
$dbPassword = '';
for ($i = 1; $i <= $dbPassLen; $i++) {
$dbPassword .= '*';
}
}

// single_database

Expand Down Expand Up @@ -80,41 +91,41 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
}

//$output->writeln('<comment>Chamilo $_configuration[db_driver]:</comment> <info>'.$_configuration['db_driver'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[main_database]:</comment> <info>'.$_configuration['main_database'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[db_host]:</comment> <info>'.$_configuration['db_host'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[db_user]:</comment> <info>'.$_configuration['db_user'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[db_password]:</comment> <info>'.$_configuration['db_password'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[main_database]:</comment> <info>' . $_configuration['main_database'] . '</info>');
$output->writeln('<comment>Chamilo $_configuration[db_host]:</comment> <info>' . $_configuration['db_host'] . '</info>');
$output->writeln('<comment>Chamilo $_configuration[db_user]:</comment> <info>' . $_configuration['db_user'] . '</info>');
$output->writeln('<comment>Chamilo $_configuration[db_password]:</comment> <info>' . $dbPassword . '</info>');

if (isset($_configuration['db_port'])) {
$output->writeln('<comment>Chamilo $_configuration[db_port]:</comment> <info>'.$_configuration['db_port'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[db_port]:</comment> <info>' . $_configuration['db_port'] . '</info>');
}

if (isset($_configuration['single_database'])) {
$output->writeln('<comment>Chamilo $_configuration[single_database]:</comment> <info>'.$_configuration['single_database'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[single_database]:</comment> <info>' . $_configuration['single_database'] . '</info>');
}

if (isset($_configuration['db_prefix'])) {
$output->writeln('<comment>Chamilo $_configuration[db_prefix]:</comment> <info>'.$_configuration['db_prefix'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[db_prefix]:</comment> <info>' . $_configuration['db_prefix'] . '</info>');
}

if (isset($_configuration['db_glue'])) {
$output->writeln('<comment>Chamilo $_configuration[db_glue]:</comment> <info>'.$_configuration['db_glue'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[db_glue]:</comment> <info>' . $_configuration['db_glue'] . '</info>');
}

if (isset($_configuration['db_prefix'])) {
$output->writeln('<comment>Chamilo $_configuration[table_prefix]:</comment> <info>'.$_configuration['table_prefix'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[table_prefix]:</comment> <info>' . $_configuration['table_prefix'] . '</info>');
}
$output->writeln('');

if (empty($chamiloVersion)) {
$output->writeln("<comment>Please check your Chamilo installation carefully the <info>'chamilo_database_version'</info> admin does not exists.</comment>");
} else {
$output->writeln('<comment>Chamilo database settings:</comment>');
$output->writeln("<comment>Chamilo setting_current['".$databaseSetting."']:</comment> <info>".$chamiloVersion."</info>");
$output->writeln("<comment>Chamilo setting_current['" . $databaseSetting . "']:</comment> <info>" . $chamiloVersion . "</info>");
}

if (isset($_configuration['system_version'])) {
$output->writeln('<comment>Chamilo $_configuration[system_version]:</comment> <info>'.$_configuration['system_version'].'</info>');
$output->writeln('<comment>Chamilo $_configuration[system_version]:</comment> <info>' . $_configuration['system_version'] . '</info>');
}

if (!version_compare(substr($chamiloVersion, 0, 5), substr($_configuration['system_version'], 0, 5), '==' )) {
Expand Down
52 changes: 52 additions & 0 deletions src/Chash/Helpers/ConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,58 @@ public function getTempFiles()
}
return $finder;
}

/**
* Lists the lib folder
* @return Finder
*/
public function getLibFolder()
{
$sysPath = $this->getSysPath();
if (is_dir($sysPath . 'main/inc/lib/')) {
return $sysPath . 'main/inc/lib/';
}

return false;
}
/**
* Lists the files in the main/inc/conf
* @param fileName
* @return Finder
*/
public function getConfFile($fileName)
{
$finder = new Finder();
$sysPath = $this->getSysPath();
if (is_dir($sysPath . 'main/inc/conf')) {
$finder->files()->name($fileName)->in($sysPath . 'main/inc/conf');
}

foreach ($finder as $file) {
return $file;
}

return false;
}
/**
* Lists the files in the main/inc/lib
* @param fileName
* @return Finder
*/
public function getLibFile($fileName)
{
$finder = new Finder();
$sysPath = $this->getSysPath();
if (is_dir($sysPath . 'main/inc/lib')) {
$finder->files()->name($fileName)->in($sysPath . 'main/inc/lib');
}

foreach ($finder as $file) {
return $file;
}

return false;
}

/**
* Sets the system's root path (e.g. /var/www/chamilo/)
Expand Down