Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
11 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM staledfs.cmd
  5. REM List and/or purge the stale DFS links for \\ntdev\release.
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM Version: < 1.0 > 09/06/2001 Suemiao Rossignol
  9. REM Version: < 2.0 > 07/17/2002 Jorge Peraza
  10. REM ------------------------------------------------------------------
  11. perl -x "%~f0" %*
  12. goto :EOF
  13. #!perl
  14. use strict;
  15. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  16. use lib $ENV{RAZZLETOOLPATH};
  17. use PbuildEnv;
  18. use Logmsg;
  19. use ParseArgs;
  20. use File::Basename;
  21. use BuildName;
  22. use GetIniSetting;
  23. use hashtext;
  24. use comlib;
  25. use LockProc;
  26. require $ENV{'sdxroot'} . '\TOOLS\sendmsg.pl';
  27. my $scriptname = basename( $0 );
  28. sub Usage {
  29. print<<USAGE;
  30. List and/or purge the stale DFS link(s) for nt releases.
  31. Usage:
  32. $scriptname: -l:<language> [-b:<branch>] [-purge|-mail:<mailto>] [-a]
  33. -l Language.
  34. Default is "usa".
  35. -n Build Number.
  36. -b Branch.
  37. Default is "main".
  38. -purge Option to purge stale link(s).
  39. Default is listing stale link(s) only.
  40. -a All languages (USA servers)
  41. -ae All languages (EU servers)
  42. -mail Send mails.
  43. -? Display Usage.
  44. Example:
  45. $scriptname
  46. $scriptname -b:idw
  47. $scriptname -l:ger
  48. USAGE
  49. exit(1)
  50. }
  51. my ( $buildNo, $branch, $isPurge,$isPurgeds, $isSendMail,,@lSendMail, $isPowerLess );
  52. my ( $dfsRoot, $lockObj, %dfsMap );
  53. my ( $dash, $dot, $totcnt, $totdwn , @staleList, @mailList, @mailDwList, @downList);
  54. my ( $isAllLangs, $isAllELangs, $sTie);
  55. GetParams();
  56. Init();
  57. if(Run()==0)
  58. {
  59. #Set error level to 1
  60. exit(1);
  61. }
  62. exit(0);
  63. #-----------------------------------------------------------------------------
  64. sub Init
  65. {
  66. splice(@staleList, 0);
  67. splice(@mailList, 0);
  68. splice(@mailDwList, 0);
  69. splice(@downList, 0);
  70. $totcnt=0;
  71. $totdwn=0;
  72. if($sTie ne "")
  73. {
  74. logmsg( "Lauguage .....[$sTie]" );
  75. }
  76. logmsg( "Build Number.....[$buildNo]" );
  77. logmsg( "Branch...........[$branch]" );
  78. logmsg( "Temp Log file ...[$ENV{LOGFILE}]" );
  79. logmsg( "Temp Error file .[$ENV{ERRFILE}]" );
  80. }
  81. sub Run
  82. {
  83. my $sTieTo;
  84. if($isAllLangs)
  85. {
  86. $sTieTo = "usa";
  87. }
  88. elsif($isAllELangs )
  89. {
  90. $sTieTo = "es";
  91. }
  92. else
  93. {
  94. $sTieTo = $sTie;
  95. }
  96. if(!TieDFS($sTieTo))
  97. {
  98. return 0;
  99. }
  100. if( !&ListStaleLinks($sTie) )
  101. {
  102. return 0;
  103. }
  104. if( $isPurge )
  105. {
  106. return 0 if( !&PurgeDFSLinks($sTieTo) );
  107. }
  108. if( $isSendMail )
  109. {
  110. if(($totcnt+$totdwn)!=0)
  111. {
  112. return 0 if( !&SendMail() );
  113. }
  114. }
  115. return 1;
  116. }
  117. sub GetParams
  118. {
  119. my $sSendMail;
  120. parseargs('?' => \&Usage, 'n:' => \$buildNo, 'b:' => \$branch, 'mail:' =>\$sSendMail, 'a' => \$isAllLangs, 'ae' => \$isAllELangs,
  121. 'purge' => \$isPurge, 'purgeds' => \$isPurgeds, 'p' =>\$isPowerLess );
  122. $branch = "main" if( !$branch );
  123. if($sSendMail)
  124. {
  125. $isSendMail = 1;
  126. @lSendMail = split("#",$sSendMail);
  127. }
  128. $sTie = ".";
  129. if(!( $isAllLangs || $isAllELangs) )
  130. {
  131. $sTie = $ENV{lang};
  132. }
  133. }
  134. #-----------------------------------------------------------------------------
  135. sub TieDFS
  136. {
  137. my $sLang;
  138. $sLang = shift;
  139. ##### Tie DFS view to hash object
  140. return 0 if( !&comlib::TieDfsView($sLang, $branch, \%dfsMap ));
  141. $dfsRoot = ( tied %dfsMap )->GetDfsRoot();
  142. return 1;
  143. }
  144. sub findServ
  145. {
  146. my $sNew = shift;
  147. #Find the sNew Server in the list passed as parameter to the function
  148. if(grep(($_ eq $sNew),@_))
  149. {
  150. return 1;
  151. }
  152. return 0;
  153. }
  154. #-----------------------------------------------------------------------------
  155. sub ListStaleLinks
  156. {
  157. my (@mList, $outstr, $outstrM);
  158. my $sLang = shift;
  159. return 0 if( !( tied %dfsMap )->ParseShare($sLang,"",$branch,"","","",\@mList) );
  160. logmsg( $dash );
  161. for my $theShare ( @mList )
  162. {
  163. # continue when the share exists in the release server
  164. $theShare =~ /^(\\\\[^\\]+)(\\[^\\]+)(.*)$/;
  165. my $server = $1;
  166. my $curShare = "$1$2";
  167. next if( -e $curShare );
  168. next if( $buildNo && $curShare !~ /$buildNo/ );
  169. next if( $curShare !~ /$branch/ );
  170. # parse the server
  171. my $msg;
  172. # print the link-share pair
  173. for my $theLink( @{$dfsMap{ $theShare }} )
  174. {
  175. if($sLang ne "")
  176. {
  177. next if( $theLink !~ /$sLang/i );
  178. }
  179. my $link = "$dfsRoot\\$theLink";
  180. if( system( "net view $server >nul 2>nul" ))
  181. {
  182. $msg = " *** [$server] is current down";
  183. $totdwn++;
  184. push( @downList, "$link $theShare" );
  185. $outstr = sprintf("\nDFS Link: %s\nShare: %s%s\n", $link, $theShare, $msg);
  186. $outstrM = sprintf("<br><font face=\"Arial\" size=\"2\"><font color=\"#000080\"><strong>DFS Link:</strong></font></font><a href=\"file:%s\">%s</a><br><font face=\"Arial\" size=\"2\"><font color=\"#000080\"><strong>Missing Share: </strong></font></font><a href=\"file:%s\">%s</a></font>", $link, $link, $theShare,$theShare);
  187. if( $isSendMail )
  188. {
  189. if(!findServ($server,@mailDwList))
  190. {
  191. push( @mailDwList, $server );
  192. }
  193. }
  194. }
  195. else
  196. {
  197. $msg = "Missing Share";
  198. $totcnt++;
  199. push( @staleList, "$link $theShare" );
  200. $outstr = sprintf("\nDFS Link: %s\nShare: %s ** %s\n", $link, $theShare, $msg);
  201. $outstrM = sprintf("<br><font face=\"Arial\" color=\"#ff0000\" size=\"2\"><strong>%s</strong></font><br><font face=\"Arial\" size=\"2\"><font color=\"#000080\"><strong>DFS Link:</strong></font></font><a href=\"file:%s\">%s</a><br><font face=\"Arial\" size=\"2\"><font color=\"#000080\"><strong>Share: </strong></font></font><a href=\"file:%s\">%s</a></font>", $msg,$link, $link, $theShare,$theShare);
  202. if( $isSendMail )
  203. {
  204. push( @mailList, $outstrM );
  205. }
  206. }
  207. logmsg( $outstr );
  208. }
  209. }
  210. logmsg( "Total [$totcnt] stale dfs links." );
  211. logmsg( "Total [$totdwn] down servers." );
  212. if( !$isPurge && $totcnt )
  213. {
  214. logmsg( "Run [staledfs.cmd -l:<lang> -purge] to purge the above stale links" );
  215. }
  216. logmsg( $dash );
  217. return 1;
  218. }
  219. #-----------------------------------------------------------------------------
  220. sub PurgeDFSLinks
  221. {
  222. my $sLang = shift;
  223. logmsg( $dash );
  224. if( !($totcnt + $totdwn) )
  225. {
  226. logmsg( "No stale links found. Exit" );
  227. return 1;
  228. }
  229. ##### Apply Semaphore lock
  230. return 0 if ( !&comlib::LockProcess( $sLang, $branch, \$lockObj ) );
  231. ##### Interaction through the stale lists
  232. my $choice = (-1);
  233. while( $choice > 3 || $choice < 1 )
  234. {
  235. printf("\n$dot\n$dot\nDo you want to Un-map the above %d link(s) (1)Yes for all (2)Yes for selection (3)Quit? ", $totcnt);
  236. chomp( $choice=<STDIN> );
  237. if( $choice == 1 )
  238. {
  239. print "\n$dot\n$dot\nConfirm un-map all the above link(s). (1)Yes. (2)No. ";
  240. chomp( $choice=<STDIN> );
  241. last if( $choice == 1);
  242. $choice = (-1);
  243. }
  244. }
  245. if( $choice == 3 ){ $lockObj->Unlock(); return 1; }
  246. my $cnt=0;
  247. my @sharePath=();
  248. push @staleList, @downList;
  249. foreach ( @staleList )
  250. {
  251. my @tmp = split( /\s/, $_);
  252. my $theLink = $tmp[0];
  253. my $theShare = $tmp[1];
  254. my $cmdLine = "dfscmd /remove $theLink $theShare";
  255. if( $choice != 1 )
  256. {
  257. my $outstr = sprintf("$dash\n-(%03d)-\n%s\n%s",(++$cnt), $theLink, $theShare );
  258. logmsg( $outstr );
  259. my $choice2 = (-1);
  260. while( $choice2 > 3 || $choice2 < 1 )
  261. {
  262. print "$dot\nDo you want to Un-map the above link (1)Yes (2)Skip (3)Quit? " ;
  263. chomp( $choice2=<STDIN> );
  264. }
  265. if ( $choice2 == 3){ $lockObj->Unlock(); return 1; }
  266. next if( $choice2 == 2);
  267. }
  268. if( $isPowerLess )
  269. {
  270. logmsg( $cmdLine );
  271. }
  272. else
  273. {
  274. &comlib::ExecuteSystem( $cmdLine );
  275. }
  276. }
  277. $lockObj->Unlock();
  278. return 1;
  279. }
  280. #-----------------------------------------------------------------------------
  281. sub SendMail
  282. {
  283. my ( $mailFrom, $mailMsg ,$mailSubject);
  284. if(!($isAllLangs||$isAllELangs))
  285. {
  286. $mailSubject = $totcnt+$totdwn . " Stale DFS Links found for \"$branch - $ENV{lang}\"";
  287. }
  288. else
  289. {
  290. $mailSubject = $totcnt+$totdwn . " Stale DFS Links found for \"$branch\"";
  291. }
  292. my $mailFrom = "ntbldi";
  293. if( $ENV{lang} =~ /usa/i || $ENV{lang} =~ /ger/i || $ENV{lang} =~ /jpn/i
  294. || $ENV{lang} =~ /fr/i )
  295. {
  296. $mailFrom = "y-ntbld";
  297. }
  298. $mailMsg = "<html><head></head><body><p><font face=\"Arial\" size=\"2\"><font color=\"#000080\">The DFS </font><a href=\"file:$dfsRoot\"><font color=\"#000080\">$dfsRoot</font></a><font color=\"#000080\"> was examined and found to have stale links and/or release servers that were unreachable. This will cause people to be unable to access the builds listed below.</font></span></font></p><p><font face=\"Arial\" color=\"#ff0000\" size=\"2\"><strong>A builder needs to investigate and correct these issues ASAP!</strong></span></font></p>";
  299. if(!($isAllLangs||$isAllELangs))
  300. {
  301. $mailMsg .= "<br/><font face=\"Arial\" color=\"#800000\" size=\"2\"><strong><u>Servers Down:</u></strong></font> <br> <font face=\"Arial\" color=\"#000080\" size=\"2\">$totdwn DFS links for $branch $ENV{lang} point to servers that are down.</font><br/><blockquote><p>";
  302. }
  303. else
  304. {
  305. $mailMsg .= "<br/><font face=\"Arial\" color=\"#800000\" size=\"2\"><strong><u>Servers Down</u></strong></font> <br> <font face=\"Arial\" color=\"#000080\" size=\"2\">$totdwn DFS links for $branch point to servers that are down.</font><br/><blockquote><p>";
  306. }
  307. $mailMsg .= "<a href=\"file:$_\">$_<a><br>" for ( @mailDwList );
  308. if(!($isAllLangs||$isAllELangs))
  309. {
  310. $mailMsg .= "</blockquote></p><br/><font face=\"Arial\" color=\"#800000\" size=\"2\"><strong><u>Stale Links</u></strong></font> <br> <font face=\"Arial\" color=\"#000080\" size=\"2\">$totcnt DFS links for $branch $ENV{lang}</font><br/><blockquote><p>";
  311. }
  312. else
  313. {
  314. $mailMsg .= "</blockquote></p><br/><font face=\"Arial\" color=\"#800000\" size=\"2\"><strong><u>Stale Links</u></strong></font> <br> <font face=\"Arial\" color=\"#000080\" size=\"2\">$totcnt DFS links for $branch</font> <br/><blockquote><p>";
  315. }
  316. $mailMsg .= "$_<br/>" for ( @mailList );
  317. $mailMsg .= "<br>Run staledfs.cmd -l:[lang] -purge, to purge the above stale links<br>";
  318. $mailMsg .= "</blockquote></p><address><br>This email was automatically generated by staledfs.cmd<br><br></address>";
  319. $mailMsg .= "<br><font face=\"Arial\" color=\"#000080\" size=\"2\">Thanks!</font><br>";
  320. $mailMsg .= "<font SIZE=\"2\" COLOR=\"#000080\"><i><b><u><p>Windows International Build Team</u> : </b></i></font><br><a HREF=\"http://ntbld/intl\"><font SIZE=\"2\" COLOR=\"#0000ff\"><u><i><b>http://ntbld/intl</b></i></u></font></a></p><font SIZE=\"2\" COLOR=\"#0000ff\"><p>NT Build Lab 26N/2233 - x34613</p></font>";
  321. if( sendmsg ('-v', $mailFrom, $mailSubject, $mailMsg,"content:text/html",@lSendMail))
  322. {
  323. print "WARNING: sendmsg failed!\n";
  324. return 0;
  325. }
  326. return 1;
  327. }
  328. #-----------------------------------------------------------------------------
  329. 1;