summaryrefslogtreecommitdiff
path: root/machine-update
blob: 90a6d17443e34a4010443ba95c159fe2fce77459 (plain)
  1. #!/usr/bin/perl -w
  2. # For Emacs: -*- mode:cperl; mode:folding; -*-
  3. #
  4. # Get a machine's critical features, And mail/http them to the Linux Counter
  5. #
  6. # (c) 1999 - Harald Tveit Alvestrand, the Linux Counter Project
  7. # 2003 - PetaMem Group (www.petamem.com)
  8. # License: GNU Copyleft - see bottom of file.
  9. # Changelog: see even more bottom of the file
  10. #
  11. # As a matter of courtesy, if you change this file on your own,
  12. # make sure it does NOT mail to the counter!
  13. #
  14. use strict;
  15. use POSIX;
  16. our $VERSION = '0.25';
  17. our $CVS_VERSION = '$Revision: 1.2 $ $Date: 2006-02-06 18:55:43 $ $Author: jonas $';
  18. our $IsInTestHarness;
  19. use vars qw(%values %oldvalues $errordata $debugdata %files); # data that is sent
  20. use vars qw($progname %option);
  21. use vars qw(%is_sys_account %is_user %is_account);
  22. # stuff that controls defaults for passwdscan & accounts subroutines
  23. my ($UID_MIN, $UID_MAX, $got_defs) = (100, 65533, '');
  24. # Make sure nothing happens, so that the script's routines
  25. # can be debugged from another file
  26. return 1 if($IsInTestHarness);
  27. &preparation;
  28. &options;
  29. &readfile;
  30. &checkconfig;
  31. if ($option{ask}) {
  32. &askquestions;
  33. }
  34. &writefile;
  35. &sendfile;
  36. # {{{ preparation
  37. #
  38. sub preparation {
  39. die "No HOME environment variable\n" if (!$ENV{HOME});
  40. die "No home diretory\n" if ! -d $ENV{HOME};
  41. # Kill some internationalization
  42. $ENV{LANG} = 'C';
  43. delete $ENV{LC_CTYPE};
  44. delete $ENV{LC_NUMERIC};
  45. delete $ENV{LC_NAME};
  46. delete $ENV{LC_TIME};
  47. delete $ENV{LC_MESSAGES};
  48. delete $ENV{LC_COLLATE};
  49. delete $ENV{LC_MONETARY};
  50. my $infodir = "$ENV{HOME}/.linuxcounter";
  51. if (! -d $infodir) {
  52. mkdir($infodir, 0766) || die "Unable to make $infodir\n";
  53. }
  54. # Keep track of where I am; need it to install crontab entry
  55. # progname is a global.
  56. $progname = $0;
  57. if ($progname !~ /^\//) {
  58. my $progdir = `pwd`;
  59. chop $progdir;
  60. $progname = "$progdir/$progname";
  61. $progname =~ s!/./!/!;
  62. }
  63. chdir($infodir) || die "Unable to change to $infodir\n";
  64. my ($sysname, $nodename, $release, $version, $machine ) = POSIX::uname();
  65. if (! -f $nodename) {
  66. print STDERR "Machine-update $VERSION. Use $0 -l to display license.\n";
  67. print STDERR "Creating the infofile for your computer.\n";
  68. # Create the infodir
  69. open(INFO, ">$nodename");
  70. print INFO "uniqueid: ", randomnumber(), "\n";
  71. close INFO;
  72. }
  73. srand time % $$; # do some seed "randomization"
  74. }
  75. # }}}
  76. # {{{ options
  77. #
  78. sub options {
  79. my $opt;
  80. while (defined($ARGV[0]) && $ARGV[0] =~ /^-/) {
  81. $opt = shift @ARGV;
  82. $opt =~ /c/ && &installcrontab;
  83. $opt =~ /d/ && $option{DEBUG}++ && print STDERR "Debug is $option{DEBUG}\n";
  84. $opt =~ /h/ && &help;
  85. $opt =~ /i/ && ($option{ask} = 1);
  86. $opt =~ /l/ && &license;
  87. $opt =~ /m/ && ($option{mail} = 1);
  88. $opt =~ /t/ && ($option{mail} = 0);
  89. $opt =~ /u/ && &uninstallcrontab;
  90. $opt =~ /v/ && die "\n\t Linux Counter machine-update version $VERSION\n"
  91. . "\tCVS version $CVS_VERSION\n";
  92. $opt =~ /x/ && ($option{info} = 1);
  93. }
  94. }
  95. # }}}
  96. # {{{ askquestions
  97. #
  98. sub askquestions {
  99. return if ! -t STDIN || ! -t STDOUT;
  100. $| = 1;
  101. print "Here you can specify some info that the script can't know for itself\n";
  102. $values{owner} = askone("Your Linux Counter reg#, if any", $values{owner});
  103. $values{key} = askone("Your machine's counter reg#, if any", $values{key});
  104. }
  105. # }}}
  106. # {{{ askone
  107. #
  108. sub askone {
  109. my $prompt = shift;
  110. my $default = shift;
  111. print $prompt;
  112. if (defined($default)) {
  113. print " [$default]";
  114. }
  115. print ':';
  116. my $ans = <STDIN>;
  117. chop $ans;
  118. &Debug("Answer was $ans\n");
  119. $ans = $default if (!length($ans));
  120. return $ans;
  121. }
  122. # }}}
  123. # {{{ readfile
  124. #
  125. sub readfile {
  126. my ($sysname, $nodename, $release, $version, $machine ) = POSIX::uname();
  127. open(INFO, $nodename) || die "Did not find infofile $nodename\n";
  128. while (<INFO>) {
  129. chop;
  130. s/#.*//;
  131. if (/^(\S+): *(.+)/) {
  132. my $key = $1;
  133. my $value = $2;
  134. if ($1 !~ /^(owner|key|uniqueid)$/) {
  135. next;
  136. }
  137. &Debug("Read $key: $value\n");
  138. $values{$key} = $value;
  139. } else {
  140. print STDERR "Unparsed info line: $_ - discarded\n";
  141. }
  142. }
  143. close INFO;
  144. %oldvalues = %values;
  145. }
  146. # }}}
  147. # {{{ writefile
  148. #
  149. sub writefile {
  150. my ($sysname, $nodename, $release, $version, $machine ) = POSIX::uname();
  151. open(INFO, ">$nodename.new");
  152. for my $val (sort keys(%values)) {
  153. &Debug("Saving $val: $values{$val}\n");
  154. print INFO "$val: $values{$val}\n";
  155. }
  156. close INFO;
  157. rename("$nodename.new", $nodename) || die "Rename failed\n";
  158. }
  159. # }}}
  160. # {{{ sendfile
  161. #
  162. sub sendfile {
  163. if ($option{mail}) {
  164. open(MAIL, "|/usr/lib/sendmail machine-registration\@counter.li.org")
  165. || die "Unable to open sendmail\n";
  166. } else {
  167. warn "--------------------------------------------------------\n";
  168. warn "This is what will be sent to the Linux Counter if you\n";
  169. warn "run the program with the -m switch. Now, NOTHING IS SENT\n";
  170. warn "--------------------------------------------------------\n";
  171. open(MAIL, ">&STDOUT");
  172. }
  173. # note that $ENV{USER} isn't (always) set in a cron job...
  174. my $user = (getpwuid($<))[0];
  175. $user = "unknown-id-$<" if !$user;
  176. print MAIL <<EOF
  177. From: $user
  178. To: machine-registration\@counter.li.org
  179. Subject: machine-update for $values{name}
  180. //MACHINE
  181. EOF
  182. ;
  183. for my $val (sort keys(%values)) {
  184. print MAIL "$val: $values{$val}\n"
  185. if length($values{$val}) > 0;
  186. }
  187. print MAIL "//END\n";
  188. # Attach files
  189. for my $file (keys(%files)) {
  190. print MAIL "//FILE $file\n";
  191. print MAIL $files{$file};
  192. print MAIL "//EOF\n";
  193. }
  194. # Attach possible other info
  195. if ($errordata) {
  196. print MAIL "----- Problem info gathered during probing -----\n";
  197. print MAIL $errordata;
  198. }
  199. $option{info} && do {
  200. print MAIL "----- Debug data for the script maintainer's aid -----\n";
  201. print MAIL $debugdata;
  202. };
  203. close MAIL;
  204. }
  205. # }}}
  206. # {{{ randomnumber
  207. #
  208. sub randomnumber {
  209. return int(rand(1_000_000_000));
  210. }
  211. # }}}
  212. # {{{ checkconfig
  213. #
  214. sub checkconfig {
  215. my ($sysname, $nodename, $release, $version, $machine ) = POSIX::uname();
  216. warn "This is not Linux, but $sysname!\n" if($sysname ne 'Linux');
  217. $values{method} = "machine-update version $VERSION";
  218. $values{os} = $sysname;
  219. $values{kernel} = $release;
  220. $values{cpu_uname} = $machine;
  221. $values{name} = $nodename; # First order guess
  222. # Credit for some of the code below goes to
  223. # Denis Havlik: <havlik@ap.univie.ac.at>
  224. # Blame is, of course, all mine - HTA -
  225. # Note - there are numerous problems with df, including:
  226. # - early versions don't support the -l option
  227. # - at least some include SAMBA filesystems in the -l option
  228. # 1: Snarf a df -T
  229. my $dfbin = &xbin("df");
  230. $files{"df -T"} = `$dfbin -T -x nfs`;
  231. $values{accounts} = &accounts;
  232. $values{users} = &active_users;
  233. my $uptime = &xbin('uptime');
  234. if($uptime) {
  235. $uptime = `$uptime`;
  236. $values{uptime_1} = $uptime; # preserve raw version
  237. $values{uptime_1} =~ s/\n.*//;
  238. }
  239. my $lastprog = xbin('last');
  240. if ($lastprog && -r "/var/run/utmp") {
  241. $values{uptime_2} = `$lastprog -xf /var/run/utmp runlevel`;
  242. $values{uptime_2} =~ s/\n.*$//s;
  243. } else {
  244. DebugInfo("Can't do last to find uptime");
  245. }
  246. # Not sure this is a Right Thing...so not saving it for the moment
  247. # This section based on a patch from Mark-Jason Dominus <mjd@plover.com>
  248. # try to guess mailer based on content of /usr/lib/sendmail link
  249. if (-l '/usr/lib/sendmail') {
  250. my $realsendmail = readlink('/usr/lib/sendmail');
  251. if ($realsendmail eq '../sbin/sendmail') {
  252. $realsendmail = '/usr/sbin/sendmail';
  253. if (-l $realsendmail) {
  254. $realsendmail = readlink($realsendmail);
  255. }
  256. }
  257. if ($realsendmail =~ m{^/var/qmail}) {
  258. $values{mailer} = "qmail";
  259. } else {
  260. &DebugInfo("Found sendmail as a link to $realsendmail\n");
  261. }
  262. }
  263. # Link method did not work. Try to guess based on presence of
  264. # config files. (this is more susceptible to the old-junk problem)
  265. if (!$values{mailer}) {
  266. if ( -d '/var/qmail') {
  267. $values{mailer} = 'qmail';
  268. } elsif ( -f '/etc/sendmail.cf' || -f '/etc/mail/sendmail.cf') {
  269. # TMDG claims recent Fedora Core has it in /etc/mail/sendmail.cf
  270. $values{mailer} = 'sendmail';
  271. } elsif ( -d '/etc/postfix') {
  272. $values{mailer} = 'postfix';
  273. }
  274. }
  275. $values{kcoresize} = -s "/proc/kcore";
  276. addonefileforsending("/proc/meminfo");
  277. addonefileforsending("/proc/cpuinfo");
  278. addonefileforsending("/proc/version");
  279. # info on what devices are in use on the system
  280. addonefileforsending("/proc/pci");
  281. addonefileforsending("/proc/bus/usb/devices");
  282. # Both Mandrake and Red Hat use this file....
  283. addonefileforsending("/etc/redhat-release");
  284. }
  285. # }}}
  286. # {{{ accounts
  287. #
  288. sub accounts {
  289. my $s;
  290. my $niss;
  291. my $ypcatbin; # will hold path to the ypcat binary (if any)
  292. open (TMP,"</etc/passwd");
  293. $s += &passwdscan;
  294. &DebugErr("Found $s accounts total\n");
  295. &Debug("Switching to NIS passwords\n");
  296. $ypcatbin = &xbin('ypcat'); # get path to ypcat binary (empty if none)
  297. if($ypcatbin) { # test whether ypcat was found
  298. open TMP, "$ypcatbin passwd 2> /dev/null|"
  299. || ($errordata .= "ypcat failed: $!\n");
  300. $niss = &passwdscan;
  301. $s += $niss;
  302. close TMP;
  303. &Debug("Status of ypcat: $?\n");
  304. &DebugErr("Found $niss accounts in ypcat passwd\n");
  305. }
  306. &DebugErr('Sysaccounts: ', join(' ', keys(%is_sys_account)), "\n");
  307. &DebugErr("Found $s accounts total\n");
  308. return $s;
  309. }
  310. # }}}
  311. # {{{ passwdscan
  312. #
  313. sub passwdscan {
  314. # Code for reading login.defs courtesy of Vassilii Khachaturov
  315. # <vassilii@tarunz.org>
  316. local (*DEFS);
  317. # Try importing UID_MIN and UID_MAX from /etc/login.defs, if possible
  318. # else just assume the above defaults for min and max non-system UID
  319. if (!$got_defs && open (DEFS, '/etc/login.defs')) {
  320. while (<DEFS>) {
  321. if (/^\s*(UID_(?:MIN|MAX))\s+(\d+)/) {
  322. # elegant, but not compatible with "strict refs":
  323. #${ $1 } = $2;
  324. if ($1 eq "UID_MIN") {
  325. $UID_MIN = $2;
  326. } else {
  327. $UID_MAX = $2;
  328. }
  329. &Debug("DEFS match: $1 = $2\n");
  330. }
  331. }
  332. close (DEFS);
  333. $got_defs = 1;
  334. }
  335. &Debug("UID_MIN = $UID_MIN, UID_MAX = $UID_MAX\n");
  336. # I suppose this is as good as it gets -
  337. # Usually user accounts have UID > 100 and
  338. # "system accounts" have UID < 100, but there is no guarantee
  339. # that
  340. # this will hold for pseudo-users like "postgress" etc.
  341. # Also nobody is usually 99 on linux, but -1 on "standard" unices.
  342. # RedHat places the dividing line at 500. Others use 400...
  343. my @line;
  344. my $s = 0;
  345. while (<TMP>) {
  346. @line = split ':';
  347. if ($line[2] >= $UID_MIN && $line[2] <= $UID_MAX
  348. && !($line[0] eq 'nobody')) {
  349. $s++;
  350. $is_account{$line[0]} = 1;
  351. } else {
  352. $is_sys_account{$line[0]} = 1;
  353. }
  354. }
  355. return $s;
  356. }
  357. # }}}
  358. # {{{ active_users
  359. #
  360. # This is kind of alpha, but please test it.
  361. # It calculates the number of "active" users based on the "wtmp" entries
  362. # unfortunately at least Mandrake 8 and 9 ship with non-world-read wtmp
  363. # and non-set-uid last, so this does not work any more...
  364. #
  365. # RJ: Actually I think the best thing to do is to bury this code and be silent about it.
  366. #
  367. sub active_users {
  368. my $userslisted;
  369. for (qw(reboot wtmp runlevel)) { # This sysaccounts shouldn't be counted. Who else?
  370. $is_sys_account{$_} = 1;
  371. }
  372. open( TMP, "/usr/bin/last 2>&1|");
  373. while (<TMP>) {
  374. chop;
  375. if (m!/var/log/wtmp: Permission denied!) { # RJ: ***Boom*** on every non-EN system
  376. &ErrorInfo("/usr/bin/last failed because /var/log/wtmp isn't readable\n");
  377. last;
  378. }
  379. last if(!$_); # RJ: quick hack to safe bad code from harm
  380. my @tmp = split;
  381. my $name = $tmp[0];
  382. if ($is_sys_account{$name}) {
  383. # do nothing
  384. } elsif (defined $is_account{$name}) {
  385. $is_user{$name} = 1;
  386. } elsif (/^\s*$/) { # blank line - do nothing
  387. } elsif ($#tmp == 9) { # OK line, but unknown user
  388. $option{DEBUG} && do {
  389. if (!$userslisted) {
  390. print STDERR 'Know users are: ',
  391. join(' ', keys(%is_account)), "\n";
  392. $userslisted = 1;
  393. }
  394. print STDERR "Unknown user: $name\n";
  395. }
  396. } else {
  397. &DebugErr("Strange line: $_\n");
  398. }
  399. }
  400. close TMP;
  401. my $i = 0;
  402. for (sort keys %is_user) {
  403. $option{DEBUG} && printf "Active user %3d: %s\n", ++$i, $_;
  404. }
  405. &Debug("$i active users found.\n");
  406. return $i;
  407. }
  408. # }}}
  409. # {{{ installcrontab
  410. #
  411. sub installcrontab {
  412. my $hour = int(rand(24));
  413. my $min = int(rand(60));
  414. my $day = int(rand(7)); # Weekday. This version runs once a week.
  415. my $cron = "";
  416. warn "Installing start of script into your crontab\n";
  417. if (open(CRON, "crontab -l |")) {
  418. &Debug("Checking crontab for machine-update\n");
  419. &Debug("Want to install as $progname\n");
  420. while (<CRON>) {
  421. if (/^#/ && $. <= 3) { # initial comment
  422. &Debug("Skipping comment: $_");
  423. next;
  424. }
  425. if (/machine-update/) {
  426. if (/ $progname -m/) {
  427. die "Crontab entry already installed: $_\n";
  428. } else {
  429. die "Another entry with machine-update: $_\n";
  430. }
  431. }
  432. $cron .= $_;
  433. }
  434. close CRON;
  435. &Debug("Result from crontab -l: ", $? / 256, "\n");
  436. if ($? == 0) {
  437. &Debug("Crontab successfully read\n");
  438. } elsif ($? == 256) {
  439. warn "You don't seem to have a crontab. I will create one.\n";
  440. } else {
  441. die "Failed to read your crontab. Please report this as a bug: $?\n";
  442. }
  443. } else {
  444. &Debug("Result from crontab open(): $?\n");
  445. die "Unable to execute crontab command. Please check your system\n";
  446. }
  447. open(CRON, "|crontab -");
  448. print CRON $cron;
  449. print CRON "$min $hour * * $day $progname -m\n";
  450. close CRON;
  451. &Debug("Result from crontab: $?\n");
  452. if ($?) {
  453. die(<<EoF);
  454. Installing new crontab failed.
  455. YOUR CRONTAB MAY BE DAMAGED - use crontab -l to check it.
  456. Here's its former content (if any):
  457. $cron
  458. EoF
  459. }
  460. print "Crontab entry successfully installed.\nWill run on day $day of every week, at $hour:$min\n";
  461. exit 0;
  462. }
  463. # }}}
  464. # {{{ uninstallcrontab
  465. #
  466. sub uninstallcrontab {
  467. my $found = 0;
  468. my $cron;
  469. print STDERR "Removing $progname from your crontab\n";
  470. open(CRON, "crontab -l |");
  471. &Debug("Checking crontab for machine-update\n");
  472. &Debug("Want to uninstall as $progname\n");
  473. while (<CRON>) {
  474. if (/^#/ && $. <= 3) { # initial comment
  475. &Debug("Skipping comment: $_");
  476. next;
  477. }
  478. if (/machine-update/) {
  479. if (/ $progname -m/) {
  480. print STDERR "Crontab entry found and removed\n";
  481. $found = 1;
  482. next; # skip stuff at end....
  483. } else {
  484. die "Another entry with machine-update: $_\nUninstall manually?\n";
  485. }
  486. }
  487. $cron .= $_;
  488. }
  489. close CRON;
  490. &Debug("Result from crontab -l: $?\n");
  491. if ($?) {
  492. die "Failed to read your crontab. You may not have one?\n";
  493. }
  494. if ($found) {
  495. open(CRON, "|crontab -");
  496. print CRON $cron;
  497. close CRON;
  498. &Debug("Result from crontab: $?\n");
  499. if ($?) {
  500. die(<<EoF);
  501. Installing new crontab failed.
  502. YOUR CRONTAB MAY BE DAMAGED - use crontab -l to check it.
  503. Here's its former content (if any):
  504. $cron
  505. EoF
  506. }
  507. } else {
  508. print STDERR "No instance of $progname found in your crontab\n";
  509. }
  510. exit 0;
  511. }
  512. # }}}
  513. # {{{ xbin execute a linux binary
  514. #
  515. # This sub is to execute a linux binary robustly. i.e. testing
  516. # whether it is present, where it is present, whether it is executable
  517. #
  518. sub xbin {
  519. my $bin = shift; # get name of binary to execute
  520. $bin = `which $bin 2>/dev/null`; # determine binarys full path
  521. chomp $bin;
  522. return $bin if(-x $bin); # if there and executable: all is well - return it
  523. if(!$bin) { # if not there
  524. &Debug("No $bin found\n"); # state so
  525. } else { # there but not executable
  526. &Debug("$bin found, but not executable\n");
  527. }
  528. return ''; # so return an empty string (binary will not exec)
  529. }
  530. # }}}
  531. # {{{ getval_from_file get value from system file @ row,col
  532. #
  533. sub getval_from_file {
  534. my $file = shift;
  535. my $row = shift;
  536. my $col = shift;
  537. my @file;
  538. my @cols;
  539. if (!(-r $file)) {
  540. &DebugErr("File $file not readable\n");
  541. return '';
  542. }
  543. sysopen(FH,$file, O_RDONLY);
  544. @file = <FH>; # read whole file to array
  545. close FH;
  546. @cols = split /\s+/, $file[$row]; # get the right row
  547. return $cols[$col]; # return the right column
  548. }
  549. # }}}
  550. sub addonefileforsending {
  551. my $file = shift;
  552. my @file;
  553. if (!(-r $file)) {
  554. &DebugErr("File $file not readable\n");
  555. return '';
  556. }
  557. sysopen(FH,$file, O_RDONLY);
  558. @file = <FH>; # read whole file to array
  559. close FH;
  560. $files{$file} = join('', @file);
  561. }
  562. # {{{ Debug print debug information if flag is set
  563. #
  564. sub Debug {
  565. $option{DEBUG} && print @_;
  566. }
  567. # }}}
  568. # {{{ DebugErr print debug on STDERR if flag is set
  569. #
  570. sub DebugErr {
  571. $option{DEBUG} && print STDERR @_;
  572. }
  573. # }}}
  574. # {{{ ErrorInfo
  575. sub ErrorInfo {
  576. $errordata .= join('', @_);
  577. }
  578. # }}}
  579. # {{{ DebugInfo
  580. sub DebugInfo {
  581. $option{info} && ($debugdata .= join('', @_));
  582. }
  583. # }}}
  584. # {{{ help print help & exit
  585. #
  586. sub help {
  587. my $host = `uname -n`;
  588. print <<EoF;
  589. machine-update version $VERSION
  590. Send machine information to the Linux Counter
  591. USE: machine-update [-i] [-(t|d|l|m|v|x|c|u|h)]
  592. SWITCHES:
  593. -i = interactive
  594. -t = test (do not send e-mail, just print it ot STDOUT - default)
  595. -d = debug (test, and print additional debug informations)
  596. -l = display license
  597. -m = mail results to linux-counter
  598. -v = print version and exit
  599. -x = send extra info to server (Debug)
  600. -c = install crontab entry
  601. -u = uninstall crontab entry
  602. -h = print usage information and exit
  603. If called with the "-i" option, will ask some questions and store the
  604. answers in $ENV{HOME}/.linuxcounter/$host
  605. EoF
  606. exit 0;
  607. }
  608. # }}}
  609. # {{{ license print license & exit
  610. #
  611. sub license {
  612. print <<EoF;
  613. Linux Counter Machine Update version $VERSION
  614. Copyright (C) 1999-2005 Harald Tveit Alvestrand
  615. 2003 PetaMem Group (www.petamem.com)
  616. This program is free software; you can redistribute it and/or modify
  617. it under the terms of the GNU General Public License as published by
  618. the Free Software Foundation; either version 2 of the License, or
  619. (at your option) any later version.
  620. This program is distributed in the hope that it will be useful,
  621. but WITHOUT ANY WARRANTY; without even the implied warranty of
  622. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  623. GNU General Public License below for more details.
  624. GNU GENERAL PUBLIC LICENSE
  625. Version 2, June 1991
  626. Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  627. 675 Mass Ave, Cambridge, MA 02139, USA
  628. Everyone is permitted to copy and distribute verbatim copies
  629. of this license document, but changing it is not allowed.
  630. Preamble
  631. The licenses for most software are designed to take away your
  632. freedom to share and change it. By contrast, the GNU General Public
  633. License is intended to guarantee your freedom to share and change free
  634. software--to make sure the software is free for all its users. This
  635. General Public License applies to most of the Free Software
  636. Foundation's software and to any other program whose authors commit to
  637. using it. (Some other Free Software Foundation software is covered by
  638. the GNU Library General Public License instead.) You can apply it to
  639. your programs, too.
  640. When we speak of free software, we are referring to freedom, not
  641. price. Our General Public Licenses are designed to make sure that you
  642. have the freedom to distribute copies of free software (and charge for
  643. this service if you wish), that you receive source code or can get it
  644. if you want it, that you can change the software or use pieces of it
  645. in new free programs; and that you know you can do these things.
  646. To protect your rights, we need to make restrictions that forbid
  647. anyone to deny you these rights or to ask you to surrender the rights.
  648. These restrictions translate to certain responsibilities for you if you
  649. distribute copies of the software, or if you modify it.
  650. For example, if you distribute copies of such a program, whether
  651. gratis or for a fee, you must give the recipients all the rights that
  652. you have. You must make sure that they, too, receive or can get the
  653. source code. And you must show them these terms so they know their
  654. rights.
  655. We protect your rights with two steps: (1) copyright the software, and
  656. (2) offer you this license which gives you legal permission to copy,
  657. distribute and/or modify the software.
  658. Also, for each author's protection and ours, we want to make certain
  659. that everyone understands that there is no warranty for this free
  660. software. If the software is modified by someone else and passed on, we
  661. want its recipients to know that what they have is not the original, so
  662. that any problems introduced by others will not reflect on the original
  663. authors' reputations.
  664. Finally, any free program is threatened constantly by software
  665. patents. We wish to avoid the danger that redistributors of a free
  666. program will individually obtain patent licenses, in effect making the
  667. program proprietary. To prevent this, we have made it clear that any
  668. patent must be licensed for everyone's free use or not licensed at all.
  669. The precise terms and conditions for copying, distribution and
  670. modification follow.
  671. GNU GENERAL PUBLIC LICENSE
  672. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  673. 0. This License applies to any program or other work which contains
  674. a notice placed by the copyright holder saying it may be distributed
  675. under the terms of this General Public License. The "Program", below,
  676. refers to any such program or work, and a "work based on the Program"
  677. means either the Program or any derivative work under copyright law:
  678. that is to say, a work containing the Program or a portion of it,
  679. either verbatim or with modifications and/or translated into another
  680. language. (Hereinafter, translation is included without limitation in
  681. the term "modification".) Each licensee is addressed as "you".
  682. Activities other than copying, distribution and modification are not
  683. covered by this License; they are outside its scope. The act of
  684. running the Program is not restricted, and the output from the Program
  685. is covered only if its contents constitute a work based on the
  686. Program (independent of having been made by running the Program).
  687. Whether that is true depends on what the Program does.
  688. 1. You may copy and distribute verbatim copies of the Program's
  689. source code as you receive it, in any medium, provided that you
  690. conspicuously and appropriately publish on each copy an appropriate
  691. copyright notice and disclaimer of warranty; keep intact all the
  692. notices that refer to this License and to the absence of any warranty;
  693. and give any other recipients of the Program a copy of this License
  694. along with the Program.
  695. You may charge a fee for the physical act of transferring a copy, and
  696. you may at your option offer warranty protection in exchange for a fee.
  697. 2. You may modify your copy or copies of the Program or any portion
  698. of it, thus forming a work based on the Program, and copy and
  699. distribute such modifications or work under the terms of Section 1
  700. above, provided that you also meet all of these conditions:
  701. a) You must cause the modified files to carry prominent notices
  702. stating that you changed the files and the date of any change.
  703. b) You must cause any work that you distribute or publish, that in
  704. whole or in part contains or is derived from the Program or any
  705. part thereof, to be licensed as a whole at no charge to all third
  706. parties under the terms of this License.
  707. c) If the modified program normally reads commands interactively
  708. when run, you must cause it, when started running for such
  709. interactive use in the most ordinary way, to print or display an
  710. announcement including an appropriate copyright notice and a
  711. notice that there is no warranty (or else, saying that you provide
  712. a warranty) and that users may redistribute the program under
  713. these conditions, and telling the user how to view a copy of this
  714. License. (Exception: if the Program itself is interactive but
  715. does not normally print such an announcement, your work based on
  716. the Program is not required to print an announcement.)
  717. These requirements apply to the modified work as a whole. If
  718. identifiable sections of that work are not derived from the Program,
  719. and can be reasonably considered independent and separate works in
  720. themselves, then this License, and its terms, do not apply to those
  721. sections when you distribute them as separate works. But when you
  722. distribute the same sections as part of a whole which is a work based
  723. on the Program, the distribution of the whole must be on the terms of
  724. this License, whose permissions for other licensees extend to the
  725. entire whole, and thus to each and every part regardless of who wrote it.
  726. Thus, it is not the intent of this section to claim rights or contest
  727. your rights to work written entirely by you; rather, the intent is to
  728. exercise the right to control the distribution of derivative or
  729. collective works based on the Program.
  730. In addition, mere aggregation of another work not based on the Program
  731. with the Program (or with a work based on the Program) on a volume of
  732. a storage or distribution medium does not bring the other work under
  733. the scope of this License.
  734. 3. You may copy and distribute the Program (or a work based on it,
  735. under Section 2) in object code or executable form under the terms of
  736. Sections 1 and 2 above provided that you also do one of the following:
  737. a) Accompany it with the complete corresponding machine-readable
  738. source code, which must be distributed under the terms of Sections
  739. 1 and 2 above on a medium customarily used for software interchange; or,
  740. b) Accompany it with a written offer, valid for at least three
  741. years, to give any third party, for a charge no more than your
  742. cost of physically performing source distribution, a complete
  743. machine-readable copy of the corresponding source code, to be
  744. distributed under the terms of Sections 1 and 2 above on a medium
  745. customarily used for software interchange; or,
  746. c) Accompany it with the information you received as to the offer
  747. to distribute corresponding source code. (This alternative is
  748. allowed only for noncommercial distribution and only if you
  749. received the program in object code or executable form with such
  750. an offer, in accord with Subsection b above.)
  751. The source code for a work means the preferred form of the work for
  752. making modifications to it. For an executable work, complete source
  753. code means all the source code for all modules it contains, plus any
  754. associated interface definition files, plus the scripts used to
  755. control compilation and installation of the executable. However, as a
  756. special exception, the source code distributed need not include
  757. anything that is normally distributed (in either source or binary
  758. form) with the major components (compiler, kernel, and so on) of the
  759. operating system on which the executable runs, unless that component
  760. itself accompanies the executable.
  761. If distribution of executable or object code is made by offering
  762. access to copy from a designated place, then offering equivalent
  763. access to copy the source code from the same place counts as
  764. distribution of the source code, even though third parties are not
  765. compelled to copy the source along with the object code.
  766. 4. You may not copy, modify, sublicense, or distribute the Program
  767. except as expressly provided under this License. Any attempt
  768. otherwise to copy, modify, sublicense or distribute the Program is
  769. void, and will automatically terminate your rights under this License.
  770. However, parties who have received copies, or rights, from you under
  771. this License will not have their licenses terminated so long as such
  772. parties remain in full compliance.
  773. 5. You are not required to accept this License, since you have not
  774. signed it. However, nothing else grants you permission to modify or
  775. distribute the Program or its derivative works. These actions are
  776. prohibited by law if you do not accept this License. Therefore, by
  777. modifying or distributing the Program (or any work based on the
  778. Program), you indicate your acceptance of this License to do so, and
  779. all its terms and conditions for copying, distributing or modifying
  780. the Program or works based on it.
  781. 6. Each time you redistribute the Program (or any work based on the
  782. Program), the recipient automatically receives a license from the
  783. original licensor to copy, distribute or modify the Program subject to
  784. these terms and conditions. You may not impose any further
  785. restrictions on the recipients' exercise of the rights granted herein.
  786. You are not responsible for enforcing compliance by third parties to
  787. this License.
  788. 7. If, as a consequence of a court judgment or allegation of patent
  789. infringement or for any other reason (not limited to patent issues),
  790. conditions are imposed on you (whether by court order, agreement or
  791. otherwise) that contradict the conditions of this License, they do not
  792. excuse you from the conditions of this License. If you cannot
  793. distribute so as to satisfy simultaneously your obligations under this
  794. License and any other pertinent obligations, then as a consequence you
  795. may not distribute the Program at all. For example, if a patent
  796. license would not permit royalty-free redistribution of the Program by
  797. all those who receive copies directly or indirectly through you, then
  798. the only way you could satisfy both it and this License would be to
  799. refrain entirely from distribution of the Program.
  800. If any portion of this section is held invalid or unenforceable under
  801. any particular circumstance, the balance of the section is intended to
  802. apply and the section as a whole is intended to apply in other
  803. circumstances.
  804. It is not the purpose of this section to induce you to infringe any
  805. patents or other property right claims or to contest validity of any
  806. such claims; this section has the sole purpose of protecting the
  807. integrity of the free software distribution system, which is
  808. implemented by public license practices. Many people have made
  809. generous contributions to the wide range of software distributed
  810. through that system in reliance on consistent application of that
  811. system; it is up to the author/donor to decide if he or she is willing
  812. to distribute software through any other system and a licensee cannot
  813. impose that choice.
  814. This section is intended to make thoroughly clear what is believed to
  815. be a consequence of the rest of this License.
  816. 8. If the distribution and/or use of the Program is restricted in
  817. certain countries either by patents or by copyrighted interfaces, the
  818. original copyright holder who places the Program under this License
  819. may add an explicit geographical distribution limitation excluding
  820. those countries, so that distribution is permitted only in or among
  821. countries not thus excluded. In such case, this License incorporates
  822. the limitation as if written in the body of this License.
  823. 9. The Free Software Foundation may publish revised and/or new versions
  824. of the General Public License from time to time. Such new versions will
  825. be similar in spirit to the present version, but may differ in detail to
  826. address new problems or concerns.
  827. Each version is given a distinguishing version number. If the Program
  828. specifies a version number of this License which applies to it and "any
  829. later version", you have the option of following the terms and conditions
  830. either of that version or of any later version published by the Free
  831. Software Foundation. If the Program does not specify a version number of
  832. this License, you may choose any version ever published by the Free Software
  833. Foundation.
  834. 10. If you wish to incorporate parts of the Program into other free
  835. programs whose distribution conditions are different, write to the author
  836. to ask for permission. For software which is copyrighted by the Free
  837. Software Foundation, write to the Free Software Foundation; we sometimes
  838. make exceptions for this. Our decision will be guided by the two goals
  839. of preserving the free status of all derivatives of our free software and
  840. of promoting the sharing and reuse of software generally.
  841. NO WARRANTY
  842. 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  843. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
  844. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  845. PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  846. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  847. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
  848. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
  849. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  850. REPAIR OR CORRECTION.
  851. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  852. WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  853. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  854. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  855. OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  856. TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  857. YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  858. PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  859. POSSIBILITY OF SUCH DAMAGES.
  860. END OF TERMS AND CONDITIONS
  861. EoF
  862. exit 0;
  863. }
  864. # }}}
  865. # Changelog for 0.2
  866. # - indentation and folding marks
  867. # - made script work with -w and use strict
  868. # - removed some localization traps
  869. # - marked some BUGS - but they`re still there (mostly localization)
  870. # - more robust binary calls
  871. # - getval_from_file data acquisition method
  872. # - fixed df (shmfs) - but only temporarily (quick hack)
  873. # - various code optimizations & cleanup (removed unneded vars)
  874. # - Memory size detection now robst and >960MB capable
  875. # - slightly better randomness
  876. #
  877. # Changelog 0.21
  878. # - added attaching of files
  879. # - added fetching of uptime_1 and uptime_2
  880. #
  881. # Changelog 0.22
  882. # - removed "manual" copying of entries
  883. # - added suppressing error messages from "xbin" calling "which"
  884. # - suppressed NFS from "df -T" listing
  885. #
  886. # Changelog 0.23
  887. # - added sending /proc/pci
  888. # - removed client-side parsing of DF output and uptime
  889. #
  890. # Changelog 0.24
  891. # - added sending /proc/version (inspired by klive)
  892. # - changed fetching of old data from "all" to "needed"
  893. # - removed CPU-parsing code
  894. # - fixed warning (harmless) from crontab creation
  895. # - added sending /proc/bus/usb/devices
  896. #
  897. # Changelog 0.25
  898. # - added sending size of /proc/kcore
  899. # - removed computation of memory client-side
  900. #
  901. #vim:ts=8:sw=4:sts=4