#!/usr/bin/perl -w

# This script copies a security advisory named on the command line, and adds
# the translation-check header to it. It also will create the
# destination directory if necessary, and copy the Makefile from the source.

# Written in 2000-2004 by Peter Karlsson <peterk@debian.org>
# © Copyright 2000-2004 Software in the public interest, Inc.
# This program is released under the GNU General Public License, v2.

# $Id: copyadvisory.pl,v 1.4 2004/04/19 05:55:37 kaare Exp $

# Modified to pt_BR team by Marco Carvalho 2006.01.07

# Get command line
$number = $ARGV[0];

# Check usage.
unless ($number)
{
	print "Usage: $0 advisorynumber\n\n";
	print "Copies the advisory from the English directory to the local one and adds\n";
	print "the translation-check header\n";
	exit;
}
if (exists $ENV{DWWW_MAINT})
{
        $maintainer = $ENV{DWWW_MAINT};
}
# Locate advisory
$number = "dsa-" . $number if $number !~ /^dsa-/;
$year = 2005;
YEAR: while (-d "../../english/security/$year")
{
	last YEAR if -e "../../english/security/$year/$number.wml";
	$year ++;
}

# Create needed file and directory names
$srcdir = "../../english/security/$year";
die "Unable to locate English version of advisory $number.\n"
	if ! -d $srcdir;
$srcfile= "$srcdir/$number.wml";
$cvsfile= "$srcdir/CVS/Entries";
$dstdir = "./$year";
$dstfile= "$dstdir/$number.wml";

# Sanity checks
die "File $srcfile does not exist\n"     unless -e $srcfile;
die "File $dstfile already exists\n"     if     -e $dstfile;
mkdir $dstdir, 0755                      unless -d $dstdir;

# Open the files
open CVS, $cvsfile
	or die "Could not read $cvsfile ($!)\n";

open SRC, $srcfile
	or die "Could not read $srcfile ($!)\n";

open DST, ">$dstfile"
	or die "Could not create $dstfile ($!)\n";

# Retrieve the CVS version number
while (<CVS>)
{
	if (m[^/$number\.wml/([0-9]*\.[0-9]*)/]o)
	{
		$revision = $1;
	}
}

close CVS;

unless ($revision)
{
	print "Could not get revision number - bug in script?\n";
	$revision = '1.1';
}

# Insert the revision number
print DST qq'#use wml::debian::translation-check translation="$revision" maintainer="$maintainer"\n';

# Copy the file
while (<SRC>)
{
	next if /\$Id/;

	s/^(<p>)?A problem has been discovered in\b/$1Um problema foi descoberto no/;
	s/\bdiscovered a problem in\b/descobriu um problema no/;
	s/We recommend that you upgrade your (.*) package immediately/Recomendamos que você atualize seu pacote $1 imediatamente/;
	s/We recommend that you upgrade your (.*) packages immediately/Recomendamos que você atualize seus pacotes $1 imediatamente/;
    s/We recommend that you upgrade your (.*) and (.*) packages/Recomendamos que você atualize seus pacotes $1 e $2/;	
	s/We recommend that you upgrade your (.*) packages/Recomendamos que você atualize seus pacotes $1/;
	s/We recommend that you upgrade your (.*) package/Recomendamos que você atualize seu pacote $1/;
	s/We recommend that you update your (.*) package immediately/Recomendamos que você atualize seu pacote $1 imediatamente/;
	s/We recommend that you update your (.*) packages immediately/Recomendamos que você atualize seus pacotes $1 imediatamente/;
	s/We recommend that you update your (.*) packages/Recomendamos que você atualize seus pacotes $1/;
	s/We recommend that you update your (.*) package/Recomendamos que você atualize seu pacote $1/;
	s/buffer overflows?/estouro de pilha/;
	s/A buffer overflows?/Um estouro de pilha/;
	s/integer overflow/estouro de inteiro/;
	s/has been discovered in/foi descoberto no/;
	s/format string vulnerability/vulnerabilidade de formato de string/;
	s/format string vulnerabilities/vulnerabilidades de formato de string/;
	s/insecure temporary files/arquivo temporário inseguro/;
	s/>insecure temporary file creation</>criação de arquivo temporário inseguro</;
	s/>local root exploit</>exploração de root</;
	s/>remote root exploit</>exploração remota de root</;
	s/>symlink attack</>ataque de link simbólico</;
	s/>remote exploit</>exploração remota</;
	s/>missing input sanitising</>Falta de limpeza da entrada</;
	s/Several vulnerabilities/Várias vulnerabilidades/;
	s/several vulnerabilities/várias vulnerabilidades/;
	s/>several</>várias</;
	s/This has been fixed in version/Isto foi corrigido na versão/;
	s/this problem has been fixed in/este problema foi corrigido na/;
	s/version (.*)/versão $1/;
	s/of the Debian package/do pacote Debian/;
	s/upstream version/versão upstream/;
	s/([Ff])or the old stable distribution/Para a antiga distribuição estável/;
	s/([Ff])or the stable distribution/Para a distribuição estável/;
	s/([Ff])or the unstable distribution/Para a distribuição instável/;
	s/([Tt])he old stable distribution/A antiga distribuição estável/;
	s/([Tt])he stable distribution/A distribuição estável/;
	s/([Tt])he unstable distribution/A distribuição instável/;
	s/does(?: not|n't) contain (.*) package/não contém o pacote $1/;
	s/distribution (\(potato|woody|sarge\))/distributionen $1/;
	s/this problem will be fixed soon/este problema será corrigido em breve/;
	s/\(potato\)/("potato")/;
	s/\(woody\)/("woody")/;
	s/\(sarge\)/("sarge")/;
	s/\(sid\)/("sid")/;

	print DST $_;
}

close SRC;
close DST;

# We're done
print "Copying done, remember to edit $dstfile\n";
