From 5daf9317210175aa4ba48f6a06f220643cc90f65 Mon Sep 17 00:00:00 2001 From: Noam Tzumie Date: Sun, 6 Jan 2013 22:02:59 +0200 Subject: [PATCH] attribute --- .gitattributes | 22 ++ ImageProcessing/ImageProcessing/Encoding1.cs | 242 ++++++------ .../ImageProcessing/ImageFiltering.cs | 370 +++++++++--------- .../ImageProcessing/ImageProcessing.csproj | 148 +++---- ImageProcessing/ImageProcessing/Program.cs | 34 +- README.md | 16 +- server/act/activate.php | 132 +++---- server/act/add_contact.php | 118 +++--- server/act/add_image.php | 114 +++--- server/act/add_permission.php | 150 +++---- server/act/change_password.php | 102 ++--- server/act/general.php | 48 +-- server/act/get_image.php | 114 +++--- server/act/login.php | 92 ++--- server/act/recover_password.php | 124 +++--- server/act/remove_contact.php | 118 +++--- server/act/remove_image.php | 114 +++--- server/act/remove_permission.php | 124 +++--- server/act/server.php | 350 ++++++++--------- server/act/signup.php | 138 +++---- server/activate.php | 130 +++--- server/add_contact.php | 26 +- server/add_image.php | 28 +- server/add_permission.php | 28 +- server/get_image.php | 30 +- server/inc/settings.php | 12 +- server/login.php | 24 +- server/remove_contact.php | 26 +- server/remove_image.php | 28 +- server/remove_permission.php | 28 +- server/signup.php | 8 +- server/simpletest/test/autorun_test.php | 44 +-- server/t.php | 26 +- 33 files changed, 1565 insertions(+), 1543 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/ImageProcessing/ImageProcessing/Encoding1.cs b/ImageProcessing/ImageProcessing/Encoding1.cs index 8186345..f28c438 100644 --- a/ImageProcessing/ImageProcessing/Encoding1.cs +++ b/ImageProcessing/ImageProcessing/Encoding1.cs @@ -1,121 +1,121 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; -using System.IO; -using System.Net; - -namespace ImageProcessing -{ - - public class Encoding1 - { - - String PROGRAM_ID = "1101000100001"; - Image inputImage; - Bitmap inputBitmap; - int SWAPS = 300; - int HIGHT = 300; - int WIDTH = 400; - int[,] path; - String imageIndex; - - public Encoding1(String dir, string index) - { - imageIndex = index; - path = new int[SWAPS, 2]; - - //retreving image from directory - inputImage = Image.FromFile(dir); - inputBitmap = new Bitmap(inputImage); - - - //resize the pic to 400 x 300 pix - inputBitmap = Resize_Image(inputBitmap, 400, 300); - - //save id in image - make_id(); - - //Encode the image - Random_Shuffle(); - Save_Path(); - Encode_Image(); - - //save encoded image - inputBitmap.Save("C:\\Users\\Public\\EncodedImage" + imageIndex + ".jpg"); - - } - - - - - public System.Drawing.Bitmap Resize_Image(System.Drawing.Bitmap value, int newWidth, int newHeight) - { - System.Drawing.Bitmap resizedImage = new System.Drawing.Bitmap(newWidth, newHeight); - System.Drawing.Graphics.FromImage((System.Drawing.Image)resizedImage).DrawImage(value, 0, 0, newWidth, newHeight); - return (resizedImage); - } - - - public void Random_Shuffle() - { - Random rand = new Random(); - - for (int i = 0; i < (path.Length / 2); i++) - { - for (int j = 0; j < 2; j++) - { - path[i, j] = rand.Next(HIGHT - 1) + 1;//[1,HIGHT] - } - } - } - - - void Save_Path() - { - System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\Users\\Public\\path" + imageIndex + ".txt"); - for (int j = 0; j < SWAPS; j++) - { - for (int k = 0; k < 2; k++) - { - file.Write(path[j, k] + " "); - } - - } - file.Close(); - } - - public void Encode_Image() - { - for (int j = 0; j < SWAPS; j++) - { - switch_line(path[j, 0], path[j, 1]); - } - } - - public void switch_line(int y1, int y2) - { - for (int i = 0; i < WIDTH; i++) - { - Color temp =inputBitmap.GetPixel(i, y1); - inputBitmap.SetPixel(i, y1, inputBitmap.GetPixel(i, y2)); - inputBitmap.SetPixel(i, y2, temp); - } - } - - - public void make_id() - { - for (int x = 0; x < PROGRAM_ID.Length; x++) - { - if (PROGRAM_ID[x] == '0') - inputBitmap.SetPixel(x, 0, Color.White); - else - inputBitmap.SetPixel(x, 0, Color.Black); - } - } - - - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; +using System.IO; +using System.Net; + +namespace ImageProcessing +{ + + public class Encoding1 + { + + String PROGRAM_ID = "1101000100001"; + Image inputImage; + Bitmap inputBitmap; + int SWAPS = 300; + int HIGHT = 300; + int WIDTH = 400; + int[,] path; + String imageIndex; + + public Encoding1(String dir, string index) + { + imageIndex = index; + path = new int[SWAPS, 2]; + + //retreving image from directory + inputImage = Image.FromFile(dir); + inputBitmap = new Bitmap(inputImage); + + + //resize the pic to 400 x 300 pix + inputBitmap = Resize_Image(inputBitmap, 400, 300); + + //save id in image + make_id(); + + //Encode the image + Random_Shuffle(); + Save_Path(); + Encode_Image(); + + //save encoded image + inputBitmap.Save("C:\\Users\\Public\\EncodedImage" + imageIndex + ".jpg"); + + } + + + + + public System.Drawing.Bitmap Resize_Image(System.Drawing.Bitmap value, int newWidth, int newHeight) + { + System.Drawing.Bitmap resizedImage = new System.Drawing.Bitmap(newWidth, newHeight); + System.Drawing.Graphics.FromImage((System.Drawing.Image)resizedImage).DrawImage(value, 0, 0, newWidth, newHeight); + return (resizedImage); + } + + + public void Random_Shuffle() + { + Random rand = new Random(); + + for (int i = 0; i < (path.Length / 2); i++) + { + for (int j = 0; j < 2; j++) + { + path[i, j] = rand.Next(HIGHT - 1) + 1;//[1,HIGHT] + } + } + } + + + void Save_Path() + { + System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\Users\\Public\\path" + imageIndex + ".txt"); + for (int j = 0; j < SWAPS; j++) + { + for (int k = 0; k < 2; k++) + { + file.Write(path[j, k] + " "); + } + + } + file.Close(); + } + + public void Encode_Image() + { + for (int j = 0; j < SWAPS; j++) + { + switch_line(path[j, 0], path[j, 1]); + } + } + + public void switch_line(int y1, int y2) + { + for (int i = 0; i < WIDTH; i++) + { + Color temp =inputBitmap.GetPixel(i, y1); + inputBitmap.SetPixel(i, y1, inputBitmap.GetPixel(i, y2)); + inputBitmap.SetPixel(i, y2, temp); + } + } + + + public void make_id() + { + for (int x = 0; x < PROGRAM_ID.Length; x++) + { + if (PROGRAM_ID[x] == '0') + inputBitmap.SetPixel(x, 0, Color.White); + else + inputBitmap.SetPixel(x, 0, Color.Black); + } + } + + + } +} diff --git a/ImageProcessing/ImageProcessing/ImageFiltering.cs b/ImageProcessing/ImageProcessing/ImageFiltering.cs index 83eeafb..dc1eb1e 100644 --- a/ImageProcessing/ImageProcessing/ImageFiltering.cs +++ b/ImageProcessing/ImageProcessing/ImageFiltering.cs @@ -1,185 +1,185 @@ -using System.Threading; -using System.Threading.Tasks; -using System.Diagnostics; -using GUI; -using System.Collections.Specialized; -using System; -using System.Drawing; -using System.Net; -using System.IO; -using System.Text; - - - -namespace ImageProcessing -{ - - public static class ImageFiltering - { - public static String PROGRAM_ID = "1101000100001"; - - public static void ImageFilter() - { - String url; - while (true) - { - url = Messages.read(); - if (url != null) - { - filter_by_image(url); - } - } - - } - - private static void filter_by_image(String url) - { - if (url.EndsWith(".jpg")) - { - filter_by_imageID(url); - } - } - - - private static void filter_by_imageID(String url) - { - Bitmap image = get_image_from_url(url); - bool result2 = image.Width == 400 && image.Height == 300; - int program_id = get_program_id(image); - bool result1 = program_id == Convert.ToInt32(PROGRAM_ID, 2); - if (result1 && result2) - { - //anlyse image id - filter_by_Permissions(image); - } - - } - - - - - private static void filter_by_Permissions(Bitmap image) - { - - //check permission from server/Data Base - int user_id = get_user_id(image); - int image_id = get_image_id(image); - - //check permission - using (var wb = new WebClient()) - { - var data = new NameValueCollection(); - data["email"] = "noam185@gmail.com"; - data["password"] = "1234"; - - - var response = wb.UploadValues("http://myscreen.cu.cc/act/permission.php", "POST", data); - String permission = Encoding.UTF8.GetString(response); - - if (permission[0] == 0)//check with eran - { - //Decode - ImageDecoder.decode_image(image, user_id,image_id); - } - - } - - } - - private static int get_user_id(Bitmap image) - { - String str_id = ""; - int pos; - for (int x = 0; x < 32; x++) - { - pos = x + PROGRAM_ID.Length + 32; - Color temp = image.GetPixel(pos, 0); - int avg_color = (temp.R + temp.G + temp.B) / 3; - if (avg_color >= 128)//White - { - str_id += "0"; - } - else//Black - { - str_id += "1"; - } - } - int id = Convert.ToInt32(str_id,2); - return id; - } - - - - - private static int get_image_id(Bitmap image) - { - String str_id = ""; - int pos; - for (int x = 0; x < 32; x++) - { - pos = x + PROGRAM_ID.Length; - Color temp = image.GetPixel(pos, 0); - int avg_color = (temp.R + temp.G + temp.B) / 3; - if (avg_color >= 128)//White - { - str_id += "0"; - } - else//Black - { - str_id += "1"; - } - } - int id = Convert.ToInt32(str_id,2); - return id; - } - - private static int get_program_id(Bitmap image) - { - String str_id = ""; - int pos; - for (int x = 0; x < 32; x++) - { - pos = x ;; - Color temp = image.GetPixel(pos, 0); - int avg_color = (temp.R + temp.G + temp.B) / 3; - if (avg_color >= 128)//White - { - str_id += "0"; - } - else//Black - { - str_id += "1"; - } - } - - - int id = Convert.ToInt32(str_id, 2); - return id; - } - - - private static Bitmap get_image_from_url(String url) - { - - Bitmap inputBitmap; - using (WebClient wc = new WebClient()) - { - Stream strm = null; - try - { - strm = wc.OpenRead(url); - - Image inputImage = Image.FromStream(strm); - inputBitmap = new Bitmap(inputImage); - } - finally - { - strm.Close(); - } - } - - return inputBitmap; - } - - } - } +using System.Threading; +using System.Threading.Tasks; +using System.Diagnostics; +using GUI; +using System.Collections.Specialized; +using System; +using System.Drawing; +using System.Net; +using System.IO; +using System.Text; + + + +namespace ImageProcessing +{ + + public static class ImageFiltering + { + public static String PROGRAM_ID = "1101000100001"; + + public static void ImageFilter() + { + String url; + while (true) + { + url = Messages.read(); + if (url != null) + { + filter_by_image(url); + } + } + + } + + private static void filter_by_image(String url) + { + if (url.EndsWith(".jpg")) + { + filter_by_imageID(url); + } + } + + + private static void filter_by_imageID(String url) + { + Bitmap image = get_image_from_url(url); + bool result2 = image.Width == 400 && image.Height == 300; + int program_id = get_program_id(image); + bool result1 = program_id == Convert.ToInt32(PROGRAM_ID, 2); + if (result1 && result2) + { + //anlyse image id + filter_by_Permissions(image); + } + + } + + + + + private static void filter_by_Permissions(Bitmap image) + { + + //check permission from server/Data Base + int user_id = get_user_id(image); + int image_id = get_image_id(image); + + //check permission + using (var wb = new WebClient()) + { + var data = new NameValueCollection(); + data["email"] = "noam185@gmail.com"; + data["password"] = "1234"; + + + var response = wb.UploadValues("http://myscreen.cu.cc/act/permission.php", "POST", data); + String permission = Encoding.UTF8.GetString(response); + + if (permission[0] == 0)//check with eran + { + //Decode + ImageDecoder.decode_image(image, user_id,image_id); + } + + } + + } + + private static int get_user_id(Bitmap image) + { + String str_id = ""; + int pos; + for (int x = 0; x < 32; x++) + { + pos = x + PROGRAM_ID.Length + 32; + Color temp = image.GetPixel(pos, 0); + int avg_color = (temp.R + temp.G + temp.B) / 3; + if (avg_color >= 128)//White + { + str_id += "0"; + } + else//Black + { + str_id += "1"; + } + } + int id = Convert.ToInt32(str_id,2); + return id; + } + + + + + private static int get_image_id(Bitmap image) + { + String str_id = ""; + int pos; + for (int x = 0; x < 32; x++) + { + pos = x + PROGRAM_ID.Length; + Color temp = image.GetPixel(pos, 0); + int avg_color = (temp.R + temp.G + temp.B) / 3; + if (avg_color >= 128)//White + { + str_id += "0"; + } + else//Black + { + str_id += "1"; + } + } + int id = Convert.ToInt32(str_id,2); + return id; + } + + private static int get_program_id(Bitmap image) + { + String str_id = ""; + int pos; + for (int x = 0; x < 32; x++) + { + pos = x ;; + Color temp = image.GetPixel(pos, 0); + int avg_color = (temp.R + temp.G + temp.B) / 3; + if (avg_color >= 128)//White + { + str_id += "0"; + } + else//Black + { + str_id += "1"; + } + } + + + int id = Convert.ToInt32(str_id, 2); + return id; + } + + + private static Bitmap get_image_from_url(String url) + { + + Bitmap inputBitmap; + using (WebClient wc = new WebClient()) + { + Stream strm = null; + try + { + strm = wc.OpenRead(url); + + Image inputImage = Image.FromStream(strm); + inputBitmap = new Bitmap(inputImage); + } + finally + { + strm.Close(); + } + } + + return inputBitmap; + } + + } + } diff --git a/ImageProcessing/ImageProcessing/ImageProcessing.csproj b/ImageProcessing/ImageProcessing/ImageProcessing.csproj index e555649..6e0466e 100644 --- a/ImageProcessing/ImageProcessing/ImageProcessing.csproj +++ b/ImageProcessing/ImageProcessing/ImageProcessing.csproj @@ -1,75 +1,75 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {CAE08220-8260-466F-9C63-8ABBFA627DDB} - Exe - Properties - ImageProcessing - ImageProcessing - v4.0 - Client - 512 - - - x86 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - {f8595926-2a07-4782-b6f0-b0c087876d24} - DataHandler - - - {7f4cb9ec-00a0-4191-97b9-baba7b18810b} - GUI - - - - + + + + Debug + x86 + 8.0.30703 + 2.0 + {CAE08220-8260-466F-9C63-8ABBFA627DDB} + Exe + Properties + ImageProcessing + ImageProcessing + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + {f8595926-2a07-4782-b6f0-b0c087876d24} + DataHandler + + + {7f4cb9ec-00a0-4191-97b9-baba7b18810b} + GUI + + + + \ No newline at end of file diff --git a/ImageProcessing/ImageProcessing/Program.cs b/ImageProcessing/ImageProcessing/Program.cs index 44545e2..ae73c1c 100644 --- a/ImageProcessing/ImageProcessing/Program.cs +++ b/ImageProcessing/ImageProcessing/Program.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ImageProcessing -{ - class Program - { - static void Main(string[] args) - { - //Encoding e = new Encoding("C:\\Users\\user\\pics\\stage\\input\\fromWeb0.jpg", "0"); - //Decoding d = new Decoding("http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash4/380823_10152328329080595_2146413406_n.jpg", "0"); - Console.Read(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ImageProcessing +{ + class Program + { + static void Main(string[] args) + { + //Encoding e = new Encoding("C:\\Users\\user\\pics\\stage\\input\\fromWeb0.jpg", "0"); + //Decoding d = new Decoding("http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash4/380823_10152328329080595_2146413406_n.jpg", "0"); + Console.Read(); + } + } +} diff --git a/README.md b/README.md index b183308..e07bc39 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -My-Screen -========= - -Team: -* Noam Tzumie -* Eran Naor -* David Krantz -* Ilan Ben Tal +My-Screen +========= + +Team: +* Noam Tzumie +* Eran Naor +* David Krantz +* Ilan Ben Tal diff --git a/server/act/activate.php b/server/act/activate.php index 28fe366..d8c3a2e 100644 --- a/server/act/activate.php +++ b/server/act/activate.php @@ -1,66 +1,66 @@ - + diff --git a/server/act/add_contact.php b/server/act/add_contact.php index 7276bdd..7ce7619 100644 --- a/server/act/add_contact.php +++ b/server/act/add_contact.php @@ -1,59 +1,59 @@ - + diff --git a/server/act/add_image.php b/server/act/add_image.php index b42d9ad..38e7218 100644 --- a/server/act/add_image.php +++ b/server/act/add_image.php @@ -1,57 +1,57 @@ - + diff --git a/server/act/add_permission.php b/server/act/add_permission.php index 20410b9..d22565e 100644 --- a/server/act/add_permission.php +++ b/server/act/add_permission.php @@ -1,75 +1,75 @@ - + diff --git a/server/act/change_password.php b/server/act/change_password.php index 616e31c..15f1d1e 100644 --- a/server/act/change_password.php +++ b/server/act/change_password.php @@ -1,51 +1,51 @@ - + diff --git a/server/act/general.php b/server/act/general.php index 548b08e..d2df96f 100644 --- a/server/act/general.php +++ b/server/act/general.php @@ -1,25 +1,25 @@ - \ No newline at end of file diff --git a/server/act/get_image.php b/server/act/get_image.php index c6a90a6..77f7adf 100644 --- a/server/act/get_image.php +++ b/server/act/get_image.php @@ -1,57 +1,57 @@ - + diff --git a/server/act/login.php b/server/act/login.php index 545dcb7..16669fc 100644 --- a/server/act/login.php +++ b/server/act/login.php @@ -1,46 +1,46 @@ - + diff --git a/server/act/recover_password.php b/server/act/recover_password.php index 7b00b3b..b6ce2cc 100644 --- a/server/act/recover_password.php +++ b/server/act/recover_password.php @@ -1,62 +1,62 @@ - + diff --git a/server/act/remove_contact.php b/server/act/remove_contact.php index a4fe84b..26cefc2 100644 --- a/server/act/remove_contact.php +++ b/server/act/remove_contact.php @@ -1,59 +1,59 @@ - + diff --git a/server/act/remove_image.php b/server/act/remove_image.php index ac7ee50..709a58d 100644 --- a/server/act/remove_image.php +++ b/server/act/remove_image.php @@ -1,57 +1,57 @@ - + diff --git a/server/act/remove_permission.php b/server/act/remove_permission.php index d11c1cc..95e96f6 100644 --- a/server/act/remove_permission.php +++ b/server/act/remove_permission.php @@ -1,62 +1,62 @@ - + diff --git a/server/act/server.php b/server/act/server.php index 31f5684..a303f9c 100644 --- a/server/act/server.php +++ b/server/act/server.php @@ -1,175 +1,175 @@ - 0, //zero is counter, for future use. - "add_contacts" => 0, - "add_images" => 0, - "add_permissions" => 0, - "remove_contacts" => 0, - "remove_images" => 0, - "remove_permissions" => 0 - ); - - public function __construct($arr) - { - //set input - $this->json = json_decode($arr); - if($this->json === null) { - throw new Exception("Bad json input"); - } - - //save extra info - $this->ip = $_SERVER['REMOTE_ADDR']; if ($ip=='') $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - $this->now = time(); //GMT 0 - - //set arrays - $this->sql = array(); - $this->mail = array(); - - //set user connection details - $this->user($this->json->login); - } - - //call for all $act methods - public function action($count=0) - { - foreach ($this->act as $key => &$value) { - if ( array_key_exists($key, $this->json) ){ - $count++; - $a = "\$this->$key(\$this->json->$key);"; - eval($a); - } - } - - return $count; - } - - public function user($arr) - { - $this->id = $arr->id; - $this->email = strtolower($arr->email); - $this->pass = $arr->password; - return 0; - } - - public function login($arr) - { - $this->sql[] = "UPDATE `users` u - SET u.`t_last`='$this->now', u.`ip`='$this->ip' - WHERE u.`email`='$arr->email' AND BINARY u.`pass`='$arr->password'"; - } - - public function add_contacts($arr) - { - //start sql - $temp_sql = "INSERT INTO `contacts` (`user`, `friend`) - SELECT u1.`id`, u2.`id` - FROM `users` as u1 - INNER JOIN `users` u2 - ON"; - - //loop contacts - foreach ($arr as &$value) { - $temp_sql .= " u2.`email`='$value' OR"; - } - $temp_sql = substr($temp_sql, 0, -3); //cut the " OR" characters - - //end sql - $temp_sql .= "\nWHERE u1.email = '$this->email' AND BINARY u1.`pass`='$this->pass'"; - - //save it - $this->sql[] = $temp_sql; - } - - public function add_images($arr) - { - //start sql - $temp_sql = "INSERT INTO `images` (`serial`, `cipher`, `owner`) - VALUES"; - - //loop images - foreach ($arr as $key => &$value) { - $temp_sql .= "\n('$key', '$value', '$this->id'),"; - } - $temp_sql = substr($temp_sql, 0, -1); //cut the "," character - - //save it - $this->sql[] = $temp_sql; - } - - public function add_permissions($arr) - { -/* - "add_permissions": - { - "user":"ilan@gmail.com", - "images": - { - "0":"duygkiu76576445twdtg", - "1":"trdcfujhkhgfuy3465457" - } - }, -*/ - - - - //start sql - $temp_sql = "INSERT INTO `permissions` (`image`, `user`) - SELECT i.`id`, u2.`id` - FROM `users` as u1 - INNER JOIN `users` u2 - ON u2.`email`='$arr->user' - INNER JOIN `contacts` c - ON c.`user`=u1.`id` AND c.`friend`=u2.`id` - INNER JOIN `images` i - ON i.`owner`=u2.`id` AND ("; - - //loop images - foreach ($arr->images as &$value) { - $temp_sql .= "i.`serial`='$value' OR "; - } - $temp_sql = substr($temp_sql, 0, -4) . ')'; //cut the " OR" characters - - //end sql - $temp_sql .= "\nWHERE u1.email = '$this->email' AND BINARY u1.`pass`='$this->pass'"; - - //save it - $this->sql[] = $temp_sql; - } - - //Reminder: - //when removing contact remove all of it's images permissions as well - public function remove_contacts($arr) - { - return 0; - } - - public function remove_images($arr) - { - return 0; - } - - public function remove_permissions($arr) - { - return 0; - } -} -?> + 0, //zero is counter, for future use. + "add_contacts" => 0, + "add_images" => 0, + "add_permissions" => 0, + "remove_contacts" => 0, + "remove_images" => 0, + "remove_permissions" => 0 + ); + + public function __construct($arr) + { + //set input + $this->json = json_decode($arr); + if($this->json === null) { + throw new Exception("Bad json input"); + } + + //save extra info + $this->ip = $_SERVER['REMOTE_ADDR']; if ($ip=='') $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + $this->now = time(); //GMT 0 + + //set arrays + $this->sql = array(); + $this->mail = array(); + + //set user connection details + $this->user($this->json->login); + } + + //call for all $act methods + public function action($count=0) + { + foreach ($this->act as $key => &$value) { + if ( array_key_exists($key, $this->json) ){ + $count++; + $a = "\$this->$key(\$this->json->$key);"; + eval($a); + } + } + + return $count; + } + + public function user($arr) + { + $this->id = $arr->id; + $this->email = strtolower($arr->email); + $this->pass = $arr->password; + return 0; + } + + public function login($arr) + { + $this->sql[] = "UPDATE `users` u + SET u.`t_last`='$this->now', u.`ip`='$this->ip' + WHERE u.`email`='$arr->email' AND BINARY u.`pass`='$arr->password'"; + } + + public function add_contacts($arr) + { + //start sql + $temp_sql = "INSERT INTO `contacts` (`user`, `friend`) + SELECT u1.`id`, u2.`id` + FROM `users` as u1 + INNER JOIN `users` u2 + ON"; + + //loop contacts + foreach ($arr as &$value) { + $temp_sql .= " u2.`email`='$value' OR"; + } + $temp_sql = substr($temp_sql, 0, -3); //cut the " OR" characters + + //end sql + $temp_sql .= "\nWHERE u1.email = '$this->email' AND BINARY u1.`pass`='$this->pass'"; + + //save it + $this->sql[] = $temp_sql; + } + + public function add_images($arr) + { + //start sql + $temp_sql = "INSERT INTO `images` (`serial`, `cipher`, `owner`) + VALUES"; + + //loop images + foreach ($arr as $key => &$value) { + $temp_sql .= "\n('$key', '$value', '$this->id'),"; + } + $temp_sql = substr($temp_sql, 0, -1); //cut the "," character + + //save it + $this->sql[] = $temp_sql; + } + + public function add_permissions($arr) + { +/* + "add_permissions": + { + "user":"ilan@gmail.com", + "images": + { + "0":"duygkiu76576445twdtg", + "1":"trdcfujhkhgfuy3465457" + } + }, +*/ + + + + //start sql + $temp_sql = "INSERT INTO `permissions` (`image`, `user`) + SELECT i.`id`, u2.`id` + FROM `users` as u1 + INNER JOIN `users` u2 + ON u2.`email`='$arr->user' + INNER JOIN `contacts` c + ON c.`user`=u1.`id` AND c.`friend`=u2.`id` + INNER JOIN `images` i + ON i.`owner`=u2.`id` AND ("; + + //loop images + foreach ($arr->images as &$value) { + $temp_sql .= "i.`serial`='$value' OR "; + } + $temp_sql = substr($temp_sql, 0, -4) . ')'; //cut the " OR" characters + + //end sql + $temp_sql .= "\nWHERE u1.email = '$this->email' AND BINARY u1.`pass`='$this->pass'"; + + //save it + $this->sql[] = $temp_sql; + } + + //Reminder: + //when removing contact remove all of it's images permissions as well + public function remove_contacts($arr) + { + return 0; + } + + public function remove_images($arr) + { + return 0; + } + + public function remove_permissions($arr) + { + return 0; + } +} +?> diff --git a/server/act/signup.php b/server/act/signup.php index 9b53284..49d85e6 100644 --- a/server/act/signup.php +++ b/server/act/signup.php @@ -1,70 +1,70 @@ -link to activate your account" . - "\n or go to http://myscreen.cu.cc/activate.php and copy this code: $code" . - "\n\n\n by the way, your password is: $pass" . - "\n don't forget it."; -mail($email, $subject, $message, $headers); - -echo '0'; //success - - -//----------------------------------------------------------------- - -function randomPassword($len) { - $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789"; - $pass = array(); //remember to declare $pass as an array - for ($i = 0; $i < $len; $i++) { - $n = rand(0, 59); - $pass[$i] = $alphabet[$n]; - } - return implode($pass); //turn the array into a string -} +link to activate your account" . + "\n or go to http://myscreen.cu.cc/activate.php and copy this code: $code" . + "\n\n\n by the way, your password is: $pass" . + "\n don't forget it."; +mail($email, $subject, $message, $headers); + +echo '0'; //success + + +//----------------------------------------------------------------- + +function randomPassword($len) { + $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789"; + $pass = array(); //remember to declare $pass as an array + for ($i = 0; $i < $len; $i++) { + $n = rand(0, 59); + $pass[$i] = $alphabet[$n]; + } + return implode($pass); //turn the array into a string +} ?> \ No newline at end of file diff --git a/server/activate.php b/server/activate.php index 336e71a..0094725 100644 --- a/server/activate.php +++ b/server/activate.php @@ -1,66 +1,66 @@ - \ No newline at end of file diff --git a/server/add_contact.php b/server/add_contact.php index 6b995b0..e742a21 100644 --- a/server/add_contact.php +++ b/server/add_contact.php @@ -1,14 +1,14 @@ - - - -

My Screen

- -
-
email: -
password: -
femail: -
-
- - + + + +

My Screen

+ +
+
email: +
password: +
femail: +
+
+ + \ No newline at end of file diff --git a/server/add_image.php b/server/add_image.php index ed28eb4..5335685 100644 --- a/server/add_image.php +++ b/server/add_image.php @@ -1,15 +1,15 @@ - - - -

My Screen

- -
-
email: -
password: -
serial: -
rsa: -
-
- - + + + +

My Screen

+ +
+
email: +
password: +
serial: +
rsa: +
+
+ + \ No newline at end of file diff --git a/server/add_permission.php b/server/add_permission.php index d9028c9..1157d6d 100644 --- a/server/add_permission.php +++ b/server/add_permission.php @@ -1,15 +1,15 @@ - - - -

My Screen

- -
-
email: -
password: -
femail: -
serial: -
-
- - + + + +

My Screen

+ +
+
email: +
password: +
femail: +
serial: +
+
+ + \ No newline at end of file diff --git a/server/get_image.php b/server/get_image.php index 4b639c4..b46c9d6 100644 --- a/server/get_image.php +++ b/server/get_image.php @@ -1,15 +1,15 @@ - - - -

My Screen

- -
-
email: -
password: -
serial: -
fid: -
-
- - - + + + +

My Screen

+ +
+
email: +
password: +
serial: +
fid: +
+
+ + + diff --git a/server/inc/settings.php b/server/inc/settings.php index 5ae6b4b..f9d5f62 100644 --- a/server/inc/settings.php +++ b/server/inc/settings.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/server/login.php b/server/login.php index 61ecabd..f4fcb59 100644 --- a/server/login.php +++ b/server/login.php @@ -1,13 +1,13 @@ - - - -

My Screen

- -
-
email: -
password: -
-
- - + + + +

My Screen

+ +
+
email: +
password: +
+
+ + \ No newline at end of file diff --git a/server/remove_contact.php b/server/remove_contact.php index 74e497a..a155cd3 100644 --- a/server/remove_contact.php +++ b/server/remove_contact.php @@ -1,14 +1,14 @@ - - - -

My Screen

- -
-
email: -
password: -
femail: -
-
- - + + + +

My Screen

+ +
+
email: +
password: +
femail: +
+
+ + \ No newline at end of file diff --git a/server/remove_image.php b/server/remove_image.php index e06e75b..57ca71a 100644 --- a/server/remove_image.php +++ b/server/remove_image.php @@ -1,15 +1,15 @@ - - - -

My Screen

- -
-
email: -
password: -
serial: -
rsa: -
-
- - + + + +

My Screen

+ +
+
email: +
password: +
serial: +
rsa: +
+
+ + \ No newline at end of file diff --git a/server/remove_permission.php b/server/remove_permission.php index 6994d16..a4cb4df 100644 --- a/server/remove_permission.php +++ b/server/remove_permission.php @@ -1,15 +1,15 @@ - - - -

My Screen

- -
-
email: -
password: -
femail: -
serial: -
-
- - + + + +

My Screen

+ +
+
email: +
password: +
femail: +
serial: +
+
+ + \ No newline at end of file diff --git a/server/signup.php b/server/signup.php index 831fc37..90321bb 100644 --- a/server/signup.php +++ b/server/signup.php @@ -1,5 +1,5 @@ -
-
email: -
password: -
+ +
email: +
password: +
\ No newline at end of file diff --git a/server/simpletest/test/autorun_test.php b/server/simpletest/test/autorun_test.php index d85ea19..67a884c 100644 --- a/server/simpletest/test/autorun_test.php +++ b/server/simpletest/test/autorun_test.php @@ -1,23 +1,23 @@ -addFile(dirname(__FILE__) . '/support/test1.php'); - $this->assertEqual($tests->getSize(), 1); - } - - function testExitStatusOneIfTestsFail() { - exec('php ' . dirname(__FILE__) . '/support/failing_test.php', $output, $exit_status); - $this->assertEqual($exit_status, 1); - } - - function testExitStatusZeroIfTestsPass() { - exec('php ' . dirname(__FILE__) . '/support/passing_test.php', $output, $exit_status); - $this->assertEqual($exit_status, 0); - } -} - +addFile(dirname(__FILE__) . '/support/test1.php'); + $this->assertEqual($tests->getSize(), 1); + } + + function testExitStatusOneIfTestsFail() { + exec('php ' . dirname(__FILE__) . '/support/failing_test.php', $output, $exit_status); + $this->assertEqual($exit_status, 1); + } + + function testExitStatusZeroIfTestsPass() { + exec('php ' . dirname(__FILE__) . '/support/passing_test.php', $output, $exit_status); + $this->assertEqual($exit_status, 0); + } +} + ?> \ No newline at end of file diff --git a/server/t.php b/server/t.php index 81f236d..23573d3 100644 --- a/server/t.php +++ b/server/t.php @@ -1,14 +1,14 @@ -
-
email: -
password: -
old_password: -
new_password: -
to: -
subject: -
message: -
time: -
filter: -
order: -
search: -
+ +
email: +
password: +
old_password: +
new_password: +
to: +
subject: +
message: +
time: +
filter: +
order: +
search: +
\ No newline at end of file