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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
#!/usr/bin/perl
################################################################################
# MandrakeOnline #
# #
# Copyright (C) 2003-2004 MandrakeSoft #
# #
# Daouda Lo <daouda@mandrakesoft.com> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License Version 2 as #
# published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
################################################################################
use strict;
use lib qw(/usr/lib/libDrakX);
use common;
BEGIN { unshift @::textdomains, 'mdkonline' }
use Gtk2::TrayIcon;
eval { require ugtk2; ugtk2->import(qw(:all)); require Gtk2::Pango; };
if ($@) {
print "This program cannot be run in console mode.\n";
c::_exit(0); #- skip ugtk2::END
}
my ($eventbox, $img);
add_icon_path("/usr/share/mdkonline/pixmaps/");
my ($menu, $url, $timeout, $refreshtm);
my $nowindow = 1;
my $arch = arch();
my ($av_pkgs, $update_label, $mLog);
my ($need_update, $raisedwindow, $isAvailable) = (0, 0, 0);
my $conffile = '/etc/sysconfig/mdkonline';
my %state = (
okay => {
colour => [ 'green' ],
changes => [ 'busy', 'critical', 'disconnected' ],
menu => [ 'update', 'configureApplet', 'check', 'weblink' ],
tt => [ N("No updates available for your system") ]
},
critical => {
colour => [ 'orange' ],
changes => [ 'okay', 'busy', 'critical', 'disconnected' ],
menu => [ 'configureApplet', 'check', 'weblink' ],
tt => [ N("Config problems. Launch \"configure\" again") ]
},
busy => {
colour => [ 'orange' ],
changes => [ 'okay', 'critical', 'error', 'disconnected' ],
menu => [ ],
tt => [ N("System is busy. Wait ...") ]
},
error => {
colour => [ 'red' ],
changes => [ 'okay' ],
menu => [ 'update', 'check', 'weblink' ],
tt => [ N("%s packages available for update", $av_pkgs) ]
},
noconfig => {
colour => [ 'orange' ],
changes => [ 'okay' ],
menu => [ 'weblink', 'register' ],
tt => [ N("Service not available. Click on \"configuration\"") ]
},
disconnected => {
colour => [ 'orange' ],
changes => [ 'okay', 'busy', 'critical', 'error' ],
menu => [ 'confNetwork' ],
tt => [ N("Network is down. Click on \"configure Network\"") ]
},
disabled => {
colour => [ 'red' ],
changes => [ 'okay', 'busy', 'critical', 'error' ],
menu => [ 'configureApplet', 'weblink' ],
tt => [ N("Service deactivated. Waiting for payment...") ]
}
);
my %actions = (
'update' => { name => N("Launch Mandrake Update"), launch => sub { installUpdates() } },
'configureApplet' => { name => N("Configuration"), launch => sub { configure() } },
'check' => { name => N("Check Updates"), launch => sub { checkUpdates() } },
'weblink' => { name => N("Online WebSite"), launch => sub { getSite() } },
'confNetwork' => { name => N("Configure Network"), launch => sub { configNetwork() } },
'register' => { name => N("Configure Now!"), launch => sub { configure() } }
);
gtkadd(my $icon = Gtk2::TrayIcon->new("MdkApplet"),
gtkadd($eventbox = Gtk2::EventBox->new,
gtkpack($img = Gtk2::Image->new)
)
);
#$icon->shape_combine_mask($img, 0, 0);
$eventbox->signal_connect(button_press_event => sub {
if (!$raisedwindow) {
if ($_[1]->button == 1) {
if (-e $conffile) { $raisedwindow = 1; showMainWindow() } else { $raisedwindow = 0; configure() }
}
}
$_[1]->button == 3 && $menu and $menu->popup(undef, undef, undef, undef, $_[1]->button, $_[1]->time);
});
my ($opt) = @ARGV;
if ($opt eq '--force' || $opt eq '-f') { setAutoStart('TRUE') };
shouldStart() or die "$ENV{HOME}/.mdkonline should be set to TRUE";
checkUpdates();
cronUpdate();
$icon->show_all;
Gtk2->main;
ugtk2::exit(0);
sub showMainWindow() {
my $w = Gtk2::Window->new('toplevel');
$w->set_title(N("Mandrake Updates Applet"));
$w->signal_connect(delete_event => sub { $w->destroy; $raisedwindow = 0 });
$w->set_position('center');
$w->set_icon(Gtk2::Gdk::Pixbuf->new_from_file('/usr/share/icons/mini/mdkonline.png'));
my ($choice, $time);
my $autocheck;
gtkadd($w,
gtkpack__(Gtk2::VBox->new(0,5),
gtkadd(gtkset_shadow_type(Gtk2::Frame->new(N("Actions")), 'etched_in'),
gtkpack_(Gtk2::VBox->new(0, 3),
1, gtksignal_connect(Gtk2::Button->new(N("Install updates")), clicked => sub { installUpdates() }),
1, gtksignal_connect(Gtk2::Button->new(N("Configure")), clicked => sub { configure() }),
1, gtksignal_connect(Gtk2::Button->new(N("Check updates")), clicked => sub { checkUpdates(); }),
1, gtksignal_connect(Gtk2::Button->new(N("See logs")), clicked => sub { displayLogs() }),
)
),
gtkadd(gtkset_shadow_type(Gtk2::Frame->new(N("Status")), 'etched_in'),
gtkpack_(Gtk2::VBox->new(0, 3),
0, gtkpack_(Gtk2::HBox->new(0, 3),
0, Gtk2::Label->new(N("Network Connection: ")),
0, Gtk2::Label->new(isNetwork() ? N("Up") : N("Down"))
),
0, gtkpack_(Gtk2::HBox->new(0, 3),
0, Gtk2::Label->new(N("New Updates: ")),
0, $update_label = Gtk2::Label->new($isAvailable ? N("Available") : N("Not Available"))
),
0, gtkpack_(Gtk2::HBox->new(0, 3),
0, Gtk2::Label->new(N("Last check: ")),
0, Gtk2::Label->new(lastCheck())
),
)
),
gtkpack(Gtk2::HSeparator->new),
gtkpack(gtksignal_connect(Gtk2::Button->new(N("Close")), clicked => sub {
$w->destroy; $raisedwindow = 0;
})
)
));
$w->show_all
}
sub setLabel {
my $label = shift;
$update_label->set_text($label) if defined $update_label;
}
sub configNetwork { $mLog .= N("Launching drakconnect\n"); system "/usr/sbin/drakconnect &" }
sub launchUpdate { $mLog .= N("Launching MandrakeUpdate\n"); system "/usr/sbin/MandrakeUpdate &" }
sub installUpdates { $mLog .= N("Launching mdkupdate --applet\n"); system "/usr/sbin/mdkupdate", "--applet" }
sub silentCheck {
my $link = "http://www.mandrakeonline.net/online3_RemoteAction.php" . '?action=UpdateList';
my %h = getVarsFromSh($conffile);
my $u;
require LWP::UserAgent;
require HTTP::Request::Common;
require HTTP::Request;
my $ua = LWP::UserAgent->new;
$ua->agent("MdkAppletAgent/0.1" . $ua->agent);
$ua->env_proxy;
# my $request = HTTP::Request->new(GET => $link . '&log=' . "ayomigration" . '&host=' . "online");
my $request = HTTP::Request->new(GET => $link . '&log=' . $h{LOGIN} . '&host=' . $h{MACHINE});
my $lnk = $link . '&log=' . $h{LOGIN} . '&host=' . $h{MACHINE};
my $response = $ua->request($request);
my $ct = $response->content;
# print "\nCONTENTS = $ct; link = $lnk \n";
if ($ct =~ /rpm/) { $u = 11 } elsif ($ct =~ m/(\d+)/) { $u = sprintf("%d",$1); } else { $u = 10 };
# 99 - log or host or action or pass empty, wrong action
# 98 - wrong pass
# 97 - host not active
my $retcode = {
10 => sub { $isAvailable = 0; $mLog .= N("System is up to date\n") ;go2State('okay') },
11 => sub {
my @contents = sort ( split /\n/, $ct);
my @t = split /\n/, `rpm -qa`;
foreach my $cand (@contents) {
$cand =~ s/\.(i586|ppc|ia64).rpm//;
$cand =~ /(.*)-(.*)-(.*)$/; my ($name, $ver, $rel) = ($1, $2, $3);
my $comp = compareWithInstalled($name, $ver, $rel, \@t);
if ($comp) { $isAvailable = 1; $mLog .= N("Checkin ... Updates are available\n"); go2State('error') and last };
}
},
97 => sub { $mLog .= N("Online services disabled. Contact MandrakeOnline site\n") ; go2State('disabled'); },
98 => sub { $mLog .= N("Wrong Password.\n"); go2State('critical'); },
99 => sub { $mLog .= N("Wrong Action or host or login.\n"); go2State('critical'); }
};
$retcode->{$u}->();
}
sub compareWithInstalled {
my ($name, $ver, $rel, $t) = @_;
my $isUpdate = 0;
foreach my $p (@{$t}) {
$p =~ /(.*)-(.*)-(.*)$/; my ($n, $v, $r) = ($1, $2, $3);
if ($name eq $n ) {
if ($ver eq $v) {
if ($rel ne $r) { $isUpdate = 1 and last }
} elsif (isNewVersion($ver, $v)) { $isUpdate = 1 and last }
}
}
$isUpdate
}
sub isNewVersion {
my ($f, $d) = @_;
if (($f =~ /^[0-9\.]+$/) && ($d =~ /^[0-9\.]+$/)) {
while (1) {
my ($f_d, $f_l) = $f =~ /^\.?([^\.]+)(.*)$/ or return $f gt $d;
my ($d_d, $d_l) = $d =~ /^\.?([^\.]+)(.*)$/ or return $f gt $d;
return 1 if ($f_d > $d_d);
return 0 if ($f_d < $d_d);
($f, $d) = ($f_l, $d_l);
}
}
return $f gt $d;
}
sub cronUpdate {
my ($to) = shift;
$timeout = Glib::Timeout->add(60*60*1000, sub {
checkUpdates();
1;
});
}
sub lastCheck {
my %h = getVarsFromSh($conffile);
my ($t, $l);
$t = $h{LASTCHECK} ;
$t =~ s/\_/ /g;
$t ? $t : N("No check")
}
sub checkUpdates {
if (!isNetwork()) {
$mLog .= N("Checking Network: seems disabled\n");
go2State('disconnected')
} elsif (!-e $conffile) {
$mLog .= N("Checking config file: Not present\n");
go2State('noconfig')
} else {
setLabel(N("Checking for Updates..."));
silentCheck();
}
if ($update_label && $update_label->get_text eq N("Checking for Updates...")) {
setLabel($isAvailable ? N("Available") : N("Not Available"));
}
}
sub go2State {
my $state = shift;
$menu && $menu->destroy;
$menu = setState($state);
}
sub isNetwork {
my $network;
$network = gethostbyname("mandrakeonline.net") ? 1 : 0;
$network;
}
sub configure {
system "/usr/sbin/mdkonline &";
$refreshtm = Glib::Timeout->add(1*60*1000, sub {
-e $conffile and Glib::Source->remove($refreshtm);
silentCheck();
1;
});
}
sub getSite {
my $b = browser();
system("$b " . "https://www.mandrakeonline.net" . "&")
}
sub browser {
require any;
my $wm = any::running_window_manager();
member ($wm, 'kwin', 'gnome-session') or $wm = 'other';
my %Br = (
'kwin' => 'konqueror',
'gnome-session' => 'mozilla',
'other' => $ENV{BROWSER} || find { -x "/usr/bin/$_"} qw(mozilla konqueror galeon)
);
$Br{$wm}
}
sub displayLogs {
# system "/usr/sbin/logdrake --explain=drakxtools &"
create_dialog(N("Logs"), $mLog, { use_markup => 1, height => 480, width => 580, scroll => 1 })
}
sub shouldStart() {
my %p = getVarsFromSh("$ENV{HOME}/.mdkonline");
my $ret = $p{AUTOSTART} eq 'FALSE' ? 0 : 1;
$ret
}
sub setState {
my $state_type = shift;
my $arr = $state{$state_type}{menu};
my $tmp = gtkcreate_pixbuf($state{$state_type}{colour}->[0]);
$img->set_from_pixbuf($tmp);
#my $tooltip = Gtk2::Tooltips->new;
gtkset_tip(new Gtk2::Tooltips, $eventbox, formatAlaTeX($state{$state_type}{tt}->[0]));
my $menu = Gtk2::Menu->new;
foreach (@$arr) {
my $l = $actions{$_}{name};
$menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label($actions{$_}{name})), activate => $actions{$_}{launch}));
}
$menu->append(gtkshow(Gtk2::SeparatorMenuItem->new));
$menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("About.."))), activate => sub { about() }));
$menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("Quit"))), activate => sub { mainQuit() }));
$menu
}
sub about {
my $b = browser();
system("$b " . "https://mandrakeonline.net/info.php" . "&")
}
sub setAutoStart {
my $state = shift;
my $file = "$ENV{HOME}/.mdkonline";
if (-f $file) {
my %s = getVarsFromSh($file);
$s{AUTOSTART} = $state;
setVarsInSh($file, \%s);
} else { output_p $file,
qq(AUTOSTART=$state
);
}
}
sub mainQuit() {
setAutoStart('FALSE');
Gtk2->main_quit
}
|