예제 #1
0
파일: Simple.php 프로젝트: Dulciane/jaws
 /**
  * Displays the captcha image
  *
  * @access  public
  * @param   int     $key    Captcha key
  * @return  mixed   Captcha raw image data
  */
 function image($key)
 {
     $value = Jaws_Utils::RandomText();
     $result = $this->update($key, $value);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     }
     $bg = dirname(__FILE__) . '/resources/simple.bg.png';
     $im = imagecreatefrompng($bg);
     imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
     // Write it in a random position..
     $darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70);
     $x = 5;
     $y = 20;
     $text_length = strlen($value);
     for ($i = 0; $i < $text_length; $i++) {
         $fnt = rand(7, 10);
         $y = rand(6, 10);
         imagestring($im, $fnt, $x, $y, $value[$i], $darkgray);
         $x = $x + rand(15, 25);
     }
     header("Content-Type: image/png");
     ob_start();
     imagepng($im);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $content;
 }
예제 #2
0
파일: Client.php 프로젝트: juniortux/jaws
 /**
  * Listen network port over given address
  *
  * @access  public
  * @param   string  $path       path of web socket server
  * @param   string  $origin     indicates the origin of the script establishing the connection
  * @param   mixed   $callback   callback function loaded when data received
  * @return  mixed   True on success or Jaws_Error on failure
  */
 public function open($path, $origin = '', $callback = null)
 {
     if (!($this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
         return $this->close();
     }
     // set send/receive timeouts
     socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $this->receive_timeout, 'usec' => 0));
     socket_set_option($this->socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $this->send_timeout, 'usec' => 0));
     // trying connect to WebSocket server
     if (false === @socket_connect($this->socket, $this->address, $this->port)) {
         return $this->close($this->socket);
     }
     $randomKey = base64_encode(Jaws_Utils::RandomText(16, true, true, true));
     $header = "GET {$path} HTTP/1.1\r\n";
     $header .= "Host: {$this->address}:{$this->port}\r\n";
     $header .= "Upgrade: websocket\r\n";
     $header .= "Connection: Upgrade\r\n";
     $header .= "Sec-WebSocket-Key: {$randomKey}\r\n";
     if (!empty($origin)) {
         $header .= "Sec-WebSocket-Origin: {$origin}\r\n";
     }
     $header .= "Sec-WebSocket-Version: 13\r\n";
     $header .= "\r\n";
     // send hand-shake header
     if (false === @socket_write($this->socket, $header)) {
         return $this->close($this->socket);
     }
     // trying receive hand-shake response
     if (false === @socket_recv($this->socket, $response, 1024, 0)) {
         $last_error = error_get_last();
         return $this->close($this->socket, $last_error['message']);
     }
     $expectedKey = $randomKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
     $expectedKey = base64_encode(sha1($expectedKey, true));
     if (preg_match('#Sec-WebSocket-Accept: (.*)\\r\\n\\r\\n$#imU', $response, $matches)) {
         $acceptKey = trim($matches[1]);
         if ($acceptKey === $expectedKey) {
             return true;
         }
     }
     $this->close($this->socket);
     return Jaws_Error::raiseError('Response header not valid');
 }
예제 #3
0
파일: Account.php 프로젝트: juniortux/jaws
 /**
  * Changes a password from a given key
  *
  * @access  public
  * @param   string   $key   Recovery key
  * @return  mixed    True on success or Jaws_Error on failure
  */
 function ChangePassword($key)
 {
     $jUser = new Jaws_User();
     $user = $jUser->GetUserByPasswordVerifyKey($key);
     if (Jaws_Error::IsError($user) || empty($user)) {
         return false;
     }
     // generate new password
     $password = Jaws_Utils::RandomText(8);
     $res = $jUser->UpdateUser($user['id'], array('username' => $user['username'], 'nickname' => $user['nickname'], 'email' => $user['email'], 'password' => $password));
     if (Jaws_Error::IsError($res)) {
         return $res;
     }
     $site_url = $GLOBALS['app']->getSiteURL('/');
     $site_name = $this->gadget->registry->fetch('site_name', 'Settings');
     $tpl = $this->gadget->template->load('NewPassword.txt');
     $tpl->SetBlock('NewPassword');
     $tpl->SetVariable('say_hello', _t('USERS_EMAIL_REPLACEMENT_HELLO', $user['nickname']));
     $tpl->SetVariable('username', $user['username']);
     $tpl->SetVariable('nickname', $user['nickname']);
     $tpl->SetVariable('password', $password);
     $tpl->SetVariable('message', _t('USERS_FORGOT_PASSWORD_CHANGED_MESSAGE', $user['username']));
     $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD'));
     $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
     $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
     $tpl->SetVariable('site-name', $site_name);
     $tpl->SetVariable('site-url', $site_url);
     $tpl->ParseBlock('NewPassword');
     $message = $tpl->Get();
     $subject = _t('USERS_FORGOT_PASSWORD_CHANGED_SUBJECT');
     $mail = Jaws_Mail::getInstance();
     $mail->SetFrom();
     $mail->AddRecipient($user['email']);
     $mail->SetSubject($subject);
     $mail->SetBody($this->gadget->ParseText($message));
     $mresult = $mail->send();
     if (Jaws_Error::IsError($mresult)) {
         return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL'));
     }
     return true;
 }
예제 #4
0
 /**
  * Displays the captcha image
  *
  * @access  public
  * @param   int     $key    Captcha key
  * @return  mixed   Captcha raw image data
  */
 function image($key = null)
 {
     $value = Jaws_Utils::RandomText();
     $result = $this->update($key, $value);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     }
     $width = 15 * imagefontwidth(5);
     $height = 3 * imagefontheight(5);
     $font = dirname(__FILE__) . '/resources/comicbd.ttf';
     $tmpimg = imagecreate($width * 2, $height * 2);
     $bgColor = imagecolorallocatealpha($tmpimg, 255, 255, 255, 127);
     $col = imagecolorallocate($tmpimg, 0, 0, 0);
     // init final image
     $img = imagecreate($width, $height);
     imagepalettecopy($img, $tmpimg);
     imagecopy($img, $tmpimg, 0, 0, 0, 0, $width, $height);
     // put text into $tmpimg
     $fsize = $height * 0.6;
     $bb = imageftbbox($fsize, 0, $font, $value);
     $tx = $bb[4] - $bb[0];
     $ty = $bb[5] - $bb[1];
     $x = floor($width - $tx / 2 - $bb[0]);
     $y = round($height - $ty / 2 - $bb[1]);
     imagettftext($tmpimg, $fsize, 0, $x, $y, -$col, $font, $value);
     // warp text
     $this->warpedImage($tmpimg, $img);
     header("Content-Type: image/png");
     ob_start();
     imagepng($img);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($img);
     imagedestroy($tmpimg);
     return $content;
 }
예제 #5
0
 /**
  * Creates a valid(registered) n user for an anonymous user
  *
  * @access  public
  * @param   string  $username   Username
  * @param   string  $user_email User's email
  * @param   string  $nickname   User's display name
  * @param   string  $fname      First name
  * @param   string  $lname      Last name
  * @param   string  $gender     User gender
  * @param   string  $ssn        Social Security number
  * @param   string  $dob        Birth date
  * @param   string  $url        User's URL
  * @param   string  $password   Password
  * @param   string  $group      Default user group
  * @return  mixed   True on success or message string
  */
 function CreateUser($username, $user_email, $nickname, $fname, $lname, $gender, $ssn, $dob, $url, $password, $group = null)
 {
     if (empty($username) || empty($nickname) || empty($user_email)) {
         return _t('USERS_USERS_INCOMPLETE_FIELDS');
     }
     $random = false;
     if (trim($password) == '') {
         $random = true;
         $password = Jaws_Utils::RandomText(8);
     }
     $jUser = new Jaws_User();
     //We already have a $username in the DB?
     $info = $jUser->GetUser($username);
     if (Jaws_Error::IsError($info) || isset($info['username'])) {
         return _t('USERS_USERS_ALREADY_EXISTS', $username);
     }
     if ($jUser->UserEmailExists($user_email)) {
         return _t('USERS_EMAIL_ALREADY_EXISTS', $user_email);
     }
     $user_enabled = $this->gadget->registry->fetch('anon_activation') == 'auto' ? 1 : 2;
     $user_id = $jUser->AddUser(array('username' => $username, 'nickname' => $nickname, 'email' => $user_email, 'password' => $password, 'status' => $user_enabled));
     if (Jaws_Error::IsError($user_id)) {
         return $user_id->getMessage();
     }
     $result = $jUser->UpdatePersonal($user_id, array('fname' => $fname, 'lname' => $lname, 'gender' => $gender, 'ssn' => $ssn, 'dob' => $dob, 'url' => $url));
     if ($result !== true) {
         //do nothing
     }
     if (!is_null($group) && is_numeric($group)) {
         $jUser->AddUserToGroup($user_id, $group);
     }
     $mail = Jaws_Mail::getInstance();
     $site_url = $GLOBALS['app']->getSiteURL('/');
     $site_name = $this->gadget->registry->fetch('site_name', 'Settings');
     $site_author = $this->gadget->registry->fetch('site_author', 'Settings');
     $activation = $this->gadget->registry->fetch('anon_activation');
     $notification = $this->gadget->registry->fetch('register_notification');
     $delete_user = false;
     $message = '';
     if ($random === true || $activation != 'admin') {
         $tpl = $this->gadget->template->load('UserNotification.txt');
         $tpl->SetBlock('Notification');
         $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $nickname));
         if ($random === true) {
             switch ($activation) {
                 case 'admin':
                     $tpl->SetVariable('message', _t('USERS_REGISTER_BY_ADMIN_RANDOM_MAIL_MSG'));
                     break;
                 case 'user':
                     $tpl->SetVariable('message', _t('USERS_REGISTER_BY_USER_RANDOM_MAIL_MSG'));
                     break;
                 default:
                     $tpl->SetVariable('message', _t('USERS_REGISTER_RANDOM_MAIL_MSG'));
             }
             $tpl->SetBlock('Notification/Password');
             $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD'));
             $tpl->SetVariable('password', $password);
             $tpl->ParseBlock('Notification/Password');
         } elseif ($activation == 'user') {
             $tpl->SetVariable('message', _t('USERS_REGISTER_ACTIVATION_MAIL_MSG'));
         } else {
             $tpl->SetVariable('message', _t('USERS_REGISTER_MAIL_MSG'));
         }
         $tpl->SetBlock('Notification/IP');
         $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
         $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
         $tpl->ParseBlock('Notification/IP');
         $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
         $tpl->SetVariable('username', $username);
         if ($activation == 'user') {
             $verifyKey = $jUser->UpdateEmailVerifyKey($user_id);
             if (Jaws_Error::IsError($verifyKey)) {
                 $delete_user = true;
                 $message = _t('GLOBAL_ERROR_QUERY_FAILED');
             } else {
                 $tpl->SetBlock('Notification/Activation');
                 $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK'));
                 $tpl->SetVariable('activation_link', $this->gadget->urlMap('ActivateUser', array('key' => $verifyKey), true));
                 $tpl->ParseBlock('Notification/Activation');
             }
         }
         $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
         $tpl->SetVariable('site-name', $site_name);
         $tpl->SetVariable('site-url', $site_url);
         $tpl->ParseBlock('Notification');
         $body = $tpl->Get();
         if (!$delete_user) {
             $subject = _t('USERS_REGISTER_SUBJECT', $site_name);
             $mail->SetFrom();
             $mail->AddRecipient($user_email);
             $mail->SetSubject($subject);
             $mail->SetBody($this->gadget->ParseText($body));
             $mresult = $mail->send();
             if (Jaws_Error::IsError($mresult)) {
                 if ($activation == 'user') {
                     $delete_user = true;
                     $message = _t('USERS_REGISTER_ACTIVATION_SENDMAIL_FAILED', $user_email);
                 } elseif ($random === true) {
                     $delete_user = true;
                     $message = _t('USERS_REGISTER_RANDOM_SENDMAIL_FAILED', $user_email);
                 }
             }
         }
     }
     //Send an email to website owner
     $mail->reset();
     if (!$delete_user && ($notification == 'true' || $activation == 'admin')) {
         $tpl = $this->gadget->template->load('AdminNotification.txt');
         $tpl->SetBlock('Notification');
         $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $site_author));
         $tpl->SetVariable('message', _t('USERS_REGISTER_ADMIN_MAIL_MSG'));
         $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
         $tpl->SetVariable('username', $username);
         $tpl->SetVariable('lbl_nickname', _t('USERS_USERS_NICKNAME'));
         $tpl->SetVariable('nickname', $nickname);
         $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL'));
         $tpl->SetVariable('email', $user_email);
         $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
         $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
         if ($activation == 'admin') {
             $verifyKey = $jUser->UpdateEmailVerifyKey($user_id);
             if (!Jaws_Error::IsError($verifyKey)) {
                 $tpl->SetBlock('Notification/Activation');
                 $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK'));
                 $tpl->SetVariable('activation_link', $this->gadget->urlMap('ActivateUser', array('key' => $verifyKey), true));
                 $tpl->ParseBlock('Notification/Activation');
             }
         }
         $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
         $tpl->SetVariable('site-name', $site_name);
         $tpl->SetVariable('site-url', $site_url);
         $tpl->ParseBlock('Notification');
         $body = $tpl->Get();
         if (!$delete_user) {
             $subject = _t('USERS_REGISTER_SUBJECT', $site_name);
             $mail->SetFrom();
             $mail->AddRecipient();
             $mail->SetSubject($subject);
             $mail->SetBody($this->gadget->ParseText($body));
             $mresult = $mail->send();
             if (Jaws_Error::IsError($mresult) && $activation == 'admin') {
                 // do nothing
                 //$delete_user = true;
                 //$message = _t('USERS_ACTIVATE_NOT_ACTIVATED_SENDMAIL', $user_email);
             }
         }
     }
     if ($delete_user) {
         $jUser->DeleteUser($user_id);
         return $message;
     }
     return true;
 }
예제 #6
0
파일: Complex.php 프로젝트: juniortux/jaws
 /**
  * Displays the captcha image
  *
  * @access  public
  * @param   int     $key    Captcha key
  * @return  mixed   Captcha raw image data
  */
 function image($key)
 {
     $value = Jaws_Utils::RandomText();
     $result = $this->update($key, $value);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     }
     $contrast = 100;
     // A value between 0 and 100
     $contrast = 1.3 * (255 * ($contrast / 100.0));
     $num_polygons = 3;
     // Number of triangles to draw
     $num_ellipses = 3;
     // Number of ellipses to draw
     $num_lines = 3;
     // Number of lines to draw
     $num_dots = 0;
     // Number of dots to draw
     $min_thickness = 2;
     // Minimum thickness in pixels of lines
     $max_thickness = 8;
     // Maximum thickness in pixles of lines
     $min_radius = 10;
     // Minimum radius in pixels of ellipses
     $max_radius = 30;
     // Maximum radius in pixels of ellipses
     $object_alpha = 95;
     // A value between 0 and 127
     $width = 15 * imagefontwidth(5);
     $height = 2.5 * imagefontheight(5);
     $im = imagecreatetruecolor($width, $height);
     imagealphablending($im, true);
     $black = imagecolorallocatealpha($im, 0, 0, 0, 0);
     $rotated = imagecreatetruecolor(70, 70);
     $x = 0;
     $text_length = strlen($value);
     for ($i = 0; $i < $text_length; $i++) {
         $buffer = imagecreatetruecolor(20, 20);
         $buffer2 = imagecreatetruecolor(40, 40);
         // Get a random color
         $red = mt_rand(0, 255);
         $green = mt_rand(0, 255);
         $blue = 255 - sqrt($red * $red + $green * $green);
         $color = imagecolorallocate($buffer, $red, $green, $blue);
         // Create character
         imagestring($buffer, 5, 0, 0, $value[$i], $color);
         // Resize character
         imagecopyresized($buffer2, $buffer, 0, 0, 0, 0, 25 + mt_rand(0, 12), 25 + mt_rand(0, 12), 20, 20);
         // Rotate characters a little
         $rotated = imagerotate($buffer2, mt_rand(-25, 25), imagecolorallocatealpha($buffer2, 0, 0, 0, 0));
         imagecolortransparent($rotated, imagecolorallocatealpha($rotated, 0, 0, 0, 0));
         // Move characters around a little
         $y = mt_rand(1, 3);
         $x += mt_rand(2, 6);
         imagecopymerge($im, $rotated, $x, $y, 0, 0, 40, 40, 100);
         $x += 22;
         imagedestroy($buffer);
         imagedestroy($buffer2);
     }
     // Draw polygons
     if ($num_polygons > 0) {
         for ($i = 0; $i < $num_polygons; $i++) {
             $vertices = array(mt_rand(-0.25 * $width, $width * 1.25), mt_rand(-0.25 * $width, $width * 1.25), mt_rand(-0.25 * $width, $width * 1.25), mt_rand(-0.25 * $width, $width * 1.25), mt_rand(-0.25 * $width, $width * 1.25), mt_rand(-0.25 * $width, $width * 1.25));
             $color = imagecolorallocatealpha($im, mt_rand(0, $contrast), mt_rand(0, $contrast), mt_rand(0, $contrast), $object_alpha);
             imagefilledpolygon($im, $vertices, 3, $color);
         }
     }
     // Draw random circles
     if ($num_ellipses > 0) {
         for ($i = 0; $i < $num_ellipses; $i++) {
             $x1 = mt_rand(0, $width);
             $y1 = mt_rand(0, $height);
             $color = imagecolorallocatealpha($im, mt_rand(0, $contrast), mt_rand(0, $contrast), mt_rand(0, $contrast), $object_alpha);
             imagefilledellipse($im, $x1, $y1, mt_rand($min_radius, $max_radius), mt_rand($min_radius, $max_radius), $color);
         }
     }
     // Draw random lines
     if ($num_lines > 0) {
         for ($i = 0; $i < $num_lines; $i++) {
             $x1 = mt_rand(-$width * 0.25, $width * 1.25);
             $y1 = mt_rand(-$height * 0.25, $height * 1.25);
             $x2 = mt_rand(-$width * 0.25, $width * 1.25);
             $y2 = mt_rand(-$height * 0.25, $height * 1.25);
             $color = imagecolorallocatealpha($im, mt_rand(0, $contrast), mt_rand(0, $contrast), mt_rand(0, $contrast), $object_alpha);
             imagesetthickness($im, mt_rand($min_thickness, $max_thickness));
             imageline($im, $x1, $y1, $x2, $y2, $color);
         }
     }
     // Draw random dots
     if ($num_dots > 0) {
         for ($i = 0; $i < $num_dots; $i++) {
             $x1 = mt_rand(0, $width);
             $y1 = mt_rand(0, $height);
             $color = imagecolorallocatealpha($im, mt_rand(0, $contrast), mt_rand(0, $contrast), mt_rand(0, $contrast), $object_alpha);
             imagesetpixel($im, $x1, $y1, $color);
         }
     }
     header("Content-Type: image/png");
     ob_start();
     imagepng($im);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $content;
 }