| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::SambaMSNRL; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27161
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
63
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
28
|
|
|
6
|
1
|
|
|
1
|
|
861
|
use File::Copy; |
|
|
1
|
|
|
|
|
10942
|
|
|
|
1
|
|
|
|
|
96
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 Module de gestion du fichier de configuration de samba (smb.conf) |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
File::SambaMSNRL - Gestion de la configuration de Samba |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.02 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
11
|
use Exporter (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4152
|
|
|
20
|
|
|
|
|
|
|
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$VERSION = 0.02; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
25
|
|
|
|
|
|
|
@EXPORT_OK = qw( |
|
26
|
|
|
|
|
|
|
new |
|
27
|
|
|
|
|
|
|
GetGlobal |
|
28
|
|
|
|
|
|
|
ModifGlobal |
|
29
|
|
|
|
|
|
|
AddParamGlobal |
|
30
|
|
|
|
|
|
|
DelParamGlobal |
|
31
|
|
|
|
|
|
|
ValeurSection |
|
32
|
|
|
|
|
|
|
ListPartages |
|
33
|
|
|
|
|
|
|
CreaPartage |
|
34
|
|
|
|
|
|
|
ListSections |
|
35
|
|
|
|
|
|
|
CreaSection |
|
36
|
|
|
|
|
|
|
ModifSection |
|
37
|
|
|
|
|
|
|
DelPartage |
|
38
|
|
|
|
|
|
|
DelValue |
|
39
|
|
|
|
|
|
|
Sauve |
|
40
|
|
|
|
|
|
|
); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 Méthodes Objets |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 new("fichier_conf_samba"); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Le fichier indiqué doit correspondre à un fichier de configuration de samba |
|
47
|
|
|
|
|
|
|
Il doit posséder au minimum une partie [global] et au moins un partage |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Retourne un nouvel objet |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Example : |
|
52
|
|
|
|
|
|
|
my $objet=File::SambaMSNRL->new("/etc/samba/smb.conf); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub new { |
|
57
|
0
|
|
|
0
|
1
|
|
my $classe = shift; |
|
58
|
0
|
|
|
|
|
|
my $smbconf = shift; |
|
59
|
0
|
|
|
|
|
|
my (%global,%det_partages,@partages,%new_partage); |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $self = { |
|
62
|
|
|
|
|
|
|
"SMB" => "/etc/samba/smb.conf", |
|
63
|
|
|
|
|
|
|
"GLOBAL" => \%global, |
|
64
|
|
|
|
|
|
|
"DET_PARTAGES" => \%det_partages, |
|
65
|
|
|
|
|
|
|
"PARTAGES" => \@partages, |
|
66
|
|
|
|
|
|
|
"NEW_PARTAGE" => \%new_partage |
|
67
|
|
|
|
|
|
|
}; |
|
68
|
0
|
0
|
|
|
|
|
$self->{SMB} = $smbconf if (defined $smbconf); |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
bless($self,$classe); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
### Chargement du fichier samba |
|
73
|
0
|
|
|
|
|
|
my @global = $self->TakeGlobal; |
|
74
|
0
|
|
|
|
|
|
$self->TakePartages; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return($self); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 GetGlobal |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Lit et renvoi la partie [global] du fichier smb.conf |
|
82
|
|
|
|
|
|
|
Le retour se fait sous la forme d'un Hash |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Params: |
|
85
|
|
|
|
|
|
|
Aucun |
|
86
|
|
|
|
|
|
|
Returns: |
|
87
|
|
|
|
|
|
|
Hash du global |
|
88
|
|
|
|
|
|
|
Example: |
|
89
|
|
|
|
|
|
|
my %global = $smb->GetGlobal; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub GetGlobal { |
|
94
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
95
|
0
|
|
|
|
|
|
my %GLOBAL = %{$this->{GLOBAL}}; |
|
|
0
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return (%GLOBAL); |
|
98
|
|
|
|
|
|
|
}; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 ModifGlobal([parametre],[nouvelle_valeur]); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Modifie l'un des parametres de la partie [global] du smb.conf |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Params: |
|
105
|
|
|
|
|
|
|
parametre = Le parametre du global à modifier |
|
106
|
|
|
|
|
|
|
nouvelle_valeur = la valeur du parametre à modifier |
|
107
|
|
|
|
|
|
|
Returns: |
|
108
|
|
|
|
|
|
|
Retourne 1 si la modification a été effectuée |
|
109
|
|
|
|
|
|
|
Retourne 0 si pas de modification |
|
110
|
|
|
|
|
|
|
Example: |
|
111
|
|
|
|
|
|
|
my $retour = $smb->ModifGlobal("workgroup","DOMAINE1"); |
|
112
|
|
|
|
|
|
|
if ($retour == 1) {print("La modification du parametre s'est déroulée avec succés\n"); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub ModifGlobal { |
|
117
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
118
|
0
|
|
|
|
|
|
my $param = shift; |
|
119
|
0
|
|
|
|
|
|
my $value = shift; |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $return = 0; |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my %GLOBAL = %{$this->{GLOBAL}}; |
|
|
0
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$param = lc($param); |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if (exists $GLOBAL{$param}) { |
|
128
|
0
|
|
|
|
|
|
$GLOBAL{$param} = $value; |
|
129
|
0
|
|
|
|
|
|
$return = 1; |
|
130
|
|
|
|
|
|
|
}; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
$this->{GLOBAL} = \%GLOBAL; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return($this,$return); |
|
135
|
|
|
|
|
|
|
}; |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 AddParamGlobal ([parametre_a_ajouter],[valeur_du_parametre]); |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Ajoute un nouveau parametre sur la partie [global] du smb.conf |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Params: |
|
142
|
|
|
|
|
|
|
parametre_a_ajouter = le nom du parametre à ajouter dans la partie global |
|
143
|
|
|
|
|
|
|
valeur_du_parametre = la valeur de ce parametre |
|
144
|
|
|
|
|
|
|
Returns: |
|
145
|
|
|
|
|
|
|
- |
|
146
|
|
|
|
|
|
|
Example: |
|
147
|
|
|
|
|
|
|
$smb->AddParamGlobal("guest ok","Yes"); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub AddParamGlobal { |
|
152
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
153
|
0
|
|
|
|
|
|
my $param = shift; |
|
154
|
0
|
|
|
|
|
|
my $value = shift; |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$param = lc($param); |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my %GLOBAL = %{$this->{GLOBAL}}; |
|
|
0
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
$GLOBAL{$param} = $value; |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
$this->{GLOBAL} = \%GLOBAL; |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
return($this); |
|
165
|
|
|
|
|
|
|
}; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 DelParamGlobal([parametre_a_supprimer]); |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Supprime un parametre dans la partie [global] du smb.conf |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Params: |
|
172
|
|
|
|
|
|
|
Nom du parametre à supprimer |
|
173
|
|
|
|
|
|
|
Returns: |
|
174
|
|
|
|
|
|
|
Retourne 0 en cas de non suppression |
|
175
|
|
|
|
|
|
|
Retourne 1 si le parametre a été correctement supprimé |
|
176
|
|
|
|
|
|
|
Example: |
|
177
|
|
|
|
|
|
|
my $result = $smb->DelParamGlobal("workgroup"); |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub DelParamGlobal { |
|
182
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
183
|
0
|
|
|
|
|
|
my $param = shift; |
|
184
|
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
my $return = 0; |
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$param = lc($param); |
|
188
|
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
my %GLOBAL = %{$this->{GLOBAL}}; |
|
|
0
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
0
|
|
|
|
|
if (exists $GLOBAL{$param}) { |
|
193
|
0
|
|
|
|
|
|
delete($GLOBAL{$param}); |
|
194
|
0
|
|
|
|
|
|
$return = 1; |
|
195
|
|
|
|
|
|
|
}; |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
$this->{GLOBAL} = \%GLOBAL; |
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return($this,$return); |
|
200
|
|
|
|
|
|
|
}; |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 ValeurSection([nom_de_partage],[nom_de_section]) |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Recherche la valeur d'une section pour un partage donné |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Params: |
|
207
|
|
|
|
|
|
|
Nom du partage |
|
208
|
|
|
|
|
|
|
Nom de la section dont on souhaite la valeur |
|
209
|
|
|
|
|
|
|
Returns: |
|
210
|
|
|
|
|
|
|
Valeur de la section d'un partage donné |
|
211
|
|
|
|
|
|
|
Example: |
|
212
|
|
|
|
|
|
|
my $valeur = $smb->ValeurSection("data","path"); |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub ValeurSection { |
|
217
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
218
|
0
|
|
|
|
|
|
my $partage_section = shift; |
|
219
|
0
|
|
|
|
|
|
my $nom_section = shift; |
|
220
|
0
|
|
|
|
|
|
my $value = undef; |
|
221
|
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my %details = %{$this->{DET_PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my @partages = @{$this->{PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
$partage_section = lc($partage_section); |
|
226
|
0
|
|
|
|
|
|
$nom_section = lc($nom_section); |
|
227
|
|
|
|
|
|
|
|
|
228
|
0
|
0
|
|
|
|
|
if (grep(/$partage_section/,@partages)) { |
|
229
|
0
|
|
|
|
|
|
my @temp = keys %{$details{$partage_section}}; |
|
|
0
|
|
|
|
|
|
|
|
230
|
0
|
0
|
|
|
|
|
if (grep(/$nom_section/,@temp)) { |
|
231
|
0
|
|
|
|
|
|
$value = $details{$partage_section}{$nom_section}; |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
}; |
|
234
|
0
|
|
|
|
|
|
return($value); |
|
235
|
|
|
|
|
|
|
}; |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 ListPartages |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Liste la totalité des partages contenus dans le fichier de configuration de samba |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Params: |
|
242
|
|
|
|
|
|
|
Aucun |
|
243
|
|
|
|
|
|
|
Returns: |
|
244
|
|
|
|
|
|
|
Tableau contenant la liste des partages |
|
245
|
|
|
|
|
|
|
Example: |
|
246
|
|
|
|
|
|
|
my @partages = ListPartages; |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub ListPartages { |
|
251
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
252
|
0
|
|
|
|
|
|
my @partages = @{$this->{PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
return (@partages); |
|
255
|
|
|
|
|
|
|
}; |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head2 ListSections |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Liste les différentes sections et leur valeur pour tous les partages samba |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Params: |
|
262
|
|
|
|
|
|
|
Aucun |
|
263
|
|
|
|
|
|
|
Returns: |
|
264
|
|
|
|
|
|
|
Hash de hash contenant le détail de chaque partage samba |
|
265
|
|
|
|
|
|
|
Example: |
|
266
|
|
|
|
|
|
|
my %details = $smb->ListSections; |
|
267
|
|
|
|
|
|
|
my @part = keys %details; |
|
268
|
|
|
|
|
|
|
foreach $keys (@part) { |
|
269
|
|
|
|
|
|
|
my @key2 = keys %{$details{$keys}}; |
|
270
|
|
|
|
|
|
|
foreach my $value (@key2) { |
|
271
|
|
|
|
|
|
|
my $valeur = $details{$keys}{$value}; |
|
272
|
|
|
|
|
|
|
}; |
|
273
|
|
|
|
|
|
|
}; |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=cut |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
sub ListSections { |
|
278
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
279
|
0
|
|
|
|
|
|
my %detail = %{$this->{DET_PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
|
return (%detail); |
|
282
|
|
|
|
|
|
|
}; |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head2 CreaPartage("nom_du_partage"); |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
Permet la creation d'un nouveau partage |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
Params: |
|
289
|
|
|
|
|
|
|
Le nom du partage à créer |
|
290
|
|
|
|
|
|
|
Returns: |
|
291
|
|
|
|
|
|
|
Retourne 1 si le partage a été créé |
|
292
|
|
|
|
|
|
|
Retourne 0 si le partage n'a pas pu être créé |
|
293
|
|
|
|
|
|
|
Example: |
|
294
|
|
|
|
|
|
|
my $result = $smb->CreaPartage("nom_du_partage"); |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=cut |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
sub CreaPartage { |
|
299
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
300
|
0
|
|
|
|
|
|
my $partage = shift; |
|
301
|
0
|
|
|
|
|
|
my %detail = %{$this->{NEW_PARTAGE}}; |
|
|
0
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
|
my @partages = @{$this->{PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
303
|
0
|
|
|
|
|
|
my $result = 1; |
|
304
|
|
|
|
|
|
|
|
|
305
|
0
|
|
|
|
|
|
$partage = lc($partage); |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
### Tester si le nom de partage n'est pas déjà utilisé ### |
|
308
|
0
|
0
|
|
|
|
|
if (grep /$partage/,@partages) { |
|
309
|
0
|
|
|
|
|
|
$result = 0; |
|
310
|
|
|
|
|
|
|
} |
|
311
|
|
|
|
|
|
|
else { |
|
312
|
|
|
|
|
|
|
### Creer le partage ### |
|
313
|
0
|
|
|
|
|
|
$detail{$partage}{comment}=$partage; |
|
314
|
0
|
|
|
|
|
|
push(@partages,$partage); |
|
315
|
|
|
|
|
|
|
}; |
|
316
|
0
|
|
|
|
|
|
$this->{NEW_PARTAGE} = \%detail; |
|
317
|
0
|
|
|
|
|
|
$this->{PARTAGES} = \@partages; |
|
318
|
0
|
|
|
|
|
|
return ($this,$result); |
|
319
|
|
|
|
|
|
|
}; |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head2 CreaSection([partage],[section],[valeur_de_la_section]); |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
Ajoute une nouvelle section au partage créé précédemment à l'aide de "CreaPartage" |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
Params: |
|
326
|
|
|
|
|
|
|
partage : Nom du partage sur lequel créer une section |
|
327
|
|
|
|
|
|
|
Section : Nom de la section à créer |
|
328
|
|
|
|
|
|
|
Valeur de la section : Valeur à inscrire pour la section indiquée |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
Returns: |
|
331
|
|
|
|
|
|
|
Retourne 1 si la création s'est déroulée correctement |
|
332
|
|
|
|
|
|
|
Retourne 0 si la création n'a pas eu lieu |
|
333
|
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
Example: |
|
335
|
|
|
|
|
|
|
my $result = $smb->CreaPartage("Data"); |
|
336
|
|
|
|
|
|
|
$smb->CreaSection("donnees","path","/home/data"); |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=cut |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
sub CreaSection { |
|
341
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
342
|
0
|
|
|
|
|
|
my $partage = shift; |
|
343
|
0
|
|
|
|
|
|
my $section = shift; |
|
344
|
0
|
|
|
|
|
|
my $value = shift; |
|
345
|
|
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
|
$partage = lc($partage); |
|
347
|
0
|
|
|
|
|
|
$section = lc($section); |
|
348
|
|
|
|
|
|
|
|
|
349
|
0
|
|
|
|
|
|
my $result = 1; |
|
350
|
0
|
|
|
|
|
|
my %new_partage = %{$this->{NEW_PARTAGE}}; |
|
|
0
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
|
|
352
|
0
|
|
|
|
|
|
my @keys = keys(%new_partage); |
|
353
|
|
|
|
|
|
|
|
|
354
|
0
|
0
|
|
|
|
|
if (!(grep(/$partage/,@keys))) { |
|
355
|
0
|
|
|
|
|
|
$result = 0; |
|
356
|
|
|
|
|
|
|
} |
|
357
|
|
|
|
|
|
|
else { |
|
358
|
|
|
|
|
|
|
### Ajouter la nouvelle section au partage en cours de creation |
|
359
|
0
|
|
|
|
|
|
$new_partage{$partage}{$section} = $value; |
|
360
|
|
|
|
|
|
|
}; |
|
361
|
|
|
|
|
|
|
|
|
362
|
0
|
|
|
|
|
|
return ($this,$result); |
|
363
|
|
|
|
|
|
|
}; |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
=head2 ModifSection([partage],[section],[valeur_de_la_section]); |
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
Modifie la valeur d'une section pour un partage donné |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
Params: |
|
370
|
|
|
|
|
|
|
[partage] : nom du partage sur lequel travailler |
|
371
|
|
|
|
|
|
|
[section] : nom de la section dans le partage indiqué |
|
372
|
|
|
|
|
|
|
[valeur_de_la_section] : Valeur de la section |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
Returns: |
|
375
|
|
|
|
|
|
|
Retourne 1 si la modification a été réalisée |
|
376
|
|
|
|
|
|
|
Retourne 0 si la modification a échouée |
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
Example: |
|
379
|
|
|
|
|
|
|
my $retour = $smb->ModifSection("games","inherit permissions","No"); |
|
380
|
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
=cut |
|
382
|
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
sub ModifSection { |
|
384
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
385
|
0
|
|
|
|
|
|
my $partage_modif = shift; |
|
386
|
0
|
|
|
|
|
|
my $section_modif = shift; |
|
387
|
0
|
|
|
|
|
|
my $value_modif = shift; |
|
388
|
|
|
|
|
|
|
|
|
389
|
0
|
|
|
|
|
|
my $result = 1; |
|
390
|
|
|
|
|
|
|
|
|
391
|
0
|
|
|
|
|
|
$partage_modif = lc($partage_modif); |
|
392
|
0
|
|
|
|
|
|
$section_modif = lc($section_modif); |
|
393
|
|
|
|
|
|
|
|
|
394
|
0
|
|
|
|
|
|
my @partages = @{$this->{PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
395
|
0
|
|
|
|
|
|
my %detail = %{$this->{DET_PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
|
|
397
|
0
|
0
|
|
|
|
|
if (grep(/$partage_modif/,@partages)) { |
|
398
|
0
|
|
|
|
|
|
$detail{$partage_modif}{$section_modif}=$value_modif; |
|
399
|
|
|
|
|
|
|
} |
|
400
|
0
|
|
|
|
|
|
else { $result = 0; }; |
|
401
|
|
|
|
|
|
|
|
|
402
|
0
|
|
|
|
|
|
return ($this,$result); |
|
403
|
|
|
|
|
|
|
}; |
|
404
|
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
=head2 DelPartage([@partages]); |
|
406
|
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
Supprime un partage du fichier smb.conf |
|
408
|
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
Params: |
|
410
|
|
|
|
|
|
|
Un tableau contenant le nom de chaque partage à supprimer |
|
411
|
|
|
|
|
|
|
Returns: |
|
412
|
|
|
|
|
|
|
Retourne une référence sur un tableau contenant le nom des partages supprimés |
|
413
|
|
|
|
|
|
|
Example: |
|
414
|
|
|
|
|
|
|
my @partages = ("data","games","mp3","avi"); |
|
415
|
|
|
|
|
|
|
my $RefPartagesSupp = $smb->DelPartage(@partages); |
|
416
|
|
|
|
|
|
|
my @PartSupp = @$RefPartagesSupp; |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
foreach my $val (@PartSupp) { |
|
419
|
|
|
|
|
|
|
print("Partage Supprimé : $val\n"); |
|
420
|
|
|
|
|
|
|
}; |
|
421
|
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=cut |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
sub DelPartage { |
|
425
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
426
|
0
|
|
|
|
|
|
my (@partage_del) = @_; |
|
427
|
|
|
|
|
|
|
|
|
428
|
0
|
|
|
|
|
|
my @retour; |
|
429
|
|
|
|
|
|
|
my $part; |
|
430
|
0
|
|
|
|
|
|
my @partages = @{$this->{PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
431
|
0
|
|
|
|
|
|
my %detail = %{$this->{DET_PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
|
|
433
|
0
|
|
|
|
|
|
foreach $part (@partage_del) { |
|
434
|
0
|
|
|
|
|
|
$part = lc($part); |
|
435
|
|
|
|
|
|
|
|
|
436
|
0
|
0
|
|
|
|
|
if (grep(/$part/,@partages)) { |
|
437
|
0
|
|
|
|
|
|
delete($detail{$part}); |
|
438
|
0
|
|
|
|
|
|
for (my $i=0;$i<=$#partages;$i++) { |
|
439
|
0
|
0
|
|
|
|
|
if ($partages[$i] eq $part) { |
|
440
|
0
|
|
|
|
|
|
splice(@partages,$i,1); |
|
441
|
0
|
|
|
|
|
|
push (@retour,$part); |
|
442
|
0
|
|
|
|
|
|
last; |
|
443
|
|
|
|
|
|
|
}; |
|
444
|
|
|
|
|
|
|
}; |
|
445
|
|
|
|
|
|
|
}; |
|
446
|
|
|
|
|
|
|
}; |
|
447
|
|
|
|
|
|
|
|
|
448
|
0
|
|
|
|
|
|
$this->{PARTAGES} = \@partages; |
|
449
|
0
|
|
|
|
|
|
$this->{DET_PARTAGES} = \%detail; |
|
450
|
|
|
|
|
|
|
|
|
451
|
0
|
|
|
|
|
|
return ($this,\@retour); |
|
452
|
|
|
|
|
|
|
}; |
|
453
|
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=head2 DelValue([nom_partage],[valeur_a_supprimer]); |
|
455
|
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
Suppression d'un parametre dans un partage |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
Params: |
|
459
|
|
|
|
|
|
|
nom_partage : Nom du partage où le paramètre doit être supprimé |
|
460
|
|
|
|
|
|
|
valeur_a_supprimer : Le paramètre à supprimer dans ce partage |
|
461
|
|
|
|
|
|
|
Returns: |
|
462
|
|
|
|
|
|
|
Retourne 1 si le parametre a été supprimé |
|
463
|
|
|
|
|
|
|
Retourne 0 si le parametre n'a pas été supprimé |
|
464
|
|
|
|
|
|
|
Example: |
|
465
|
|
|
|
|
|
|
my $retour = $smb->DelValue("games","inherit permissions"); |
|
466
|
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
=cut |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub DelValue { |
|
470
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
471
|
0
|
|
|
|
|
|
my $partage = shift; |
|
472
|
0
|
|
|
|
|
|
my $value = shift; |
|
473
|
|
|
|
|
|
|
|
|
474
|
0
|
|
|
|
|
|
$partage = lc($partage); |
|
475
|
0
|
|
|
|
|
|
$value = lc($value); |
|
476
|
|
|
|
|
|
|
|
|
477
|
0
|
|
|
|
|
|
my $retour = 1; |
|
478
|
|
|
|
|
|
|
|
|
479
|
0
|
|
|
|
|
|
my @partages = @{$this->{PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
480
|
0
|
|
|
|
|
|
my %detail = %{$this->{DET_PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
|
|
482
|
0
|
0
|
|
|
|
|
if (grep(/$partage/,@partages)) { |
|
483
|
|
|
|
|
|
|
|
|
484
|
0
|
0
|
|
|
|
|
if (exists $detail{$partage}) { |
|
485
|
0
|
|
|
|
|
|
delete $detail{$partage}{$value}; |
|
486
|
0
|
|
|
|
|
|
$this->{DET_PARTAGES} = \%detail; |
|
487
|
|
|
|
|
|
|
} |
|
488
|
|
|
|
|
|
|
else { |
|
489
|
0
|
|
|
|
|
|
$retour = 0; |
|
490
|
|
|
|
|
|
|
}; |
|
491
|
|
|
|
|
|
|
} |
|
492
|
|
|
|
|
|
|
else { |
|
493
|
0
|
|
|
|
|
|
$retour = 0; |
|
494
|
|
|
|
|
|
|
}; |
|
495
|
|
|
|
|
|
|
|
|
496
|
0
|
|
|
|
|
|
return($this,$retour); |
|
497
|
|
|
|
|
|
|
}; |
|
498
|
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
=head2 Sauve([nom_du_fichier]); |
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
Sauvegarde des modifications effectuées > Ecriture du fichier final |
|
502
|
|
|
|
|
|
|
Pour que l'enregistrement se passe correctement, il faut au minimum une partie global et un partage. |
|
503
|
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
Params: |
|
505
|
|
|
|
|
|
|
Nom du fichier à sauvegarder. Ce paramêtre est facultatif. |
|
506
|
|
|
|
|
|
|
S'il n'est pas donné, le fichier est enregistré sous son nom d'origine. |
|
507
|
|
|
|
|
|
|
Dans ce cas, une sauvegarde de ce fichier est réalisée dans le même répertoire avant l'écriture. |
|
508
|
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
Returns: |
|
510
|
|
|
|
|
|
|
Si sauvegarde avec le nom du fichier d'origine, renvoi le nom du fichier sauvegardé |
|
511
|
|
|
|
|
|
|
Si sauvegarde avec un nouveau nom, renvoi 1 |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
Example: |
|
514
|
|
|
|
|
|
|
my $retour = $smb->Sauve("/etc/samba/smbnew.conf"); |
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=cut |
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
sub Sauve { |
|
519
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
520
|
0
|
|
|
|
|
|
my $fic_sauve = shift; |
|
521
|
|
|
|
|
|
|
|
|
522
|
0
|
|
|
|
|
|
my $retour; |
|
523
|
0
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); |
|
524
|
|
|
|
|
|
|
|
|
525
|
0
|
|
|
|
|
|
my %partage_a_sauver = %{$this->{NEW_PARTAGE}}; |
|
|
0
|
|
|
|
|
|
|
|
526
|
0
|
|
|
|
|
|
my %det_part = %{$this->{DET_PARTAGES}}; |
|
|
0
|
|
|
|
|
|
|
|
527
|
0
|
|
|
|
|
|
my $smb = $this->{SMB}; |
|
528
|
0
|
|
|
|
|
|
my %global = %{$this->{GLOBAL}}; |
|
|
0
|
|
|
|
|
|
|
|
529
|
0
|
|
|
|
|
|
$year = $year+1900; |
|
530
|
0
|
|
|
|
|
|
my $save = "$smb-$mon$year-$hour$min$sec"; |
|
531
|
|
|
|
|
|
|
|
|
532
|
0
|
0
|
0
|
|
|
|
if ((defined $fic_sauve) and ($smb ne $fic_sauve)) { |
|
533
|
0
|
|
|
|
|
|
$smb = $fic_sauve; |
|
534
|
0
|
|
|
|
|
|
$retour = 1; |
|
535
|
|
|
|
|
|
|
} |
|
536
|
|
|
|
|
|
|
else { |
|
537
|
|
|
|
|
|
|
### Sauvegarde du fichier d'origine ### |
|
538
|
0
|
|
|
|
|
|
copy("$smb","$save"); |
|
539
|
0
|
|
|
|
|
|
$retour = $save; |
|
540
|
|
|
|
|
|
|
}; |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
### Integration du nouveau partage dans la liste des partages à enregistrer |
|
543
|
0
|
|
|
|
|
|
my @keys_new = keys(%partage_a_sauver); |
|
544
|
|
|
|
|
|
|
|
|
545
|
0
|
0
|
|
|
|
|
if ($#keys_new >= 0) { |
|
546
|
0
|
|
|
|
|
|
foreach my $key_new (@keys_new) { |
|
547
|
0
|
|
|
|
|
|
my @section_new = keys(%{$partage_a_sauver{$key_new}}); |
|
|
0
|
|
|
|
|
|
|
|
548
|
0
|
|
|
|
|
|
foreach my $sectio (@section_new) { |
|
549
|
0
|
|
|
|
|
|
$det_part{$key_new}{$sectio}=$partage_a_sauver{$key_new}{$sectio}; |
|
550
|
|
|
|
|
|
|
}; |
|
551
|
|
|
|
|
|
|
}; |
|
552
|
|
|
|
|
|
|
}; |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
### Mettre le premier caractere en majuscule (uniquement pour Yes ou No) |
|
555
|
0
|
|
|
|
|
|
my @keys_maj = keys(%det_part); |
|
556
|
|
|
|
|
|
|
|
|
557
|
0
|
|
|
|
|
|
foreach my $_key (@keys_maj) { |
|
558
|
0
|
|
|
|
|
|
my @section_maj = keys(%{$det_part{$_key}}); |
|
|
0
|
|
|
|
|
|
|
|
559
|
0
|
|
|
|
|
|
foreach my $_section (@section_maj) { |
|
560
|
0
|
0
|
|
|
|
|
if ($det_part{$_key}{$_section} =~ /^yes$|^no$/i) { |
|
561
|
0
|
|
|
|
|
|
$det_part{$_key}{$_section} = ucfirst($det_part{$_key}{$_section}); |
|
562
|
|
|
|
|
|
|
}; |
|
563
|
|
|
|
|
|
|
}; |
|
564
|
|
|
|
|
|
|
}; |
|
565
|
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
### Ouverture du fichier en ecriture |
|
567
|
0
|
0
|
|
|
|
|
open(FICSMB,">",$smb)||croak("Impossible de créer le fichier $smb !!!\n"); |
|
568
|
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
### En-tête personnalisé |
|
570
|
0
|
|
|
|
|
|
print FICSMB (";============================================================================\n"); |
|
571
|
0
|
|
|
|
|
|
print FICSMB (";================== xxxxxxx perl -- SambaMSNRL xxxxxxx ==================\n"); |
|
572
|
0
|
|
|
|
|
|
print FICSMB (";============ xxxx raphael.gommeaux\@gmail.com xxxx ===========\n"); |
|
573
|
0
|
|
|
|
|
|
print FICSMB (";============================================================================\n\n\n"); |
|
574
|
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
### Ecriture du global dans le fichier |
|
576
|
0
|
|
|
|
|
|
my @keys_global = sort(keys(%global)); |
|
577
|
0
|
|
|
|
|
|
my $maj_key; |
|
578
|
|
|
|
|
|
|
|
|
579
|
0
|
0
|
|
|
|
|
if ($#keys_global >= 0) { |
|
580
|
0
|
|
|
|
|
|
print FICSMB ("[global]\n"); |
|
581
|
0
|
|
|
|
|
|
foreach my $key_global (@keys_global) { |
|
582
|
0
|
|
|
|
|
|
$maj_key = $global{$key_global}; |
|
583
|
|
|
|
|
|
|
|
|
584
|
0
|
0
|
|
|
|
|
if ($global{$key_global} =~ /^yes$|^no$/i) { |
|
585
|
0
|
|
|
|
|
|
$maj_key = lc($maj_key); |
|
586
|
0
|
|
|
|
|
|
$maj_key = ucfirst($maj_key); |
|
587
|
|
|
|
|
|
|
} |
|
588
|
0
|
|
|
|
|
|
print FICSMB ("\t$key_global = $maj_key\n"); |
|
589
|
|
|
|
|
|
|
}; |
|
590
|
|
|
|
|
|
|
} |
|
591
|
0
|
|
|
|
|
|
else { croak("Impossible de trouver la partie global...\n"); }; |
|
592
|
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
### Separation entre le global et les partages |
|
594
|
0
|
|
|
|
|
|
print FICSMB ("\n;=========================================================================\n\n"); |
|
595
|
|
|
|
|
|
|
### Ecriture des partages dans le fichier |
|
596
|
0
|
|
|
|
|
|
my @keys_detail_part = sort(keys(%det_part)); |
|
597
|
0
|
0
|
|
|
|
|
if ($#keys_detail_part >= 0) { |
|
598
|
0
|
|
|
|
|
|
foreach my $key_part (@keys_detail_part) { |
|
599
|
0
|
|
|
|
|
|
print FICSMB ("\n[$key_part]\n"); |
|
600
|
0
|
|
|
|
|
|
my @section = sort(keys(%{$det_part{$key_part}})); |
|
|
0
|
|
|
|
|
|
|
|
601
|
0
|
|
|
|
|
|
foreach my $sectio (@section) { |
|
602
|
0
|
|
|
|
|
|
my $det_maj = $det_part{$key_part}{$sectio}; |
|
603
|
0
|
0
|
|
|
|
|
if ($det_maj =~ /^yes$|^no$/i) { |
|
604
|
0
|
|
|
|
|
|
$det_maj = lc($det_maj); |
|
605
|
0
|
|
|
|
|
|
$det_maj = ucfirst($det_maj); |
|
606
|
|
|
|
|
|
|
}; |
|
607
|
0
|
|
|
|
|
|
print FICSMB ("\t$sectio = $det_maj\n"); |
|
608
|
|
|
|
|
|
|
}; |
|
609
|
|
|
|
|
|
|
}; |
|
610
|
|
|
|
|
|
|
} |
|
611
|
0
|
|
|
|
|
|
else { croak("Pas de partages à enregistrer... surement une erreur...\n");}; |
|
612
|
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
### Fermeture du fichier |
|
614
|
0
|
|
|
|
|
|
close FICSMB; |
|
615
|
|
|
|
|
|
|
|
|
616
|
0
|
|
|
|
|
|
return($retour); |
|
617
|
|
|
|
|
|
|
}; |
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
=head2 load("nom_du_fichier"); |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
Charge un fichier de configuration samba |
|
624
|
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
Params: |
|
626
|
|
|
|
|
|
|
Nom du fichier de configuration |
|
627
|
|
|
|
|
|
|
Returns: |
|
628
|
|
|
|
|
|
|
Retourne un tableau contenant le fichier chargé |
|
629
|
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
=cut |
|
631
|
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
sub load { |
|
633
|
0
|
|
|
0
|
1
|
|
my $name = shift; |
|
634
|
|
|
|
|
|
|
|
|
635
|
0
|
|
|
|
|
|
my @smbconf; |
|
636
|
|
|
|
|
|
|
|
|
637
|
0
|
0
|
|
|
|
|
if (-z $name) { croak("Le fichier $name est vide !!!\n");}; |
|
|
0
|
|
|
|
|
|
|
|
638
|
0
|
0
|
|
|
|
|
open(FICSMB,$name)||croak("Impossible de lire le fichier $name !!!!!\n"); |
|
639
|
0
|
|
|
|
|
|
my @smb = ; |
|
640
|
0
|
|
|
|
|
|
close FICSMB; |
|
641
|
|
|
|
|
|
|
|
|
642
|
0
|
|
|
|
|
|
return (@smb); |
|
643
|
|
|
|
|
|
|
}; |
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
=head2 TakePartages |
|
646
|
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
Charge la liste des partages présents dans le fichier de configuration de samba |
|
648
|
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
=cut |
|
650
|
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
sub TakePartages { |
|
652
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
653
|
0
|
|
|
|
|
|
my @SHARES; |
|
654
|
|
|
|
|
|
|
my @SHARES_DET; |
|
655
|
0
|
|
|
|
|
|
my $share_detail; |
|
656
|
0
|
|
|
|
|
|
my $fin; |
|
657
|
0
|
|
|
|
|
|
my %share_detail; |
|
658
|
0
|
|
|
|
|
|
my $part; |
|
659
|
0
|
|
|
|
|
|
my $ligne; |
|
660
|
|
|
|
|
|
|
|
|
661
|
0
|
|
|
|
|
|
my @SMB = load($this->{SMB}); |
|
662
|
|
|
|
|
|
|
|
|
663
|
0
|
|
|
|
|
|
for (my $i=0;$i<=$#SMB;$i++) { |
|
664
|
0
|
|
|
|
|
|
chomp($SMB[$i]); |
|
665
|
0
|
|
|
|
|
|
$ligne = $SMB[$i]; |
|
666
|
|
|
|
|
|
|
|
|
667
|
0
|
0
|
0
|
|
|
|
if (($ligne =~ /\[/) and (!($ligne =~ /\[global\]/))) { |
|
|
|
0
|
0
|
|
|
|
|
|
668
|
0
|
|
|
|
|
|
$part = lc($SMB[$i]); |
|
669
|
|
|
|
|
|
|
|
|
670
|
0
|
|
|
|
|
|
$part =~ s/\[//; |
|
671
|
0
|
|
|
|
|
|
$part =~ s/\]//; |
|
672
|
0
|
|
|
|
|
|
$part =~ s/ //g; |
|
673
|
|
|
|
|
|
|
|
|
674
|
0
|
|
|
|
|
|
push(@SHARES,$part); |
|
675
|
|
|
|
|
|
|
} |
|
676
|
|
|
|
|
|
|
### Ne passe pas dans cette boucle si : |
|
677
|
|
|
|
|
|
|
### - pas encore trouvé de partage |
|
678
|
|
|
|
|
|
|
### - la ligne est vide |
|
679
|
|
|
|
|
|
|
### - la ligne commence par un ; ou un # |
|
680
|
|
|
|
|
|
|
### - la ligne commence par une ou plusieurs tabulations suivies d'un ; ou d'un # |
|
681
|
|
|
|
|
|
|
### - la ligne commence par un ou plusieurs espaces suivis d'un ; ou d'un # |
|
682
|
|
|
|
|
|
|
elsif (($#SHARES >= 0) and (!($ligne =~ /^\s*$|^;|^\t*;|^\s*;|^#|^\t*#|^\s*#/))) { |
|
683
|
0
|
|
|
|
|
|
$ligne =~ /(.+)=(.+)/; |
|
684
|
0
|
|
|
|
|
|
my $section = $1; |
|
685
|
0
|
|
|
|
|
|
my $valeur = $2; |
|
686
|
|
|
|
|
|
|
|
|
687
|
0
|
0
|
0
|
|
|
|
if (($valeur eq "") or ($valeur eq " ")) |
|
688
|
|
|
|
|
|
|
{ |
|
689
|
0
|
|
|
|
|
|
$section = $ligne; |
|
690
|
0
|
|
|
|
|
|
$section =~ s/=//; |
|
691
|
|
|
|
|
|
|
} |
|
692
|
|
|
|
|
|
|
|
|
693
|
0
|
|
|
|
|
|
$section =~ s/\t//; |
|
694
|
0
|
|
|
|
|
|
$section =~ s/^ +//; |
|
695
|
0
|
|
|
|
|
|
$section =~ s/ +$//; |
|
696
|
|
|
|
|
|
|
|
|
697
|
0
|
|
|
|
|
|
$section = lc($section); |
|
698
|
|
|
|
|
|
|
|
|
699
|
0
|
|
|
|
|
|
$valeur =~ s/\t//; |
|
700
|
0
|
|
|
|
|
|
$valeur =~ s/^ +//; |
|
701
|
0
|
|
|
|
|
|
$valeur =~ s/ +$//; |
|
702
|
|
|
|
|
|
|
|
|
703
|
0
|
|
|
|
|
|
$share_detail{$part}{$section} = $valeur; |
|
704
|
|
|
|
|
|
|
}; |
|
705
|
|
|
|
|
|
|
}; |
|
706
|
|
|
|
|
|
|
|
|
707
|
0
|
|
|
|
|
|
$this->{PARTAGES} = \@SHARES; |
|
708
|
0
|
|
|
|
|
|
$this->{DET_PARTAGES} = \%share_detail; |
|
709
|
|
|
|
|
|
|
|
|
710
|
0
|
|
|
|
|
|
return $this; |
|
711
|
|
|
|
|
|
|
}; |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
=head2 TakeGlobal |
|
714
|
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
Charge la partie global du fichier de configuration samba |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
=cut |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
sub TakeGlobal { |
|
720
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
721
|
0
|
|
|
|
|
|
my @smb = load($this->{SMB}); |
|
722
|
0
|
|
|
|
|
|
my %GLOBAL; |
|
723
|
|
|
|
|
|
|
|
|
724
|
0
|
|
|
|
|
|
for (my $i=0;$i<=$#smb;$i++) { |
|
725
|
0
|
|
|
|
|
|
chomp($smb[$i]); |
|
726
|
0
|
0
|
|
|
|
|
if ($smb[$i] eq "[global]") { |
|
727
|
0
|
|
|
|
|
|
for (my $j=$i+1;$j<=$#smb;$j++) { |
|
728
|
0
|
0
|
|
|
|
|
if (grep (/\[/,$smb[$j])) { |
|
729
|
0
|
|
|
|
|
|
last; |
|
730
|
|
|
|
|
|
|
} |
|
731
|
|
|
|
|
|
|
else { |
|
732
|
0
|
|
|
|
|
|
chomp($smb[$j]); |
|
733
|
0
|
0
|
0
|
|
|
|
if ((!($smb[$j] =~ /^;/)) and (!($smb[$j] =~ /^#/)) and (grep (/=/,$smb[$j]))) { |
|
|
|
|
0
|
|
|
|
|
|
734
|
|
|
|
|
|
|
# $smb[$j] =~ /(.*?)=(.*)/; |
|
735
|
0
|
|
|
|
|
|
$smb[$j] =~ m/([^=]+) = (.+)/x; |
|
736
|
0
|
|
|
|
|
|
my $section_global = $1; |
|
737
|
0
|
|
|
|
|
|
my $valeur_section = $2; |
|
738
|
|
|
|
|
|
|
|
|
739
|
0
|
0
|
0
|
|
|
|
if (($valeur_section eq "") or ($valeur_section eq " ")) |
|
740
|
|
|
|
|
|
|
{ |
|
741
|
0
|
|
|
|
|
|
$section_global = $smb[$j]; |
|
742
|
0
|
|
|
|
|
|
$section_global =~ s/=//; |
|
743
|
|
|
|
|
|
|
} |
|
744
|
|
|
|
|
|
|
|
|
745
|
0
|
|
|
|
|
|
$section_global =~ s/\t//; |
|
746
|
|
|
|
|
|
|
|
|
747
|
0
|
|
|
|
|
|
$section_global =~ s/^ +//; |
|
748
|
0
|
|
|
|
|
|
$section_global =~ s/ +$//; |
|
749
|
0
|
|
|
|
|
|
$section_global = lc($section_global); |
|
750
|
0
|
|
|
|
|
|
$valeur_section =~ s/\t//; |
|
751
|
0
|
|
|
|
|
|
$valeur_section =~ s/^ +//; |
|
752
|
0
|
|
|
|
|
|
$valeur_section =~ s/ +$//; |
|
753
|
|
|
|
|
|
|
|
|
754
|
0
|
|
|
|
|
|
$GLOBAL{$section_global}=$valeur_section; |
|
755
|
|
|
|
|
|
|
}; |
|
756
|
|
|
|
|
|
|
}; |
|
757
|
|
|
|
|
|
|
}; |
|
758
|
|
|
|
|
|
|
}; |
|
759
|
|
|
|
|
|
|
}; |
|
760
|
0
|
|
|
|
|
|
$this->{GLOBAL} = \%GLOBAL; |
|
761
|
0
|
|
|
|
|
|
return (%GLOBAL); |
|
762
|
|
|
|
|
|
|
}; |
|
763
|
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
1; |