public function check_password_complexity($password, $passwordCheck)
 {
     $retval = array('result' => false, 'passcheck' => 0, 'info' => "Password too short or not given");
     if ($password != $passwordCheck) {
         $retval['info'] = "Passwords don't match.";
     } elseif (!is_null($password) && strlen($password) < 8) {
         $retval['info'] = "Password too short; must be at least 8 characters.";
     } elseif (!is_null($password)) {
         if ($password == $passwordCheck) {
             $retval['passcheck'] = 1;
             $regexList = array('one number' => '/[0-9]{1,}/', 'one lowercase letter' => '/[a-z]{1,}/', 'one uppercase letter' => '/[A-Z]{1,}/');
             $passes = 0;
             $retval['info'] = "";
             foreach ($regexList as $text => $regex) {
                 $passFailText = "FAIL";
                 if (preg_match($regex, $password)) {
                     $passes++;
                     $passFailText = "ok";
                 } else {
                     $retval['info'] = ToolBox::create_list($retval['info'], $text, " and ");
                 }
             }
             if ($passes == count($regexList)) {
                 $retval['result'] = true;
             } else {
                 $retval['info'] = "Password must contain at least one " . $retval['info'];
             }
         } else {
             $retval['info'] = "passwords don't match";
         }
     }
     $this->logger->log_by_class(__METHOD__ . ": result=(" . ToolBox::interpret_bool($retval['result'], array(0, 1)) . "), " . "passcheck=(" . $retval['passcheck'] . ")", 'precheck');
     return $retval;
 }
Beispiel #2
0
function debug_backtrace($printItForMe = NULL, $removeHR = NULL)
{
    if (is_null($printItForMe)) {
        if (defined('DEBUGPRINTOPT')) {
            $printItForMe = constant('DEBUGPRINTOPT');
        } elseif (isset($GLOBALS['DEBUGPRINTOPT'])) {
            $printItForMe = $GLOBALS['DEBUGPRINTOPT'];
        }
    }
    if (is_null($removeHR)) {
        if (defined('DEBUGREMOVEHR')) {
            $removeHR = constant('DEBUGREMOVEHR');
        } elseif (isset($GLOBALS['DEBUGREMOVEHR'])) {
            $removeHR = $GLOBALS['DEBUGREMOVEHR'];
        }
    }
    //create our own backtrace data.
    $stuff = \debug_backtrace();
    if (is_array($stuff)) {
        $i = 0;
        foreach ($stuff as $num => $arr) {
            if ($arr['function'] !== "debug_print_backtrace") {
                $fromClass = '';
                if (isset($arr['class']) && strlen($arr['class'])) {
                    $fromClass = $arr['class'] . '::';
                }
                $args = '';
                foreach ($arr['args'] as $argData) {
                    $args = ToolBox::create_list($args, ToolBox::truncate_string(ToolBox::debug_print($argData, 0, 1, false), 600), ', ');
                }
                $fileDebug = "";
                if (isset($arr['file'])) {
                    $fileDebug = " from file <u>" . $arr['file'] . "</u>, line #" . $arr['line'];
                }
                $tempArr[$num] = $fromClass . $arr['function'] . '(' . $args . ')' . $fileDebug;
            }
        }
        array_reverse($tempArr);
        $myData = null;
        foreach ($tempArr as $num => $func) {
            $myData = ToolBox::create_list($myData, "#" . $i . " " . $func, "\n");
            $i++;
        }
    } else {
        //nothing available...
        $myData = $stuff;
    }
    $backTraceData = ToolBox::debug_print($myData, $printItForMe, $removeHR);
    return $backTraceData;
}
 /**
  * 
  * @param bool/optional $onlyInUse	If specified, returns only those with the
  *										given value in the "in_use" column.
  * 
  * @return type
  * @throws ErrorException
  */
 public static function get_all(Database $dbObj, $characterId, $onlyInUse = null)
 {
     $sql = 'SELECT * FROM ' . self::tableName . ' WHERE ';
     //'character_id=:id';
     $params = array('character_id' => $characterId);
     if (!is_null($onlyInUse) && is_bool($onlyInUse)) {
         $params['in_use'] = ToolBox::interpret_bool($onlyInUse, array('f', 't'));
     }
     $addThis = "";
     foreach (array_keys($params) as $n) {
         $addThis = ToolBox::create_list($addThis, $n . '=:' . $n, ' AND ');
     }
     $sql .= $addThis;
     try {
         $dbObj->run_query($sql, $params);
         $retval = $dbObj->farray_fieldnames(self::pkeyField);
     } catch (Exception $e) {
         throw new ErrorException(__METHOD__ . ":: failed to retrieve character weapons, DETAILS::: " . $e->getMessage());
     }
     return $retval;
 }
 public function update()
 {
     $updateSql = "";
     $params = $this->_clean_data_array($this->_data);
     foreach ($params as $k => $v) {
         if (count($this->booleanFields) && in_array($k, $this->booleanFields)) {
             $params[$k] = ToolBox::interpret_bool($v, array('f', 't'));
         }
         $updateSql = ToolBox::create_list($updateSql, $k . '=:' . $k, ',');
     }
     $sql = "UPDATE " . $this->_dbTable . " SET " . $updateSql . " WHERE " . $this->_dbPkey . "=:id";
     $params['id'] = $this->id;
     try {
         $this->dbObj->run_update($sql, $params);
         $retval = true;
     } catch (Exception $ex) {
         throw new LogicException(__METHOD__ . ": unable to update table '" . $this->_dbTable . "', DETAILS::: " . $ex->getMessage());
     }
     return $retval;
 }
Beispiel #5
0
 private function check_chroot($path, $translatePath = TRUE)
 {
     if ($translatePath === TRUE) {
         $path = $this->filename2absolute($path);
     }
     //now, let's go through the root directory structure, & make sure $path is within that.
     $rootPieces = explode('/', $this->root);
     $pathPieces = explode('/', $path);
     if (is_file($path)) {
         $filename = array_pop($pathPieces);
     }
     if ($rootPieces[0] == '') {
         array_shift($rootPieces);
     }
     if (count($rootPieces) > 1 && $rootPieces[count($rootPieces) - 1] == '') {
         array_pop($rootPieces);
     }
     if ($pathPieces[0] == '') {
         array_shift($pathPieces);
     }
     $retval = TRUE;
     $tmp = '';
     foreach ($rootPieces as $index => $dirName) {
         $pathDir = $pathPieces[$index];
         if ($pathDir != $dirName) {
             $retval = FALSE;
             ToolBox::debug_print(__METHOD__ . ": comparing rootPieces to pathPieces... rootPieces::: " . ToolBox::debug_print($rootPieces, 0) . " pathPieces::: " . ToolBox::debug_print($pathPieces, 0));
             ToolBox::debug_print(__METHOD__ . ": failed... root=(" . $this->root . "), tmp=(" . $tmp . "), dirName=(" . $dirName . "), translatePath=(" . $translatePath . ")");
             break;
         }
         $tmp = ToolBox::create_list($tmp, $dirName, '/');
     }
     return $retval;
 }
 /**
  * 
  * @param $uid		(int/optional) Find tokens just for this uid
  * @param $type		(int/optional) Find tokens just of this type
  * @param $limit	(int/optional) Limit number of results (pagination)
  * @param $offset	(int/optional) Offset number of results (pagination)
  * 
  * @return type
  * @throws Exception
  */
 public function get_all($uid = null, $type = null, $limit = null, $offset = 0)
 {
     $sql = "SELECT *, (a.max_uses - a.total_uses) AS remaining_uses, \n\t\t\t(NOW() - a.expiration) AS time_remaining FROM cswal_auth_token_table \n\t\t\tAS a INNER JOIN cswal_token_type_table AS t USING (token_type_id)";
     $params = array();
     if (!is_null($uid)) {
         $params['uid'] = $uid;
     }
     if (!is_null($type)) {
         $params['token_type_id'] = $type;
     }
     if (count($params) > 0) {
         $criteria = "";
         foreach ($params as $field => $val) {
             $criteria = ToolBox::create_list($criteria, $field . '=:' . $field, " AND ");
         }
         $sql .= " WHERE " . $criteria;
     }
     $sql .= " ORDER BY t.token_type, t.token_desc";
     if (!is_null($limit) && is_numeric($limit)) {
         $sql .= " LIMIT " . $limit;
     }
     if (!is_null($offset) && is_numeric($offset)) {
         $sql .= " OFFSET " . $offset;
     }
     try {
         $numrows = $this->db->run_query($sql, $params);
         $retval = array();
         if ($numrows > 0) {
             $retval = $this->db->farray_fieldnames('auth_token_id');
         }
     } catch (Exception $ex) {
         throw new Exception(__METHOD__ . ": failed to retrieve tokens, SQL::: " . $sql . "\n\nDETAILS::: " . $ex->getMessage());
     }
     return $retval;
 }
 public function create_sql_insert_string(array $data)
 {
     #$retval = "";
     if (is_array($data) && count($data)) {
         $fields = "";
         $values = "";
         foreach ($data as $k => $v) {
             $fields = ToolBox::create_list($fields, $k, ", ");
             $values = ToolBox::create_list($values, ':' . $k, ", ");
         }
         if (strlen($fields) && strlen($values)) {
             $retval = ' (' . $fields . ') VALUES (' . $values . ')';
         } else {
             throw new Exception(__METHOD__ . ": no fields (" . $fields . ") or values (" . $values . ") created... " . $this->gfObj->debug_print($data, 0));
         }
     } else {
         throw new Exception(__METHOD__ . ": unable to create insert string, no fields given");
     }
     return $retval;
 }
Beispiel #8
0
 public function test_create_list()
 {
     $this->assertEquals("first", ToolBox::create_list("", "first"));
     $this->assertEquals("first, second", ToolBox::create_list("first", "second"));
     $this->assertEquals("1-2", ToolBox::create_list("1", "2", "-"));
 }
 /**
  * Update the permission value.
  * 
  * @param int $id			The ID of the record to update.
  * @param array $changes	Field=>value array of changes.
  * 
  * @return int				Number of records updated; MySQL might return 0 if nothing about the record was actually changed.
  * 
  * @throws exception
  * @throws InvalidArgumentException
  */
 public function update($id, array $changes)
 {
     $sql = 'UPDATE ' . self::TABLE . ' SET ';
     $params = array();
     $changeList = "";
     foreach ($changes as $key => $value) {
         switch ($key) {
             case 'object':
             case 'user_id':
             case 'group_id':
                 $params[$key] = $value;
                 $changeList = ToolBox::create_list($changeList, "{$key}=:{$key}");
                 break;
             case 'perms':
                 $this->translate_perms($value);
                 $params[$key] = $value;
                 $changeList = ToolBox::create_list($changeList, "{$key}=:{$key}");
                 break;
             default:
                 throw new InvalidArgumentException("unknown column '" . $key . "'");
         }
     }
     $params['id'] = $id;
     $sql .= $changeList . ' WHERE ' . self::PKEY . ' = :id';
     $result = $this->db->run_update($sql, $params);
     return $result;
 }
 /**
  * Update a single record with the given changes.
  * 
  * @recId			(int) ID to update.
  * @updates			(array) field=>value list of changes.
  * 
  * @RETURN (int)	SUCCESS: (int) is the number of records updated (should always be 1)
  * @EXCEPTION		FAIL: exception indicates the error.
  * 
  * TODO: remove arg #3, since it is now unused
  * TODO: remove arg #4, since arg #1 can be an array (to make the same specification)
  */
 public function update_record($recId, array $updates)
 {
     if ((is_numeric($recId) && $recId >= 0 or is_array($recId) && count($recId)) && is_array($updates) && count($updates) > 0) {
         $updateString = "";
         $params = array();
         foreach ($updates as $f => $v) {
             $updateString = ToolBox::create_list($updateString, $f . '=:' . $f, ', ');
             $params[$f] = $v;
         }
         if (is_array($recId)) {
             foreach ($recId as $f => $v) {
                 $whereClause = ToolBox::create_list($whereClause, $f . '=:' . $f, ' AND ');
                 $params[$f] = $v;
             }
         } else {
             $whereClause = $this->pkeyField . '=:id';
             $params['id'] = $recId;
         }
         $sql = 'UPDATE ' . $this->tableName . ' SET ' . $updateString . ' WHERE ' . $whereClause;
         try {
             $retval = $this->dbObj->run_update($sql, $params);
         } catch (Exception $e) {
             throw new Exception(__METHOD__ . ":: failed to update record (" . $recId . "), DETAILS::: " . $e->getMessage());
         }
     } else {
         throw new Exception(__METHOD__ . ":: failed to update record (" . $recId . "), invalid recordId (" . $recId . "), or no data in array::: " . ToolBox::debug_var_dump($updates, 0));
     }
     return $retval;
 }
 /**
  * Pulls a list of files in the current directory, & arranges them by section & 
  * 	name, or vice-versa.
  */
 private function arrange_directory_contents($dir, $primaryIndex = 'section', $secondaryIndex = 'name')
 {
     $fsObj = new FileSystem($this->tmplFs->root);
     if ($fsObj->cd($dir)) {
         $directoryInfo = $fsObj->ls(null, false);
         $arrangedArr = array();
         if (is_array($directoryInfo)) {
             foreach ($directoryInfo as $index => $data) {
                 $myType = $data['type'];
                 if ($myType == 'file' && !in_array($index, $this->ignoredList[$myType])) {
                     $filename = ToolBox::create_list($fsObj->cwd, $index, '/');
                     $filename = preg_replace('/^\\/templates/', '', $filename);
                     $filename = preg_replace('/^\\/\\//', '/', $filename);
                     //call another method to rip the filename apart properly, then arrange things as needed.
                     $pieces = $this->parse_filename($index);
                     $myPriIndex = $pieces[$primaryIndex];
                     $mySecIndex = $pieces[$secondaryIndex];
                     if (strlen($myPriIndex) && strlen($mySecIndex)) {
                         //only load if it's got BOTH parts of the filename.
                         $arrangedArr[$myPriIndex][$mySecIndex] = $filename;
                     }
                 }
             }
         }
     } else {
         $arrangedArr = array();
     }
     return $arrangedArr;
 }
Beispiel #12
0
 /**
  * Removes all the crap from the url, so we can figure out what section we
  * 	need to load templates & includes for.
  */
 public static function clean_url($url = NULL)
 {
     //make sure we've still got something valid to work with.
     if (strlen($url)) {
         //if there's an "APPURL" constant, drop that from the url.
         if (defined('APPURL') && strlen(constant('APPURL'))) {
             $dropThis = preg_replace('/^\\//', '', constant('APPURL'));
             $dropThis = preg_replace('/\\//', '\\/', $dropThis);
             $url = preg_replace('/^' . $dropThis . '/', '', $url);
         }
         //check the string to make sure it doesn't begin with a "/"
         if ($url[0] == '/') {
             $url = substr($url, 1, strlen($url));
         }
         //check the last char for a "/"...
         if ($url[strlen($url) - 1] == '/') {
             //last char is a '/'... kill it.
             $url = substr($url, 0, strlen($url) - 1);
         }
         //if we've been sent a query, kill it off the string...
         if (preg_match('/\\?/', $url)) {
             $url = preg_split('/\\?/', $url);
             $url = $url[0];
         }
         if (preg_match("/\\./", $url)) {
             //disregard file extensions, but keep everything else...
             //	i.e. "index.php/yermom.html" becomes "index/yermom"
             $tArr = explode('/', $url);
             $tUrl = null;
             foreach ($tArr as $tUrlPart) {
                 $temp = explode(".", $tUrlPart);
                 if (strlen($temp[0])) {
                     $tUrlPart = $temp[0];
                 }
                 $tUrl = ToolBox::create_list($tUrl, $tUrlPart, '/');
             }
             $url = $tUrl;
         }
     } else {
         $url = null;
     }
     return $url;
 }