Projet

Général

Profil

« Précédent | Suivant » 

Révision a9d6ac9a

Ajouté par jim-p il y a plus de 9 ans

Do not execute on GET, only pre-fill Host box so the user can press the button to execute. Turn alias creation links into submit buttons for POST. While here, remove some backticks and simplify a little.

Voir les différences:

usr/local/www/diag_dns.php
34 34
$pgtitle = array(gettext("Diagnostics"),gettext("DNS Lookup"));
35 35
require("guiconfig.inc");
36 36

  
37
/* Cheap hack to support both $_GET and $_POST */
38
if ($_GET['host'])
39
	$_POST = $_GET;
40

  
41
$host = trim($_POST['host'], " \t\n\r\0\x0B[];\"'");
37
$host = trim($_REQUEST['host'], " \t\n\r\0\x0B[];\"'");
42 38
$host_esc = escapeshellarg($host);
43 39

  
44
if($_GET['createalias'] == "true" && (is_hostname($host) || is_ipaddr($host))) {
45
	if($_GET['override'])
40
$a_aliases = &$config['aliases']['alias'];
41
$aliasname = str_replace(array(".","-"), "_", $host);
42
$alias_exists = false;
43
$counter=0;
44
foreach($a_aliases as $a) {
45
	if($a['name'] == $aliasname) {
46
		$alias_exists = true;
47
		$id=$counter;
48
	}
49
	$counter++;
50
}
51

  
52
if(isset($_POST['create_alias']) && (is_hostname($host) || is_ipaddr($host))) {
53
	if($_POST['override'])
46 54
		$override = true;
47
	$a_aliases = &$config['aliases']['alias'];
48
	$type = "hostname";
49 55
	$resolved = gethostbyname($host);
56
	$type = "hostname";
50 57
	if($resolved) {
51
		$dig=`dig "{$host_esc}" A | grep "{$host_esc}" | grep -v ";" | awk '{ print $5 }'`;
52
		$resolved = explode("\n", $dig);
58
		$resolved = array();
59
		exec("/usr/bin/dig {$host_esc} A | /usr/bin/grep {$host_esc} | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $5 }'", $resolved);
53 60
		$isfirst = true;
54 61
		foreach($resolved as $re) {
55 62
			if($re <> "") {
56 63
				if(!$isfirst) 
57 64
					$addresses .= " ";
58
				$addresses .= $re . "/32";
65
				$addresses .= rtrim($re) . "/32";
59 66
				$isfirst = false;
60 67
			}
61 68
		}
62 69
		$newalias = array();
63
		$aliasname = str_replace(array(".","-"), "_", $host);
64
		$alias_exists = false;
65
		$counter=0;
66
		foreach($a_aliases as $a) {
67
			if($a['name'] == $aliasname) {
68
				$alias_exists = true;
69
				$id=$counter;
70
			}
71
			$counter++;
72
		}
73 70
		if($override) 
74 71
			$alias_exists = false;
75 72
		if($alias_exists == false) {
......
100 97
	} else {
101 98
		// Test resolution speed of each DNS server.
102 99
		$dns_speeds = array();
103
		$resolvconf_servers = `grep nameserver /etc/resolv.conf | cut -f2 -d' '`;
104
		$dns_servers = explode("\n", trim($resolvconf_servers));
100
		$dns_servers = array();
101
		exec("/usr/bin/grep nameserver /etc/resolv.conf | /usr/bin/cut -f2 -d' '", $dns_servers);
105 102
		foreach ($dns_servers as $dns_server) {
106
			$query_time = `dig {$host_esc} @{$dns_server} | grep Query | cut -d':' -f2`;
103
			$query_time = exec("/usr/bin/dig {$host_esc} " . escapeshellarg("@" . trim($dns_server)) . " | /usr/bin/grep Query | /usr/bin/cut -d':' -f2");
107 104
			if($query_time == "")
108 105
				$query_time = gettext("No response");
109 106
			$new_qt = array();
110 107
			$new_qt['dns_server'] = $dns_server;
111
			$new_qt['query_time'] = $query_time;			
108
			$new_qt['query_time'] = $query_time;
112 109
			$dns_speeds[] = $new_qt;
113 110
			unset($new_qt);
114 111
		}
......
129 126
			$type = "hostname";
130 127
			$resolved = gethostbyname($host);
131 128
			if($resolved) {
132
				$dig=`dig {$host_esc} A | grep {$host_esc} | grep -v ";" | awk '{ print $5 }'`;
133
				$resolved = explode("\n", $dig);
129
				$resolved = array();
130
				exec("/usr/bin/dig {$host_esc} A | /usr/bin/grep {$host_esc} | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $5 }'", $resolved);
134 131
			}
135 132
			$hostname = $host;
136 133
			if ($host != $resolved)
......
202 199
				} else {
203 200
					echo $resolved; 
204 201
				} 
205
				if($found > 0) {
206
					if($alias_exists) {
207
						echo "<br/><font size='-2'>An alias already exists for the hostname " . htmlspecialchars($host) . ".  To overwrite, click <a href='diag_dns.php?host=" . trim(urlencode(htmlspecialchars($host))) . "&createalias=true&override=true'>here</a>.";
208
					} else { 
209
						if(!$createdalias) {
210
							echo "<br/><font size='-2'><a href='diag_dns.php?host=" . trim(urlencode(htmlspecialchars($host))) . "&createalias=true'>Create alias</a> out of these entries.";
211
						} else {
212
							echo "<br/><font size='-2'>Alias created with name " . htmlspecialchars($newalias['name']);
213
						}
202
				if($found > 0) { ?>
203
					<br/><font size='-2'>
204
				<?PHP	if($alias_exists) { ?>
205
							An alias already exists for the hostname <?= htmlspecialchars($host) ?>. <br />
206
							<input type="hidden" name="override" value="true"/>
207
							<input type="submit" name="create_alias" value="Overwrite Alias"/>
208
				<?PHP	} else {
209
						if(!$createdalias) { ?>
210
							<input type="submit" name="create_alias" value="Create Alias from These Entries"/>
211
					<?PHP	} else { ?>
212
							Alias created with name <?= htmlspecialchars($newalias['name']) ?>
213
					<?PHP	}
214 214
					}
215 215
				}
216 216
?>
......
273 273
		</td>
274 274
		</tr>
275 275
	</table>
276
</form>
277 276
</td></tr></table>
277
</form>
278 278
<?php include("fend.inc"); ?>

Formats disponibles : Unified diff