[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-unattended/var/se3/unattended/install/tools/ -> msparse.pl (source)

   1  #!/usr/bin/perl
   2  #
   3  # This script outputs the download urls of every language of a patch. 
   4  # Input: [microsoft family download url] [local download directory]
   5  #
   6  use strict;
   7  my %lang=(
   8          ara => 'ar', # Arabic
   9          csy => 'cs', # Czech
  10          dan => 'da', # Danish
  11          nld => 'nl', # Dutch
  12          enu => 'en', # English
  13          fin => 'fi', # Finnish
  14          fra => 'fr', # French
  15          deu => 'de', # German
  16          ell => 'el', # Greek
  17          heb => 'he', # Hebrew
  18          hun => 'hu', # Hungarian
  19          ita => 'it', # Italian
  20          jpn => 'ja', # Japanese
  21          kor => 'ko', # Korean
  22          nor => 'no', # Norwegian
  23          plk => 'pl', # Polish
  24          ptb => 'pt-br', # Portuguese (Brazilian)
  25          ptg => 'pt-pt', # Portuguese (Portugal)
  26          rus => 'ru', # Russian
  27          esn => 'es', # Spanish
  28          sve => 'sv', # Swedish
  29          trk => 'tr', # Turkish
  30          );
  31  #%lang=(enu => 'en');
  32  
  33  @ARGV == 2 || die "Usage: msparse.pl [microsoft family download url] [local download directory]\n\ne.g. msparse.pl \"http://www.microsoft.com/downloads/details.aspx?FamilyId=AC1141D2-6CE1-403E-832B-0574ADB0C296&displaylang=en\" updates/winxpsp1\n";
  34  my $url=$ARGV[0];
  35  my $type=$ARGV[1];
  36  
  37  $type =~ s/^\/+//g;
  38  $type =~ s/\/+$//g;
  39  
  40  $url =~ s/amp;/\&/g;
  41  $url =~ s/displaylang=[a-z]{2}(?:-[a-z]{2})?//ig;
  42  $url =~ s/\&\&+/\&/g;
  43  $url =~ s/\?\&/\?/;
  44  $url =~ s/\&$//;
  45  
  46  my $devnull;
  47  my $eol;
  48  if ($^O eq "MSWin32") {
  49    $devnull = "nul";
  50    $eol = "\n";
  51  } else {
  52    $devnull = "/dev/null";
  53    $eol = "\r\n";
  54  }
  55  
  56  my ($urls, $title1, $title2, $desc, $link, $run, $recheck);
  57  foreach my $k (keys (%lang)) {
  58      open(f,"wget -O - \"$url\&displaylang=$lang{$k}\" 2>$devnull |");
  59      while(<f>) {
  60          chomp;
  61          if ($k =~ /enu/i) {
  62              $title1 = "$1" if /\<h1.*?\>(.*?)\<\/h1\>/;
  63              defined $link
  64                  or $link = $1 if /href=[\"\']\s*(http:\/\/[^\"\']*(\d{6}))[\"\']\>[^\<]*\2/i;
  65              defined $link
  66                  or $link = $1 if /href=[\"\']\s*(http:\/\/[^\"\']*)[\"\']\>[^\<]*Knowledge Base Article/i;
  67              defined $link
  68                  or $link = $1 if /href=[\"\']\s*(http:\/\/[^\"\']*)[\"\']\>[^\<]*Security Update/i;
  69              $link = $1 if /href=[\"\']\s*(http:\/\/[^\"\']*)[\"\']\>[^\<]*Security Bulletin [^Pp]/i;
  70              $link = $1 if /href=[\"\']\s*(http:\/\/[^\"\']*)[\"\']\>[^\<]*[^wW] Security Bulletin/i;
  71              $link = $1 if /href=[\"\']\s*(http:\/\/[^\"\']*)[\"\']\>Security Bulletin\</i;
  72  #            $link = $1 if /href=[\"\']\s*(http:\/\/[^\"\']*)[\"\']\>[^\<]*ms\d{2}-\d{3}/i;
  73          }
  74  
  75          if (/\<a href=[\"\']([^\"\']*-client-[^\"\']*)[\"\']\>/i) {
  76              my $dl=$1;
  77              if ($dl =~/.*?;u=(.*)/) {
  78                  $dl=$1;
  79                  $dl=~s#%2f#/#g;
  80                  $dl=~s#%3a#:#g;
  81              }
  82              my @a=split(/\//,$dl);
  83              if ($a[$#a] =~ /$k/i) {
  84                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($a[$#a]);
  85                  $run = lc($type)."/".$a[$#a] unless defined $run;
  86              } elsif ($a[$#a] =~ /$lang{$k}\.exe/i) {
  87                  $a[$#a] =~ s/$lang{$k}\.exe/$k.exe/i;
  88                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($a[$#a]);
  89                  $run = lc($type)."/".$a[$#a] unless defined $run;
  90              } else {
  91                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($k)."/".lc($a[$#a]);
  92                  $run = lc($type)."/".lc($k)."/".$a[$#a] unless defined $run;
  93              }
  94          }
  95  
  96          if (/if \((?:g_IsIE|useDlWindow\(\))\) \{window.open\([\"\']([^\"\']*)[\"\']/) {
  97              my $dl=$1;
  98              my @a=split(/\//,$dl);
  99              if ($a[$#a] =~ /$k/i) {
 100                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($a[$#a]);
 101                  $run = lc($type)."/".$a[$#a] unless defined $run;
 102              } elsif ($a[$#a] =~ /$lang{$k}\.exe/i) {
 103                  $a[$#a] =~ s/$lang{$k}\.exe/$k.exe/i;
 104                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($a[$#a]);
 105                  $run = lc($type)."/".$a[$#a] unless defined $run;
 106              } else {
 107                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($k)."/".lc($a[$#a]);
 108                  $run = lc($type)."/".lc($k)."/".$a[$#a] unless defined $run;
 109              }
 110          }
 111  
 112          if (/\<a id=[\"\']btnDownload[\"\'] class=[\"\']downloadButton[\"\'] href=[\"\']([^\"\']*)[\"\']\>/) {
 113              my $dl=$1;
 114              my @a=split(/\//,$dl);
 115              if ($a[$#a] =~ /$k/i) {
 116                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($a[$#a]);
 117                  $run = lc($type)."/".$a[$#a] unless defined $run;
 118              } elsif ($a[$#a] =~ /$lang{$k}\.exe/i) {
 119                  $a[$#a] =~ s/$lang{$k}\.exe/$k.exe/i;
 120                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($a[$#a]);
 121                  $run = lc($type)."/".$a[$#a] unless defined $run;
 122              } else {
 123                  $urls->{uc($k)} = "URL|".uc($k)."|$dl|".lc($type)."/".lc($k)."/".lc($a[$#a]);
 124                  $run = lc($type)."/".lc($k)."/".$a[$#a] unless defined $run;
 125              }
 126          }
 127          if (defined $run) {
 128              unless ($run =~ /%WINLANG%/) {
 129                  $run =~ s/([-_\/])$k/$1%WINLANG%/i;
 130                  $run =~ s/$k\.exe/%WINLANG%\.exe/i;
 131                  $run =~ s/\//\\/g;
 132              }
 133          }
 134      }
 135  }
 136  
 137  if (defined $link) {
 138      $link =~ s/default.*(\d{6})/\?kbid=$1/i if $link =~ /scid=kb/i;
 139      $link =~ s/\/support\/misc\/kblookup.asp\?id=/\/\?kbid=/i if $link =~ /\/support\/misc\/kblookup.asp\?id=/i;
 140      $link =~ s/\/\?id=/\/\?kbid=/i if $link =~ /\/?id=/i;
 141      $link =~ s/(ms\d{2}-\d{3})\.asp/$1.mspx/i if $link =~ /ms\d{2}-\d{3}\.asp/i;
 142  }
 143  
 144  $recheck = 0;
 145  if (defined $link) {
 146      open(f,"wget -O - \"$link\" 2>&1 |");
 147      while(<f>) {
 148          if ($link =~ /kbid=/i) {
 149              if (/href=[\"\']\s*(http:\/\/[^\"\']*ms\d{2}-\d{3}\.mspx)[\"\']\>[^\<]*ms\d{2}-\d{3}/i) {
 150                  $link = $1;
 151                  $recheck = 1;
 152              }
 153          } else {
 154              defined $title2
 155                  or $title2 = "$1" if /\<h1.*?\>(.*?)(?:\<\/h1\>|$)/;
 156              defined $desc
 157                  or $desc = "$1" if /\<h2.*?\>(.*?)(?:\<\/h2\>|$)/;
 158          }
 159          if (/(http.*?) \[following\]/i) {
 160              $link = "$1";
 161              $link =~ s/default.*(\d{6})/\?kbid=$1/i if (defined $link && $link =~ /scid=kb/i);
 162              $link =~ s/\/support\/misc\/kblookup.asp\?id=/\/\?kbid=/i if (defined $link && $link =~ /\/support\/misc\/kblookup.asp\?id=/i);
 163              $link =~ s/\/\?id=/\/\?kbid=/i if (defined $link && $link =~ /\/?id=/i);
 164          }
 165      }
 166      $link =~ s/technet\/treeview.*?(technet)/$1/i if ($link =~ /technet\/treeview/i);
 167      if ($recheck == 1 || $link =~ /ms\d{2}-\d{3}\.asp/i) {
 168          $link =~ s/(ms\d{2}-\d{3})\.asp/$1.mspx/i;
 169  
 170          undef $title2;
 171          undef $desc;
 172          open(f,"wget -O - \"$link\" 2> $devnull |");
 173          while(<f>) {
 174              defined $title2
 175                  or $title2 = "$1" if /\<h1.*?\>(.*?)(?:\<\/h1\>|$)/;
 176              defined $desc
 177                  or $desc = "$1" if /\<h2.*?\>(.*?)(?:\<\/h2\>|$)/;
 178          }
 179      }
 180  }
 181  
 182  if (defined $title1) {
 183      $title1 =~ s/^ +//g;
 184      $title1 =~ s/ +$//g;
 185      $title1 =~ s/ *\.\. *//g;
 186  }
 187  
 188  if (defined $title2) {
 189      $title2 =~ s/^ +//g;
 190      $title2 =~ s/ +$//g;
 191      $title2 =~ s/ *\.\. *//g;
 192  }
 193  
 194  if (defined $desc) {
 195      $desc =~ s/^ +//g;
 196      $desc =~ s/ +$//g;
 197      $desc =~ s/ *\.\. *//g;
 198  }
 199  
 200  if (defined $link) {
 201      $link =~ s/^ +//g;
 202      $link =~ s/ +$//g;
 203  }
 204  
 205  print "$eol";
 206  print ":: $title1$eol" if defined $title1;
 207  print ":: $title2$eol" if defined $title2;
 208  print ":: \"$desc\"$eol" if defined $desc;
 209  print ":: <$link>$eol" if defined $link;
 210  print ":: <$url>$eol" if defined $url;
 211  foreach (sort keys %lang) {
 212      if (defined $urls->{uc($_)}) {
 213          print ":: $urls->{uc($_)}$eol";
 214      } else {
 215          print ":: No Download found for " . uc($_) . ".$eol";
 216      }
 217  }
 218  print "todo.pl \".reboot-on 194 %Z%\\$run /?\"$eol" if defined $run;


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1