File: listlinks.php

package info (click to toggle)
htcheck-php 1%3A2.0.0~rc1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 344 kB
  • ctags: 903
  • sloc: php: 3,258; makefile: 7
file content (504 lines) | stat: -rw-r--r-- 12,759 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
<?php

//    listlinks.php
//    Shows a List of Links previously set with a form
//
//    Part of the ht://Check package
//
//    Copyright (c) 1999-2004 Comune di Prato - Prato - Italy
//    Author: Gabriele Bartolini - Prato - Italy <angusgb@users.sourceforge.net>
//
//    For copyright details, see the file COPYING in your distribution
//    or the GNU General Public License version 2 or later 
//    <http://www.gnu.org/copyleft/gpl.html>
//
//    $Id: listlinks.php,v 1.25 2004/06/29 10:06:25 angusgb Exp $

///////
   //    Global settings
///////

include ("./include/global.inc.php");


if (!isset($dbname))
{
   // Error
   DisplayErrMsg($strErrorNoDBSelected);
   echo "<a href=\"index.php\">" . $strMainPage . "</a>";
   die;
}

$strSection=$strListofLinks;
$pagetitle = "Database: $dbname - " . $strSection;
eval("\$strhome = \"$strDBHome \";");
$linkbar = "<a href=\"index.php?dbname=". $dbname . "\">". $strhome."</a>";

// A database has been selected

include ("./include/header.inc.php");

if (isset ($cmd))
{

   if (!isset($initpage))
      $initpage=0;

   if (!isset($pagesize))
      $pagesize=30;

   $strwhere = "";
   $otherinfo = '&cmd=' . urlencode($cmd);
   
   if (isset($linkresult) && $linkresult!="AllLinks")
   {
      $strwhere = $strwhere . "AND Link.LinkResult $whatlinkresult '$linkresult' ";
      $otherinfo = $otherinfo . '&whatlinkresult=' . urlencode($whatlinkresult)
         . '&linkresult=' . urlencode($linkresult);
   }
   
   if (isset($linktype) && $linktype!="AllLinks")
   {
      $strwhere = $strwhere . "AND Link.LinkType $whatlinktype '$linktype' ";
      $otherinfo = $otherinfo . '&whatlinktype=' . urlencode($whatlinktype)
         . '&linktype=' . urlencode($linktype);
   }

   if (isset($linkdomain) && $linkdomain!="AllLinks")
   {
      $strwhere = $strwhere . "AND Link.LinkDomain $whatlinkdomain '$linkdomain' ";
      $otherinfo = $otherinfo . '&whatlinkdomain=' . urlencode($whatlinkdomain)
         . '&linkdomain=' . urlencode($linkdomain);
   }

   $num=count($src); // Count the elements

   // Set the source filter   
   for ($i=0; $i<$num; $i++)
   {
      if (isset($src[$i]) && $src[$i] && strlen($src[$i]) > 0)
      {
         if(isset($whatsrc[$i]))
         {
            $strwhere = $strwhere . "AND Url.Url " . $whatsrc[$i]
               . " '" . $src[$i] . "' ";
            $otherinfo = $otherinfo . "&whatsrc[$i]=" . urlencode($whatsrc[$i])
               . "&src[$i]=" . urlencode($src[$i]);
          }
      }
   }
   
   $num=count($dest); // Count the elements

   // Set the destination filter   
   for ($i=0; $i<$num; $i++)
   {
      if (isset($dest[$i]) && $dest[$i] && strlen($dest[$i]) > 0)
      {
         if(isset($whatdest[$i]))
         {
            $strwhere = $strwhere . "AND Schedule.Url " . $whatdest[$i]
               . " '" . $dest[$i] . "' ";
            $otherinfo = $otherinfo . "&whatdest[$i]="
               . urlencode($whatdest[$i]) . "&dest[$i]=" . urlencode($dest[$i]);
          }
      }
   }

   $num=count($anchor); // Count the elements

   // Set the destination filter   
   for ($i=0; $i<$num; $i++)
   {
      if (isset($anchor[$i]) && $anchor[$i] && strlen($anchor[$i]) > 0)
      {
         if(isset($whatanchor[$i]))
         {
            $strwhere = $strwhere . "AND Link.Anchor " . $whatanchor[$i]
               . " '" . $anchor[$i] . "' ";
            $otherinfo = $otherinfo . "&whatanchor[$i]="
               . urlencode($whatanchor[$i]) . "&anchor[$i]=" . urlencode($anchor[$i]);
          }
      }
   }

   // Show all the URLs, retrieved ones as well as not
   $strGenSQL = "SELECT Link.*, "
      . "Url.Url as UrlSrc, "
      . "Schedule.Url as UrlDest, "
      . "HtmlStatement.Statement "
      . "FROM Url, Schedule, Link "
      . "LEFT JOIN HtmlStatement "
      . "ON HtmlStatement.IDUrl = Link.IDUrlSrc "
      . "AND HtmlStatement.TagPosition = Link.TagPosition "
      . "WHERE Schedule.IDUrl = Link.IDUrlDest "
      . "AND Url.IDUrl = Link.IDUrlSrc "
      . $strwhere
      . " ORDER BY UrlSrc ASC "
      . " LIMIT " . $initpage . ", " . $pagesize;

   if (!isset($count))
   {
      $strCountSQL="select count(*) from Schedule, Url, Link "
         . "LEFT JOIN HtmlStatement "
         . "ON HtmlStatement.IDUrl = Link.IDUrlSrc "
         . "AND HtmlStatement.TagPosition = Link.TagPosition "
         . "WHERE Schedule.IDUrl = Link.IDUrlDest "
         . "AND Url.IDUrl = Link.IDUrlSrc "
         . $strwhere;

      $count = $MyDB->CountEntries($strCountSQL,$dbname,true);
      if ($count<0)
      {
         DisplayErrMsg($MyDB->errmsg);
         return;
      }
      $MyDB->Free();
   }

?>

<!--
<?php echo $strCountSQL; ?><br>
Records found: <?php echo $count; ?><br>
<?php echo $strGenSQL; ?><br>
-->


<?php

// HTTP results
   
?>
<h4><?php echo $strSection; ?></h4>
<p>
<?
if ($count) printf ($strListPageInfo, number_format($initpage+1), number_format(($initpage+$pagesize)>$count?$count:$initpage+$pagesize), number_format($count));
?>  
<br>
<?php WritePageLink($initpage, $pagesize, $count, $dbname, $otherinfo); ?>
</p>

<?php

   $result=$MyDB->Query($dbname, $strGenSQL);
   
   if ($result)
   {
      DisplayErrMsg($MyDB->errmsg);
      die;
   }
   
   if ($MyDB->NumRows())
   {
      // At least one occurrence found

?>
<table>
<tr>
<th> N. </th>
<th> <?php echo $strReferencingUrl; ?> \ <?php echo $strReferencedUrl; ?> \ <?php echo $strHTMLStatement; ?> </th>
<th class="noprint"> <?php echo $strLinkType; ?> </th>
<th class="noprint"> <?php echo $strLinkResult; ?> </th>
<th class="noprint"><?php echo $strShow; ?></th>
</tr>
      
<?php
      $i=0;
      while ($row = $MyDB->FetchArray())
      {
         // Get next row
         $i++;

         // If HTML statement to be shown is too large, we cut it, depending
         // on MaxTagStrLenght setting in 'global.inc'
         $htmlstat = $row["Statement"];
         
         if (empty($htmlstat))
            $htmlstat = $strRedirection;
         else if (strlen($htmlstat) > $MaxTagStrLength)
            $htmlstat = '<I>' . substr($htmlstat, 0, $MaxTagStrLength) . '...</I>';

         ($i % 2)? $trclass='odd':$trclass='even';
?>
 <tr class="<?php echo $trclass; ?>">
   <td align="right"> <?php echo number_format($initpage+$i); ?> </td>
   <td class="url" align="left">
   <strong><?php echo $strReferencingUrl; ?></strong>: <a href="showurl.php?dbname=<?php echo $dbname; ?>&IDUrl=<?php echo $row["IDUrlSrc"]; ?>"><?php echo GetURL($row["UrlSrc"]); ?></a><br>
   <strong><?php echo $strReferencedUrl; ?></strong>: <a href="showurl.php?dbname=<?php echo $dbname; ?>&IDUrl=<?php echo $row["IDUrlDest"]; ?>"><?php echo GetURL($row["UrlDest"]); ?></a><br>
   <strong><?php echo $strHTMLStatement; ?></strong>: <?php echo $htmlstat; ?></td>
   <td align="center" class="noprint"><?php echo GetTextString($row["LinkType"]) ; ?></td>
   <td align="center" valign="middle" class="noprint"><?php
   // Show the image or the text
   if ($ShowIcons)
   {
?>
<IMG src="img/<?php echo $row["LinkResult"]; ?>.png" alt="<?php
   echo GetTextString($row["LinkResult"]); ?>"
   width="40" height="35" border=1" bordercolor="black">
<?php
   }
   else echo GetTextString($row["LinkResult"]); // No Icons
 ?></td>
   <td align="center" class="noprint">
<?php
   if (strcmp($row["LinkType"], "Redirection"))  // It's not a redirection
   {
?>
   <a href="showlink.php?dbname=<?php echo $dbname; ?>&IDUrl=<?php echo $row["IDUrlSrc"]; ?>&TagPosition=<?php echo $row["TagPosition"]; ?>&AttrPosition=<?php echo $row["AttrPosition"]; ?>"><?php echo $strShowLink; ?></a>
<?php
   }
   else echo '-';
?>
   </td>
 </tr>
<?php         
      }

?>
</table>
<?php      
      // Page management

      WritePageLink($initpage, $pagesize, $count, $dbname,$otherinfo);
   }
   else
   {
?>
<p><?php echo $strNoOccurrencies; ?></p>

<?php
   }

   $MyDB->Free();
}
else
{
?>
<p><?php echo $strFilterLinks; ?>:</p>

<form action="<?php echo $PHP_SELF; ?>" method="GET">
<input type="hidden" name="dbname" value="<?php echo $dbname; ?>">
<table>

<?php

   // Retrieving all the LinkResults found
   $strSQL="SELECT count(*) as Count, LinkResult "
      . "FROM Link GROUP BY LinkResult "
      . "ORDER BY LinkResult ASC";

   $result=$MyDB->Query($dbname, $strSQL);
   
   if ($result)
   {
      DisplayErrMsg($MyDB->errmsg);
      die;
   }
   
   if ($MyDB->NumRows())
   {
?>
<tr>
<td colspan="2">
<strong><?php echo $strLinkResult; ?> : </strong>
<select name="whatlinkresult">
 <option value="="><?php echo $strLike; ?></option>
 <option value="!="><?php echo $strNotLike; ?></option>
</select>
<select name="linkresult">
 <option value="AllLinks"><?php echo $strAllLinks; ?></option>
<?php
      while ($row = $MyDB->FetchArray())
      {
?>
 <option value="<?php echo $row["LinkResult"]; ?>">
   <?php echo GetTextString($row["LinkResult"]); ?> (<?php echo $row["Count"]; ?>)</option>
<?php
      }
?>
</select>
</td>
</tr>

<?php

   }

   $MyDB->Free();

   // Retrieving all the LinkType found
   $strSQL="SELECT count(*) as Count, LinkType "
      . "FROM Link GROUP BY LinkType "
      . "ORDER BY LinkType ASC";

   $result=$MyDB->Query($dbname, $strSQL);
   
   if ($result)
   {
      DisplayErrMsg($MyDB->errmsg);
      die;
   }
   
   if ($MyDB->NumRows())
   {

?>
<tr>
<td colspan="2">
<strong><?php echo $strLinkType; ?> : </strong>
<select name="whatlinktype">
 <option value="="><?php echo $strLike; ?></option>
 <option value="!="><?php echo $strNotLike; ?></option>
</select>
<select name="linktype">
 <option value="AllLinks"><?php echo $strAllLinks; ?></option>
<?php
      while ($row = $MyDB->FetchArray())
      {
?>
 <option value="<?php echo $row["LinkType"]; ?>">
   <?php echo GetTextString($row["LinkType"]); ?> (<?php echo $row["Count"]; ?>)</option>
<?php
      }
?>
</select>
</td>
</tr>
<?php
   }

   $MyDB->Free();

   // Retrieving all the LinkDomain found
   $strSQL="SELECT count(*) as Count, LinkDomain "
      . "FROM Link GROUP BY LinkDomain "
      . "ORDER BY LinkDomain ASC";

   $result=$MyDB->Query($dbname, $strSQL);
   
   if ($result)
   {
      DisplayErrMsg($MyDB->errmsg);
      die;
   }
   
   if ($MyDB->NumRows())
   {

?>
<tr>
<td colspan="2">
<strong><?php echo $strLinkDomain; ?> : </strong>
<select name="whatlinkdomain">
 <option value="="><?php echo $strLike; ?></option>
 <option value="!="><?php echo $strNotLike; ?></option>
</select>
<select name="linkdomain">
 <option value="AllLinks"><?php echo $strAllLinks; ?></option>
<?php
      while ($row = $MyDB->FetchArray())
      {
?>
 <option value="<?php echo $row["LinkDomain"]; ?>">
   <?php echo GetTextString($row["LinkDomain"]); ?> (<?php echo $row["Count"]; ?>)</option>
<?php
      }
?>
</select>
</td>
</tr>
<?php
   }

   $MyDB->Free();

?>

<tr>
<th>
<?php echo $strReferencingUrl; ?> : 
</th>
<th>
<?php echo $strReferencedUrl; ?> : 
</th>
</tr>
<?php
   for ($i=0; $i<$NumFilterRows; $i++)
   {
?>
<tr>
<td>
<select name="whatsrc[<?php echo $i; ?>]">
 <option value="LIKE"><?php echo $strLike; ?></option>
 <option value="NOT LIKE"><?php echo $strNotLike; ?></option>
 <option value="REGEXP"><?php echo $strRegExp; ?></option>
 <option value="NOT REGEXP"><?php echo $strNotRegExp; ?></option>
</select>
<input name="src[<?php echo $i; ?>]" type="text" value="<?php echo (is_array($src)?$src[$i]:''); ?>"
   size="30" maxlength="255">
</td>
<td>
<select name="whatdest[<?php echo $i; ?>]">
 <option value="LIKE"><?php echo $strLike; ?></option>
 <option value="NOT LIKE"><?php echo $strNotLike; ?></option>
 <option value="REGEXP"><?php echo $strRegExp; ?></option>
 <option value="NOT REGEXP"><?php echo $strNotRegExp; ?></option>
</select>
<input name="dest[<?php echo $i; ?>]" type="text" value="<?php echo (is_array($dest)?$dest[$i]:''); ?>"
   size="30" maxlength="255">
</td>
</tr>
<?php
   }
?>

<tr>
<th colspan="2">
<?php echo $strAnchor; ?> :
</th>
</tr>
<?php
   for ($i=0; $i<$NumFilterRows; $i++)
   {
?>
<tr>
<td colspan="2">
<select name="whatanchor[<?php echo $i; ?>]">
 <option value="LIKE"><?php echo $strLike; ?></option>
 <option value="NOT LIKE"><?php echo $strNotLike; ?></option>
 <option value="REGEXP"><?php echo $strRegExp; ?></option>
 <option value="NOT REGEXP"><?php echo $strNotRegExp; ?></option>
</select>
<input name="anchor[<?php echo $i; ?>]" type="text" value="<?php echo $anchor[$i]; ?>"
   size="30" maxlength="255">
</td>
</tr>
<?php
   }
?>



<tr>
<td colspan="2" align="right">
<input type="submit" name="cmd" value="<?php echo $strLinkSubmit; ?>">
</td>
</tr>
</form>
</table>

<p align="justify">
<?php echo $strHelpOnString; ?>
</p>
<p align="justify">
<?php echo $strHelpOnRegExp; ?>
</p>

<?php
}
?>

<br>

<?php include ("./include/footer.inc.php"); ?>