Skip to content

Commit

Permalink
Changes on CLIHelper and WebDig
Browse files Browse the repository at this point in the history
+ Added to CLIHelper: method getDirPath()
+ Added to CLIHelper: method getFilePath()
+ Added to CLIHelper: method getUrlDir()
+ Added to CLIHelper: method ggetUrlFile()
+ Added to WebDig: example/targets/dump-vars.php
+ Added to WebDig: example/targets/autentication-simple
  • Loading branch information
fititnt committed Oct 23, 2011
1 parent bcb18b4 commit 9f9ae81
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 10 deletions.
92 changes: 90 additions & 2 deletions CLIHelper/library/CLIHelper.php
Expand Up @@ -89,17 +89,105 @@ public function del( $name )
}

/*
* Return generic variable
* Return the absolute directory path of file that called this method
*
* return String
*/
public function getDirPath( )
{
$path = dirname(__FILE__); //Or just __DIR__ for PHP 5.3+
return $path;
}

/*
* Return the absolute file path of file that called this method
*
* return String
*/
public function getFilePath( )
{
$path = __FILE__;
return $path;
}

/*
* Return the URL directory path, if is accessed by browser.
* Fallback to get directory path if is acessed by Command Line Interface
*
* return String
*/
public function getUrlDir( )
{
if( $this->browser)
{
//Gambiarra? Gambiarra @todo: change it.
if ( $_SERVER['PHP_SELF'] ) //Check if is not root. Maybe do a better check later?
{
$currentUrl = $this->getUrlFile();
$urlInfo = explode('/', $currentUrl);
array_pop($urlInfo);//Get of last element of array
$url = implode('/', $urlInfo);

} else {
$url = $this->getUrlFile();
}
}
else
{
$url = $this->getDirPath();
}
return $url;
}

/*
* Return the URL file path, if is accessed by browser.
* Fallback to get file path if is acessed by Command Line Interface
*
*
* return String
*/
public function getUrlFile( )
{

if( $this->browser)
{
if ( empty($_SERVER["HTTPS"]) ){
$url = 'https://';
} else {
$url = 'http://';
}

$url .= $_SERVER["SERVER_NAME"];

if ($_SERVER["SERVER_PORT"] != "80"){
$url .= ':'. $_SERVER["SERVER_PORT"];
}

$url .= $_SERVER["REQUEST_URI"];
}
else
{
$url = $this->getFilePath();
}



return $url;
}

/*
* Return the absolute file path of file that called this method
*
* @var String $name: name of var to return
*
* return Mixed $this->$name: value of var
*/
public function get( $name )
public function getUrlPathCurrent( $name )
{
return $this->$name;
}


/*
* Return SAPI name
*
Expand Down
2 changes: 1 addition & 1 deletion WebDig/examples/authentication-apache.php
Expand Up @@ -12,7 +12,7 @@
include_once '../library/WebDig.php';

$wd = new WebDig();
echo $wd/*->setDebug('debug-autentication-apache.log', TRUE)*/
echo $wd->setDebug('debug-autentication-apache.log', TRUE)
->setTarget('http://auth.fititnt.org/')
->post( array(
'username' => 'infinitum',
Expand Down
33 changes: 33 additions & 0 deletions WebDig/examples/authentication-simple.php
@@ -0,0 +1,33 @@
<?php
/*
* @package WebDig
* @author Emerson Rocha Luiz - emerson at webdesign.eng.br - http://fititnt.org
* @copyright Copyright (C) 2011 Webdesign Assessoria em Tecniligia da Informacao. All rights reserved.
* @license GNU General Public License version 3. See license-gpl3.txt
* @license Massachusetts Institute of Technology. See license-mit.txt
* @version 0.1alpha
*
*/
//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); //better debug. Or not. Haha!
include_once '../../CLIHelper/library/CLIHelper.php';
include_once '../library/WebDig.php';



$clih = new CLIHelper();

//echo $clih->getUrlDir();

$wd = new WebDig();

$wd ->setDebug('autentication-simple-debug.log', TRUE) //Setup debug file in current directory
->setCookie('autentication-simple-cookie.log') //Setup cookies file
->setTarget( $clih->getUrlDir() . '/targets/autentication-simple/login.php' ) //Target to go
->post( array(
'username' => 'user',
'password' => 'pass'
)
)
->get('content');

$wd->debug();
File renamed without changes.
39 changes: 39 additions & 0 deletions WebDig/examples/targets/autentication-simple/etc.php
@@ -0,0 +1,39 @@
<?php
/*
* @package WebDig
* @author Emerson Rocha Luiz - emerson at webdesign.eng.br - http://fititnt.org
* @copyright Copyright (C) 2011 Webdesign Assessoria em Tecniligia da Informacao. All rights reserved.
* @license GNU General Public License version 3. See license-gpl3.txt
* @license Massachusetts Institute of Technology. See license-mit.txt
* @version 0.1alpha
*
*/
session_start();

if ( !isset($_SESSION['autorized']) ) die('You are not autorized to see this page. You must have cookies enabled');
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Another example</title>
</head>
<body>
<p>User: <?php echo $_SESSION['username']; ?></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent semper
dignissim dolor, ut aliquam arcu consectetur in. Integer ornare euismod
nisi, a ultricies ligula dictum ut. Aenean id diam justo, in semper elit.
In hac habitasse platea dictumst. Maecenas quis mi tellus.</p>
<p>Nulla facilisi. Suspendisse potenti. Proin fermentum commodo volutpat.
Nam in scelerisque est.</p>

<div id="menu">
<ul>
<li><a href="login.php">Login</a></li>
<li><a href="result.php">Result</a></li>
<li><a href="etc.php">Etc</a></li>
<li><a href="login.php?logout=1">Logout</a></li>
</ul>
</div>
</body>
</html>

78 changes: 78 additions & 0 deletions WebDig/examples/targets/autentication-simple/login.php
@@ -0,0 +1,78 @@
<?php
/*
* @package WebDig
* @author Emerson Rocha Luiz - emerson at webdesign.eng.br - http://fititnt.org
* @copyright Copyright (C) 2011 Webdesign Assessoria em Tecniligia da Informacao. All rights reserved.
* @license GNU General Public License version 3. See license-gpl3.txt
* @license Massachusetts Institute of Technology. See license-mit.txt
* @version 0.1alpha
*
*/
$loginError = FALSE;
session_start();

if( isset($_REQUEST['logout']))
{
$_SESSION = array();
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
}
else if( isset($_REQUEST['username']) )
{

if ( $_REQUEST['username'] == 'user' && $_REQUEST['password'] == 'pass')
{
//Session
$_SESSION['username'] = $_REQUEST['username'];
$_SESSION['password'] = $_REQUEST['password'];
$_SESSION['autorized'] = TRUE;

//Redirect
header('Location: result.php');

} else {
$loginError = TRUE;
//header('Location: error.php');
}
}


?>
<!DOCTYPE HTML>
<html>
<head>
<title>Login</title>
</head>
<body>
<fieldset>
<legend>Login</legend>
<?php if ( $loginError ) { ?>
<p>Your username and password do not mach, or you do not have one account. <a href="login.php">Try again</a></p>
<?php } ?>
<form action="login.php" method="post">
<label>Username</label>
<input name="username" id="mod-login-username" type="text" size="15" />
<br />
<label>Password</label>
<input name="password" type="password" size="15" />
<br />
<input type="submit"/>
</form>
</fieldset>

<div id="menu">
<ul>
<li><a href="login.php">Login</a></li>
<li><a href="result.php">Result</a></li>
<li><a href="etc.php">Etc</a></li>
<li><a href="login.php?logout=1">Logout</a></li>
</ul>
</div>
</body>
</html>
31 changes: 31 additions & 0 deletions WebDig/examples/targets/autentication-simple/result.php
@@ -0,0 +1,31 @@
<?php
/*
* @package WebDig
* @author Emerson Rocha Luiz - emerson at webdesign.eng.br - http://fititnt.org
* @copyright Copyright (C) 2011 Webdesign Assessoria em Tecniligia da Informacao. All rights reserved.
* @license GNU General Public License version 3. See license-gpl3.txt
* @license Massachusetts Institute of Technology. See license-mit.txt
* @version 0.1alpha
*
*/
session_start();

if ( !isset($_SESSION['autorized']) ) die('You are not autorized to see this page. You must have cookies enabled');
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Your are logged</title>
</head>
<body>
<p>Hi, <?php echo $_SESSION['username']; ?></p>
<div id="menu">
<ul>
<li><a href="login.php">Login</a></li>
<li><a href="result.php">Result</a></li>
<li><a href="etc.php">Etc</a></li>
<li><a href="login.php?logout=1">Logout</a></li>
</ul>
</div>
</body>
</html>
42 changes: 42 additions & 0 deletions WebDig/examples/targets/dump-vars.php
@@ -0,0 +1,42 @@
<?php
/*
* @package WebDig
* @author Emerson Rocha Luiz - emerson at webdesign.eng.br - http://fititnt.org
* @copyright Copyright (C) 2011 Webdesign Assessoria em Tecniligia da Informacao. All rights reserved.
* @license GNU General Public License version 3. See license-gpl3.txt
* @license Massachusetts Institute of Technology. See license-mit.txt
* @version 0.1alpha
*
*/

echo '<fieldset><legend>$_POST</legend><pre>';
if ( isset($_POST ) && !empty( $_POST ) ){
print_r( $_POST );
} else {
echo 'Not set or empty';
}
echo '</pre></fieldset>';

echo '<fieldset><legend>$_GET</legend><pre>';
if ( isset( $_GET ) && !empty( $_GET ) ){
print_r( $_GET );
} else {
echo 'Not set or empty';
}
echo '</pre></fieldset>';

echo '<fieldset><legend>$_COOKIE</legend><pre>';
if ( isset( $_COOKIE ) && !empty( $_COOKIE ) ){
print_r( $_COOKIE );
} else {
echo 'Not set or empty';
}
echo '</pre></fieldset>';

echo '<fieldset><legend>$_SESSION</legend><pre>';
if ( isset($_SESSION ) && !empty($_SESSION ) ){
print_r( $_SESSION );
} else {
echo 'Not set or empty';
}
echo '</pre></fieldset>';
10 changes: 3 additions & 7 deletions WebDig/library/WebDig.php
Expand Up @@ -85,7 +85,7 @@ function __construct()
curl_setopt( $this->curl, CURLOPT_TIMEOUT , 30);//The maximum number of seconds to allow cURL functions to execute.

//SSL
curl_setopt( $this->curl, CURLOPT_SSL_VERIFYPEER, $this->certificate); //SSL Certificate.
//curl_setopt( $this->curl, CURLOPT_SSL_VERIFYPEER, $this->certificate); //SSL Certificate.
//Emulate Google Agent by default
curl_setopt( $this->curl, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
}
Expand Down Expand Up @@ -269,12 +269,8 @@ public function getInfo( $option = NULL )
*/
public function post( $data, $target = NULL, $method = FALSE, $debug = FALSE )
{
$response = $this->dig( $target = NULL,
$method = FALSE,
$debug = FALSE,
array('POST' => $data)
);
return $response;
$response = $this->dig( $target, $method, $debug, array( 'POST' => $data) );
return $this;
}

/*
Expand Down

0 comments on commit 9f9ae81

Please sign in to comment.