Page 1 of 1

Mystery form fields

Posted: Sat Feb 13, 2010 11:59 pm
by Weiry
I have said generated page of various php files.
Source:

Code: Select all

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>  <meta name="Description" content="Information architecture, Web Design, Web Standards." /> <meta name="Keywords" content="your, keywords" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />  <link type="text/css" rel="stylesheet" href="./images/Envision.css" /> <link type="text/css" rel="stylesheet" href="./inc/js/theme/ui-lightness/jquery-ui.css" media="all" /> <link type="text/css" rel="stylesheet" href="./inc/js/theme/ui-lightness/ui.datepicker.css" media="all" />     <script type="text/javascript" src="./inc/js/jquery.js"></script>     <script type="text/javascript" src="./inc/js/jquery.ui.core.js"></script>     <script type="text/javascript" src="./inc/js/jquery.ui.datepicker.js"></script>     <script type="text/javascript" src="./inc/js/showhide.js"></script> <title>WeiryNet</title>             <style type="text/css">         .showhide{position:absolute;margin-top:2px;margin-left:485px}        .title{position:absolute;margin-left:5px;margin-top:5px;font-weight:bold}        .header{background:#edfdce;width:100%;height:25px;}        .header2{background:#fdcece;width:100%;height:25px;}        .container{position:absolute;width:500px;height:400px;overflow:auto;}        #postFont{padding-left:10px;padding-right:10px;padding-bottom:10px;font-family:Verdana;font-size:12px;}        .paragraph1{margin-left:15px;margin-right:15px;margin-top:5px;}        .paragraph2{margin-left:15px;margin-right:15px;margin-top:5px;}        .paragraph3{margin-left:15px;margin-right:15px;margin-top:5px;}        </style> </head><!-- Head data ends here --> <body> <!-- wrap starts here --> <div id="wrap">                 <!--header -->         <div id="header">                                       <h1 id="logo-text"><a href="./">maintenance</a></h1>                    <p id="slogan">maintenance for your business...</p>                             <div id="header-links">                 <form action="#" method="get" class="searchform" >                 <p>                                 <a href="./">Home</a> |                     <a href="./">Contact</a> |                     <a href="./">Site Map</a>                           </p>                        </form>             </div>                                      </div>          <!-- menu -->           <div id="menu">             <ul>                 <li id="current"><a href="./">Home</a></li>                 <li><a href="./">Support</a></li>                 <li class="last"><a href="./">About</a></li>                    </ul>         </div>      <!-- end header -->                                 <!-- alerts -->                 <div id='alerts'>                     <p><a href='?p=alerts'>                     <strong>ALERT: A vaccine for YOU GOT AIDS has been found</strong>                     </a></p>                 <!-- alerts end here -->                 </div>              <!-- content-wrap starts here -->         <div id="content-wrap">                             <!-- Start the sidebar -->             <div id="sidebar">                 <h4>User Options</h4>                   <form name="logoutForm" action="tpl/logout.php" method="post" class="loginform">                     <ul class="sidemenu">                                                                                       <li><a href='./?a=acp'>Admin Control Panel</a></li>                         <li><a href='./?a=createAlert'>Create New Alert</a></li>                                                                             <li>Your Jobs</li>                         <li>Recent Job Updates</li>                         <li><input name="loginAuth" class="button" value="Logout" type="submit" /></li>                     </ul>                 </form>                                 <h3>Sidebar Menu</h3>                 <ul class="sidemenu">                                   <li><a href="index.html">Home</a></li>                     <li><a href="#TemplateInfo">Contact</a></li>                        <li><a href="#TemplateInfo">Site Map</a></li>                                       </ul>                                   <h3>Support Styleshout</h3>                 <div class="left-box">                     <p>This is a textbox on the right hand side of the page</p>                 </div>                                                                      </div>          <!-- End the sidebar -->                             <div id="main">                             <h2>Create a new alert</h2>             <script type='text/javascript'>             $(function() {                $('#datepicker').datepicker();            });            </script>             <form name='createAlert' action='?a=createAlert' method='post'>                 <p>                     Title:<br/><input type='text' name='title' size='50'/><br/><br/>                     Message:</br><textarea name='message' cols='50' rows='15'></textarea><br/>                     Alert End Date:<br/><input type='text' name='endDate' id='datepicker'><br/><br/>                     <input type='submit' name='createAlertAuth' value='Submit'/>                 </p>             </form>                         </div>                 <!-- content-wrap ends here -->         </div>                             <!--footer starts here-->         <div id="footer">             <p>                 &copy; 2009 <strong>WeiryNet</strong> |                 Design by: <a href="http://www.styleshout.com/">styleshout</a> |                 Valid <a href="http://validator.w3.org/check?uri=referer">XHTML</a> |                 <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                <a href="index.html">Home</a>&nbsp;|&nbsp;                <a href="index.html">Sitemap</a>&nbsp;|&nbsp;                <a href="index.html">RSS Feed</a>             </p>         </div>  <!-- wrap ends here --> </div>  </body> </html>
The <form name='createAlert' action='?a=createAlert' method='post'> is where things get interesting.
You can see when the form is submitted, there should only be 4 fields in $_POST:
title,message,endDate,createAlertAuth

Here is the mysterious part, on the page after being submitted i am receiving 2 extra form fields being submitted.
(Source for ?a=createAlert):

Code: Select all

<?php
    if($session->isAdmin()){
        if(!isset($_POST['createAlertAuth'])){
            $alerts->displayCreateAlertsForm();
        }else{
            $userID = $_SESSION['userData']['userID'];
            $title = mysql_real_escape_string($_POST['title']);
            $title = mysql_real_escape_string($_POST['message']);
            $title = mysql_real_escape_string($_POST['endDate']);
            
            var_dump($_POST);
            //$alerts->createAlert($userID,$title,$message,$endDate);
        }
    }
?>
Output of the var_dump($_POST);

Code: Select all

array(6) {
     ["title"]=> string(4) "Test"
     ["message"]=> string(12) "Test message"
     ["endDate"]=> string(10) "02/20/2010"
     ["createAlertAuth"]=> string(6) "Submit"
     ["username"]=> string(0) ""
     ["password"]=> string(0) "" 
}
Now if you didn't spot the problem, you will notice there are the 2 extra fields (username, password). These 2 fields don't occur anywhere on the page where the information is being submitted from, nor should the file where these 2 fields are located be included and the fact that there is a logout form in place of where the login form would appear if the user is not logged in, proves that the login form is not being included.

Could someone possibly point me in the direction where these fields are even coming from??

Re: Mystery form fields

Posted: Sun Feb 14, 2010 12:23 am
by requinix
How about the full source code?

Re: Mystery form fields

Posted: Sun Feb 14, 2010 12:29 am
by Weiry
Allow me to go and scrounge around the 5 or so php pages that generate it...

index.php

Code: Select all

<?php
require_once("config.inc.php");
?>
<?php include_once('tpl/headData.php'); ?>
<!-- Head data ends here -->
<body>
<?php
if(!isset($_POST['username']) && !isset($_POST['password'])){
    $_POST['username'] = ""; $_POST['password'] = "";
}else{
    $user = mysql_real_escape_string($_POST['username']);
    $pass = mysql_real_escape_string($_POST['password']);
    
    if(!$session->isLoggedIn()){    //  if the user is not logged in
        if(!($session->login($user,$pass))){
            $session->displayRedirect('Error: Invalid Username/Password');
        }else{
            $session->displayRedirect('You successfully logged in');
        }
    }
}
?>
<!-- wrap starts here -->
<div id="wrap">
        
        <!--header -->
        <?php include_once("tpl/header.php"); ?>
        <!-- end header -->
        
        <?php
        $alert = $alerts->getRecentAlert();
        if($alert){print "
        <!-- alerts -->
        <div id='alerts'>
            <p><strong>{$alert['message']}</strong></p>
        <!-- alerts end here -->
        </div>";
        }?>
        
        <!-- content-wrap starts here -->
        <div id="content-wrap">
                
            <!-- Start the sidebar -->
            <?php include_once('tpl/sidebar.php'); ?>
            <!-- End the sidebar -->
                
            <div id="main">
                <?php
                    if(isset($_GET['p'])){
                        switch($_GET['p']){
                            case "alerts":
                                if(empty($_GET['id'])){$alerts->getAllAlerts();}else{$alerts->getAlert($_GET['id']);}
                                break;
                            case "job":
                                if(isset($_GET['id'])){$jobs->displayJob($_GET['id']);}else{$session->displayRedirect('Error: Select a job');}
                                break;
                            default:
                                continue;
                        }
                    }elseif(isset($_GET['a']) && $session->isAdmin()){
                        if(!isset($_GET['a'])){include_once(TPL_A.'acp.php');}else{
                            switch($_GET['a']){
                                case "acp":
                                    include_once(TPL_A.'acp.php');
                                    break;
                                case "jobList":
                                    include_once(TPL_A.'jobList.php');
                                    break;
                                case "createAlert":
                                    include_once(TPL_A.'createAlert.php');
                                    break;
                                default:
                                    include_once('./tpl/404.php');
                                    break;
                            }
                        }
                    }elseif($session->isLoggedIn() && !($session->isAdmin())){
                        if(!isset($_GET['u'])){include_once(TPL_U.'ucp.php');}else{
                            switch($_GET['u']){
                                case "userJobs":
                                    include_once(TPL_U.'userJobs.php');
                                    break;
                                case "ucp":
                                    include_once(TPL_U.'ucp.php');
                                    break;
                                default:
                                    include_once('./tpl/404.php');
                                    break;
                            }
                        }
                    }else{
                        include_once('default.php');
                    }
                ?>
            </div>
        
        <!-- content-wrap ends here --> 
        </div>
                    
        <!--footer starts here-->
        <?php include_once('tpl/footer.php'); ?>
 
<!-- wrap ends here -->
</div>
 
</body>
</html>
 
sidebar.php

Code: Select all

 
<div id="sidebar">
                <?php
                    if(!$session->isLoggedIn()){
                        include_once('login.php'); 
                    }else{
                        include_once('usrOp.php');
                    }
                ?>
                
                <h3>Sidebar Menu</h3>
                <ul class="sidemenu">               
                    <li><a href="index.html">Home</a></li>
                    <li><a href="#TemplateInfo">Contact</a></li>    
                    <li><a href="#TemplateInfo">Site Map</a></li>                       
                </ul>   
                
                <h3>Support Styleshout</h3>
                <div class="left-box">
                    <p>This is a textbox on the right hand side of the page</p>
                </div>                          
                                
            </div>
login.php

Code: Select all

 
<h4>Login</h4>  
                <form name="loginForm" action="./" method="post" class="loginform">
                    <table class="loginform">
                    <tr>
                        <td>Username:</td>
                        <td><input name="username" class="textbox" type="text" /></td>
                        <td>
                            <?php
                                if(isset($_POST['authSubmit'])){
                                    if($error->value("username")){
                                        print $error->printError("username");
                                    }
                                }
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td><input name="password" class="textbox" type="password" /></td>
                        <td>
                            <?php
                                if(isset($_POST['authSubmit'])){
                                    if($error->value("password")){
                                        print $error->printError("password");
                                    }
                                }
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input name="loginAuth" class="button" value="Login" type="submit" /></td>
                    </tr>
                    </table>    
                </form> 
usrOp.php

Code: Select all

<h4>User Options</h4>   
                <form name="logoutForm" action="tpl/logout.php" method="post" class="loginform">
                    <ul class="sidemenu">               
                        <?php if($session->isAdmin()){?>
                        
                        <li><a href='./?a=acp'>Admin Control Panel</a></li>
                        <li><a href='./?a=createAlert'>Create New Alert</a></li>
                            <?php }elseif($session->isLoggedIn() && !($session->isAdmin())){ ?>
                        <li><a href='./?u=ucp'>User Account Control</a></li>
                            <?php } ?>
                        
                        <li>Your Jobs</li>
                        <li>Recent Job Updates</li>
                        <li><input name="loginAuth" class="button" value="Logout" type="submit" /></li>
                    </ul>
                </form> 
createAlert.php

Code: Select all

<?php
    if($session->isAdmin()){
        if(!isset($_POST['createAlertAuth'])){
            $alerts->displayCreateAlertsForm();
        }else{
            $userID = $_SESSION['userData']['userID'];
            $title = mysql_real_escape_string($_POST['title']);
            $message = mysql_real_escape_string($_POST['message']);
            $endDate = mysql_real_escape_string($_POST['endDate']);
            
            var_dump($_POST);
            if($alerts->createAlert($userID,$title,$message,$endDate)==true){
                $session->displayRedirect('Successful: Created new alert.');
            }
        }
    }
?> 
alerts.php

Code: Select all

 
<?php
#
#
#
#
#
#
#
#
#
#
 
class Alerts{
 
    private $database;
    private $validator;
    
    function __Construct(dbConnector $dbConnector, Validator $validator){
        $this->database = $dbConnector;
        $this->validator = $validator;
    }
    
    public function displayCreateAlertsForm(){
        print "
            <h2>Create a new alert</h2>
            <script type='text/javascript'>
            $(function() {
                $('#datepicker').datepicker();
            });
            </script>
            <form name='createAlert' action='?a=createAlert' method='post'>
                <p>
                    Title:<br/><input type='text' name='title' size='50'/><br/><br/>
                    Message:</br><textarea name='message' cols='50' rows='15'></textarea><br/>
                    Alert End Date:<br/><input type='text' name='endDate' id='datepicker'><br/><br/>
                    <input type='submit' name='createAlertAuth' value='Submit'/>
                </p>
            </form>
        ";
    }
    
    public function createAlert($userID,$title,$message,$endDate){
        if(!$this->validator->validate($userID,'number'))
            return ERROR_VALIDATE_NUMBER;
        if(!$this->validator->validate($title,'string'))
            return ERROR_VALIDATE_STRING;
        if(!$this->validator->validate($message,'string'))
            return ERROR_VALIDATE_STRING;
        if(!$this->validator->validate($endDate,'date'))
            return ERROR_VALIDATE_DATE;
            
        $q = "SELECT `user_id` FROM ".TBL_ADMIN." WHERE `user_id` = '{$userID}'";
        if($this->database->query($q)){
            $date = "date";
            $q = "INSERT INTO `alerts` (`user_id`,`startDate`,`endDate`,`title`,`message`)
                    VALUES ('{$userID}','{$date}','{$endDate}','{$title}','{$message}')";
            $r = $this->database->query($q) or die("MySQL Error: ".mysql_error());
            if($r){
                return true;
            }
        }
        return false;
    }
 
    public function getAllAlerts(){
        $q = "SELECT * FROM `alerts` ORDER BY `id` DESC";
        $r = $this->database->query($q);
        if($r){
            while($row = $this->database->fetchAssoc($r)){
                $this->displayAlert($row,true);
            }
        }
        return false;
    }
    
    public function getAlert($alertID){
        $q = "SELECT * FROM `alerts` WHERE `id` = '{$alertID}'";
        $r = $this->database->query($q);
        if($r){
            $this->displayAlert($this->database->fetchAssoc($r));
        }
        return false;
    }
    
    public function getRecentAlert(){
        $q = "SELECT * FROM `alerts` ORDER BY `id` DESC";
        $r = $this->database->query($q);
        if($r){
            // TO DO - Date Check
            // check alert expiery date
            // if date has not been reached
            // return the alert or else dont return the alert
            $alert = $this->database->fetchAssoc($r);
            print "
                <!-- alerts -->
                <div id='alerts'>
                    <p><a href='?p=alerts'>
                    <strong>ALERT: {$alert['title']}</strong>
                    </a></p>
                <!-- alerts end here -->
                </div>";
        }
        return false;
    }
    
    public function displayAlert($row,$short=false){
        $msg = $row['message'];
        $message = $this->shortDescription($msg,$row['id'],$short);
        print " <div id='alertList'>
                    <a href='?p=alerts&id={$row['id']}'>
                    <h2>ALERT: {$row['title']}</h2>
                    </a>
                    {$message}
                </div>";
    }
    
    public function shortDescription($text,$postID,$short){
        if($short){
            if(strlen($text) >= 255){
                return implode(array_splice(str_split($text,1), 0, 255))."<br><a href='?p=alerts&id={$postID}'>Read More</a>";
            }
        }
        return $text;
    }
};

Re: Mystery form fields

Posted: Sun Feb 14, 2010 2:14 am
by requinix
Right at the top of index.php:

Code: Select all

if(!isset($_POST['username']) && !isset($_POST['password'])){
    $_POST['username'] = ""; $_POST['password'] = "";
They show up because the code put them there.