Line 3... |
Line 3... |
3 |
* Print tickets of the new user
|
3 |
* Print tickets of the new user
|
4 |
*
|
4 |
*
|
5 |
* @author Tom Houdayer
|
5 |
* @author Tom Houdayer
|
6 |
* @copyright Copyright (C) ALCASAR (http://www.alcasar.net)
|
6 |
* @copyright Copyright (C) ALCASAR (http://www.alcasar.net)
|
7 |
* @license GPL-3.0
|
7 |
* @license GPL-3.0
|
8 |
* @version $Id: ticket_user.php 2493 2018-02-26 01:27:02Z tom.houdayer $
|
8 |
* @version $Id: ticket_user.php 2698 2019-02-05 10:25:12Z tom.houdayer $
|
9 |
*/
|
9 |
*/
|
10 |
|
10 |
|
11 |
require_once __DIR__ . '/../lib/alcasar/TicketsGenerator.php';
|
11 |
require_once __DIR__ . '/../lib/alcasar/TicketsGenerator.php';
|
12 |
$langue_imp = ((isset($_POST['langue_imp'])) ? $_POST['langue_imp'] : 'en');
|
12 |
$langue_imp = ((isset($_POST['langue_imp'])) ? $_POST['langue_imp'] : 'en');
|
13 |
require_once __DIR__ . '/../lib/langues_imp.php';
|
13 |
require_once __DIR__ . '/../lib/langues_imp.php';
|
- |
|
14 |
require_once '/etc/freeradius-web/config.php';
|
- |
|
15 |
require_once __DIR__ . '/../lib/sql/drivers/mysql/functions.php';
|
14 |
|
16 |
|
15 |
// Get datas from form
|
17 |
// Get datas from form
|
16 |
if ((!isset($_POST['log_imp'])) || (!isset($_POST['passwd_imp'])) || (!isset($_POST['exp_imp'])) || (!isset($_POST['sto_imp'])) || (!isset($_POST['mas_imp'])) || (!isset($_POST['mds_imp']))) {
|
18 |
if ((!isset($_POST['username'])) || (!isset($_POST['password']))) {
|
17 |
exit();
|
19 |
exit();
|
18 |
}
|
20 |
}
|
19 |
$log_imp = $_POST['log_imp'];
|
21 |
$username = $_POST['username'];
|
20 |
$passwd_imp = $_POST['passwd_imp'];
|
22 |
$password = $_POST['password'];
|
- |
|
23 |
|
- |
|
24 |
// Get user attributes
|
- |
|
25 |
$userAttr = [];
|
- |
|
26 |
$link = da_sql_pconnect($config);
|
- |
|
27 |
if ($link) {
|
- |
|
28 |
$user_uid = da_sql_escape_string($link, $username);
|
21 |
$exp_imp = ((($_POST['exp_imp'] === '') || ($_POST['exp_imp'] === '-')) ? $l_without : utf8_decode($_POST['exp_imp']));
|
29 |
$sql = "SELECT attribute, value FROM (( SELECT attribute, value FROM radcheck WHERE (attribute IN ('Max-All-Session', 'Max-Daily-Session', 'Expiration')) AND username = '$user_uid') UNION ( SELECT attribute, value FROM radgroupcheck gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE (attribute IN ('Max-All-Session', 'Max-Daily-Session', 'Expiration')) AND username = '$user_uid' ORDER BY ug.priority) UNION ( SELECT attribute, value FROM radgroupcheck WHERE groupname = 'ldap' AND (attribute IN ('Max-All-Session', 'Max-Daily-Session', 'Expiration'))) UNION ( SELECT attribute, value FROM radreply WHERE (attribute IN ('Session-Timeout')) AND username = '$user_uid') UNION ( SELECT attribute, value FROM radgroupreply gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE (attribute IN ('Session-Timeout')) AND username = '$user_uid' ORDER BY ug.priority) UNION ( SELECT attribute, value FROM radgroupreply WHERE groupname = 'ldap' AND (attribute IN ('Session-Timeout')))) attrs GROUP BY attribute;";
|
- |
|
30 |
$res = da_sql_query($link, $config, $sql);
|
- |
|
31 |
if ($res) {
|
- |
|
32 |
while ($row = da_sql_fetch_array($res, $config)) {
|
- |
|
33 |
$userAttr[$row['attribute']] = $row['value'];
|
- |
|
34 |
}
|
- |
|
35 |
}
|
- |
|
36 |
}
|
- |
|
37 |
|
- |
|
38 |
// Format user attributes
|
22 |
$sto_imp = ((($_POST['sto_imp'] === '') || ($_POST['sto_imp'] === '-')) ? $l_unlimited : utf8_decode($_POST['sto_imp']));
|
39 |
$userAttr['Session-Timeout'] = ((isset($userAttr['Session-Timeout'])) ? formatTime($userAttr['Session-Timeout']) : $l_unlimited);
|
23 |
$mas_imp = ((($_POST['mas_imp'] === '') || ($_POST['mas_imp'] === '-')) ? $l_unlimited : utf8_decode($_POST['mas_imp']));
|
40 |
$userAttr['Max-All-Session'] = ((isset($userAttr['Max-All-Session'])) ? formatTime($userAttr['Max-All-Session']) : $l_unlimited);
|
24 |
$mds_imp = ((($_POST['mds_imp'] === '') || ($_POST['mds_imp'] === '-')) ? $l_unlimited : utf8_decode($_POST['mds_imp']));
|
41 |
$userAttr['Max-Daily-Session'] = ((isset($userAttr['Max-Daily-Session'])) ? formatTime($userAttr['Max-Daily-Session']) : $l_unlimited);
|
- |
|
42 |
$userAttr['Expiration'] = ((isset($userAttr['Expiration'])) ? date('d - m - Y', strtotime($userAttr['Expiration'])) : $l_without);
|
25 |
|
43 |
|
26 |
// Generate tickets
|
44 |
// Generate tickets
|
27 |
$ticketsGenerator = new TicketsGenerator(['language' => $langue_imp]);
|
45 |
$ticketsGenerator = new TicketsGenerator(['language' => $langue_imp]);
|
28 |
|
46 |
|
29 |
// Add user
|
47 |
// Add user ticket
|
30 |
$ticketsGenerator->addTicket([
|
48 |
$ticketsGenerator->addTicket([
|
31 |
'username' => $log_imp,
|
49 |
'username' => $username,
|
32 |
'password' => $passwd_imp,
|
50 |
'password' => $password,
|
33 |
'maxAllSession' => $mas_imp,
|
51 |
'maxAllSession' => $userAttr['Max-All-Session'],
|
34 |
'sessionTimeout' => $sto_imp,
|
52 |
'sessionTimeout' => $userAttr['Session-Timeout'],
|
35 |
'maxDailySession' => $mds_imp,
|
53 |
'maxDailySession' => $userAttr['Max-Daily-Session'],
|
36 |
'expiration' => $exp_imp
|
54 |
'expiration' => $userAttr['Expiration']
|
37 |
]);
|
55 |
]);
|
38 |
|
56 |
|
39 |
// Save the PDF and redirect user to it
|
57 |
// Save the PDF and redirect user to it
|
40 |
$filename = 'ticket_' . $log_imp . '.pdf';
|
58 |
$filename = 'ticket_' . $username . '.pdf';
|
41 |
// Remove accents
|
59 |
// Remove accents
|
42 |
$filename = strtr(utf8_decode($filename), utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'), 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'); // TODO : manage all UTF-8 chars
|
60 |
$filename = strtr(utf8_decode($filename), utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'), 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'); // TODO : manage all UTF-8 chars
|
43 |
|
61 |
|
44 |
$ret = $ticketsGenerator->saveAs($filename);
|
62 |
$ret = $ticketsGenerator->saveAs($filename);
|
45 |
if (!$ret) {
|
63 |
if (!$ret) {
|
46 |
echo $content_generation;
|
- |
|
47 |
echo 'Error during tickets report generation';
|
64 |
echo 'Error during tickets report generation';
|
48 |
exit();
|
65 |
exit();
|
49 |
}
|
66 |
}
|
50 |
|
67 |
|
51 |
header('Location: ' . $filename);
|
68 |
header('Location: ' . $filename);
|
- |
|
69 |
|
- |
|
70 |
|
- |
|
71 |
/**
|
- |
|
72 |
* Format time in seconds to days/hours/minutes/secondes.
|
- |
|
73 |
*
|
- |
|
74 |
* @param int $time Time in seconds.
|
- |
|
75 |
*
|
- |
|
76 |
* @return string Formated time.
|
- |
|
77 |
*/
|
- |
|
78 |
function formatTime($time)
|
- |
|
79 |
{
|
- |
|
80 |
$days = floor($time / 86400); $rest = $time % 86400;
|
- |
|
81 |
$hours = floor($rest / 3600); $rest = $rest % 3600;
|
- |
|
82 |
$minutes = floor($rest / 60);
|
- |
|
83 |
$secondes = $rest % 60;
|
- |
|
84 |
|
- |
|
85 |
$result = '';
|
- |
|
86 |
if ($days != 0) $result .= $days.' J ';
|
- |
|
87 |
if ($hours != 0) $result .= $hours.' H ';
|
- |
|
88 |
if ($minutes != 0) $result .= $minutes.' m ';
|
- |
|
89 |
if ($secondes != 0) $result .= $secondes.' s ';
|
- |
|
90 |
|
- |
|
91 |
return $result;
|
- |
|
92 |
}
|