#!/usr/bin/perl #use strict; use Tk; use Tk::Balloon; use FindBin qw($Bin); push(@INC, $Bin); require 'rsauto.conf'; my $choice=0; my $refreshtime=10; #local %computers; push(@INC, "$networkdir\\data"); require 'compmap.txt'; #while($choice != 5){ # &printMenu(); # $choice=; # chomp $choice; # if($choice > 0 && $choice < 6){ # if($choice == 1){ # &startAuto(); # }elsif($choice == 2){ # &stopAuto(); # }elsif($choice == 3){ # &restartAuto(); # }elsif($choice == 5){ # &forceUpdate(); # } # } #} my $window=MainWindow->new(-title => 'RealSync Automation'); $window->bind('', \&startAuto); $window->bind('', \&stopAuto); $window->bind('', \&restartAuto); $window->bind('', sub{exit(0)}); $window->bind('', \&startmachine); $window->bind('', \&stopmachine); $window->bind('', \&startAuto); $window->bind('', \&stopAuto); $window->bind('', \&restartAuto); $window->bind('', sub{exit(0)}); $window->bind('', \&startmachine); $window->bind('', \&stopmachine); my @packopts=qw/-side left -fill x -expand yes/; my $balloon = $window->Balloon(); my $f=$window->Frame; my $bf=$window->Frame; my @button=(); $button[0]=$f->Button(-text => 'start', -relief => 'groove', -underline => 0, -command => \&startAuto)->pack(@packopts); $balloon->attach($button[0], -msg => 'Let all enabled computers begin automation'); $button[1]=$f->Button(-text => 'stop', -relief => 'groove', -underline => 1, -command => \&stopAuto)->pack(@packopts); $balloon->attach($button[1], -msg => 'Make all clients stop after current connection'); $button[2]=$f->Button(-text => 'restart', -relief => 'groove', -underline => 0, -command => \&restartAuto)->pack(@packopts); $balloon->attach($button[2], -msg => "Restart the script on all client machines\n(The server will be reset to the default)"); #$f->Button(-text => 'force update', # -relief => 'groove', # -command => \&forceUpdate)->pack(@packopts); #my $eb=$window->Button(-text => 'exit menu', # -relief => 'groove', # -command => sub {exit(0)})->grid(-row => 2, -col => 0); $button[3]=$f->Button(-text => 'exit menu', -relief => 'groove', -underline => 1, -command => sub {exit(0)})->pack(@packopts); my $llb=$bf->Scrolled('Listbox', -scrollbars => 'w', # -height => 10, -selectmode => 'extended'); # -width => -1); $llb->bind('',\&startmachine); $llb->grid(-row => 0, -col=> 0); my $mf=$bf->Frame; $mf->Button(-text => 'Enable ->', -underline => 0, -command => \&startmachine)->pack(qw/-side top -expand no/); $mf->Button(-text => '<- Disable', -underline => 3, -command => \&stopmachine)->pack(qw/-side bottom -expand no/); $mf->grid(-row => 0, -col => 1); #$top->Label(-text => 'right', # -relief => 'groove')->grid(-row => 0, -col=> 2); my $rlb=$bf->Scrolled('Listbox', -scrollbars => 'e', # -height => 10, -selectmode => 'extended'); # -width => -1); $rlb->bind('',\&stopmachine); $rlb->grid(-row => 0, -col=> 2); foreach my $but (@button){ $but->bind('',sub{ $but->configure(-relief =>'raised')}); $but->bind('',sub{ $but->configure(-relief =>'groove')}); } &createLists(); #$f->pack(qw/-side top -fill x -expand no/); $f->grid(-row => 0, -col => 0); $bf->grid(-row => 1, -col => 0); $window->repeat(1000*$refreshtime,\&updateLists); MainLoop; sub createLists { foreach my $key (sort(keys %computers)){ if(-f "$networkdir/start/${key}stop.txt"){ $llb->insert('end',$key); }else{ $rlb->insert('end',$key); } } &enableButtons(); } sub enableButtons { if(-f $startfile){ $button[0]->configure(-state => 'disabled'); $button[0]->bind(''); $button[1]->configure(-state => 'normal'); $button[1]->bind('',sub{ $button[1]->configure(-relief => 'raised')}); $button[2]->configure(-state => 'disabled'); $button[2]->bind(''); }else{ $button[0]->configure(-state => 'normal'); $button[0]->bind('',sub{ $button[0]->configure(-relief => 'raised')}); $button[1]->configure(-state => 'disabled'); $button[1]->bind(''); $button[2]->configure(-state => 'normal'); $button[2]->bind('',sub{ $button[2]->configure(-relief => 'raised')}); } } sub updateLists { my @select1; my @select2; enableButtons(); foreach(0..($llb->index('end')-1)){ my $comp=$llb->get($_); if(! -f "$networkdir/start/${comp}stop.txt"){ push(@select1, $_); $rlb->insert('end',$comp); } } @select1=sort numerically @select1; foreach(@select1){ $llb->delete($_); } foreach(0..($rlb->index('end')-1)){ my $comp=$rlb->get($_); if(-f "$networkdir/start/${comp}stop.txt"){ push(@select2, $_); $llb->insert('end',$comp); } } @select2=sort numerically @select2; foreach(@select2){ $rlb->delete($_); } } sub numerically { $b <=> $a; } sub stopmachine { my @selects=(); foreach ($rlb->curselection){ push(@selects,$_); my $comp=$rlb->get($_); $llb->insert('end',$comp); open(FILE, ">$networkdir\\start\\${comp}stop.txt"); close(FILE); } @selects = sort numerically @selects; foreach (@selects){ $rlb->delete($_); } } sub startmachine { my @selects=(); foreach ($llb->curselection){ # print "$_\n"; push(@selects, $_); my $comp=$llb->get($_); $rlb->insert('end',$comp); unlink("$networkdir\\start\\${comp}stop.txt"); } @selects = sort numerically @selects; foreach (@selects){ # print "$_\n"; $llb->delete($_); } } sub forceUpdate { if(! -f $updatefile){ open(TEMP, ">$updatefile"); close(TEMP); } sleep(5); unlink $updatefile; } sub restartAuto { # print "calling restart\n"; if(! -f $restartfile){ open(TEMP, ">$restartfile"); close(TEMP); } } sub stopAuto { # print "calling stop\n"; $button[0]->configure(-state => 'normal'); $button[1]->configure(-state => 'disabled'); $button[2]->configure(-state => 'normal'); if(-f $startfile){ unlink $startfile; } } sub startAuto { # print "calling start\n"; $button[0]->configure(-state => 'disabled'); $button[1]->configure(-state => 'normal'); $button[2]->configure(-state => 'disabled'); if(! -f $startfile){ open(TEMP, ">$startfile"); close(TEMP); } } sub printMenu { print< "; }