search.php
author rejo
Mon, 31 Mar 2008 21:10:19 +0000
changeset 120 982f722376b4
parent 119 f74e4f88b680
child 126 cb06e3e29ed8
permissions -rw-r--r--
[feladat @ 223] Bugfix. No domain id was provided when entering 'edit record' page from a search query. Changed code so 'edit record' does not rely on domain id provided by user but determines it from the record id that is about to be changed. This closes ticket:31.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     1
<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     2
119
f74e4f88b680 [feladat @ 222]
rejo
parents: 110
diff changeset
     3
/*  Poweradmin, a friendly web-based admin tool for PowerDNS.
47
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     4
 *  See <https://rejo.zenger.nl/poweradmin> for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     5
 *
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     6
 *  Copyright 2007, 2008  Rejo Zenger <rejo@zenger.nl>
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     7
 *
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     9
 *  it under the terms of the GNU General Public License as published by
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    11
 *  (at your option) any later version.
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    12
 *
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    16
 *  GNU General Public License for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    17
 *
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    20
 */
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    21
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    22
require_once('inc/toolkit.inc.php');
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    23
include_once('inc/header.inc.php');
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    24
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    25
if (!(verify_permission(search))) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    26
	error(ERR_PERM_SEARCH);
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    27
	include_once('inc/footer.inc.php');
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    28
	exit;
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    29
	
79
0c0aa144356a [feladat @ 156]
peter
parents: 71
diff changeset
    30
} else {
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    31
	echo "     <h2>" . _('Search zones and records') . "</h2>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    32
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    33
	if ($_POST['submit']) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    34
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    35
		if (verify_permission(zone_content_view_others)) { $perm_view = "all" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    36
		elseif (verify_permission(zone_content_view_own)) { $perm_view = "own" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    37
		else { $perm_view = "none" ; }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    38
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    39
		if (verify_permission(zone_content_edit_others)) { $perm_edit = "all" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    40
		elseif (verify_permission(zone_content_edit_own)) { $perm_edit = "own" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    41
		else { $perm_edit = "none" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    42
	
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    43
		$holy_grail = $_POST['query'];
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    44
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    45
		$result = search_zone_and_record($holy_grail,$perm_view);
79
0c0aa144356a [feladat @ 156]
peter
parents: 71
diff changeset
    46
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    47
		if (is_array($result['zones'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    48
			echo "     <h3>" . _('Zones found') . ":</h3>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    49
			echo "     <table>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    50
			echo "      <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    51
			echo "       <th>&nbsp;</th>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    52
			echo "       <th>" . _('Name') . "</th>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    53
			echo "       <th>" . _('Type') . "</th>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    54
			echo "       <th>" . _('Master') . "</th>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    55
			echo "      </tr>\n";
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    56
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    57
			foreach ($result['zones'] as $zone) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    58
				echo "      <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    59
				echo "          <td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    60
				echo "           <a href=\"edit.php?id=" . $zone['zid'] . "\"><img src=\"images/edit.gif\" title=\"" . _('Edit zone') . " " . $zone['name'] . "\" alt=\"[ " . _('Edit zone') . " " . $zone['name'] . " ]\"></a>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    61
				if ( $perm_edit != "all" || $perm_edit != "none") {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    62
					$user_is_zone_owner = verify_user_is_owner_zoneid($zone['zid']);
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    63
				}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    64
				if ( $perm_edit == "all" || ( $perm_edit == "own" && $user_is_zone_owner == "1") ) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    65
					echo "           <a href=\"delete_domain.php?id=" . $zone['zid'] . "\"><img src=\"images/delete.gif\" title=\"" . _('Delete zone') . " " . $zone['name'] . "\" alt=\"[ ". _('Delete zone') . " " . $zone['name'] . " ]\"></a>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    66
				}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    67
				echo "          </td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    68
				echo "       <td>" . $zone['name'] . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    69
				echo "       <td>" . $zone['type'] . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    70
				if ($zone['type'] == "SLAVE") {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    71
					echo "       <td>" . $zone['master'] . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    72
				} else {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    73
					echo "       <td>&nbsp;</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    74
				}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    75
				echo "      </tr>\n";
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    76
			}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    77
			echo "     </table>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    78
		}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    79
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    80
		if (is_array($result['records'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    81
			echo "     <h3>" . _('Records found') . ":</h3>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    82
			echo "     <table>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    83
			echo "      <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    84
			echo "       <th>&nbsp;</th>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    85
			echo "       <th>" . _('Name') . "</th>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    86
			echo "       <th>" . _('Type') . "</th>\n";
110
455405c757e1 [feladat @ 210]
rejo
parents: 82
diff changeset
    87
			echo "       <th>" . _('Priority') . "</th>\n";
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    88
			echo "       <th>" . _('Content') . "</th>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    89
			echo "       <th>" . _('TTL') . "</th>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    90
			echo "      </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    91
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    92
			foreach ($result['records'] as $record) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    93
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    94
				echo "      <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    95
				echo "          <td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    96
				echo "           <a href=\"edit_record.php?id=" . $record['rid'] . "\"><img src=\"images/edit.gif\" title=\"" . _('Edit record') . " " . $record['name'] . "\" alt=\"[ " . _('Edit record') . " " . $record['name'] . " ]\"></a>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    97
				if ( $perm_edit != "all" || $perm_edit != "none") {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    98
					$user_is_zone_owner = verify_user_is_owner_zoneid($record['zid']);
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    99
				}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   100
				if ( $perm_edit == "all" || ( $perm_edit == "own" && $user_is_zone_owner == "1") ) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   101
					echo "           <a href=\"delete_record.php?id=" . $record['rid'] . "\"><img src=\"images/delete.gif\" title=\"" . _('Delete record') . " " . $record['name'] . "\" alt=\"[ ". _('Delete record') . " " . $record['name'] . " ]\"></a>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   102
				}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   103
				echo "          </td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   104
				echo "       <td>" . $record['name'] . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   105
				echo "       <td>" . $record['type'] . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   106
				if ($record['type'] == "MX") {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   107
					echo "       <td>" . $record['prio'] . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   108
				} else {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   109
					echo "       <td>&nbsp;</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   110
				}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   111
				echo "       <td>" . $record['content'] . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   112
				echo "       <td>" . $record['ttl'] . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   113
				echo "      </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   114
			}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   115
			echo "     </table>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   116
		}
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   117
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   118
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   119
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   120
	echo "     <h3>" . _('Query') . ":</h3>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   121
	echo "     <table>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   122
	echo "      <form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   123
	echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   124
	echo "        <td class=\"n\">" . _('Enter a hostname or IP address') . "</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   125
	echo "        <td class=\"n\"><input type=\"text\" class=\"input\" name=\"query\" value=\"" . $holy_grail . "\"></td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   126
	echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   127
	echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   128
	echo "        <td class=\"n\">&nbsp;</td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   129
	echo "        <td class=\"n\"><input type=\"submit\" class=\"button\" name=\"submit\" value=\"" . _('Search') . "\"></td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   130
	echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   131
	echo "      </form>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   132
	echo "     </table>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   133
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   134
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   135
include_once('inc/footer.inc.php');
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   136
?>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   137