Jump to content

Destramic

Members
  • Posts

    969
  • Joined

  • Last visited

Everything posted by Destramic

  1. thanks but i've made my own cropper (with help from scootstah) as seen here: http://jsfiddle.net/destramic/ybq2mab5/ barand thank you for help...worked perfectly ....sorry for such a late reply also using the following worked great to get selected part of image. var selected = $('whatever'), offset = selected.position(), selected_x = offset.left, selected_y = offset.top, selected_x2 = selected.width(), selected_y2 = selected.height(); i will try and post my code to help future developers when i'm done (hopefully in the next couple of weeks) thanks guys!!!!
  2. yes thank you ...seems i was no where close to what i wanted haha...i'm bit confused on your x, y positions barand...obviously mine must be wrong but how are you getting yours please? i'd like to get by JavaScript if possible thanks for your help!
  3. hey guys i'm trying to crop a certain part of a image using imagecopyresized...i'm using js to get the coordinates of the image and the selected area that i'm after here is how i get the co-ordinates: var offset = image.position(), image_x = offset.left, image_y = offset.top, image_x2 = selected.width(), image_y2 = selected.height(), offset = selected.position(), selected_x = offset.left, selected_y = offset.top, selected_x2 = selected.width(), selected_y2 = selected.height(); co-ordinates image ----------------- x = 8 y = 8 selected area ----------------- x = 172 y = 75 x2 = 327 y2 = 292 i'm then using this function to try and get just the selected area as a image but it's not outputting correctley function crop($image, $selected_x = 0, $selected_y = 0, $image_x = 0, $image_y = 0, $selected_width = null, $selected_height = null) { list($width, $height) = getimagesize($image); $thumbnail = imagecreatetruecolor($width, $height); $image_source = imagecreatefromjpeg($image); imagecopyresized($thumbnail, $image_source, $selected_x, $selected_y, $image_x, $image_y, $selected_width, $selected_height, $width, $height); imagejpeg($thumbnail, "image-cropped.jpg", 100); } crop('image.jpg', 172, 75, 8, 8, 327, 292); image output: is it possible to get the selected image in the blue grid saved as a image please? any help on what i'm doing wrong would be great..please let me know if you need more info thank you
  4. ouch!...now that is bad boy! thank you
  5. brilliant stuff, just what i need thanks all
  6. Ops sorry...i thought when testing before putting window location in it was working. Just think it looks ugly being in the handlers...but doesn't look like I have much of a choice...thank you for your patience guys
  7. yeah sorry... ok well i think something like this would work a lot better $(document).ready(function(){ function socket_open(port, https){ var location = window.location, host = location.hostname, protocol = "http"; if (https){ protocol = "https"; } var url = protocol + '://' + host + ':' + port; console.log(url); $.ajax({ 'url' : url, 'success' : function() { return true; }, 'error' : function() { return false; } }); } if (socket_open(8080)){ console.log("successful"); } else{ console.log('error'); } }); just one problem with this though the url has apostrophes around it causing the function to always return false. i tied to replace apostrophes in var url but still didnt work like i said i just want a script like this just in case the socket goes down, that way i can show something like page temporary down / redirect thanks guys
  8. the only problem i can see with it really is the span containing the + doesn't align centre or vertically middle. once i have the cropper and upload working correctly i'll put a link up for you to see
  9. sorry requinix im not sure if what i'm trying to do is not possible of i'm doing something wrong here: $(document).ready(function(){ function web_socket_open(){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { if (xhr.status === 200){ console.log('yes'); // returns return true; } return false; } } xhr.open('GET', 'http://127.0.0.1:8080', true); xhr.send(null); } if (web_socket_open()){ console.log('yes'); } else { console.log('no'); } }); when executing the web_socket_open function it returns no (returning false in if statement)...then in console log it shows yes during the http request, which comes from the function itself.. ideally i would like it just to return true as it should do? as url is correct thanks for your help.
  10. brilliant thank you...looks top notch now: http://jsfiddle.net/destramic/ztdpou8w/
  11. i'll be happy to pay for someone to get it to how i want...pm me if interested thank you
  12. can anyone please help me on how to display this ul as 3 rows please? to look like this: ___________________ |_____|______|______| |_____|______|______| |_____|______|______| thank you
  13. sorry i haven't been around to test and get back to you i've tried running this code...which returns not connected twice before returning connected...how can i get it just to return one or the other please? var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://127.0.0.1:8080', true); xhr.send(null); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { console.log('connected') } else { console.log('not connected') } } thank you
  14. never heard of websocket class looked at it...but not sure what to do to be honest. ideally i would like to know if the socket was down...that way i can display page not available or something (fingers crossed that doesn't happen)...but just a precaution. is there a better way to do this please?...i ran script and waited ages with no console log thank you
  15. i'm wanting to check if the web-socket is open...i'm using a xml http request...unless there's is a better way you can suggest using the code below returns undefined function web_socket_open(href){ var request = new XMLHttpRequest(href); request.onreadystatechange = function() { if (request.readyState === 4 && request.status === 200) { return true; } return false; } } console.log(web_socket_open('http://127.0.0.1:8080')); what am i doing wrong here please? thank you
  16. thank you....flex works well although i'm unable to to get the ul into 3 rows. http://jsfiddle.net/destramic/ztdpou8w/8/ i used: li .row-two{ order: 2; } but all li's appear inline how can i achieve a break please? thank you
  17. hey guys im trying to make grid for a image cropper script im making...but im having a bit of trouble getting it to work/look the way i want it to. i'm not the best when it comes to css. you can see my grid here: https://jsfiddle.net/destramic/ztdpou8w/ the problem i have is where you stretch the grid too much or shrink it too small everything goes out of place...i'm more concerned about the border separation when stretching. how can i change size of grid but also making it looking consistent please? thank you
  18. here's a tutorial i found which seems decent enough to get you started: http://www.inmotionhosting.com/support/edu/website-design/using-php-and-mysql/php-insert-database if you need any help post in relevant section. welcome to phpfreaks
  19. do you mean cache? any you array should be: $test = array( 'dog', 'cow', 'shee' ); or are you using a template engine like smarty or some other nonsense?
  20. Destramic

    aes

    a lot of work still to be done here but just in case someone else is learning how to encrypt db details i now have added a method to encrypt and decrypt array (mysql rows) ensuring the column name init vector is called : {column name}_init_vector <?php const ENCRYPTION_ALGORITHM = 'AES-128-CBC'; class AES { private $_master_key; public function __construct() { $this->_master_key = "5e2a0626516f3108e55e25e4bb6a62835c2f5d2b2b8d194c9acca63ef8beff6bfb947233bd83cfda9021e5a80bc183bcd835180c9955b733fd1a6d9d"; } public function generate_master_key($length = 60) { if (!is_numeric($length)) { return null; } $max_attempts = 10; $attempts = 0; do { $bytes = openssl_random_pseudo_bytes($length, $cryptographically_strong); $attempts++; } while (!$cryptographically_strong && $attempts < $max_attempts); if (!$cryptographically_strong) { return false; } $hex = bin2hex($bytes); return $hex; } public function encrypt($value, $master_key) { $init_vector = openssl_random_pseudo_bytes(openssl_cipher_iv_length(ENCRYPTION_ALGORITHM)); $ciphertext = openssl_encrypt($value, ENCRYPTION_ALGORITHM, $master_key, false, $init_vector); return array( 'init_vector' => $init_vector, 'ciphertext' => $ciphertext ); } public function decrypt($ciphertext, $init_vector, $master_key) { $plaintext = openssl_decrypt($ciphertext, ENCRYPTION_ALGORITHM, $master_key, false, $init_vector); return $plaintext; } public function encrypt_array($array) { $encrypted_array = array(); $master_key = $this->_master_key; foreach ($array as $key => $data) { foreach ($data as $column => $value) { $encryption = $this->encrypt($value, $master_key); $init_vector_column = $column . '_init_vector'; $encrypted_array[$key][$column] = $encryption['ciphertext']; $encrypted_array[$key][$init_vector_column] = $encryption['init_vector']; } } return $encrypted_array; } public function decrypt_array($array) { $decrypted_array = array(); $master_key = $this->_master_key; foreach ($array as $key => $data) { foreach ($data as $column => $value) { $init_vector = $column . '_init_vector'; if (array_key_exists($init_vector, $data)) { $init_vector = $data[$init_vector]; $decrypted_value = $this->decrypt($value, $init_vector, $master_key); $decrypted_array[$key][$column] = $decrypted_value; } } } return $decrypted_array; } } $aes = new AES; $data = array( array('name' => 'destramic', 'age' => '28'), array('name' => 'alan', 'age' => '99') ); $encryption = $aes->encrypt_array($data); print_r($encryption); $decryption = $aes->decrypt_array($encryption); print_r($decryption); :happy-04: :happy-04: :happy-04:
  21. Destramic

    aes

    ok brilliant...i'll stick with just the one key then...umm and as for sql injection this is just a test i've got all that sorted...but thanks for pointing out
  22. Destramic

    aes

    brilliant thank you i've changed everything you've told me the only thing i may be a bit concerned about is storing the master keys inside another table which is relationship with the users table by the user_id but it works brilliantly....i can use this on users address and even sessions. <?php const ENCRYPTION_ALGORITHM = 'AES-128-CBC'; class AES { public function master_key($length = 60) { if (!is_numeric($length)) { return null; } $max_attempts = 10; $attempts = 0; do { $bytes = openssl_random_pseudo_bytes($length, $cryptographically_strong); $attempts++; } while (!$cryptographically_strong && $attempts < $max_attempts); if (!$cryptographically_strong) { return false; } $hex = bin2hex($bytes); return $hex; } public function encrypt($value, $master_key) { $init_vector = openssl_random_pseudo_bytes(openssl_cipher_iv_length(ENCRYPTION_ALGORITHM)); $ciphertext = openssl_encrypt($value, ENCRYPTION_ALGORITHM, $master_key, false, $init_vector); return array( 'init_vector' => $init_vector, 'ciphertext' => $ciphertext ); } public function decrypt($ciphertext, $init_vector, $master_key) { $plaintext = openssl_decrypt($ciphertext, ENCRYPTION_ALGORITHM, $master_key, false, $init_vector); return $plaintext; } } $aes = new AES; $server_master_key = $aes->master_key(); // destramic // ricky $name = "destramic"; $encryption = $aes->encrypt($name, $server_master_key); //print_r($encryption); //echo $aes->decrypt($encryption['ciphertext'], $encryption['init_vector'], $server_master_key); // mysql stuff $link = mysqli_connect("127.0.0.1", "root", "root", "test"); //$insert = "INSERT INTO `users`(`name`, `name_init_vector`) // VALUES ('" . $encryption['ciphertext'] ."', '" . $encryption['init_vector'] . "')"; //$result = mysqli_query($link, $insert); //$user_id = mysqli_insert_id($link); //$insert_key = "INSERT INTO `encryption_keys` (`encryption_key`, `user_id`) // VALUES ('" . $server_master_key ."', '" . $user_id . "')"; //$result = mysqli_query($link, $insert_key); $select = "SELECT u.name, u.name_init_vector, ek.encryption_key FROM users u LEFT JOIN encryption_keys ek ON ek.user_id = u.user_id"; $result = mysqli_query($link, $select); $rows = mysqli_fetch_all($result, MYSQLI_ASSOC); //print_r($rows); $decrypted_rows = array(); foreach ($rows as $key => $array) { foreach ($array as $column => $value) { $init_vector = $column . '_init_vector'; if (array_key_exists($init_vector, $array) && array_key_exists('encryption_key', $array)) { $init_vector = $array[$init_vector]; $master_key = $array['encryption_key']; $decrypted_value = $aes->decrypt($value, $init_vector, $master_key); $decrypted_rows[$key][$column] = $decrypted_value; } } } print_r($decrypted_rows); can't honestly say how much i appropriate yours and the other guys time and help on here!!!
  23. Destramic

    aes

    yep i'm with you...thank you for your post although how do i use AES_CBC_DECRYPT() and AES_CBC_DECRYPT()? i have the extension php_openssl.dll included but i get also is openssl_random_pseudo_bytes() fine for the 16 random bytes? thank you
  24. Destramic

    aes

    i've been reading up about security for users data in my db come across aes (hopefully im on the right track for good security?). now i may be over complicating things (as usual) but when a user creates a account i was planning on creating a mysql_aes_key with the users password (after it has been password hashed) creating a user content key then to use my encrypt method to encrypt the user content key with a random master key, creating the user content key encryption also i wanted to create a master key for each user inside a table as well as storing the user content key in the users db row. here is what i've come up with or sourced should i say: <?php class AES { public function random_string($length = 60) { if (!is_numeric($length)) { return null; } $bytes = openssl_random_pseudo_bytes($length, $cryptographically_strong); $hex = bin2hex($bytes); if (!$cryptographically_strong) { $this->random_string($length); } return $hex; } public function mysql_aes_key($key) { $new_key = str_repeat(chr(0), 16); for($i=0,$len=strlen($key);$i<$len;$i++) { $new_key[$i%16] = $new_key[$i%16] ^ $key[$i]; } return $new_key; } public function encrypt($val, $key) { $key = $this->mysql_aes_key($key); $pad_value = 16-(strlen($val) % 16); $val = str_pad($val, (16*(floor(strlen($val) / 16)+1)), chr($pad_value)); $encryption = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $val, MCRYPT_MODE_ECB, mcrypt_create_iv( mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_DEV_URANDOM)); return $encryption; } public function decrypt($val, $key) { $key = $this->mysql_aes_key($key); $val = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $val, MCRYPT_MODE_ECB, mcrypt_create_iv( mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_DEV_URANDOM)); return rtrim($val); } } $master_key = "354fdedcc54d356bf681571e3dcacf73dd818656ffddc779d33b925e0b3f32fae01642fe7719bb9504c80de4f4193933f36948770f2ac832b5364514"; $users_password = "helloworldthisismypassword"; $aes = new AES; // $aes->random_string(); // master key $user_content_key = $aes->mysql_aes_key($users_password); $user_content_key_encrypted = $aes->encrypt($user_content_key, $master_key); //echo $a = $aes->encrypt('ricky', $user_content_key); //echo $aes->decrypt($a, $user_content_key); // inserts and selects perfect $link = mysqli_connect("127.0.0.1", "root", "root", "test"); $insert = "INSERT INTO `users`(`password`, `encryption_key`, `name`, `age`) VALUES ('" . $users_password."','" . $user_content_key . "',AES_ENCRYPT('ricky', '" . $user_content_key_encrypted . "'),AES_ENCRYPT('28', '" . $user_content_key_encrypted . "'))"; //$result = mysqli_query($link, $insert); $select = "SELECT AES_DECRYPT(name, '" . $user_content_key_encrypted . "') AS name, AES_DECRYPT(age, '" . $user_content_key_encrypted . "') AS age FROM users"; $result = mysqli_query($link, $select); $rows = mysqli_fetch_array($result); //print_r($rows); // select 2 $select2 = "SELECT @content_key := AES_ENCRYPT(u.encryption_key, ek.encryption_key), AES_DECRYPT(u.name, @content_key) as `name` FROM users u LEFT JOIN encryption_keys ek ON ek.user_id = u.user_id"; $result2 = mysqli_query($link, $select2); $rows2 = mysqli_fetch_array($result2); //print_r($rows2); inserting a user and selecting works fine...but im not sure if what im trying to do on my 2nd select query is secure (although it doesnt work)....but i would like to do something like this: SELECT @content_key := AES_ENCRYPT(u.encryption_key, ek.encryption_key), AES_DECRYPT(u.name, @content_key) as `name` FROM users u LEFT JOIN encryption_keys ek ON ek.user_id = u.user_id am i on the right track with what im trying to do here please guys?...advise would be great thank you
  25. thats the plan got this for data...so i can cache...the json for one page is like 4000 rows so caching it should save some memory and cpu <?php namespace Utility; use \Exception as Exception; define('DS', DIRECTORY_SEPARATOR); class Cache { protected $_cache_directory = "C:\\nginx\html\cache\\"; protected $_lifetime = 108000; protected $_extension = ".txt"; protected $_extensions = array('cache', 'txt', 'csv'); public $_filename; public function save($data, $san = true) { if (is_null($data)) { return false; } $filename = $this->get_filename(); $file = pathinfo($filename); try { if (!$this->make_directory($file['dirname'])) { throw new Exception(''); } } catch (Exception $exception) { } $extension = $file['extension']; $file = fopen($filename, "w+"); if ($extension === 'csv') { $start = true; foreach ($data as $csv_data) { if ($start) { $keys = array_keys($csv_data); $start = false; fputcsv($file, $keys); } fputcsv($file, $csv_data); } } else { fwrite($file, $data); } fclose($file); $lifetime = time() + $this->get_lifetime(); touch($filename, $lifetime); } public function load($filename = null) { if (is_null($filename)) { $filename = $this->get_filename(); } if (!file_exists($filename)) { return false; } $file = pathinfo($filename); $extension = $file['extension']; if ($extension === 'csv') { $start = true; $headers = array(); $data = array(); $file = fopen($filename,'r'); while(($csv_data = fgetcsv($file)) !== false) { if($start) { $headers = array_values($csv_data); $start = false; continue; } $data[] = array_combine($headers, $csv_data); } fclose($file); } else { $data = file_get_contents($filename); } return $data; } public function remove($filename = null) { if (is_null($filename)) { return false; } if(!file_exists($filename)) { return false; } unlink($filename); return true; } public function is_cached($filename = null) { if (is_null($filename)) { return false; } echo $filename = $this->format_filename($filename); $this->set_filename($filename); if (!file_exists($filename)) { return false; } $time = filemtime($filename); if ($time < time()) { $this->remove($filename); return false; } return true; } public function remove_all() { $files = glob($this->get_cache_directory() . "*"); foreach($files as $file) { if(is_file($file)) { unlink($file); } } } protected function format_filename($filename) { $filename = $this->get_cache_directory() . $filename; if (DS === '/') { $replace = "\\"; } else { $replace = "/"; } if (strpos($filename, $replace)) { $filename = str_replace($replace, DS, $filename); } if (strpos($filename, DS.DS)) { $filename = str_replace(DS.DS, DS, $filename); } $info = pathinfo($filename); if (!in_array($info['extension'], $this->_extensions)) { $filename = $info['dirname'] . DS . $info['filename'] . $this->_extension; } return $filename; } protected function make_directory($directory) { if (!is_dir($directory)) { mkdir($directory, 0755, true); return true; } return false; } protected function get_cache_directory() { return $this->_cache_directory; } protected function set_filename($filename) { $this->_filename = $filename; } protected function get_filename() { return $this->_filename; } public function extension($extension) { if (in_array($extension, $this->_extensions)) { $this->_extension = '.' . $extension; } } public function lifetime($lifetime, $period = "days") { $period = strtolower($period); switch($period) { case 'seconds': break; case 'minutes': $lifetime = $lifetime * 60; break; case 'hours': $lifetime = $lifetime * 60 * 60; break; default: case 'days': $lifetime = $lifetime * 60 * 60 * 24; break; case 'weeks': $lifetime = $lifetime * 60 * 60 * 24 * 7; break; case 'months': $lifetime = $lifetime * 60 * 60 * 24 * 30; break; case 'years': $lifetime = $lifetime * 60 * 60 * 24 * 365; break; } $this->_lifetime = $lifetime; } protected function get_lifetime() { return $this->_lifetime; } } $cache = new Cache; if ($cache->is_cached('json/categories.csv')) { print_r($cache->load()); } else { // database shizzle $data = array(array('name' => 'ricky', 'age' => '28')); $cache->save($data); } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.