Skip to content

Commit

Permalink
Fixe mysql error where mysql_real_escape_string and email validity ch…
Browse files Browse the repository at this point in the history
…ecking
  • Loading branch information
Jnesselr committed Feb 21, 2013
1 parent 196d445 commit d83f8a5
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.pyc
*.DS_Store
.idea/
extensions/config.php
bumblebee/config.json
bumblebee/cache*
Expand Down
2 changes: 1 addition & 1 deletion classes/verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function username($username, &$reason)

public static function email($email)
{
return eregi("^[_a-z0-9-]+((\+)?(\.)?[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email);
return filter_var($email, FILTER_VALIDATE_EMAIL);
}

}
Expand Down
4 changes: 3 additions & 1 deletion controllers/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ public function update_sort()
}

//find our our current max
$sql = "SELECT min(user_sort) FROM jobs WHERE id IN (" . mysql_real_escape_string(implode($jids, ",")) . ")";
$sql = "SELECT min(user_sort) FROM jobs WHERE id IN (" .
mysqli_real_escape_string(db()->getLink(), implode($jids, ",")) .
")";
$min = (int)db()->getValue($sql);

//now actually update.
Expand Down
2 changes: 1 addition & 1 deletion framework/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private function saveDb()
//$val = str_replace("\\\"", "\"", $val);

//add it if we have it...
$fields[] = "`$key` = '" . mysql_real_escape_string($val) . "'";
$fields[] = "`$key` = '" . mysqli_real_escape_string(db()->getLink(), $val) . "'";
}
}

Expand Down
2 changes: 1 addition & 1 deletion framework/schematracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private function getChange($name)

$sql = file_get_contents($path);

$sql .= "\nINSERT INTO schema_changes SET name='" . mysql_real_escape_string($name) . "';\n";
$sql .= "\nINSERT INTO schema_changes SET name='" . mysqli_real_escape_string(db()->getLink(), $name) . "';\n";

return $sql;
}
Expand Down
2 changes: 1 addition & 1 deletion models/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function getStream() {
$sql = "
SELECT id, user_id
FROM activities
WHERE user_id = '" . mysql_real_escape_string(User::$me->id) . "'
WHERE user_id = '" . mysqli_real_escape_string(db()->getLink(), User::$me->id) . "'
ORDER BY id DESC
";

Expand Down
10 changes: 5 additions & 5 deletions models/bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public function getCurrentJob()
public function getJobs($status = null, $sortField = 'user_sort', $sortOrder = 'ASC')
{
if ($status !== null)
$statusSql = " AND status = '" . mysql_real_escape_string($status) . "'";
$statusSql = " AND status = '" . mysqli_real_escape_string(db()->getLink(), $status) . "'";

$sql = "
SELECT id
FROM jobs
WHERE bot_id = " . mysql_real_escape_string($this->id) ."
WHERE bot_id = " . mysqli_real_escape_string(db()->getLink(), $this->id) ."
{$statusSql}
ORDER BY {$sortField} {$sortOrder}
";
Expand All @@ -105,7 +105,7 @@ public function getErrorLog()
$sql = "
SELECT id
FROM error_log
WHERE bot_id = '". mysql_real_escape_string($this->id) ."'
WHERE bot_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY error_date DESC
";

Expand Down Expand Up @@ -262,7 +262,7 @@ public function getStats()
$sql = "
SELECT status, count(status) as cnt
FROM jobs
WHERE bot_id = ". mysql_real_escape_string($this->id) ."
WHERE bot_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
GROUP BY status
";

Expand All @@ -287,7 +287,7 @@ public function getStats()
SELECT sum(verified_time - finished_time) as wait, sum(finished_time - taken_time) as runtime, sum(verified_time - taken_time) as total
FROM jobs
WHERE status = 'complete'
AND bot_id = ". mysql_real_escape_string($this->id);
AND bot_id = ". mysqli_real_escape_string(db()->getLink(), $this->id);

$stats = db()->getArray($sql);

Expand Down
2 changes: 1 addition & 1 deletion models/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function byGUID($guid)
$sql = "
SELECT id
FROM comments
WHERE guid = '".mysql_real_escape_string($guid)."'";
WHERE guid = '".mysqli_real_escape_string(db()->getLink(), $guid)."'";
$id = db()->getValue($sql);

//send it!
Expand Down
2 changes: 1 addition & 1 deletion models/job.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function getErrorLog()
$sql = "
SELECT id
FROM error_log
WHERE job_id = '".mysql_real_escape_string($this->id)."'
WHERE job_id = '".mysqli_real_escape_string(db()->getLink(), $this->id)."'
ORDER BY error_date DESC
";

Expand Down
6 changes: 3 additions & 3 deletions models/oauthconsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static function findByKey($key)
$sql = "
SELECT id
FROM oauth_consumer
WHERE consumer_key = '". mysql_real_escape_string($key) ."'
WHERE consumer_key = '". mysqli_real_escape_string(db()->getLink(), $key) ."'
";
$id = db()->getValue($sql);

Expand Down Expand Up @@ -94,12 +94,12 @@ public function delete()
{
//delete all our tokens
db()->execute("
DELETE FROM oauth_token WHERE consumer_id = ". mysql_real_escape_string($this->id) ."
DELETE FROM oauth_token WHERE consumer_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
");

//delete all our nonces
db()->execute("
DELETE FROM oauth_token_nonce WHERE consumer_id = ". mysql_real_escape_string($this->id) ."
DELETE FROM oauth_token_nonce WHERE consumer_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
");

parent::delete();
Expand Down
14 changes: 7 additions & 7 deletions models/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public function getUrl()
public function getJobs($status = null, $sortField = 'user_sort', $sortOrder = 'ASC')
{
if ($status !== null)
$statusSql = " AND status = '".mysql_real_escape_string($status)."'";
$statusSql = " AND status = '".mysqli_real_escape_string(db()->getLink(), $status)."'";

$sql = "
SELECT id
FROM jobs
WHERE queue_id = '".mysql_real_escape_string($this->id)."'
WHERE queue_id = '".mysqli_real_escape_string(db()->getLink(), $this->id)."'
{$statusSql}
ORDER BY {$sortField} {$sortOrder}
";
Expand Down Expand Up @@ -95,7 +95,7 @@ public function getActiveJobs($sortField = 'user_sort', $sortOrder = 'ASC')
$sql = "
SELECT id
FROM jobs
WHERE queue_id = '".mysql_real_escape_string($this->id)."'
WHERE queue_id = '".mysqli_real_escape_string(db()->getLink(), $this->id)."'
AND status IN ('available', 'taken')
ORDER BY {$sortField} {$sortOrder}
";
Expand All @@ -107,7 +107,7 @@ public function getBots()
$sql = "
SELECT id
FROM bots
WHERE queue_id = '".mysql_real_escape_string($this->id)."'
WHERE queue_id = '".mysqli_real_escape_string(db()->getLink(), $this->id)."'
ORDER BY last_seen DESC
";

Expand Down Expand Up @@ -176,7 +176,7 @@ public function getStats()
$sql = "
SELECT status, count(status) as cnt
FROM jobs
WHERE queue_id = ". mysql_real_escape_string($this->id)."
WHERE queue_id = ". mysqli_real_escape_string(db()->getLink(), $this->id)."
GROUP BY status
";

Expand All @@ -201,7 +201,7 @@ public function getStats()
SELECT sum(taken_time - created_time) as wait, sum(finished_time - taken_time) as runtime, sum(verified_time - created_time) as total
FROM jobs
WHERE status = 'complete'
AND queue_id = ". mysql_real_escape_string($this->id) ."
AND queue_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
";

$stats = db()->getArray($sql);
Expand Down Expand Up @@ -230,7 +230,7 @@ public function getErrorLog()
$sql = "
SELECT id
FROM error_log
WHERE queue_id = '". mysql_real_escape_string($this->id) ."'
WHERE queue_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY error_date DESC
";

Expand Down
4 changes: 2 additions & 2 deletions models/s3file.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ public function getJobs()
$sql = "
SELECT id
FROM jobs
WHERE source_file_id = '". mysql_real_escape_string($this->id) ."'
OR file_id = '". mysql_real_escape_string($this->id) ."'
WHERE source_file_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
OR file_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY id DESC
";

Expand Down
2 changes: 1 addition & 1 deletion models/shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function byUrl($url)
$sql = "
SELECT id
FROM shortcodes
WHERE url = '".mysql_real_escape_string($url)."'
WHERE url = '".mysqli_real_escape_string(db()->getLink(), $url)."'
";

$value = db()->getValue($sql);
Expand Down
6 changes: 3 additions & 3 deletions models/sliceconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getBots()
$sql = "
SELECT id
FROM bots
WHERE slice_config_id = '". mysql_real_escape_string($this->id) ."'
WHERE slice_config_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY name
";

Expand All @@ -81,7 +81,7 @@ public function getSliceJobs()
$sql = "
SELECT id
FROM slice_jobs
WHERE slice_config_id = '". mysql_real_escape_string($this->id) ."'
WHERE slice_config_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY id DESC
";

Expand All @@ -94,7 +94,7 @@ public function expireSliceJobs()
UPDATE slice_jobs
SET status = 'expired'
WHERE status = 'complete'
AND slice_config_id = '". mysql_real_escape_string($this->id) ."'
AND slice_config_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
";

db()->execute($sql);
Expand Down
4 changes: 2 additions & 2 deletions models/sliceengine.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getAllConfigs()
$sql = "
SELECT id
FROM slice_configs
WHERE engine_id = '". mysql_real_escape_string($this->id) ."'
WHERE engine_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY config_name
";

Expand All @@ -94,7 +94,7 @@ public function getMyConfigs()
$sql = "
SELECT id
FROM slice_configs
WHERE engine_id = '". mysql_real_escape_string($this->id) ."'
WHERE engine_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
AND (user_id = '" . User::$me->id . "' OR id = '" . $this->get('default_config_id') . "')
ORDER BY config_name
";
Expand Down
4 changes: 2 additions & 2 deletions models/slicejob.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public static function byConfigAndSource($config_id, $source_id)
$sql = "
SELECT id
FROM slice_jobs
WHERE slice_config_id = ".mysql_real_escape_string($config_id)."
AND input_id = ".mysql_real_escape_string($source_id)."
WHERE slice_config_id = ".mysqli_real_escape_string(db()->getLink(), $config_id)."
AND input_id = ".mysqli_real_escape_string(db()->getLink(), $source_id)."
AND user_id = " . User::$me->id . "
AND status = 'complete'
";
Expand Down
2 changes: 1 addition & 1 deletion models/token.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function byToken($token)
$sql = "
SELECT id
FROM tokens
WHERE hash = '".mysql_real_escape_string($token)."'
WHERE hash = '".mysqli_real_escape_string(db()->getLink(), $token)."'
";
$id = db()->getValue($sql);

Expand Down
24 changes: 12 additions & 12 deletions models/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static function hashPass($pass)

public static function byUsername($username)
{
$username = mysql_real_escape_string($username);
$username = mysqli_real_escape_string(db()->getLink(), $username);

//look up the token
$sql = "
Expand All @@ -169,7 +169,7 @@ public static function byUsername($username)

public static function byUsernameAndPassword($username, $password)
{
$username = mysql_real_escape_string($username);
$username = mysqli_real_escape_string(db()->getLink(), $username);
$pass_hash = sha1($password);

//look up the combo.
Expand All @@ -187,7 +187,7 @@ public static function byUsernameAndPassword($username, $password)

public static function byEmail($email)
{
$email = mysql_real_escape_string($email);
$email = mysqli_real_escape_string(db()->getLink(), $email);

//look up the token
$sql = "
Expand Down Expand Up @@ -249,7 +249,7 @@ public function getActivityStream()
$sql = "
SELECT id, user_id
FROM activities
WHERE user_id = '". mysql_real_escape_string($this->id) ."'
WHERE user_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY id DESC
";

Expand All @@ -275,7 +275,7 @@ public function getQueues()
$sql = "
SELECT id
FROM queues
WHERE user_id = ". mysql_real_escape_string($this->id) ."
WHERE user_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
ORDER BY name
";

Expand All @@ -287,7 +287,7 @@ public function getDefaultQueue()
$sql = "
SELECT id FROM queues
WHERE name = 'Default'
AND user_id = ". mysql_real_escape_string($this->id) ."
AND user_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
";
$q = new Queue(db()->getValue($sql));

Expand All @@ -308,7 +308,7 @@ public function getBots()
$sql = "
SELECT id, queue_id, job_id
FROM bots
WHERE user_id = ". mysql_real_escape_string($this->id) ."
WHERE user_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
ORDER BY name
";

Expand All @@ -323,7 +323,7 @@ public function getJobs($status = null, $sortField = 'user_sort', $sortOrder = '
$sql = "
SELECT id
FROM jobs
WHERE user_id = ". mysql_real_escape_string($this->id) ."
WHERE user_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
{$statusSQL}
ORDER BY {$sortField} {$sortOrder}
";
Expand All @@ -336,7 +336,7 @@ public function getAuthorizedApps()
$sql = "
SELECT id, consumer_id
FROM oauth_token
WHERE user_id = ". mysql_real_escape_string($this->id) ."
WHERE user_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
AND type = 2
ORDER BY id
";
Expand All @@ -349,7 +349,7 @@ public function getMyApps()
$sql = "
SELECT id
FROM oauth_consumer
WHERE user_id = ". mysql_real_escape_string($this->id) ."
WHERE user_id = ". mysqli_real_escape_string(db()->getLink(), $this->id) ."
ORDER BY name
";

Expand All @@ -361,7 +361,7 @@ public function getErrorLog()
$sql = "
SELECT id
FROM error_log
WHERE user_id = '". mysql_real_escape_string($this->id) ."'
WHERE user_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY error_date DESC
";

Expand All @@ -373,7 +373,7 @@ public function getMySliceConfigs()
$sql = "
SELECT id, engine_id
FROM slice_configs
WHERE user_id = '". mysql_real_escape_string($this->id) ."'
WHERE user_id = '". mysqli_real_escape_string(db()->getLink(), $this->id) ."'
ORDER BY engine_id DESC
";

Expand Down

0 comments on commit d83f8a5

Please sign in to comment.