Bonjour,

Je sollicite de l'aide pour une modification d'un script perl , c'est un programme perl qui sert à la redirection d'url sur un outil squid , pour lesquels je souhaite ajouter un autre condition dans la boucle ( prise en compte de l'url de Production) :

Il fixe les problemes de redirection sur les url de test ( $INTERNALIP|$TESTURL):$TESTPORT/ ), et je souhaiterai qu'il fasse la même chose pour les url de Prod ($INTERNALIP|$PRODUCTIONURL):$PRODPORT)

J'ai tenté une modification en rajoutant un condition elseif , cependant en testant ça fonctionne pour l'url de Production et plus pour celle de Test. Est ce que j'ai raté qql chose dans la modification ?

Merci de votre aide.

programme à l'origine :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#!/usr/bin/perl
 
$INTERNALIP="15.40.40.36";
$PRODUCTIONURL="add.prt.fr"; 
$TESTURL="test.add.prt.fr"; 
$TESTPORT="8001";
 
# turn off write buffering 
$| = 1;
while (<>) { 
 
  # get the URL from the request 
  chomp($url = $_);
 
  if ($url =~ m/($INTERNALIP|$TESTURL):$TESTPORT/)
  {
    # fix up the cname and port
    $url =~ s^:$TESTPORT^^; 
    $url =~ s^$INTERNALIP^$TESTURL^; 
 
    # fix the protocol 
    $url =~ s^https://^http://^; 
  }
  else
  {
    # fix up the name 
    $url =~ s^$INTERNALIP^$PRODUCTIONURL^; 
 
    # fix the protocol 
    $url =~ s^http://^https://^; 
  }
 
  # return the fixed URL to squid 
  print "$url\n"; 
}
programme modifiée :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#!/usr/bin/perl
 
$INTERNALIP="15.40.40.36";
$PRODUCTIONURL="add.prt.fr"; 
$TESTURL="test.add.prt.fr"; 
$TESTPORT="8001";
$PRODPORT="8000";
 
# turn off write buffering 
$| = 1;
while (<>) { 
 
  # get the URL from the request 
  chomp($url = $_);
 
  if ($url =~ m/($INTERNALIP|$TESTURL):$TESTPORT/)
  {
    # fix up the cname and port
    $url =~ s^:$TESTPORT^^; 
    $url =~ s^$INTERNALIP^$TESTURL^; 
 
    # fix the protocol 
    $url =~ s^https://^http://^; 
  }
elsif ($url =~ m/($INTERNALIP|$PRODUCTIONURL):$PRODPORT/)
 
  {
 
    # fix up the cname and port
 
    $url =~ s^:$PRODPORT^^; 
 
    $url =~ s^$INTERNALIP^$PRODURL^; 
 
 
 
    # fix the protocol 
 
    $url =~ s^https://^http://^; 
 
  }
  else
  {
    # fix up the name 
    $url =~ s^$INTERNALIP^$PRODUCTIONURL^; 
 
    # fix the protocol 
    $url =~ s^http://^https://^; 
  }
 
  # return the fixed URL to squid 
  print "$url\n"; 
}