/[smecontribs]/rpms/smeserver-thinclient/contribs10/smeserver-thinclient-2.1-archive.patch
ViewVC logotype

Annotation of /rpms/smeserver-thinclient/contribs10/smeserver-thinclient-2.1-archive.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Thu Oct 29 18:35:39 2020 UTC (4 years, 1 month ago) by brianr
Branch: MAIN
CVS Tags: smeserver-thinclient-2_1-4_el7_sme
Initial import

1 brianr 1.1 diff -up smeserver-thinclient-2.1/root/etc/e-smith/web/functions/thinclient.archive smeserver-thinclient-2.1/root/etc/e-smith/web/functions/thinclient
2     --- smeserver-thinclient-2.1/root/etc/e-smith/web/functions/thinclient.archive 2016-04-03 21:25:05.000000000 +1000
3     +++ smeserver-thinclient-2.1/root/etc/e-smith/web/functions/thinclient 2016-04-25 20:18:35.000000000 +1000
4     @@ -27,6 +27,8 @@ use esmith::cgi;
5     use esmith::ConfigDB;
6     use esmith::util;
7     use FileHandle;
8     +use File::Basename;
9     +use File::Path qw(make_path remove_tree);
10    
11     sub showInitial ($$$$);
12     sub showStatusReport ($$$$);
13     @@ -40,7 +42,8 @@ sub saveDistribution ($);
14     sub saveConfiguration ($);
15     sub showDistributionPanel ($$$);
16     sub showWorkstationPanel ($$$);
17     -
18     +sub checkarchive ($);
19     +sub readini($);
20    
21     BEGIN
22     {
23     @@ -61,8 +64,8 @@ my $pxeclients = esmith::ConfigDB->open(
24     my $hosts = esmith::ConfigDB->open_ro('hosts');
25    
26    
27     -my $version = '2.1-2';
28     +my $version = '2.1-3';
29     my $email = 'trevorbatley@users.sourceforge.net';
30     my $title = 'Thin Client Configuration';
31     my $copyright = 'copyright (c) 2004, Trevor Batley, <a href=mailto:'.$email.'>'.$email.'</a>';
32     my $sendreports = 'Please raise Bugs and Feature Requests in <a target=_blank href=http://bugs.contribs.org/>Bugzilla</a> (SMEContribs => smeserver-thinclient)';
33     @@ -384,12 +387,12 @@ sub showPXEGlobals($)
34     sub showPXEDists($)
35     {
36     my ($q) = @_;
37     - my $tftproot = "/tftproot/";
38     + my $tftproot = "/tftpboot/";
39     if ($config->get('tftpd'))
40     {
41     if ($config->get('tftpd')->prop('status') eq 'enabled')
42     {
43     - $tftproot = $config->get('tftpd')->prop('tftproot')
44     + $tftproot = $config->get('tftpd')->prop('tftproot') || "/tftpboot/";
45     }
46     }
47    
48     @@ -430,30 +433,30 @@ sub showPXEDists($)
49     foreach my $dist (sort @distkeys)
50     {
51     my $distrec = $pxeclients->get($dist);
52     - my $dtype = $distrec->prop('install') || "Manual";
53     - if ($dtype ne "Manual")
54     + my $install = $distrec->prop('install') || "Manual";
55     + if ($install eq "Manual" || $install eq 'Archive')
56     {
57     print $q->Tr (esmith::cgi::genSmallCell ($q, $dist, 'normal'),
58     - esmith::cgi::genSmallCell ($q, $tftproot . ($distrec->prop('dir') || ""), 'normal'),
59     - esmith::cgi::genSmallCell ($q, "RPM", 'normal'),
60     - esmith::cgi::genSmallCell ($q,
61     + esmith::cgi::genSmallCell ($q, $tftproot.($distrec->prop('dir') || ""), 'normal'),
62     + esmith::cgi::genSmallCell ($q, $install, 'normal'),
63     + esmith::cgi::genCell ($q,
64     $q->a ({href => $q->url (-absolute => 1)
65     . "?state=showDist&acct=Delete&dist="
66     - . $dist}, 'Remove...'), 'normal'));
67     + . $dist}, 'Remove...'), 'normal'),
68     + esmith::cgi::genCell ($q,
69     + $q->a ({href => $q->url (-absolute => 1)
70     + . "?state=showDist&acct=Change&dist="
71     + . $dist}, 'Modify...'), 'normal'));
72     }
73     else
74     {
75     print $q->Tr (esmith::cgi::genSmallCell ($q, $dist, 'normal'),
76     esmith::cgi::genSmallCell ($q, $tftproot . ($distrec->prop('dir') || ""), 'normal'),
77     - esmith::cgi::genSmallCell ($q, $dtype, 'normal'),
78     - esmith::cgi::genSmallCell ($q,
79     + esmith::cgi::genSmallCell ($q, $install, 'normal'),
80     + esmith::cgi::genCell ($q,
81     $q->a ({href => $q->url (-absolute => 1)
82     . "?state=showDist&acct=Delete&dist="
83     - . $dist}, 'Remove...'), 'normal'),
84     - esmith::cgi::genSmallCell ($q,
85     - $q->a ({href => $q->url (-absolute => 1)
86     - . "?state=showDist&acct=Change&dist="
87     - . $dist}, 'Modify...'), 'normal'));
88     + . $dist}, 'Remove...'), 'normal'));
89     }
90     }
91     print $q->end_table;
92     @@ -541,15 +544,18 @@ sub showDistributionPanel($$$)
93    
94     my $action = $q->param ('acct');
95     my $dist = $q->param ('dist') || "";
96     - my $dir = "";
97     - my $prog = "pxelinux.0";
98     - my $tftproot = "/tftproot/";
99     + my $dir = $q->param ('dir') || "";
100     + my $prog = $q->param ('prog') || "pxelinux.0";
101     + my $ini = $q->param('ini') || "";
102     + my $origdir = $q->param('origdir') || "";
103     + my $install = $q->param('install') || "Manual";
104     + my $tftproot = "/tftpboot/";
105     if ($config->get('tftpd'))
106     {
107     - if ($config->get('tftpd')->prop('status') eq 'enabled')
108     - {
109     - $tftproot = $config->get('tftpd')->prop('tftproot')
110     - }
111     + if ($config->get('tftpd')->prop('status') eq 'enabled')
112     + {
113     + $tftproot = $config->get('tftpd')->prop('tftproot') || "/tftpboot/";
114     + }
115     }
116    
117     esmith::cgi::genHeaderNonCacheable ($q, $config, $action . " Distribution");
118     @@ -558,18 +564,18 @@ sub showDistributionPanel($$$)
119    
120     if ($err ne '') {showStatusReport ($q, 'error', $err, $log)};
121    
122     - print $q->start_table ({-class => "sme-noborders"});
123     -
124     # --- Distribution Name
125     if ($action eq 'Add')
126     {
127     - print $q->p ('You can add a Distribution via a prebuilt rpm.<BR><BR>',
128     - 'Select the rpm file to load from your local workstation. No checking is done on this file!',
129     + print $q->p ('You can add a Distribution via a prebuilt archive.<BR><BR>',
130     + 'Select the file to load from your local workstation. Minimal checking is done on this file!',
131     );
132     + print $q->p ;
133     + print $q->start_table ({-class => "sme-noborders"});
134     print $q->Tr (
135     - $q->td ({-class => "sme-noborders-label"}, "Distribution .rpm:"),
136     + $q->td ({-class => "sme-noborders-label"}, "Archive:"),
137     $q->td ({-class => "sme-noborders-content"},
138     - $q->filefield(-name => 'rpmfile',
139     + $q->filefield(-name => 'archive',
140     -default => "smeserver-thinclient-<dist>-<version>.noarch.rpm",
141     -size => 32)));
142    
143     @@ -581,67 +587,163 @@ sub showDistributionPanel($$$)
144     );
145    
146     $dist = "";
147     + print $q->p ;
148     print $q->Tr (
149     - esmith::cgi::genNameValueRow ($q, "Name", "dist", $dist),
150     - );
151     + $q->td ({-class => "sme-noborders-label"}, "Distribution:"),
152     + $q->td ({-class => "sme-noborders-content"}, $q->textfield (-name => "dist", -override => 1, -default => $dist, -size => 32)));
153     + print $q->Tr (
154     + $q->td ({-class => "sme-noborders-label"}, "Directory:".$tftproot),
155     + $q->td ({-class => "sme-noborders-content"}, $q->textfield (-name => "dir", -override => 1, -default => $dir, -size => 32)));
156     + print $q->Tr (
157     + $q->td ({-class => "sme-noborders-label"}, "Executable:"),
158     + $q->td ({-class => "sme-noborders-content"}, $q->textfield (-name => "prog", -override => 1, -default => $prog, -size => 32)));
159     + print $q->end_table;
160     }
161     - else
162     + elsif ($action eq 'Confirm')
163     + # Confirm ONLY applies to Distributions from an archive or if they have entered the name of an existing Distribution
164     {
165     - my $install = $pxeclients->get_prop($dist, 'install') || "Manual";
166     - if ($install eq "Manual")
167     + if ($pxeclients->get($dist))
168     {
169     - print $q->p ('This ONLY alters the parameters within dhcp, so any changes required to directories or ',
170     - 'files associated with your Distribution must be manually performed by you.');
171     + print $q->p ('<B>'.$dist.'</B> already exists. Do you really want to do this? Or do you want to define a new name and directory below?');
172     }
173     - # --- Warning messages
174     else
175     {
176     - if ($action eq 'Delete')
177     - {
178     - print $q->p ('This Distribution was installed as an rpm, it will be removed via rpm -e!');
179     - }
180     - else
181     - {
182     - print $q->p ('This Distribution was installed as an rpm, we should not be able to do this!');
183     - }
184     + if ( $dir && -e "$tftproot$dir" )
185     + {
186     + print $q->p ($tftproot.$dir.' already exists. Do you really want to put this here? Or do you want to define a new directory below?');
187     + }
188     + }
189     + if ($ini)
190     + {
191     + print $q->p ('These values came from your uploaded archive, you can change them if you want.<BR>',
192     + 'We will move the content to the new directory, if you change it.'
193     + );
194     + }
195     + else
196     + {
197     + my $message = "Please enter the values you want for this distribution.<BR>";
198     + if ($install eq "Manual")
199     + {
200     + $message .= "This will just store these parameters in the database.";
201     + }
202     + else
203     + {
204     + $message .= "Files from the archive will be installed into the directory you define.";
205     + }
206     + print $q->p ($message);
207     + }
208     + print $q->p ;
209     + print $q->start_table ({-class => "sme-noborders"});
210     + print $q->Tr ($q->td ({-class => "sme-noborders-label"}, "Distribution:"),
211     + $q->td ({-class => "sme-noborders-content"},
212     + $q->textfield (-name => "dist", -override => 1, -default => $dist, -size => 32)));
213     + print $q->Tr ($q->td ({-class => "sme-noborders-label"}, "Directory:".$tftproot),
214     + $q->td ({-class => "sme-noborders-content"},
215     + $q->textfield (-name => "dir", -override => 1, -default => $dir, -size => 32)));
216     + print $q->Tr (
217     + $q->td ({-class => "sme-noborders-label"}, "Executable:"),
218     + $q->td ({-class => "sme-noborders-content"}, $q->textfield (-name => "prog", -override => 1, -default => $prog, -size => 32)));
219     + print $q->end_table;
220     + print $q->p ('Press Confirm to install this distribution in the directory defined.');
221     + print $q->p ;
222     + print $q->hidden (-name=>'install', -value=>'archive');
223     + }
224     + elsif ($action eq 'Delete')
225     + {
226     + my $record = $pxeclients->get($dist);
227     + $dir = $record->prop('dir') || "";
228     + $prog = $record->prop('prog') || "pxelinux.0";
229     + my $install = $record->prop('install') || "Manual";
230     + print $q->p ('This will delete the '.$dist.' Distribution from the database');
231     + if ($install eq 'Manual' || $install eq 'Archive')
232     + {
233     + if ($dir)
234     +# Don't try to delete the tftp root directory :)
235     + {
236     + print $q->p ('If you want to remove the '.$tftproot.$dir.' directory, and all files, please tick "Delete the '.$tftproot.$dir.' directory and all contents?"');
237     + }
238     + else
239     + {
240     + print $q->p ("You can't delete the $tftproot$dir directory, so you'll have to manipulate the files yourself");
241     + }
242     + }
243     + else
244     + {
245     + print $q->p ('This Distribution was installed as an rpm, it will be removed via rpm -e!<BR>',
246     + 'Which will remove all associated files and database entries.',
247     + );
248     }
249     + print $q->p ;
250     + print $q->start_table ({-class => "sme-noborders"});
251     print $q->Tr(
252     $q->td ({-class => "sme-noborders-label"}, "Name: "),
253     $q->td({-class => "sme-noborders-content"}, $dist),
254     );
255     -
256     - my $record = $pxeclients->get($dist);
257     - $dir = $record->prop('dir') || "";
258     - $prog = $record->prop('prog') || "pxelinux.0";
259     + print $q->Tr(
260     + $q->td ({-class => "sme-noborders-label"}, "Directory: "),
261     + $q->td ({-class => "sme-noborders-content"}, $tftproot.$dir),
262     + );
263     + print $q->Tr(
264     + $q->td ({-class => "sme-noborders-label"}, "Executable: "),
265     + $q->td ({-class => "sme-noborders-content"}, $prog),
266     + );
267     + print $q->end_table;
268     + if ($install eq 'Manual' || $install eq 'Archive')
269     + {
270     + if ($dir)
271     +# Don't try to delete the tftp root directory :)
272     + {
273     + print $q->p ("<input type=\"checkbox\" name=\"deldir\" value=\"yes\" />Delete the $tftproot$dir directory and all contents?");
274     + print $q->p ;
275     + }
276     + print $q->hidden (-name=>'dir', -value=>$dir);
277     + }
278     print $q->hidden (-name=>'dist', -value=>$dist);
279     print $q->hidden (-name=>'install', -value=>$install);
280     }
281     -
282     - # --- Default Distribution
283     - if ($action eq 'Delete')
284     + elsif ($action eq 'Change')
285     {
286     + my $record = $pxeclients->get($dist);
287     + $dir = $record->prop('dir') || "";
288     + $prog = $record->prop('prog') || "pxelinux.0";
289     + print $q->p ('You can alter the '.$dist.' Distribution parameters in the database');
290     + if ($dir)
291     +# Don't try to move the tftp root directory :)
292     + {
293     + print $q->p ('If you want to move the '.$tftproot.$dir.' directory, and all files,<BR>',
294     + '- please enter the new directory name in the Directory box, and<BR>',
295     + '- tick "Move '.$tftproot.$dir.' and contents?"'
296     + );
297     + }
298     + else
299     + {
300     + print $q->p ("You can't move the $tftproot$dir directory, so you'll have to manipulate the files yourself");
301     + }
302     + print $q->p ;
303     + print $q->start_table ({-class => "sme-noborders"});
304     + print $q->Tr (
305     + esmith::cgi::genNameValueRow ($q, "Name", "dist", $dist),
306     + );
307     print $q->Tr(
308     - $q->td ({-class => "sme-noborders-label"}, "Directory: " . $tftproot),
309     - $q->td ({-class => "sme-noborders-content"}, $dir),
310     - );
311     + $q->td ({-class => "sme-noborders-label"}, "Directory: "),
312     + $q->td ({-class => "sme-borders-content"}, "$tftproot<input type=\"text\" name=\"dir\" value=\"$dir\">"),
313     + );
314     print $q->Tr(
315     - $q->td ({-class => "sme-noborders-label"}, "Executable: "),
316     - $q->td ({-class => "sme-noborders-content"}, $prog),
317     - );
318     - print $q->hidden (-name=>'dir', -value=>$dir);
319     - print $q->hidden (-name=>'prog', -value=>$prog);
320     + $q->td ({-class => "sme-noborders-label"}, "Executable: "),
321     + $q->td ({-class => "sme-borders-content"}, "<input type=\"text\" name=\"prog\" value=\"$prog\">"),
322     + );
323     + print $q->end_table;
324     + if ($dir)
325     +# Don't try to move the tftp root directory :)
326     + {
327     + print $q->p ({-class => "sme-noborders-content"}, "<input type=\"checkbox\" name=\"movedir\" value=\"yes\">Move $tftproot$dir and contents?");
328     + print $q->p ;
329     + }
330     }
331     else
332     {
333     - print $q->Tr (
334     - esmith::cgi::genNameValueRow ($q, "Directory \(/tftpboot/\)", 'dir', $dir),
335     - );
336     - print $q->Tr (
337     - esmith::cgi::genNameValueRow ($q, "Executable", 'prog', $prog),
338     - );
339     + showStatusReport ($q, 'error', "We should never get here (Action=$action)", $log)
340     }
341     -
342     - print $q->end_table,"\n";
343    
344     print $q->submit (-name=>'acct', -value=>$action);
345     if ($action ne 'Delete')
346     @@ -649,6 +751,7 @@ sub showDistributionPanel($$$)
347     print $q->submit (-name=>'reset', -value=>'Reset');
348     print $q->hidden (-name=>'origacct', -value=>$action);
349     print $q->hidden (-name=>'origdist', -value=>$dist);
350     + print $q->hidden (-name=>'origdir', -value=>$dir);
351     }
352     print $q->defaults (-name=>'Cancel');
353    
354     @@ -677,12 +780,12 @@ sub showWorkstationPanel($$$)
355     my $base = "";
356     my $status = "";
357     my $distdir = "";
358     - my $tftproot = "/tftproot/";
359     + my $tftproot = "/tftpboot/";
360     if ($config->get('tftpd'))
361     {
362     if ($config->get('tftpd')->prop('status') eq 'enabled')
363     {
364     - $tftproot = $config->get('tftpd')->prop('tftproot')
365     + $tftproot = $config->get('tftpd')->prop('tftproot') || "/tftpboot/";
366     }
367     }
368    
369     @@ -1031,96 +1134,242 @@ sub saveClient ($)
370     sub saveDistribution ($)
371     {
372     my ($q) = @_;
373     + my $action = $q->param('acct');
374     + my $dist = $q->param('dist');
375     + my $dir = $q->param('dir');
376     + my $prog = $q->param('prog');
377     + my $archive = $q->param('archive');
378     + my $ext = $q->param('ext') || "";
379     + my $deldir = $q->param('deldir');
380     + my $movedir = $q->param('movedir');
381     + my $install = $q->param('install') || "Manual";
382     + my $origacct = $q->param('origacct');
383     + my $origdist = $q->param('origdist');
384     + my $origdir = $q->param('origdir');
385     + my $origprog = $q->param('origprog');
386     + my $safe_filename_characters = "a-zA-Z0-9_.-";
387     + my $tftproot = $config->get('tftpd')->prop('tftproot') || "/tftpboot/";
388     + my $ini = "";;
389    
390     if ($q->param('reset'))
391     {
392     - my $origacct = $q->param('origacct');
393     - my $origdist = $q->param('origdist');
394     $q = new CGI("");
395     $q->param(-name=>'acct', -value=>$origacct);
396     $q->param(-name=>'dist', -value=>$origdist);
397     + $q->param(-name=>'dir', -value=>$origdir);
398     + $q->param(-name=>'prog', -value=>$origprog);
399     showDistributionPanel ($q, '', '');
400     return;
401     }
402    
403     - my $action = $q->param('acct');
404     - my $dist = $q->param('dist');
405     - my $dir = $q->param('dir');
406     - my $prog = $q->param('prog');
407     -
408     - if ($action eq "Add")
409     + if ($action eq 'Add')
410     {
411     - my $rpmfile = $q->param('rpmfile');
412     - if ("$rpmfile" ne "")
413     + if ($archive)
414     {
415     - unlink ("/tmp/thinclient.rpm");
416     - open (WR,">/tmp/thinclient.rpm") || die ("Error while opening temporally file.\n");
417     - while (<$rpmfile>)
418     - {
419     - print WR;
420     - }
421     - close WR;
422     - if (system ("/bin/rpm -Uvh /tmp/thinclient.rpm > /var/log/thinclient.log 2>&1"))
423     - {
424     - showDistributionPanel($q, "Error occurred during rpm install.", "/var/log/thinclient.log");
425     - return;
426     - }
427     - $dist = "via .rpm";
428     +# If we are adding via an archive:
429     +# - upload the archive
430     +# - extract the archive
431     +# - check if it has a thinclient.ini file and load defaults if it does
432     + $install = "Archive";
433     + # Untaint the filename
434     + if ( $archive =~ /^([$safe_filename_characters]+)$/ )
435     + {
436     + $archive = $1;
437     + }
438     + else
439     + {
440     + die "Filename contains invalid characters";
441     + }
442     + # Upload the file
443     + my $fharchive = $q->param('archive');
444     + remove_tree ("/tmp/$archive");
445     + open (WR,">/tmp/$archive") || die ("Error while opening temporally file.\n");
446     + binmode WR;
447     + while ( <$fharchive> )
448     + {
449     + print WR;
450     + }
451     + close WR;
452     + # Extract the archive
453     + my ( $name, $path, $ext ) = fileparse ( $archive, qr/\.[^.]*/ );
454     + my $unzip = "/bin/tar -xf /tmp/$archive -C /tmp/thinclient";
455     + if ($ext eq ".rpm")
456     + {
457     + $unzip = "/bin/rpm -Uvh /tmp/$archive";
458     + $install = $archive;
459     + }
460     + elsif ($ext eq ".zip")
461     + {
462     + $unzip = "/usr/bin/unzip /tmp/$archive -d /tmp/thinclient";
463     + }
464     + else
465     + {
466     + $unzip = "/bin/tar -xf /tmp/$archive -C /tmp/thinclient";
467     + }
468     + remove_tree ("/tmp/thinclient");
469     + mkdir "/tmp/thinclient";
470     + if (system ($unzip." > /var/log/thinclient.log 2>&1"))
471     + {
472     + showDistributionPanel($q, "Error occurred during archive extract.(ext=$ext)", "/var/log/thinclient.log");
473     + return;
474     + }
475     + # Now that we have unpacked it, delete the uploaded archive
476     + unlink "/tmp/$archive";
477     + # If there is a thinclient.ini within the archive, use the parameters in it
478     + if (-e "/tmp/thinclient/thinclient.ini")
479     + {
480     + my $cfg = readini( "/tmp/thinclient/thinclient.ini" );
481     + unlink "/tmp/thinclient/thinclient.ini";
482     + $dist = $cfg->{"params"}->{"dist"};
483     + $dir = $cfg->{"params"}->{"dir"};
484     + $prog = $cfg->{"params"}->{"prog"} || "pxelinux.0";
485     + $ini = "yes";
486     + }
487     + if ($ext ne ".rpm")
488     +# rpms do everything themselves (db params & install)
489     +# We ask for confirmation of parameters for all other archive types
490     + {
491     + $q = new CGI("");
492     + $q->param(-name=>'acct', -value=>"Confirm");
493     + $q->param(-name=>'dist', -value=>$dist);
494     + $q->param(-name=>'dir', -value=>$dir);
495     + $q->param(-name=>'prog', -value=>$prog);
496     + $q->param(-name=>'install', -value=>$install);
497     + $q->param(-name=>'ini', -value=>$ini);
498     + showDistributionPanel ($q, '', '');
499     + return;
500     + }
501     }
502     else
503     {
504     - if ($dist eq "")
505     - {
506     - showDistributionPanel ($q, "You must either, enter a Name, or select an rpm to load. $action unsuccessfull", '');
507     +# It must be a Manual entry
508     + if ($pxeclients->get($dist))
509     + {
510     + $q = new CGI("");
511     + $q->param(-name=>'acct', -value=>"Confirm");
512     + $q->param(-name=>'dist', -value=>$dist);
513     + $q->param(-name=>'dir', -value=>$dir);
514     + $q->param(-name=>'prog', -value=>$prog);
515     + $q->param(-name=>'install', -value=>"Manual");
516     + showDistributionPanel ($q, '', '');
517     + return;
518     + }
519     + my %newvalues = ('type' => 'dist',
520     + 'dir' => $dir,
521     + 'prog' => $prog,
522     + 'install' => 'Manual');
523     + my $distrecord = $pxeclients->new_record($dist, \%newvalues);
524     + }
525     + }
526     + elsif ($action eq 'Confirm')
527     + {
528     +# We ONLY get to Confirm, if it's an archive install (non rpm)
529     +# Move the contents of the archive into the specified directory
530     +# and update the config
531     + if ( $dist eq "" )
532     + {
533     + showDistributionPanel ($q, "You MUST define a Distribution name.", '');
534     return;
535     - }
536     - my %newvalues = ('type' => 'dist',
537     - 'dir' => $dir,
538     - 'prog' => $prog,
539     - 'install' => 'Manual');
540     - my $distrecord = $pxeclients->new_record($dist, \%newvalues);
541     + }
542     + if ( $dir =~ /^([$safe_filename_characters]+)$/ )
543     + {
544     + $dir = $1;
545     + }
546     + else
547     + {
548     + die "Directory contains invalid characters\n";
549     }
550     + rename ("/tmp/thinclient", "$tftproot$dir");
551     + my %newvalues = ('type' => 'dist',
552     + 'dir' => $dir,
553     + 'prog' => $prog,
554     + 'install' => 'Archive');
555     + my $distrecord = $pxeclients->new_record($dist, \%newvalues);
556     }
557     - else
558     + elsif ($action eq "Delete")
559     {
560     - my $install = $q->param('install');
561     -
562     - if ($action eq "Delete")
563     + if ($install eq "Manual" || $install eq "Archive")
564     {
565     - if ($install eq "Manual")
566     - {
567     my $distrecord = $pxeclients->get($dist);
568     $distrecord->delete;
569     - }
570     - else
571     - {
572     + # If they ticked the delete directory box, delete it
573     + if ( $dir =~ /^([$safe_filename_characters]+)$/ )
574     + {
575     + $dir = $1;
576     + }
577     + else
578     + {
579     + die "Filename contains invalid characters";
580     + }
581     + if ($deldir eq 'yes')
582     + {
583     + remove_tree ("$tftproot$dir");
584     + }
585     + }
586     + else
587     + # We have to assume it's via rpm
588     + {
589     my $rpm = $pxeclients->get_prop($dist, 'install');
590     if (system ("/bin/rpm -e $rpm > /var/log/thinclient.log 2>&1"))
591     {
592     showDistributionPanel($q, "Error occurred during rpm uninstall.", "/var/log/thinclient.log");
593     return;
594     }
595     - }
596     }
597     - elsif ($action eq "Change")
598     + }
599     + elsif ($action eq "Change")
600     + {
601     + if ($install eq "Manual" || $install eq "Archive")
602     {
603     - if ($install eq "Manual")
604     - {
605     - my $distrecord = $pxeclients->get($dist);
606     - $distrecord->set_prop('dir' => $dir);
607     - $distrecord->set_prop('prog' => $prog);
608     - }
609     - else
610     - {
611     - showDistributionPanel ($q, "This Distribution was installed via rpm. You can\'t modify these settings.", '');
612     - return;
613     - }
614     + if ($dist eq $origdist)
615     + # If the Distribution name hasn't changed, just update the fields
616     + {
617     + my $distrecord = $pxeclients->get($origdist);
618     + $distrecord->set_prop('dir' => $dir);
619     + $distrecord->set_prop('prog' => $prog);
620     + }
621     + else
622     + # If the Distribution name has changed, create the new one and delete the old
623     + {
624     + my %newvalues = ('type' => 'dist',
625     + 'dir' => $dir,
626     + 'prog' => $prog,
627     + 'install' => 'Archive');
628     + my $distrecord = $pxeclients->new_record($dist, \%newvalues);
629     + my $distrecord = $pxeclients->get($origdist);
630     + $distrecord->delete;
631     + }
632     + if ($dir ne $origdir && $movedir eq 'yes')
633     + {
634     + if ( $origdir =~ /^([$safe_filename_characters]+)$/ )
635     + {
636     + $origdir = $1;
637     + }
638     + else
639     + {
640     + die "Filename contains invalid characters";
641     + }
642     + if ( $dir =~ /^([$safe_filename_characters]+)$/ )
643     + {
644     + $dir = $1;
645     + }
646     + else
647     + {
648     + die "Filename contains invalid characters";
649     + }
650     + rename ("$tftproot$origdir", "$tftproot$dir");
651     + }
652     }
653     else
654     {
655     + showDistributionPanel ($q, "This Distribution was installed via rpm. You can\'t modify these settings.", '');
656     + return;
657     + }
658     + }
659     + else
660     + {
661     showDistributionPanel ($q, "$action, Oops!", '');
662     return;
663     - }
664     }
665    
666     if (system ("/sbin/e-smith/signal-event thinclient-conf > /var/log/thinclient.log 2>&1"))
667     @@ -1129,9 +1378,9 @@ sub saveDistribution ($)
668     return;
669     }
670    
671     - showInitial ($q, "success", "$action of Distribution [$dist], successfull", "");
672     -
673     + showInitial ($q, "success", "$action of Distribution $dist, successfull", "");
674     return;
675     +
676     }
677    
678     # ----------------------------------------------------------------------------
679     @@ -1197,3 +1446,64 @@ sub checkip($)
680     return 'OK';
681     }
682    
683     +# ----------------------------------------------------------------------------
684     +# ---
685     +# --- subroutine checkarchive
686     +# --- check the archive type and determine appropriate command to extract
687     +# ---
688     +# ----------------------------------------------------------------------------
689     +
690     +sub checkarchive($)
691     + {
692     + my ($archive) = @_;
693     +
694     + return undef unless defined $archive;
695     +
696     + my ($ext) = $archive =~ /((\.[^.\s]+)+)$/;
697     + if ($ext eq "tar.gz" || $ext eq "tgz" || $ext eq "tar.bz2" || $ext eq "tbz2" )
698     + {
699     + return "/bin/tar -xf /tmp/$archive -C /tmp/thinclient/", $ext;
700     +
701     + }
702     + elsif ($ext eq "zip")
703     + {
704     + return "/usr/bin/unzip /tmp/$archive -d /tmp/thinclient/", $ext;
705     + }
706     + elsif ($ext eq "rpm")
707     + {
708     + return "/bin/rpm -Uvh /tmp/$archive", $ext;
709     + }
710     + else
711     + {
712     + # We'll try tar and hope it understands the extension.....
713     + return "/bin/tar -xf /tmp/$archive -C /tmp/thinclient/", $ext;
714     + }
715     + }
716     +
717     +# ----------------------------------------------------------------------------
718     +# ---
719     +# --- subroutine read an ini file
720     +# ---
721     +# ----------------------------------------------------------------------------
722     +
723     +sub readini($)
724     + {
725     + my ($ini) = @_;
726     + my $cfg;
727     + my $section;
728     + open (INI, "$ini") || die "Can't open $ini: $!\n";
729     + while (<INI>) {
730     + chomp;
731     + if ( /^\s*\[\s*(.+?)\s*\]\s*$/ )
732     + {
733     + $section = $1;
734     + }
735     + if ( /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ )
736     + {
737     + $cfg->{$section}->{$1} = $2;
738     + }
739     + }
740     + close (INI);
741     + return $cfg;
742     + }
743     +
744     \ No newline at end of file

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed