Changeset 192

Show
Ignore:
Timestamp:
08/09/06 15:44:02 (2 years ago)
Author:
rollercow
Message:

More small sanity changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • admin.lib.php

    r191 r192  
    725725                echo "</select><br />\n"; 
    726726                echo "<input type=\"submit\" name=\"delete\" value=\"Delete selected\" />\n"; 
     727                echo "</form>\n"; 
     728                //close and start a new form, so pressing enter in the 2nd bit of the form submits with addnew rather than delete 
     729                echo "<form name=\"emailform\" id=\"emailform\" action=\"".$this->adminPath."updateauthusers\" method=\"post\">\n"; 
    727730                echo "<h3>"._("Add Address")."</h3>\n"; 
    728731                echo "<input type=\"text\" name=\"name\" id=\"name\" />\n"; 
     
    734737                echo "</div>\n"; 
    735738        } 
    736 //got here, need to check for valid email address and such before hitting the db 
    737739        //udates the list of authorised users. 
    738740        function updateAuthorisedUsers($quiet=FALSE) { 
     741                //hack so we get error returned from validEmail 
     742                global $error; 
     743                //if we have a delete action 
    739744                if(isset($_POST['delete'])) { 
    740745                        if (count($_POST['emaillist'])==0) { 
     
    743748                                $del = "("; 
    744749                                foreach($_POST['emaillist'] as $addr) { 
    745                                         $del .= "email='$addr' OR "; 
     750                                        if(validEmail($addr)) { 
     751                                                $del .= "email='$addr' OR "; 
     752                                        } else { 
     753                                                error(2,_("Invalid email address : ".$error)); 
     754                                                return; 
     755                                        } 
    746756                                } 
    747757                                $del = substr($del, 0, -4).")"; 
     
    754764                                } 
    755765                        } 
    756                 } elseif(isset($_POST['addnew'])) { 
    757                         if(trim($_POST['name'])=="") { 
    758                                 $error = _("Check name"); 
     766                }  
     767                //if we have a add action 
     768                elseif(isset($_POST['addnew'])) { 
     769                        if(trim($_POST['name'])=="" or !eregi("^([a-z0-9]+([:space:][a-z0-9]*))$",trim($_POST['name']))) { 
     770                                $this->error = _("Check name"); 
    759771                        } 
    760772                        if(!validEmail($_POST['email'])) { 
    761                                 $error = _("Check e-mail address"); 
    762                         } 
    763                         if($error==""){ 
     773                                $this->error = _("Invalid e-mail address : ".$error); 
     774                        } 
     775                        if($this->error==""){ 
    764776                                $name = addslashes(trim($_POST['name'])); 
    765777                                $email = addslashes(trim($_POST['email'])); 
     
    770782                                        echo "<div class=\"updateinfo\">"._("Address added")."</div>\n"; 
    771783                                } 
     784                        } 
     785                        else { 
     786                                error(3,$this->error); 
    772787                        } 
    773788                } 
     
    825840                        error(4, _("No entries marked for deletion.")); 
    826841                } else { 
    827                         //Need to check the entries exist first 
    828842                        if ($_REQUEST[submit]==_("Yes")) { 
    829843                                $sql = "DELETE FROM entries WHERE ("; 
     
    834848                                $sql .= ") AND user_id = {$this->id};"; 
    835849                                db_query($sql); 
    836                                 echo count($_POST['entry'])._(" post(s) deleted"); 
     850                                echo db_affected_rows($sql)._(" post(s) deleted"); 
    837851                        } else { 
    838852                                error(4, _("Entries not deleted.")); 
     
    859873                $description = ''; 
    860874                //sanitise username 
    861                 if (isset($_POST['username']) && trim($_POST['username']) != "" && (int)$_POST['username'] == 0) { 
     875                if (trim($_POST['username']) != "") { 
    862876                        if (safeuname($_POST['username'])) { 
    863                                 $username = addslashes(trim(strip_tags($_POST['username'])))
     877                                $username = $_POST['username']
    864878                        } else { 
    865                                 $this->inputError = _("Invalid Username Provided"); 
    866                         } 
    867                 } else { 
    868                         $this->inputError = _("No Username Provided"); 
    869                 } 
    870                 //sanitise name 
    871                 if (isset($_POST['name']) && trim($_POST['name']) != "" && (int)$_POST['name'] == 0) { 
    872                         $name = addslashes(trim(strip_tags($_POST['name']))); 
    873                 } else { 
    874                         $this->inputError = _("No Real Name Provided"); 
    875                 } 
    876                 //sanitise title 
    877                 if (isset($_POST['title']) && trim($_POST['title']) != "" && (int)$_POST['title'] == 0) { 
     879                                $this->error = _("Invalid Username Provided"); 
     880                        } 
     881                } else { 
     882                        $this->error = _("No Username Provided"); 
     883                } 
     884                //sanitise name, perhaps a bit too strict? 
     885                if (trim($_POST['name'])) { 
     886                        if (eregi("^([a-z]+([:space:][a-z]*))$",trim($_POST['name']))) { 
     887                                $name = trim($_POST['name']); 
     888                        } 
     889                        else { 
     890                                $this->error = _("Invalid Name Provided"); 
     891                        } 
     892                } else { 
     893                        $this->error = _("No Real Name Provided"); 
     894                } 
     895                //sanitise title, regexp? ^([a-z0-9]+([:space:][a-z0-9]*))$ as a base form and '\', '-', '.', ',', ':', ';', '?', '!' 
     896                if (isset($_POST['title']) && trim($_POST['title']) != "") { 
    878897                        $title = addslashes(trim(strip_tags($_POST['title']))); 
    879898                } else { 
    880                         $this->inputError = _("No Title Provided"); 
    881                 } 
    882                 //sanitise description 
    883                 if (isset($_POST['description']) && trim($_POST['description']) != "" && (int)$_POST['description'] == 0) { 
     899                        $this->error = _("No Title Provided"); 
     900                } 
     901                //sanitise description, same check as title gets 
     902                if (isset($_POST['description']) && trim($_POST['description']) != "") { 
    884903                        $description = addslashes(trim(strip_tags($_POST['description']))); 
    885904                } else { 
    886                         $this->inputError = _("No Description Provided"); 
     905                        $this->error = _("No Description Provided"); 
    887906                } 
    888907                //check the user doesn't already exist 
     
    890909                $sqlNum = db_num_rows($sql); 
    891910                if ($sqlNum != 0) { 
    892                         $this->inputError = _("Username already in use!"); 
     911                        $this->error = _("Username already in use!"); 
    893912                } 
    894913                //check there is a system user with this name (ie if they are a sucs member) 
    895914                if(!posix_getpwnam($username)) { 
    896                         $this->inputError = _("You need to be a SUCS member to sign up for a blog here!"); 
     915                        $this->error = _("You need to be a SUCS member to sign up for a blog here!"); 
    897916                } else { 
    898917                        //check the user is a member of the users, staff or socieys groups 
    899918                        $posixInfo = posix_getpwnam($username); 
    900919                        if ($posixInfo[gid] != 100 && $posixInfo[gid] != 106 && $posixInfo[gid] != 113) { 
    901                                 $this->inputError = _("Err, No, Your not realy a system user now are you?"); 
     920                                $this->error = _("Err, No, Your not realy a system user now are you?"); 
    902921                        } 
    903922                } 
    904923                //if we dont have any errors 
    905                 if (!$this->inputError) { 
     924                if (!$this->error) { 
    906925                        //encrypt the password 
    907926                        $cryptPassword = crypt($password); 
     
    933952        function addUserForm() { 
    934953                echo "<div class=\"entry\">\n"; 
    935                 if ($this->inputError != "") { 
    936                         echo "<div class=\"errorinfo\">"._("Error")." : " . $this->inputError . "</div>\n"; 
     954                if ($this->error != "") { 
     955                        echo "<div class=\"errorinfo\">"._("Error")." : " . $this->error . "</div>\n"; 
    937956                } 
    938957                echo "<h2>"._("Register for a Blog")."</h2>\n"; 
     
    940959                echo "<form action=\"".$this->adminPath."adduser\" method=\"post\" id=\"adduserform\">\n"; 
    941960                echo "<p>\n"; 
    942                 echo "<input type=\"text\" name=\"username\" id=\"username\" value=\"" . (($this->inputError != "") ? strip_tags(trim($_POST['username'])) : "") . "\" size=\"30\" maxlength=\"60\" tabindex=\"1\" />\n"; 
     961                echo "<input type=\"text\" name=\"username\" id=\"username\" value=\"" . (($this->error != "") ? strip_tags(trim($_POST['username'])) : "") . "\" size=\"30\" maxlength=\"60\" tabindex=\"1\" />\n"; 
    943962                echo "<label for=\"username\">"._("Username")."</label>\n"; 
    944963                echo "</p>\n"; 
    945964                echo "<p>\n"; 
    946                 echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"" . (($this->inputError != "") ? strip_tags(trim($_POST['name'])) : "") . "\" size=\"30\" maxlength=\"60\" tabindex=\"2\" />\n"; 
     965                echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"" . (($this->error != "") ? strip_tags(trim($_POST['name'])) : "") . "\" size=\"30\" maxlength=\"60\" tabindex=\"2\" />\n"; 
    947966                echo "<label for=\"name\">"._("Real name")."</label>\n"; 
    948967                echo "</p>\n"; 
    949968                echo "<p>\n"; 
    950                 echo "<input type=\"text\" name=\"title\" id=\"title\" value=\"" . (($this->inputError != "") ? strip_tags(trim($_POST['title'])) : "") . "\" size=\"30\" maxlength=\"60\" tabindex=\"3\" />\n"; 
     969                echo "<input type=\"text\" name=\"title\" id=\"title\" value=\"" . (($this->error != "") ? strip_tags(trim($_POST['title'])) : "") . "\" size=\"30\" maxlength=\"60\" tabindex=\"3\" />\n"; 
    951970                echo "<label for=\"title\">"._("Title")."</label>\n"; 
    952971                echo "</p>\n"; 
    953972                echo "<p>\n"; 
    954                 echo "<input type=\"text\" name=\"description\" id=\"description\" value=\"" . (($this->inputError != "") ? strip_tags(trim($_POST['description'])) : "") . "\" size=\"30\" maxlength=\"60\" tabindex=\"4\" />\n"; 
     973                echo "<input type=\"text\" name=\"description\" id=\"description\" value=\"" . (($this->error != "") ? strip_tags(trim($_POST['description'])) : "") . "\" size=\"30\" maxlength=\"60\" tabindex=\"4\" />\n"; 
    955974                echo "<label for=\"title\">"._("Description")."</label>\n"; 
    956975                echo "</p>\n";