initial commit of file from CVS for smeserver-tw-logonscript on Sat Sep 7 16:43:57 AEST 2024
This commit is contained in:
0
root/usr/lib/.gitignore
vendored
Normal file
0
root/usr/lib/.gitignore
vendored
Normal file
@@ -0,0 +1,297 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
#
|
||||
# $Id: ibayletters.pm,v 1.8 2005/09/06 05:49:52 apc Exp $
|
||||
#
|
||||
|
||||
package esmith::FormMagick::Panel::ibayletters;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use esmith::FormMagick;
|
||||
use esmith::AccountsDB;
|
||||
use esmith::ConfigDB;
|
||||
use esmith::DomainsDB;
|
||||
use esmith::cgi;
|
||||
use esmith::util;
|
||||
use File::Basename;
|
||||
use Exporter;
|
||||
use Carp;
|
||||
use Data::Dumper;
|
||||
our @ISA = qw(esmith::FormMagick Exporter);
|
||||
#we can not have the same subroutine declared two time
|
||||
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
|
||||
our @EXPORT = qw(
|
||||
print_ibay_table
|
||||
wherenext
|
||||
reload_settings_button
|
||||
save_info
|
||||
);
|
||||
|
||||
our $VERSION = sprintf '%d.%03d', q$Revision: 1.8 $ =~ /: (\d+).(\d+)/;
|
||||
|
||||
our $accountdb = esmith::AccountsDB->open();
|
||||
our $configdb = esmith::ConfigDB->open();
|
||||
|
||||
sub new
|
||||
{
|
||||
my $proto = shift;
|
||||
my $class = ref($proto) || $proto;
|
||||
my $self = esmith::FormMagick::new($class);
|
||||
$self->{calling_package} = (caller)[0];
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub genSelect {
|
||||
my $selectname = shift;
|
||||
my $selected = shift;
|
||||
my $names = shift;
|
||||
my $values = shift;
|
||||
my $OUT;
|
||||
$OUT = "<select name=\"$selectname\">\n";
|
||||
my $size = $#{$names}+1;
|
||||
for (my $i = 0; $i < $size; $i++){
|
||||
my $select = "";
|
||||
if($values->[$i] eq $selected){
|
||||
$select = "selected";
|
||||
}
|
||||
$OUT.="<option value=\"".$values->[$i]."\" $select>".$names->[$i]."</option>\n";
|
||||
}
|
||||
|
||||
$OUT.= "</select>\n";
|
||||
return $OUT;
|
||||
|
||||
}
|
||||
|
||||
sub get_group_list {
|
||||
my $self = shift;
|
||||
my @groups = $accountdb->groups();
|
||||
my %groups = ();
|
||||
foreach my $g (@groups) {
|
||||
$groups{$g->key()} = $g->prop('Description')." (".
|
||||
$g->key.")";
|
||||
}
|
||||
return %groups;
|
||||
}
|
||||
|
||||
|
||||
*wherenext = \&CGI::FormMagick::wherenext;
|
||||
|
||||
sub print_group_table {
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
my $group = $self->localise('Group');
|
||||
|
||||
my %groups = get_group_list();
|
||||
print $q->br();
|
||||
print $q->br();
|
||||
print $self->localise('GROUP_LIST_DESCRIPTION');
|
||||
print $q->br();
|
||||
print $q->br();
|
||||
print $q->end_table,"\n";
|
||||
print $q->start_table({-CLASS => "sme-border"}),"\n";
|
||||
print $q->Tr (
|
||||
esmith::cgi::genSmallCell($q, $group,"header"),
|
||||
esmith::cgi::genSmallCell($q, $self->localise('CUSTOM_BATCH_FILE'),"header")),"\n";
|
||||
foreach my $group_name (keys %groups){
|
||||
print $q->Tr (
|
||||
esmith::cgi::genSmallCell($q, $groups{$group_name}),
|
||||
esmith::cgi::genSmallCell($q, "<a href=\"ibayletters?page_stack=;page=0;groupname=$group_name&action=createcustombatchfile&wherenext=CustomBatchGroup\">$group_name.bat</a>","normal"));
|
||||
|
||||
}
|
||||
print $q->end_table,"\n";
|
||||
return "";
|
||||
}
|
||||
|
||||
sub print_ibay_table {
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
my $name = $self->localise('NAME');
|
||||
my $description = $self->localise('DESCRIPTION');
|
||||
my $drive_letter = $self->localise('DRIVE_LETTER');
|
||||
my $group = $self->localise('Group');
|
||||
my @ibays = $accountdb->ibays();
|
||||
my @names = ('F'..'Z','NONE');
|
||||
my @values = ('F'..'Z','NONE');
|
||||
my %group_list = get_group_list();
|
||||
unless ( scalar @ibays )
|
||||
{
|
||||
print $q->Tr($q->td($self->localise('NO_IBAYS_DEFINED')));
|
||||
return "";
|
||||
}
|
||||
|
||||
print $q->start_table({-CLASS => "sme-border"}),"\n";
|
||||
print $q->Tr (
|
||||
esmith::cgi::genSmallCell($q, $name,"header"),
|
||||
esmith::cgi::genSmallCell($q, $description,"header"),
|
||||
esmith::cgi::genSmallCell($q, $group,"header"),
|
||||
esmith::cgi::genSmallCell($q, $drive_letter,"header")),"\n";
|
||||
my $scriptname = basename($0);
|
||||
|
||||
foreach my $i (@ibays)
|
||||
{
|
||||
my $ibayname = $i->key();
|
||||
my $ibaydesc = $i->prop('Name');
|
||||
my $ibaygroup = $i->prop('Group');
|
||||
my $driveletter = $i->prop('DriveLetter') || 'NONE';
|
||||
|
||||
print $q->Tr (
|
||||
esmith::cgi::genSmallCell($q, $ibayname,"normal"),
|
||||
esmith::cgi::genSmallCell($q, $ibaydesc,"normal"),
|
||||
esmith::cgi::genSmallCell($q, $group_list{$ibaygroup}|| $ibaygroup,"normal"),
|
||||
esmith::cgi::genSmallCell($q, genSelect("$ibayname","$driveletter",\@names,\@values),"normal"));
|
||||
}
|
||||
|
||||
my $db = esmith::ConfigDB->open_ro();
|
||||
my $smb = $db->get("smb");
|
||||
my $logon_drive = $smb->prop("LogonDrive");
|
||||
|
||||
|
||||
print $q->Tr (
|
||||
esmith::cgi::genSmallCell($q, $self->localise('HOME_DRIVE'),"normal"),
|
||||
esmith::cgi::genSmallCell($q, $self->localise('USERS_HOME_DRIVE'),"normal"),
|
||||
esmith::cgi::genSmallCell($q, "","normal"),
|
||||
esmith::cgi::genSmallCell($q, genSelect("logondrive","$logon_drive",\@names,\@values),"normal"));
|
||||
|
||||
print $q->end_table,"\n";
|
||||
print $q->hidden (-name => 'IbayLettersSave', -override => 1, -default => 1);
|
||||
print $q->hidden (-name => 'WorkgroupSave', -id => 'WorkgroupSave', -override => 1, -default => 0);
|
||||
print $q->submit (-name => 'sendbutton', -value => $self->localise('SAVE') );
|
||||
print "<p>".$self->localise('SMB_NEEDS_RESTART_PROCEED')." </p>";
|
||||
print "<input type=\"button\" class=\"button-like\" onClick=\"document.getElementById('WorkgroupSave').value = 1; this.form.submit(); \" value=\"".$self->localise('RELOAD_WORKGROUP_SETTINGS')."\">";
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
sub get_batch_contents(){
|
||||
|
||||
my ($self) = @_;
|
||||
my $group_name = $self->cgi->param('groupname');
|
||||
|
||||
my $batchfileName = "/home/e-smith/files/samba/netlogon/custom/$group_name.bat";
|
||||
my @batchfileTemp;
|
||||
my $batchfileContents="";
|
||||
my $returnValue;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
if ( -f $batchfileName) {
|
||||
open(BATCHFILE,"<$batchfileName") or print $self->localise('FILE_DOES_NOT_EXIT_WILL_BE_CREATED')." $batchfileName";
|
||||
while(<BATCHFILE>){
|
||||
push(@batchfileTemp,$_);
|
||||
}
|
||||
close(BATCHFILE);
|
||||
|
||||
$batchfileContents .= join ("",@batchfileTemp);
|
||||
}
|
||||
$returnValue ='<textarea name="batchfilecontents" rows="30" cols="60">';
|
||||
$returnValue .= $batchfileContents;
|
||||
$returnValue .= '</textarea><br>';
|
||||
$returnValue .= $q->hidden (-name => 'saveBatchFile', -override => 1, -default => 1);
|
||||
$returnValue .= $q->hidden (-name => 'save', -override => 1, -default => 1);
|
||||
$returnValue .= $q->hidden (-name => 'group_name', -override => $group_name, -default => $group_name);
|
||||
$returnValue .= $q->submit (-name => 'sendbutton', -value => 'Save');
|
||||
|
||||
return $returnValue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
sub save_info {
|
||||
my ($self) = @_;
|
||||
|
||||
if( defined $self->cgi->param('wherenext') && $self->cgi->param('wherenext') eq "CustomBatchGroup"){
|
||||
$self->wherenext('CustomBatchGroup');
|
||||
return;
|
||||
}
|
||||
|
||||
if( defined $self->cgi->param('saveBatchFile') && $self->cgi->param('saveBatchFile') eq "1"){
|
||||
|
||||
my $group_name = $self->cgi->param('groupname');
|
||||
|
||||
# Untainting the variable, not sure why it all of a sudden started doing that.
|
||||
if($group_name =~ /^(\w{1,4})$/) {
|
||||
$group_name = $1;
|
||||
}
|
||||
|
||||
if(!getgrnam($group_name)){
|
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
||||
open LOG, ">>/var/log/netlogon_error.log";
|
||||
print LOG ($year+1900)."-$mon-$mday at $hour:$min:$sec someone tried to create arbritrary files. Details below:\n";
|
||||
foreach my $key (sort(keys(%ENV))) {
|
||||
print LOG "$key = $ENV{$key}\n";
|
||||
}
|
||||
print LOG "----------------------------------------------\n";
|
||||
die('hacking attempt');
|
||||
}
|
||||
|
||||
|
||||
my $batchfileName = "/home/e-smith/files/samba/netlogon/custom/$group_name.bat";
|
||||
|
||||
|
||||
my $batchContents = $self->cgi->param('batchfilecontents');
|
||||
open BATCHFILE,">$batchfileName";
|
||||
print BATCHFILE "$batchContents";
|
||||
close(BATCHFILE);
|
||||
chmod(0755, "$batchfileName");
|
||||
$self->success($self->localise('BATCH_FILE_SAVED_SUCCESSFULLY')." $batchfileName");
|
||||
$self->wherenext('First');
|
||||
return;
|
||||
|
||||
}
|
||||
if( $self->cgi->param('WorkgroupSave') eq "1"){
|
||||
if (system ("/sbin/e-smith/signal-event", "workgroup-update") == 0){
|
||||
$self->success($self->localise('WORKGROUP_SETTINGS_MODIFICATION_SUCCESSFULL'));
|
||||
}else {
|
||||
$self->error($self->localise('WORKGROUP_SETTINGS_MODIFICATION_UNSUCESSFULL'));
|
||||
}
|
||||
$self->wherenext('First');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( $self->cgi->param('IbayLettersSave') eq "1"){
|
||||
my @ibays = $accountdb->ibays();
|
||||
my $smb = $configdb->get("smb");
|
||||
my @check = ();
|
||||
|
||||
foreach my $i (@ibays){
|
||||
if($self->cgi->param($i->key()) ne "NONE"){
|
||||
push(@check, $self->cgi->param($i->key()) );
|
||||
}
|
||||
}
|
||||
push(@check, $self->cgi->param('logondrive') );
|
||||
my %counts = ();
|
||||
|
||||
for (@check){
|
||||
$counts{$_}++;
|
||||
}
|
||||
my $error = 0;
|
||||
my $error_msg;
|
||||
foreach my $keys (keys %counts) {
|
||||
if ($counts{$keys} >1 ){
|
||||
$error =1 ;
|
||||
$error_msg.= $self->localise('DRIVE_LETTER_SELECTED_MORE_THAN_ONCE')." $keys<br>";
|
||||
}
|
||||
}
|
||||
if($error eq 1){
|
||||
$self->error($error_msg);
|
||||
$self->wherenext('First');
|
||||
return;
|
||||
}
|
||||
foreach my $i (@ibays){
|
||||
my $ibayname = $i->key();
|
||||
my $acct = $accountdb->get($ibayname);
|
||||
if ($acct->prop('type') eq 'ibay') {
|
||||
$acct->merge_props(DriveLetter => $self->cgi->param("$ibayname"));
|
||||
}
|
||||
}
|
||||
$smb->merge_props(LogonDrive => $self->cgi->param('logondrive'));
|
||||
$self->success($self->localise('DRIVE_LETTERS_SUCCESSFULLY_MODIFIED'));
|
||||
$self->wherenext('First');
|
||||
return;
|
||||
}
|
||||
$self->wherenext('First');
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user