search.php
author peter
Sat, 29 Dec 2007 14:42:34 +0000
changeset 55 a885f557678f
parent 50 ed18c8317cff
child 62 ce4919f37489
permissions -rwxr-xr-x
[feladat @ 102] Fixed the queries so both MySQL and PostgreSQL are supported. The 'REGEXP' queries are currently fixed with a workaround.
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
47
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     3
/*  PowerAdmin, a friendly web-based admin tool for PowerDNS.
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');
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    23
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    24
if (isset($_POST['s_submit']) || isset($_POST['q']))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    25
{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    26
	$submitted=true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    27
	$search_result=search_record($_POST['q']);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    28
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    29
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    30
// we will continue after the search form ... 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    31
include_once('inc/header.inc.php');
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    32
?>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    33
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    34
    <h2><? echo _('Search zones or records'); ?></h2>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    35
    <h3>Query</h3>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    36
    <table>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    37
     <form method="post" action="<? echo $_SERVER['PHP_SELF']?>">
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    38
      <tr>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    39
       <td class="n"><? echo _('Enter a hostname or IP address'); ?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    40
       <td class="n"><input type="text" class="input" name="q"></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    41
      </tr>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    42
      <tr>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    43
       <td class="n">&nbsp;</td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    44
       <td class="n"><input type="submit" class="button" name="s_submit" value="<? echo _('Search'); ?>"></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    45
      </tr>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    46
     </form>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    47
    </table>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    48
      
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    49
<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    50
// results
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    51
if ($submitted)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    52
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    53
	echo '<br><br>';
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    54
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    55
  	// let's check if we found any domains ...
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    56
	if (count($search_result) == 2 && count($search_result['domains']))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    57
  	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    58
	?>
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    59
	<h4><? echo _('Zones found'); ?>:</h4>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    60
	<table>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    61
	 <tr>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    62
	  <th>&nbsp;</th>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    63
	  <th><? echo _('Name'); ?></th>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    64
	  <th><? echo _('Records'); ?></th>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    65
	  <th><? echo _('Owner'); ?></th>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    66
         </tr>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    67
<?php
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    68
foreach($search_result['domains'] as $d)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    69
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    70
?>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    71
         <tr>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    72
<?
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    73
  if (level(5))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    74
  {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    75
  ?>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    76
     <td class="n">
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    77
      <a href="edit.php?id=<? echo $d["id"] ?>"><img src="images/edit.gif" title="<? echo _('Edit zone') . " " . $d['name']; ?>" alt="[ <? echo _('Edit zone') . " " . $d['name']; ?> ]"></a>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    78
      <a href="delete_domain.php?id=<? echo $d["id"] ?>"><img src="images/delete.gif" title="<? print _('Delete zone') . " " . $d['name']; ?>" alt="[<? echo _('Delete zone') . " " . $d['name']; ?>]"></a>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    79
     </td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    80
<?
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    81
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    82
else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    83
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    84
?>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    85
     <td class="n">
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    86
      &nbsp;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    87
     </td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    88
<?
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    89
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    90
?>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    91
     <td class="y"><? echo $d['name']?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    92
     <td class="y"><? echo $d['numrec']?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    93
     <td class="y"><? echo get_owner_from_id($d['owner'])?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    94
    </tr>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    95
			<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    96
		} // end foreach ...
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    97
		?>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    98
	</table>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    99
	<br><br>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   100
	<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   101
	} // end if
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   102
	
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   103
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   104
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   105
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   106
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   107
	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   108
	// any records ?!
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   109
	if(count($search_result['records']))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   110
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   111
		?>
2
9a485c41cfcf [feladat @ 3]
rejo
parents: 1
diff changeset
   112
		<b><? echo _('Records found'); ?>:</b>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   113
		<p>
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   114
		<table>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   115
			<tr>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   116
				<td class="n">&nbsp;</td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   117
				<td class="n"><? echo _('Name'); ?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   118
				<td class="n"><? echo _('Type'); ?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   119
				<td class="n"><? echo _('Content'); ?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   120
				<td class="n"><? echo _('Priority'); ?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   121
				<td class="n"><? echo _('TTL'); ?></td>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   122
			</tr>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   123
		<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   124
		foreach($search_result['records'] as $r)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   125
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   126
		?>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   127
			<tr>
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   128
				<td class="n">
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   129
			<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   130
			if (($r["type"] != "SOA" && $r["type"] != "NS") ||
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   131
			  ($GLOBALS["ALLOW_SOA_EDIT"] && $r["type"] == "SOA") ||
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   132
			  ($GLOBALS["ALLOW_NS_EDIT"] && $r["type"] == "NS") ||
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   133
			  ($r["type"] == "NS" && get_name_from_record_id($r["id"]) != get_domain_name_from_id(recid_to_domid($r["id"])) && 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   134
			  $GLOBALS["ALLOW_NS_EDIT"] != 1))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   135
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   136
				?>
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   137
				<a href="edit_record.php?id=<? echo $r['id']?>&amp;domain=<? echo $r['domain_id']?>"><img src="images/edit.gif" alt="[ <? echo _('Edit record'); ?> ]" border="0"></a>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   138
				<a href="delete_record.php?id=<? echo $r['id']?>&amp;domain=<? echo $r['domain_id']?>"><img src="images/delete.gif" alt="[ <? echo _('Delete record'); ?> ]" border="0"></a>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   139
				<?php 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   140
			} // big if ;-)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   141
			?>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   142
			</td>
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   143
			<td class="y"><? echo $r['name']?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   144
			<td class="y"><? echo $r['type']?></td>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   145
			<td class="y"><? echo $r['content']?></td>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   146
			<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   147
			if ($r['prio'] != 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   148
			{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   149
				?><td class="y"><? echo $r['prio']?></td><?php
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   150
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   151
			else 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   152
			{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   153
			?><td class="n"></td><?php
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   154
			} // else
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   155
			?><td class="y"><? echo $r['ttl']?></td>
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   156
			</tr>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   157
			<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   158
		} // foreach
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   159
	?>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   160
	</table>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   161
	<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   162
	} // if
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   163
	if(count($search_result['domains']) == 0 && count($search_result['records']) == 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   164
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   165
	?>
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   166
		<table border="0" cellspacing="4">
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   167
			<tr>
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   168
				<td width="510" class="n">
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   169
				<? echo _('Nothing found for query'); ?> "<? echo $_POST['q']?>"
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   170
				</td>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   171
			</tr>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   172
		</table>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   173
	<?
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   174
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   175
		
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   176
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   177
include_once('inc/footer.inc.php');
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   178
?>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   179