2019-12-08 02:33:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of RaspiSMS.
|
|
|
|
*
|
|
|
|
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the GPL-3.0 license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace controllers\internals;
|
|
|
|
|
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Class to call the console scripts.
|
2019-12-08 02:33:53 +01:00
|
|
|
*/
|
|
|
|
class Console extends \descartes\InternalController
|
|
|
|
{
|
2020-01-07 01:31:34 +01:00
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Start launcher daemon.
|
2020-01-07 01:31:34 +01:00
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function launcher()
|
2019-12-08 02:33:53 +01:00
|
|
|
{
|
2020-01-08 18:20:17 +01:00
|
|
|
new \daemons\Launcher();
|
2019-12-08 02:33:53 +01:00
|
|
|
}
|
2019-12-17 14:38:16 +01:00
|
|
|
|
2020-01-07 01:31:34 +01:00
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Start sender daemon.
|
2020-01-07 01:31:34 +01:00
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function sender()
|
2019-12-17 14:38:16 +01:00
|
|
|
{
|
2020-01-07 01:31:34 +01:00
|
|
|
new \daemons\Sender();
|
|
|
|
}
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2020-01-07 01:31:34 +01:00
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Start webhook daemon.
|
2020-01-07 01:31:34 +01:00
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function webhook()
|
2020-01-07 01:31:34 +01:00
|
|
|
{
|
|
|
|
new \daemons\Webhook();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Start a phone daemon.
|
|
|
|
*
|
2020-01-07 01:31:34 +01:00
|
|
|
* @param $id_phone : Phone id
|
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function phone($id_phone)
|
2020-01-07 01:31:34 +01:00
|
|
|
{
|
|
|
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
|
|
|
$internal_phone = new \controllers\internals\Phone($bdd);
|
|
|
|
|
|
|
|
$phone = $internal_phone->get($id_phone);
|
|
|
|
if (!$phone)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
new \daemons\Phone($phone);
|
2019-12-17 14:38:16 +01:00
|
|
|
}
|
2020-02-19 02:32:52 +01:00
|
|
|
|
|
|
|
/**
|
2020-03-04 01:40:47 +01:00
|
|
|
* Create a user or update an existing user.
|
|
|
|
*
|
2020-02-19 02:32:52 +01:00
|
|
|
* @param $email : User email
|
|
|
|
* @param $password : User password
|
|
|
|
* @param $admin : Is user admin
|
2020-03-04 01:40:47 +01:00
|
|
|
* @param $api_key : User API key, if null random api key is generated
|
2020-02-19 02:32:52 +01:00
|
|
|
*/
|
2020-03-04 01:40:47 +01:00
|
|
|
public function create_update_user(string $email, string $password, bool $admin, ?string $api_key = null)
|
2020-02-19 02:32:52 +01:00
|
|
|
{
|
|
|
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
|
|
|
$internal_user = new \controllers\internals\User($bdd);
|
|
|
|
|
2020-02-21 03:55:14 +01:00
|
|
|
$user = $internal_user->get_by_email($email);
|
|
|
|
if ($user)
|
|
|
|
{
|
|
|
|
$api_key = $api_key ?? $internal_user->generate_random_api_key();
|
|
|
|
$success = $internal_user->update($user['id'], $email, $password, $admin, $api_key);
|
2020-03-04 01:40:47 +01:00
|
|
|
|
2020-02-21 03:55:14 +01:00
|
|
|
exit($success ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
2020-02-19 02:32:52 +01:00
|
|
|
$success = $internal_user->create($email, $password, $admin, $api_key);
|
2020-02-21 03:55:14 +01:00
|
|
|
exit($success ? 0 : 1);
|
2020-02-19 02:32:52 +01:00
|
|
|
}
|
2019-12-08 02:33:53 +01:00
|
|
|
}
|