-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.pl
198 lines (163 loc) · 5.43 KB
/
controls.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package controls;
use warnings;
use strict;
use FindBin;
use File::Basename;
use Win32::Registry;
use Win32::Process;
our $reg_lib=".\\registry_lib";
our $mongo_lib=".\\mongo";
our $MONGO_PID;
our $NAGIOS_HOST="deb-nagios-uat";
chdir $FindBin::Bin;
sub check_reg {
my ($p,$remote_command_obj,$reg_file_prod,$reg_file_uat);
$reg_file_uat="Default%20Settings";
$reg_file_prod="Prod-Settings";
$p = "Software\\SimonTatham\\Putty\\Sessions\\$reg_file_prod";
$main::HKEY_CURRENT_USER->Open($p, $remote_command_obj) || die "Prod registry session check fails! $!";
$p = "Software\\SimonTatham\\Putty\\Sessions\\$reg_file_uat";
$main::HKEY_CURRENT_USER->Open($p, $remote_command_obj) || die "UAT registry session check fails! $!";
}
sub load_reg{
chdir $reg_lib;
system ("start add_reg.bat ");
chdir "../";
check_reg;
}
sub do_requires{
require "db_connect.pl";
require "window_view.pl";
require "open_dash.pl";
}
sub show_newly_updated {
my @newly_updated=&db::show_newly_updated();
return @newly_updated;
}
sub search_client_servers {
my $search_arg = shift;
my @search_hosts_results=&db::lookup_cs($search_arg);
return @search_hosts_results;
}
sub search_dashboard_apps {
my $search_arg = shift;
my @search_hosts_results=&db::lookup_daps($search_arg);
return @search_hosts_results;
}
sub launch_deb {
my ($token,$process,$options,$key,$login,$remote_command_obj,$p,$home,$command,$reg_key,%hash_vals,$user,$deb_login);
$user = $open_dash::dashboard_user;
if ($user){
my @found = &db::lookup_cs("DEB DR PARIS");
my $deb_info = pop(@found);
my @fields=split(/\|/,$deb_info);
$deb_login = pop(@fields);
$deb_login =~ s/.*@//;
$deb_login =~ s/\n//;
$deb_login = $user."@".$deb_login;
my $key = &db::get_deb_key($deb_login);
if ($key =~ "NO_KEY_FOUND") {
$deb_login =~ s/.*@//;
&db::update_missed_login("$user | $deb_login");
} else {
$key=&db::do_lookup_missed_logins($deb_login);
$home="/mnt/backup/archives";
$command="";
$reg_key="PROD-Settings";
$p = "Software\\SimonTatham\\Putty\\Sessions\\$reg_key";
$main::HKEY_CURRENT_USER->Open($p, $remote_command_obj) || die "Failed Setting the remote command $!";
my $k="RemoteCommand";
$remote_command_obj->GetValues(\%hash_vals);
$remote_command_obj->SetValueEx($k,0,1,$command);
$options=" -load Prod-Settings -ssh $deb_login -pw $key";
Win32::Process::Create($process,"putty.exe",$options,0,0,".") || die $!;
}
}
}
sub launch_backuppc {
my ($token,$process,$options,$key,$login,$remote_command_obj,$p,$home,$command,$reg_key,%hash_vals);
$login="backuppc\@backuppc-prod.ullink.lan";
$token="backuppc";
$key=&db::lookup_backuppc_key($token);
$key=~s/\n//g;
$home="/etc/nagios3/ulconf/conf";
$command="bash";
$reg_key="PROD-Settings";
$p = "Software\\SimonTatham\\Putty\\Sessions\\$reg_key";
$main::HKEY_CURRENT_USER->Open($p, $remote_command_obj) || die "Failed Setting the remote command $!";
my $k="RemoteCommand";
$remote_command_obj->GetValues(\%hash_vals);
$remote_command_obj->SetValueEx($k,0,1,$command);
$options=" -load Prod-Settings -ssh $login -pw $key";
Win32::Process::Create($process,"putty.exe",$options,0,0,".") || die $!;
}
sub launch_nagios {
my ($process,$options,$key,$login,$remote_command_obj,$p,$home,$command,$reg_key,%hash_vals);
$login=$open_dash::dashboard_user."\@".$NAGIOS_HOST;
$login=~s/\n//g;
$key=&db::do_lookup_missed_logins($login);
if (defined $key)
{
$key=~s/\n//g;
$options=" -load Prod-Settings -ssh $login -pw $key";
}else{
my $user=$open_dash::dashboard_user;
$user=~s/\n//g;
&db::update_missed_login("$user | ".$NAGIOS_HOST);
$options=" -load Prod-Settings -ssh $login ";
}
$home="/etc/nagios/ulconf/conf";
$command="cd $home; bash";
$reg_key="PROD-Settings";
$p = "Software\\SimonTatham\\Putty\\Sessions\\$reg_key";
$main::HKEY_CURRENT_USER->Open($p, $remote_command_obj) || die "Failed Setting the remote command $!";
my $k="RemoteCommand";
$remote_command_obj->GetValues(\%hash_vals);
$remote_command_obj->SetValueEx($k,0,1,$command);
Win32::Process::Create($process,"putty.exe",$options,0,0,".") || die $!;
}
sub update_cs{
my @params = split(/\|/,pop @_);
&db::resetter_cs(@params);
}
sub update_ds{
my @params = split(/\|/,pop @_);
&db::resetter_ds(@params);
}
#Display contents of the database
sub print_db{
&db::show_db;
}
#Failed Login pop-up
#Enables user input for failed password lookups.
sub show_popup{
my $msg_arg = shift;
my $message= $msg_arg;
&screen::draw_popup($message);
}
#Pop-up Display for default username and password to use for Dashboard Login
sub dash_user_popup{
#return 1;
my $dash_creds=&screen::draw_dash_popup();
while($dash_creds =~ /NO_CREDS/){
$dash_creds=&screen::draw_dash_popup();
}
my @creds=split(/\|/,$dash_creds);
&open_dash::set_creds(@creds);
}
# Load all putty registry entries the program requires
# Verify Mongo is installed and running
# Import all source code required
# Display the GUI
# Obtain username and password data to use for connecting to Dashboard applications
# Initialize the database and load data
# Listen for user input
sub start{
print "Prod Tool Running in Client Mode \n";
load_reg;
do_requires;
&screen::draw_main;
dash_user_popup;
&screen::do_loop;
}
start;