Subversion Repositories ALCASAR

Rev

Rev 1831 | Rev 2285 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1831 Rev 2168
Line 1... Line 1...
1
<?php
1
<?php
2
CONST ROOT = '/';
-
 
3
require_once(ROOT.'/var/www/html/acc/manager/lib/alcasar/ticketspdf.class.php');
-
 
4
 
-
 
5
/*
2
/**
6
TODO :
-
 
7
- refonte de GenRandUsersName()
3
 * Print tickets of new users
8
- traiter si $nbfailuser (nombre de ticket non créé pour cause de doublon)
-
 
9
*/
4
 *
10
 
-
 
11
// POUR LES BESOINS DU DEVELOPPEMENT
-
 
12
// BUFFERISATION DES DONNEES ENVOYEES AU CLIENT (compatibilité avec les fichiers existants)
-
 
13
ob_start();
-
 
14
//Common Functions
-
 
15
function sec_imp($time)
5
 * @author    Tom Houdayer
16
/* Formatage des secondes avant l'impression */
6
 * @copyright Copyright (C) ALCASAR (http://www.alcasar.net)
17
{
-
 
18
	$jour = 0;$heure = 0;$minute = 0;$seconde = 0;
-
 
19
	$jour = floor($time/86400);
-
 
20
	$reste = $time%86400;
-
 
21
    	if ($jour!=0) $result = $jour.' J ';
-
 
22
	$heure = floor($reste/3600);
-
 
23
    	$reste = $reste%3600;
7
 * @license   GPL-3.0
24
    	if ($heure!=0) $result = $result.$heure.' H ';
-
 
25
	$minute = floor($reste/60);
-
 
26
    	if ($minute!=0) $result = $result.$minute.' min ';
8
 * @version   $Id: ticket_voucher.php 2168 2017-04-18 17:39:54Z tom.houdayer $
27
	$seconde = $reste%60;
-
 
28
    	if ($seconde!=0) $result = $result.$seconde.' s ';
-
 
29
   	return $result;
-
 
30
}
9
 */
31
	
10
 
32
function GenPassword($nb_car="8")
-
 
33
	{
-
 
34
 /* generation aléatoire du mot de passe */
11
require_once __DIR__ . '/../lib/alcasar/TicketsGenerator.php';
35
	$password = "";
-
 
36
	$chaine  = "aAzZeErRtTyYuUIopP152346897mMLkK";
12
require_once '/etc/freeradius-web/config.php';
37
	$chaine .= "jJhHgGfFdDsSqQwWxXcCvVbBnN152346897";
13
require_once '../lib/sql/drivers/'.$config['sql_type'].'/functions.php';;
38
	while($nb_car != 0)
-
 
39
		{
-
 
40
		$i = rand(0,71);
-
 
41
		$password = $password.$chaine[$i];
14
require_once '../lib/attrshow.php';
42
		$nb_car --;
-
 
43
		}
-
 
44
	return $password ;
-
 
45
	}
-
 
46
function GenRandUsersName()
15
require_once '../lib/defaults.php';
47
{
-
 
48
	$nb_car= 12;
-
 
49
	$chaine = "AZE489RTYU2PML5KJ35HGF9DSQWXCV3BN267";
-
 
50
	//$i = rand(0,25);
-
 
51
	//$j = rand(0,25);
-
 
52
	//$k = rand(0,25);
-
 
53
	$userName = "";
-
 
54
	while($nb_car != 0)
-
 
55
		{
-
 
56
		$i = rand(0,35);
-
 
57
		$userName .= $chaine[$i];
16
require_once '../lib/functions.php';
58
		$nb_car --;
-
 
59
		}
-
 
60
	//return "T".$chaine[$i].substr(time(),4).$chaine[$j].$chaine[$k];
17
if ($config['sql_use_operators'] === 'true') {
61
	return $userName;
18
	require_once '../lib/operators.php';
62
}
19
}
63
 
20
 
-
 
21
 
-
 
22
// Get datas from form
64
if (isset($_POST['nbtickets'])&& is_numeric($_POST['nbtickets'])){
23
if ((!isset($_POST['nbtickets'])) || (!is_numeric($_POST['nbtickets']))){
-
 
24
	header('Location: voucher_new.php');
-
 
25
	exit();
-
 
26
}
65
	$nbtickets = (int)$_POST['nbtickets'];
27
$nbTickets  = (int)$_POST['nbtickets'];
-
 
28
$langue_imp = ((isset($_POST['langue_imp'])) ? $_POST['langue_imp'] : 'en');
-
 
29
require_once __DIR__ . '/../lib/langues_imp.php';
-
 
30
 
-
 
31
if ($config['general_lib_type'] === 'sql' && $config['sql_use_operators'] === 'true') {
-
 
32
	$show_ops = 1;
-
 
33
	$colspan  = 2;
66
} else {
34
} else {
-
 
35
	$show_ops = 0;
-
 
36
	$colspan  = 1;
-
 
37
}
67
	header("Location: voucher_new.php");
38
if ($config['sql_use_operators'] === 'true') {
68
	exit;
39
	$text      = ',op';
-
 
40
	$passwd_op = ",':='";
69
}
41
}
70
 
42
 
71
//	Langue du Ticket d'impression en fonction de la liste déroulante
-
 
72
if (isset($_POST["langue_imp"])) { $langue_imp = $_POST["langue_imp"]; } else { $langue_imp = "en"; };
-
 
73
if (is_file("../lib/langues_imp.php")) include("../lib/langues_imp.php") ;
-
 
74
 
-
 
75
require(ROOT.'etc/freeradius-web/config.php');
-
 
76
require('../lib/attrshow.php');
43
// Connect to database
77
require('../lib/defaults.php');
44
$link = da_sql_pconnect($config);
78
if ($config[general_lib_type] == 'sql' && $config[sql_use_operators] == 'true'){
-
 
79
	$colspan=2;
45
if (!$link) {
80
	$show_ops=1;
-
 
81
}else{
-
 
82
	$show_ops = 0;
46
	exit('ERR_DATABASE_CONNECT');
83
	$colspan=1;
-
 
84
}
47
}
85
 
48
 
86
$LIBpath = "../lib/";
49
$nbFailUsers = 0;
-
 
50
 
-
 
51
 
-
 
52
 
87
require(ROOT.'etc/freeradius-web/config.php');
53
// Generate tickets
88
if (is_file($LIBpath."sql/drivers/$config[sql_type]/functions.php"))
54
$ticketsGenerator = new TicketsGenerator(['language' => $langue_imp]);
89
	{
55
 
90
	include_once($LIBpath."sql/drivers/$config[sql_type]/functions.php");
-
 
91
	}
56
 
-
 
57
for ($i = 0; $i < $nbTickets; $i++) {
-
 
58
	// Generate username and password
-
 
59
	$login  = generateRandomString(8);
-
 
60
	$passwd = generateRandomString(12);
92
else
61
	$password = $passwd;
93
	{
62
	
-
 
63
	// Check user exist
94
	echo "<b>Could not include SQL library</b><br>\n";
64
	require '../lib/'.$config['general_lib_type'].'/user_info.php';
-
 
65
	if ($user_exists === 'yes') {
-
 
66
		$nbFailUsers++;
95
	exit();
67
		continue;
96
	}
68
	}
-
 
69
 
97
include_once($LIBpath.'functions.php');
70
	// Create user in database
98
if ($config['sql_use_operators'] == 'true')
71
	require '../lib/'.$config['general_lib_type'].'/create_user.php';
99
	{
72
 
-
 
73
	// Get group infos
100
	include_once($LIBpath."operators.php");
74
	if ((isset($group)) && ($group !== '')) {
-
 
75
		$loginUser = $login;
101
	$text = ',op';
76
		$login = $group;
-
 
77
		require '../lib/sql/group_info.php';
102
	$passwd_op = ",':='";
78
		$login = $loginUser;
103
	}
79
	}
104
$link = @da_sql_pconnect($config);
-
 
105
 
80
 
-
 
81
	// Format datas
-
 
82
	$sto_imp = (($sto_imp    === '') ? $l_unlimited : formatTime($sto_imp));
-
 
83
	$mas_imp = (($mas_imp    === '') ? $l_unlimited : formatTime($mas_imp));
-
 
84
	$mds_imp = (($mds_imp    === '') ? $l_unlimited : formatTime($mds_imp));
-
 
85
	$mms_imp = (($mms_imp    === '') ? $l_unlimited : formatTime($mms_imp));
-
 
86
	$exp_imp = (($Expiration === '') ? $l_without   : date('d - m - Y', strtotime($Expiration)));
-
 
87
 
-
 
88
	// Add user
-
 
89
	$ticketsGenerator->addTicket([
-
 
90
		'username'        => $login,
-
 
91
		'password'        => $password,
-
 
92
		'maxAllSession'   => $mas_imp,
-
 
93
		'sessionTimeout'  => $sto_imp,
-
 
94
		'maxDailySession' => $mds_imp,
-
 
95
		'expiration'      => $exp_imp
-
 
96
	]);
-
 
97
}
-
 
98
 
-
 
99
 
-
 
100
// Generate the PDF
-
 
101
$ticketsGenerator->output();
-
 
102
 
-
 
103
 
-
 
104
/**
-
 
105
 * Format time in seconds to days/hours/minutes/secondes.
-
 
106
 *
-
 
107
 * @param int $time Time in seconds.
-
 
108
 *
-
 
109
 * @return string Formated time.
-
 
110
 */
-
 
111
function formatTime($time)
-
 
112
{
-
 
113
	$days     = floor($time / 86400); $reste = $time  % 86400;
-
 
114
	$hours    = floor($reste / 3600); $reste = $reste % 3600;
-
 
115
	$minutes  = floor($reste / 60);
106
$nbfailuser = 0;
116
	$secondes = $reste % 60;
107
 
117
 
108
// Préparation de la fiche PDF
118
	return "$days J $hours H $minutes min $secondes s";
109
$pdf = new ticketsPDF(2,3);
-
 
110
$pdf->setTicketsTitle($l_title_imp);
-
 
111
$pdf->setTicketsFooter($l_footer_imp);
-
 
-
 
119
}
112
 
120
 
-
 
121
/**
-
 
122
 * Generate a random string.
-
 
123
 *
-
 
124
 * @param int $length Length of the string.
-
 
125
 *
-
 
126
 * @return string Random string.
113
if ($link)
127
 */
-
 
128
function generateRandomString($length = 8)
114
{
129
{
115
	if (is_file($LIBpath."crypt/$config[general_encryption_method].php"))
-
 
116
	{
-
 
117
		include($LIBpath."crypt/$config[general_encryption_method].php");
-
 
118
		// ajout des comptes (mêmes attributs pour tous sauf login + mdp)
-
 
119
 
-
 
120
		for ($i = 1; $i <= $nbtickets; $i++) 
-
 
121
		{
-
 
122
			// effacement des variables
-
 
123
			$login = "";
130
	$string  = '';
124
			$passwd = "";
-
 
125
			// création des données uniques
-
 
126
			$login = GenRandUsersName();
-
 
127
			$passwd = GenPassword();
-
 
128
			
-
 
129
			// création des variables d'impression
-
 
130
			$login_imp = $login;
-
 
131
			$passwd1_imp = $passwd;
-
 
132
			// encryption du mot de passe (pas besoins, déjà présent dans le fichier create_user.php)
-
 
133
			//$passwd = da_encrypt($passwd);
-
 
134
			
-
 
135
			// test si l'usager existe
-
 
136
			if (is_file("../lib/$config[general_lib_type]/user_info.php"))
-
 
137
				include("../lib/$config[general_lib_type]/user_info.php");
-
 
138
				
-
 
139
			if ($user_exists == "no"){
-
 
140
				// Création de l'usager
-
 
141
				if (is_file("../lib/$config[general_lib_type]/create_user.php"))
-
 
142
				 	include("../lib/$config[general_lib_type]/create_user.php");
-
 
143
				/*  Petit traitement pré-impression pour la lisibilité */
-
 
144
				/*  Récupération des attributs du groupe le cas échéant */
-
 
145
				if ($group!=''){
-
 
146
				 	$saved_login = $login;
-
 
147
				 	$login = $group;
-
 
148
				 	if (is_file("../lib/sql/group_info.php"))
-
 
149
				 		include("../lib/sql/group_info.php");
-
 
150
				 	$login = $saved_login;}
-
 
151
				/*  Si les valeurs de durée sont vide remplissage avec la valeur 'Illimitée'*/
-
 
152
				/*  et formatage des secondes sous le format Heure min ses*/
131
	$chars   = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
153
				if ($sto_imp==''){ $sto_imp=$l_unlimited;}
-
 
154
				 	else { $sto_imp=sec_imp($sto_imp);}
-
 
155
				if ($mas_imp==''){ $mas_imp=$l_unlimited;}
-
 
156
					else { $mas_imp=sec_imp($mas_imp);}
-
 
157
				if ($mds_imp==''){ $mds_imp=$l_unlimited;}
-
 
158
				 	else { $mds_imp=sec_imp($mds_imp);}
132
	$randoms = openssl_random_pseudo_bytes($length);
159
				if ($mms_imp==''){ $mms_imp=$l_unlimited;}
-
 
160
				 	else { $mms_imp=sec_imp($mms_imp);}	
-
 
161
				/*Formatage de la date afin d'être lisible dans toute les langues 'jj mm yyyy'*/
-
 
162
				$exp_imp = $Expiration;
-
 
163
				if ($exp_imp!=''){ $exp_imp=date("d - m - Y",strtotime($exp_imp));}
-
 
164
				 	else { $exp_imp=$l_without;}
133
	for ($i = 0; $i < $length; $i++) {
165
				// Ajout d'un ticket sur la fiche PDF
-
 
166
				$pdf->newTickets();
-
 
167
				$pdf->Ln(5);
-
 
168
				$pdf->addInfos($l_login_imp, $login_imp);
-
 
169
				$pdf->addInfos($l_password_imp, $passwd1_imp);
134
		$string .= $chars[ord($randoms[$i]) % 62];
170
				$pdf->Ln(5);
-
 
171
				$pdf->addInfos($l_max_all_session_imp, $mas_imp);
-
 
172
				$pdf->addInfos($l_session_timeout_imp, $sto_imp);
-
 
173
				$pdf->addInfos($l_max_daily_session_imp, $mds_imp);
-
 
174
				$pdf->addInfos($l_expiration_imp, $exp_imp);
-
 
175
				$pdf->Ln(10);
-
 
176
				$pdf->addComment($l_explain);
-
 
177
 
135
	}
178
				// Création du duplicata
-
 
179
				$pdf->newTickets();
-
 
180
				$pdf->Ln(5);
-
 
181
				$pdf->addInfos($l_login_imp, $login_imp);
-
 
182
				$pdf->addInfos($l_password_imp, $passwd1_imp);
-
 
183
				$pdf->Ln(5);
-
 
184
				$pdf->addInfos($l_max_all_session_imp, $mas_imp);
-
 
185
				$pdf->addInfos($l_session_timeout_imp, $sto_imp);
-
 
186
				$pdf->addInfos($l_max_daily_session_imp, $mds_imp);
-
 
187
				$pdf->addInfos($l_expiration_imp, $exp_imp);
-
 
188
				$pdf->Ln(10);
-
 
189
				$pdf->addComment($l_duplicate,'C');//à mettre en rouge
-
 
190
			} else {
-
 
191
				$nbfailuser++;
-
 
192
			}# if user
-
 
193
		} # end for
-
 
194
	} # end if (is file)
-
 
195
} # end if (link)
136
	return $string;
196
 
137
}
197
//Affichage de la fiche de tickets
-
 
198
ob_end_clean();
-
 
199
$pdf->Output();
-
 
200
?>
-