Commit c1a346d8 authored by Remi Germain's avatar Remi Germain
Browse files

fix xss

parent 9d763330
......@@ -7,10 +7,10 @@ class App
{
const DB_NAME = 'camagru';
const DB_USER = 'root';
// const DB_PASS = 'rootpass';
const DB_PASS = 'root';
//const DB_HOST = '172.18.0.2';
const DB_HOST = 'localhost';
const DB_PASS = 'rootpass';
// const DB_PASS = 'root';
const DB_HOST = '172.18.0.2';
// const DB_HOST = 'localhost';
private static $database;
private static $title = 'camagru';
......@@ -59,7 +59,8 @@ class App
public static function path()
{
return ("http://" . $_SERVER['REMOTE_ADDR'] . "/");
return ("http://" . $_SERVER['REMOTE_ADDR'] . ":" . $_SERVER['SERVER_PORT'] . "/");
//return ("http://localhost:8008/");
}
Public static function getPath($file)
......@@ -108,11 +109,11 @@ class App
{
$pagination = 1;
if (isset($_GET['pagination']))
$pagination = $_GET['pagination'];
$pagination = $_GET['pagination'];
if ($pagination > $count * $nb)
$pagination = $count;
else if ($pagination <= 0)
$pagination = 1;
$pagination = 1;
return ($pagination);
}
......@@ -129,8 +130,8 @@ class App
{
$res['status'] = $status;
$res['msg'] = $msg;
if (substr($msg, -1 != "."))
$res['msg'] .= ".";
// if (substr($msg, -1) != ".")
// $res['msg'] .= ".";
$res[$new] = $text;
print(json_encode($res));
}
......
......@@ -15,7 +15,7 @@ class Comment
{
if (!App::sessionExist())
Error::notAccess();
else
else if (Image::getImgById($id_image))
{
$val = array("user_id" => $_SESSION['id'], "id_image" => $id_image, "date" => date("Y/m/d H:i"), "comment" => $comment);
if (App::getDb()->setprepare("INSERT INTO comment (user_id, `image`, `date`, comment) VALUES(:user_id, :id_image, :date, :comment)", $val))
......@@ -27,6 +27,8 @@ class Comment
else
Error::server();
}
else
Error::server();
}
}
......
......@@ -56,6 +56,10 @@ class Connection
public static function register($valid = "0")
{
$pattern_email = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i";
$pattern_username = "/^[a-zA-Z0-9]{6,31}$/i";
$pattern_pass = "/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,199}$/i";
$ret = static::find_user($_POST['email'], NULL, $_POST['username']);
if ($_POST['password'] != $_POST['confpassword'])
Error::not_samePass();
......@@ -63,6 +67,12 @@ class Connection
Error::user_Exist($_POST['username']);
else if ($ret && $ret['email'] == $_POST['email'])
Error::mail_Exist($_POST['email']);
else if (!preg_match($pattern_email, $_POST['email']))
Error::createJson("Wrong email!");
else if (!preg_match($pattern_username, $_POST['username']))
Error::createJson("Wrong username!");
else if (!preg_match($pattern_pass, $_POST['password']))
Error::createJson("Wrong password!");
else
{
$val = array(
......@@ -72,7 +82,7 @@ class Connection
"creation_date" => date("Y/m/d H:i"),
"valid" => $valid);
if (!APP::getDB()->setprepare("INSERT INTO user (username, email, pass, creation_date, valid) VALUE(:username, :email, :pass, :creation_date, :valid)", $val))
return (Error::server());
return (Error::server());
$val = array(
"sys" => "No synopis",
"logo" => base64_encode(file_get_contents(App::getPath("vue/img/profil.png"))));
......
......@@ -48,13 +48,13 @@ class Notification
self::sendMail($mail, $_SESSION['username'] . " have comment your image", $msg);
}
public static function newFollow($username, $mail, $image_id)
public static function newFollow($username, $mail, $userid)
{
App::session();
$link = App::path() . "Public/index.php?p=user_home&id=" . $image_id;
$link = App::path() . "Public/index.php?p=user_home&id=" . $userid;
$msg = "<html>Hi " . $username . ", <br><br>" . $_SESSION['username'] .
"</div>have follow you !<br>" .
"<a href=\"" . $link . "\">" . $_SESSION['usernamme'] . "home pages </a>Link</html>";
"<a href=\"" . $link . "\">" . $_SESSION['username'] . "home pages </a>Link</html>";
self::sendMail($mail, $_SESSION['username'] . " have follow you!", $msg);
}
......
......@@ -12,12 +12,21 @@ class Sugestion
public static function Category($text)
{
return (App::getDb()->getprepare("SELECT * FROM category WHERE name LIKE ? LIMIT 5", [$text]));
$val = App::getDb()->getprepare("SELECT * FROM category WHERE name LIKE ? LIMIT 5", [$text]);
foreach ($val as $key => $key2)
{
if ($val[$key]['image'] == null)
{
$enco = base64_encode(file_get_contents(App::getPath("vue/img/notag.png")));
$val[$key]['image'] = $enco;
}
}
return ($val);
}
public static function Title($text)
{
return (App::getDb()->getprepare("SELECT * FROM image WHERE title LIKE ? LIMIT 10", [$text]));
return (App::getDb()->getprepare("SELECT * FROM image WHERE title LIKE ? LIMIT 10", [$text]));
}
}
......
......@@ -19,7 +19,7 @@ class User
$info['follower'] = intval($follower['follower']);
$info['like'] = intval($like['like']);
$info['notif'] = $notif;
return ($info);
return ($info);
}
static Public function getUserId($username)
......@@ -29,10 +29,11 @@ class User
static Public function changeMail($new_mail)
{
$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i";
App::session();
if (!App::sessionExist())
Error::notAccess();
else
else if (preg_match($pattern, $new_mail))
{
$val = array("new_mail" => $new_mail, "old_email" => $_SESSION['mail']);
if (!App::getDb()->getprepare("SELECT user.email FROM user WHERE user.email = ?", [$new_mail]))
......@@ -45,14 +46,17 @@ class User
else
Error::mail_Exist($new_mail);
}
else
Error::createJson("Wrong email!");
}
static Public function changeusername($new_username)
{
$pattern = "/^[a-zA-Z0-9]{6,31}$/i";
App::session();
if (!App::sessionExist())
Error::notAccess();
else
else if (preg_match($pattern, $new_username))
{
if (strlen($new_username) <= 6)
return (Error::createJson("username must be higher 6 character"));
......@@ -67,14 +71,17 @@ class User
else
Error::username_Exist($new_username);
}
else
Error::createJson("Wrong username!");
}
static Public function changePassword($old_pass, $new_pass, $conf_pass)
{
$pattern = "/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,199}$/i";
App::session();
if (!App::sessionExist())
Error::notAccess();
else
else if (preg_match($pattern, $new_pass))
{
if ($new_pass !== $conf_pass)
return (Error::not_samePass());
......@@ -89,6 +96,8 @@ class User
else
Error::createJson("Your old password not like this!");
}
else
Error::createJson("Wrong password!");
}
static Public function changeLogo($img)
......@@ -140,7 +149,7 @@ class User
App::session();
if (!App::sessionExist())
Error::notAccess();
else
else if (App::userExist($username))
{
$id_follower = User::getUserId($username);
if ($id_follower == $_SESSION['id'])
......@@ -157,10 +166,10 @@ class User
}
else
{
if (App::getDb()->setprepare("INSERT INTO follower (user_id, follower) VALUES(:user_id, :follower)", $val))
if (App::getDb()->setprepare("INSERT INTO `follower` (`user_id`, `follower`) VALUES(:user_id, :follower)", $val))
{
$info = User::getUserInfo(Image::getImgById($id_image)['username']);
Notification::newFollow($info['username'], $info['email'], $id_image);
$info = User::getUserInfo($username);
Notification::newFollow($username, $info['email'], $_SESSION['id']);
App::createJson("Modification success!");
}
else
......@@ -168,6 +177,8 @@ class User
}
}
}
else
Error::server();
}
static Public function userLikeImage($id_image)
......@@ -175,23 +186,25 @@ class User
App::session();
if (!App::sessionExist())
Error::notAccess();
else
else if (Image::getImgById($id_image))
{
$val = array("user_id" => $_SESSION['id'], "image_id" => $id_image);
if (Image::userLikeImage($id_image))
{
if (!App::getDb()->setprepare("DELETE FROM `favorite` WHERE user_id = :user_id AND image_id = :image_id", $val))
if (!App::getDb()->setprepare("DELETE FROM `favorite` WHERE `user_id` = :user_id AND `image_id` = :image_id", $val))
return (Error::server());
}
else
{
if (!App::getDb()->setprepare("INSERT INTO `favorite` VALUES(:user_id, :image_id)", $val))
return (Error::server());
if (!App::getDb()->setprepare("INSERT INTO `favorite` (`user_id`, `image_id`) VALUES(:user_id, :image_id)", $val))
return (Error::server());
$info = User::getUserInfo(Image::getImgById($id_image)['username']);
Notification::newLike($info['username'], $info['email'], $id_image);
}
App::createJson("Modification success!");
}
else
Error::server();
}
}
?>
\ No newline at end of file
......@@ -22,7 +22,7 @@ if(isset($_POST["submit"]))
{
if ($_POST['username'] == $_SESSION['username'] &&
$_POST['email'] == $_SESSION['mail'] && !isset($_POST['logo']))
print(json_encode(array("status" => -1)));
return print(json_encode(array("status" => -1)));
if ($_POST['email'] !== $_SESSION['mail'])
User::changeMail($_POST['email']);
if ($_POST['username'] !== $_SESSION['username'])
......
......@@ -11,21 +11,31 @@ use App\App;
if(isset($_POST) && isset($_POST["submit"]) && isset($_POST["sugestion"]))
{
$text = trim($_POST['sugestion']);
$new_text = "%" . substr($text, 1) . "%";
$type = "other";
$val = NULL;
if (strlen($text) <= 0 || (strlen($text) == 1 && ($text[0] == "@" || $text[0] == "#")))
$type = "help";
else if (substr($text, 0, 1) == "@")
if (strlen($text) <= 0)
return App::createJson(null, 1, "type", "help");
if ($text[0] == "@")
{
$val = Sugestion::User($new_text);
$type = "user";
$text = substr($text, 1);
}
else if (substr($text, 0, 1) == "#")
else if ($text[0] == "#")
{
$val = Sugestion::Category($new_text);
$type = "category";
$text = substr($text, 1);
}
else
{
$type = "other";
$mode = 0;
}
$new_text = "%" . str_replace("%", "\\%", $text) . "%";
$val = NULL;
if (strlen($text) <= 0)
$type = "help";
else if ($type == "user")
$val = Sugestion::User($new_text);
else if ($type == "category")
$val = Sugestion::Category($new_text);
else
$val = Sugestion::Title($new_text);
App::createJson($val, 1, "type", $type);
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment