diff --git a/chash.php b/chash.php
index c48b63b..e94c928 100755
--- a/chash.php
+++ b/chash.php
@@ -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();
diff --git a/src/Chash/Command/Email/CommonChamiloEmailCommand.php b/src/Chash/Command/Email/CommonChamiloEmailCommand.php
new file mode 100644
index 0000000..0bd303b
--- /dev/null
+++ b/src/Chash/Command/Email/CommonChamiloEmailCommand.php
@@ -0,0 +1,43 @@
+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);
+ }
+}
diff --git a/src/Chash/Command/Email/SendEmailCommand.php b/src/Chash/Command/Email/SendEmailCommand.php
new file mode 100644
index 0000000..e0c5a78
--- /dev/null
+++ b/src/Chash/Command/Email/SendEmailCommand.php
@@ -0,0 +1,134 @@
+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;
+ }
+}
diff --git a/src/Chash/Command/Installation/StatusCommand.php b/src/Chash/Command/Installation/StatusCommand.php
index f4e0ac1..2d6b641 100644
--- a/src/Chash/Command/Installation/StatusCommand.php
+++ b/src/Chash/Command/Installation/StatusCommand.php
@@ -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');
}
@@ -32,7 +33,8 @@ 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)) {
@@ -40,7 +42,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$output->writeln("For example: chamilo:status --path=/var/www/chamilo");
return 0;
}
-
+
$databaseSettings = array(
'driver' => 'pdo_mysql',
'host' => $_configuration['db_host'],
@@ -48,6 +50,15 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
'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
@@ -80,29 +91,29 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
}
//$output->writeln('Chamilo $_configuration[db_driver]: '.$_configuration['db_driver'].'');
- $output->writeln('Chamilo $_configuration[main_database]: '.$_configuration['main_database'].'');
- $output->writeln('Chamilo $_configuration[db_host]: '.$_configuration['db_host'].'');
- $output->writeln('Chamilo $_configuration[db_user]: '.$_configuration['db_user'].'');
- $output->writeln('Chamilo $_configuration[db_password]: '.$_configuration['db_password'].'');
+ $output->writeln('Chamilo $_configuration[main_database]: ' . $_configuration['main_database'] . '');
+ $output->writeln('Chamilo $_configuration[db_host]: ' . $_configuration['db_host'] . '');
+ $output->writeln('Chamilo $_configuration[db_user]: ' . $_configuration['db_user'] . '');
+ $output->writeln('Chamilo $_configuration[db_password]: ' . $dbPassword . '');
if (isset($_configuration['db_port'])) {
- $output->writeln('Chamilo $_configuration[db_port]: '.$_configuration['db_port'].'');
+ $output->writeln('Chamilo $_configuration[db_port]: ' . $_configuration['db_port'] . '');
}
if (isset($_configuration['single_database'])) {
- $output->writeln('Chamilo $_configuration[single_database]: '.$_configuration['single_database'].'');
+ $output->writeln('Chamilo $_configuration[single_database]: ' . $_configuration['single_database'] . '');
}
if (isset($_configuration['db_prefix'])) {
- $output->writeln('Chamilo $_configuration[db_prefix]: '.$_configuration['db_prefix'].'');
+ $output->writeln('Chamilo $_configuration[db_prefix]: ' . $_configuration['db_prefix'] . '');
}
if (isset($_configuration['db_glue'])) {
- $output->writeln('Chamilo $_configuration[db_glue]: '.$_configuration['db_glue'].'');
+ $output->writeln('Chamilo $_configuration[db_glue]: ' . $_configuration['db_glue'] . '');
}
if (isset($_configuration['db_prefix'])) {
- $output->writeln('Chamilo $_configuration[table_prefix]: '.$_configuration['table_prefix'].'');
+ $output->writeln('Chamilo $_configuration[table_prefix]: ' . $_configuration['table_prefix'] . '');
}
$output->writeln('');
@@ -110,11 +121,11 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$output->writeln("Please check your Chamilo installation carefully the 'chamilo_database_version' admin does not exists.");
} else {
$output->writeln('Chamilo database settings:');
- $output->writeln("Chamilo setting_current['".$databaseSetting."']: ".$chamiloVersion."");
+ $output->writeln("Chamilo setting_current['" . $databaseSetting . "']: " . $chamiloVersion . "");
}
if (isset($_configuration['system_version'])) {
- $output->writeln('Chamilo $_configuration[system_version]: '.$_configuration['system_version'].'');
+ $output->writeln('Chamilo $_configuration[system_version]: ' . $_configuration['system_version'] . '');
}
if (!version_compare(substr($chamiloVersion, 0, 5), substr($_configuration['system_version'], 0, 5), '==' )) {
diff --git a/src/Chash/Helpers/ConfigurationHelper.php b/src/Chash/Helpers/ConfigurationHelper.php
index c6c5bd2..29180eb 100644
--- a/src/Chash/Helpers/ConfigurationHelper.php
+++ b/src/Chash/Helpers/ConfigurationHelper.php
@@ -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/)