bpt22 pushed to branch main at Root / DBRoot / PostgreSQL

Commits:

1 changed file:

Changes:

  • ansible/verify-hostnames.sh
    1 1
     #!/bin/sh
    
    2 2
     
    
    3
    -set -x
    
    4
    -
    
    5 3
     pg_hba="$1"
    
    6 4
     
    
    7 5
     # Extrair hostnames não-IP e não-localhost
    
    8 6
     hostnames=$(
    
    9 7
     awk '
    
    10
    -  $1 == "hostssl" &&
    
    11
    -  $4 != "" &&
    
    12
    -  $4 != "localhost" &&
    
    13
    -  $4 !~ /^([0-9]{1,3}\.){3}[0-9]{1,3}(\/[0-9]+)?$/ &&
    
    14
    -  $4 !~ /:/ { print $4 }
    
    8
    +function is_ipv4(addr) {
    
    9
    +  return (addr ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(\/[0-9]+)?$/)
    
    10
    +}
    
    11
    +
    
    12
    +$1 == "hostssl" {
    
    13
    +  addr = $4
    
    14
    +
    
    15
    +  # Ignora se for vazio, localhost ou conter ":"
    
    16
    +  if (addr == "" || addr == "localhost" || index(addr, ":") > 0) {
    
    17
    +    next
    
    18
    +  }
    
    19
    +
    
    20
    +  # Ignora se for IP (com ou sem máscara)
    
    21
    +  if (is_ipv4(addr)) {
    
    22
    +    next
    
    23
    +  }
    
    24
    +
    
    25
    +  print addr
    
    26
    +}
    
    15 27
     ' "$pg_hba"
    
    16 28
     )
    
    17 29