Visa källkod

Nedanstående filer finns i denna katalog. Klicka på en fil för att visa dess innehåll.

bth-cards/

  1. .buildpath
  2. .project
  3. CCard.php
  4. CCardHand.php
  5. CDeck.php
  6. argyle.jpg
  7. card.php
  8. common.php
  9. deck.php
  10. grunge.jpg
  11. hand.php
  12. index.php
  13. sessDest.php
  14. sessions.php
  15. sessions_mroos.php
  16. source.php
  17. template.php
  18. tiles.jpg

Stäng "source.php"

<?php

// ===============================================================
// Contents: Listar alla filer i en mapp och visar källkoden för
//           vald fil.
// Author: Staffan Lindsgård
// Notes: Baserat på originalkod av Mikael Roos. De ändringar som
//        gjorts är till för att göra slutresultatet mer
//        semantiskt korrekt och överlag mer funktionellt för min
//        layout.
// ===============================================================

// ===========================================================================================
//
// PListDirectory.php
//
// Description: An implementation of a PHP pagecontroller for a web-site.
// Shows a directory listning.
//
// Author: Mikael Roos
//

// -------------------------------------------------------------------------------------------
//
// Settings for this pagecontroller.
//

// Separator between directories and files, change between Unix/Windows
$SEPARATOR = '/'; 	// Unix, Linux, MacOS, Solaris
//$SEPARATOR = '\\'; 	// Windows 

// Show the content of files named config.php, except the rows containing DB_USER, DB_PASSWORD
//$HIDE_DB_USER_PASSWORD = FALSE; 
$HIDE_DB_USER_PASSWORD = TRUE; 

// Which directory to use as basedir, end with separator
$BASEDIR = '.' . $SEPARATOR;

// The link to this page, usefull to change when using this pagecontroller for other things,
// such as showing stylesheets in a separate directory, for example.
$HREF = 'source.php?';


// -------------------------------------------------------------------------------------------
//
// Page specific code
//

$html = <<<EOD
				<h1>Visa källkod</h1>
				<p>Nedanstående filer finns i denna katalog. Klicka på en fil för att visa dess innehåll.</p>\n
EOD;


// -------------------------------------------------------------------------------------------
//
// Verify the input variable _GET, no tampering with it
//
$currentdir	= isset($_GET['dir']) ? $_GET['dir'] : '';

$fullpath1 	= realpath($BASEDIR);
$fullpath2 	= realpath($BASEDIR . $currentdir);
$len = strlen($fullpath1);
if(	strncmp($fullpath1, $fullpath2, $len) !== 0 ||
	strcmp($currentdir, substr($fullpath2, $len+1)) !== 0 ) {
	die('Tampering with directory?');
}
$fullpath = $fullpath2;
$currpath = substr($fullpath2, $len+1);


// -------------------------------------------------------------------------------------------
//
// Show the name of the current directory
//
$start		= basename($fullpath1);
$dirname 	= basename($fullpath);
$html .= <<<EOD
				<p><a href='{$HREF}dir='>{$start}</a>{$SEPARATOR}{$currpath}</p>\n
EOD;


// -------------------------------------------------------------------------------------------
//
// Open and read a directory, show its content
//
$dir 	= $fullpath;
$curdir1 = empty($currpath) ? "" : "{$currpath}{$SEPARATOR}";
$curdir2 = empty($currpath) ? "" : "{$currpath}";

$list = Array();
if(is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
        	if($file != '.' && $file != '..' && $file != '.svn') {
        		$curfile = $fullpath . $SEPARATOR . $file;
        		if(is_dir($curfile)) {
          	  		$list[$file] = "<a href='{$HREF}dir={$curdir1}{$file}'>{$file}{$SEPARATOR}</a>";
          	  	} else if(is_file($curfile)) {
          	  	  $list[$file] = "<a href='{$HREF}dir={$curdir2}&amp;file={$file}'>{$file}</a>";
          	  	}
          	 }
        }
        closedir($dh);
    }
}

ksort($list);

$html .= "				<ol>\n";
foreach($list as $val => $key) {
	$html .= "					<li>{$key}</li>\n";
}
$html .= "				</ol>\n";


// -------------------------------------------------------------------------------------------
//
// Show the content of a file, if a file is set
//
$dir 	= $fullpath;
$file	= "";

if(isset($_GET['file'])) {
	$file = basename($_GET['file']);

	$content = htmlspecialchars(file_get_contents($dir . $SEPARATOR . $file, 'FILE_TEXT'));

	// Remove password and user from config.php, if enabled
	if($HIDE_DB_USER_PASSWORD == TRUE && $file == 'config.php') {

		$pattern[0] 	= '/(DB_PASSWORD|DB_USER)(.+)/';
		$replace[0] 	= '/* <em>\1,  is removed and hidden for security reasons </em> */ );';
		
		$content = preg_replace($pattern, $replace, $content);
	}
	
	$html .= <<<EOD
				<h2><a href='{$HREF}'>Stäng "{$file}"</a></h2>
				<pre class="code"><code>{$content}</code></pre>
EOD;
}


// -------------------------------------------------------------------------------------------
//
// Create and print out the html-page
//

$pagetitle = "Titta på källkod";
$customhead = "";

require_once('common.php');

$html = <<< EOD
{$page_top}
{$html}
{$page_bottom}
EOD;


header("Content-Type: text/html; charset=UTF-8");
echo $html;
exit;

?>