 |
Gubed PHP Debugger Support forum for Gubed PHP Debugger
|
| View previous topic :: View next topic |
| Author |
Message |
flz
Joined: 06 Jul 2005 Posts: 6
|
Posted: 2005-07-07, 12:08 Post subject: modifications to the link rewrite |
|
|
Hi,
a couple of days ago i stumbled over the gubed debugger, and i think it's a very handy piece of software. After i figured out i didn't need all that stuff i downloaded because there is a windows installer gubed worked right out of the box. I almost couldn't believe it!
But when i went on to make the test to debug my own app, it didn't work. The login screen (of my app) always kept returning, and i couldn't get into the main app. After looking at the server-side code, i realized some of the tricks to get from one page to another weren't supported by the link rewrite part of gubed, so i tried to make some changes.
Some things that didn't seem to work:
- use of $PHP_SELF in links and forms
- in forms a hidden parameter led to the running script itself. jumping to another script via "action" wasn't possible.
- a relative path already contained in links was duplicated
to make $PHP_SELF working i inserted:
| Code: | | $PHP_SELF = $GLOBALS['gbd']['Script']; |
after:
| Code: | | $_SERVER['PHP_SELF'] = $GLOBALS['gbd']['Script']; |
in line 171 of StartSession.php.
and the link rewrite section in GubedFunctions.php:
| Code: |
// Replace all relative links and actions in $output
if(strpos(strtolower($output), '<html')) {
preg_match_all("/<!--.*-->|<(\\/?[\\w]+)[^>]*>([^<]*)/", $output, $matches, PREG_PATTERN_ORDER);
// print_r($matches);
$attributes = Array('href', 'usemap', 'src', 'action', 'background', 'cite', 'classid', 'codebase', 'data', 'longdesc', 'profile');
// echo "<pre>";
for($cnt = 0; $cnt < count($matches[0]); $cnt++) {
// echo htmlentities("{$matches[0][$cnt]}");
foreach($attributes as $attribute) {
$attribute = strtolower($attribute);
preg_match_all("/(.*?){$attribute}\\s*=\\s*(\".*?\"|'.*?'|[^\"\'].+?\\s)(.*)/si", $matches[0][$cnt], $submatches, PREG_PATTERN_ORDER);
if(count($submatches[0]) > 0) {
for($cnt2 = 0; $cnt2 < count($submatches[0]); $cnt2++) {
if(substr($submatches[2][$cnt2], 0, 1) == '"') {
$submatches[2][$cnt2] = substr($submatches[2][$cnt2], 1, strlen($submatches[2][$cnt2]) - 2);
$quote = '"';
} elseif(substr($submatches[2][$cnt2], 0, 1) == "'") {
$submatches[2][$cnt2] = substr($submatches[2][$cnt2], 1, strlen($submatches[2][$cnt2]) - 2);
$quote = "'";
} else
$quote = '';
if(!preg_match("/^.+:\\/\\//", $submatches[2][$cnt2]) ) {
$locallink = false; //if true no parsing
$relink = ""; //name and path of the target
if(substr($submatches[2][$cnt2], 0, 1) == '?') {
$submatches[2][$cnt2] = '&' . substr($submatches[2][$cnt2], 1);
$relink = $GLOBALS['gbd']['Script'] . $submatches[2][$cnt2];
} elseif(preg_match("/.*\\.ph.{0,5}.*/i", $submatches[2][$cnt2])) {
if (strpos($submatches[2][$cnt2],'/')!==false) $relink = str_replace('?', '&', $submatches[2][$cnt2]);
else $relink = $GLOBALS['gbd']['BaseURL'] .str_replace('?', '&', $submatches[2][$cnt2]);
} elseif (trim($submatches[2][$cnt2])!="") {
$locallink = true;
$submatches[0][$cnt2] = "{$attribute}={$quote}http://" . $_SERVER['HTTP_HOST'] . $GLOBALS['gbd']['BaseURL'] . $submatches[2][$cnt2] . $quote;
}
if (!$locallink) $submatches[0][$cnt2] = "{$attribute}={$quote}http://" . $_SERVER['HTTP_HOST'] . $GLOBALS['gbd']['StartSession'] . $relink . $quote;
$submatches[0][$cnt2] = $submatches[1][$cnt2] . $submatches[0][$cnt2] . $submatches[3][$cnt2];
}
$matches[0][$cnt] = join('', $submatches[0]);
if($attribute == 'action') {
if (trim($submatches[2][$cnt2])=="") $relink = $GLOBALS['gbd']['Script'];
if ((strpos($relink,'&'))!==false) $relink = substr_replace($relink,'?',(strpos($relink,'&')),1);
$matches[0][$cnt] .= "<input type=\"hidden\" name=\"gbdScript\" value=\"$relink\" />";
}
}
// $submatches = print_r($submatches, true);
// echo htmlentities($submatches);
}
}
}
// echo htmlentities($output);
// echo htmlentities(join("", $matches[0]));
// print_r(headers_sent());
echo join("", $matches[0]);
} else
echo $output;
|
what i tried to get with these changes:
- always add a hidden parameter to forms to support method get.
- place the actual targetscript in this parameter
- check if there is already a path contained in links to php-scripts
please let me know what you think, ciao,
Frank |
|
| Back to top |
|
 |
Guest
|
Posted: 2005-07-07, 16:51 Post subject: Re: modifications to the link rewrite |
|
|
| Quote: | | But when i went on to make the test to debug my own app, it didn't work. The login screen (of my app) always kept returning, and i couldn't get into the main app. After looking at the server-side code, i realized some of the tricks to get from one page to another weren't supported by the link rewrite part of gubed, so i tried to make some changes. |
I think perhaps this is a bug that was fixed after 0.2.0. Could you try with 0.2.1, there's a preview version of it at http://x.mccabe.nu/public/Gubed/0.2.1 (it will be released in a day or so if I dont get any complaints bout it)
| Quote: | | - use of $PHP_SELF in links and forms |
Yeah, ok.. I've forgotten about those auto registered globals, I always use $_SERVER[] etc...
| Quote: |
| Code: | | $PHP_SELF = $GLOBALS['gbd']['Script']; |
|
Ill add this, except I think it needs to be done only if $PHP_SELF is already set.
| Quote: |
- in forms a hidden parameter led to the running script itself. jumping to another script via "action" wasn't possible.
|
I think this is fixed by above mentioned bugfix, let me know otherwise
| Quote: |
- a relative path already contained in links was duplicated
|
I dont understand, can you give an example?
| Quote: |
and the link rewrite section in GubedFunctions.php:
| Code: |
// Replace all relative links and actions in $output
...
echo $output;
|
|
Ill have to take a closer look at the diffs :] ...
It would be great if you could let me know what problems persists with 0.2.1,
thanks!!
/Linus |
|
| Back to top |
|
 |
flz
Joined: 06 Jul 2005 Posts: 6
|
Posted: 2005-07-08, 8:05 Post subject: |
|
|
Hi Linus,
thanks for your reply,
| Quote: | | I think perhaps this is a bug that was fixed after 0.2.0. Could you try with 0.2.1, |
I'll have a look at it
| Quote: | | Yeah, ok.. I've forgotten about those auto registered globals, I always use $_SERVER[] etc... |
i know they shouldn't be used Sometime we'll rewrite the stuff...
| Quote: | Ill add this, except I think it needs to be done only if $PHP_SELF is already set.
|
i'm not sure what you mean, i think it's needed with register globals on.
| Quote: |
| Quote: | | - in forms a hidden parameter led to the running script itself. ... |
think this is fixed by above mentioned bugfix, let me know otherwise
|
yes
| Quote: |
| Quote: | - a relative path already contained in links was duplicated
|
I dont understand, can you give an example?
|
well eg.
| Code: | | <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> |
rewrites to
| Code: | <form action="http://maia/gub/serverscripts/StartSession.php?gbdScript=/debugtest//debugtest/start.php" method="post">
<input type="hidden" name="gbdScript" value="/debugtest//debugtest/start.php" /> |
which won't work, because the $GLOBALS['gbd']['BaseURL'] part is already present in the target. i made a mistake here, i look for a slash anywhere in the original link, but only a slash at the beginning indicates the link is already relative to root directory.
ciao, Frank |
|
| Back to top |
|
 |
flz
Joined: 06 Jul 2005 Posts: 6
|
Posted: 2005-07-08, 11:41 Post subject: |
|
|
Hi Linus,
i've looked at the version 0.2.1 now. The bug where always the same script was inserted into the hidden input is gone, but now empty actions won't work anymore. In the hidden input $GLOBALS['gbd']['LocalSettings'] is used which gives me an error because it's not set.
things i noticed:
- a path relative to root could be used with any link
- the hidden input is needed whenever StartSession is called, because it won't work without when method is "get".
| Code: | | <form action="?param=test" method="get"> |
will not work without the hidden input.
- the value needed in the hidden imput is basically the same as the scriptname in the link to StartSession, but without the ? changed to &.
I tried to do the following now:
- introduce $seslink, this is the rewritten link with path from root on. When $seslink is filled, StartSession is called and the hidden input is added and $seslink is inserted in the hidden input. (That way the link for the hidden input doesn't have to be created from scratch again)
- check for a slash at the beginning of the link and do not insert BaseUrl when present.
| Code: |
if(!preg_match("/^.+:\\/\\//", $submatches[2][$cnt2]) ) {
$seslink = false;
if($attribute == 'action' && $submatches[2][$cnt2] == '') {
$seslink = $GLOBALS['gbd']['Script'];
} elseif(substr($submatches[2][$cnt2], 0, 1) == '?') {
$submatches[2][$cnt2] = '&' . substr($submatches[2][$cnt2], 1);
$seslink = $GLOBALS['gbd']['Script'] . '&' . substr($submatches[2][$cnt2], 1);
} elseif(preg_match("/.*\\.(html|php|phtml|htm|php.).*/i", $submatches[2][$cnt2])) {
if (substr($submatches[2][$cnt2],0,1)=='/')
$seslink = str_replace('?', '&', $submatches[2][$cnt2]);
else
$seslink = $GLOBALS['gbd']['BaseURL'] .str_replace('?', '&', $submatches[2][$cnt2]);
} elseif(preg_match("/javascript:.*/i", $submatches[2][$cnt2])) {
$submatches[0][$cnt2] = "{$attribute}= " . $quote . $submatches[2][$cnt2] . $quote;
} else {
if (substr($submatches[2][$cnt2],0,1)=='/')
$submatches[0][$cnt2] = "{$attribute}={$quote}{$protocol}" . $_SERVER['HTTP_HOST'] . $submatches[2][$cnt2] . $quote;
else
$submatches[0][$cnt2] = "{$attribute}={$quote}{$protocol}" . $_SERVER['HTTP_HOST'] . $GLOBALS['gbd']['BaseURL'] . $submatches[2][$cnt2] . $quote;
}
if ($seslink) $submatches[0][$cnt2] = "{$attribute}={$quote}http://" . $_SERVER['HTTP_HOST'] . $GLOBALS['gbd']['StartSession'] . $seslink . $quote;
$submatches[0][$cnt2] = $submatches[1][$cnt2] . $submatches[0][$cnt2] . $submatches[3][$cnt2];
}
$matches[0][$cnt] = join('', $submatches[0]);
if($attribute == 'action') {
if ((strpos($seslink,'&'))!==false) $seslink = substr_replace($seslink,'?',(strpos($seslink,'&')),1);
if ($seslink) $matches[0][$cnt] .= "<input type=\"hidden\" name=\"gbdScript\" value=\"$seslink\" />";
}
|
ciao,
Frank |
|
| Back to top |
|
 |
Simboo
Joined: 12 Jul 2006 Posts: 1
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|