PageRenderTime 34ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Snep/Usuario.php

https://bitbucket.org/efepimenta/snep-3
PHP | 206 lines | 61 code | 22 blank | 123 comment | 0 complexity | d3f88abff90d23679846d03e1f5679d7 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  1. <?php
  2. /**
  3. * This file is part of SNEP.
  4. *
  5. * SNEP is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as
  7. * published by the Free Software Foundation, either version 3 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * SNEP is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with SNEP. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
  17. */
  18. require_once "Snep/Channel.php";
  19. /**
  20. * Usuário Snep
  21. *
  22. * Classe que representa usuários do sistema. Geralmente associados a ramais e
  23. * agentes.
  24. *
  25. * @category Snep
  26. * @package Snep
  27. * @copyright Copyright (c) 2010 OpenS Tecnologia
  28. * @author Henrique Grolli Bassotto
  29. */
  30. abstract class Snep_Usuario extends Snep_Channel {
  31. /**
  32. * Name do usuário
  33. *
  34. * @var string
  35. */
  36. protected $callerid;
  37. /**
  38. * Grupo do usuário
  39. *
  40. * @var string
  41. */
  42. protected $group;
  43. /**
  44. * Numero que identifica o usuário no banco de dados e através do sistema.
  45. *
  46. * @var int
  47. */
  48. protected $numero;
  49. /**
  50. * Senha de acesso a interface.
  51. *
  52. * @var string
  53. */
  54. protected $senha;
  55. /**
  56. * Name de usuário para acesso a interface.
  57. *
  58. * @var string
  59. */
  60. protected $username;
  61. /**
  62. * Construtor da classe
  63. *
  64. * @param int $numero
  65. * @param string $callerid
  66. * @param string $usuario
  67. * @param string $senha
  68. */
  69. public function __construct($numero, $callerid, $usuario, $senha) {
  70. $this->setNumero($numero);
  71. $this->setCallerid($callerid);
  72. $this->setPassword($senha);
  73. $this->setGroup('users');
  74. $this->username = $usuario;
  75. }
  76. /**
  77. * Imprime usuario
  78. *
  79. * @return string
  80. */
  81. public function __toString() {
  82. return (string)$this->usuario;
  83. }
  84. /**
  85. * Retorna o callerid do usuário.
  86. *
  87. * @return string callerid
  88. */
  89. public function getCallerid() {
  90. return $this->callerid;
  91. }
  92. /**
  93. * Retorna a que grupo de usuários pertence esse ramal.
  94. *
  95. * @return string group
  96. */
  97. public function getGroup() {
  98. return $this->group;
  99. }
  100. /**
  101. * Retorna o numero do grupo
  102. *
  103. * @return int numero
  104. */
  105. public function getNumero() {
  106. return $this->numero;
  107. }
  108. /**
  109. * Retorna a senha de um ramal
  110. *
  111. * @return string password
  112. */
  113. public function getPassword() {
  114. return $this->senha;
  115. }
  116. /**
  117. * Returns an encrypted & utf8-encoded
  118. */
  119. public function encrypt($string, $encryption_key) {
  120. $encrypt_method = "AES-256-CBC";
  121. $secret_key = $encryption_key;
  122. // hash
  123. $key = hash('sha256', $secret_key);
  124. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  125. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  126. return base64_encode($output);
  127. }
  128. /**
  129. * Returns decrypted original string
  130. */
  131. public function decrypt($string, $encryption_key) {
  132. $encrypt_method = "AES-256-CBC";
  133. $secret_key = $encryption_key;
  134. // hash
  135. $key = hash('sha256', $secret_key);
  136. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  137. return openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  138. }
  139. /**
  140. * Define um nome para o usuário. (callerid)
  141. *
  142. * @param string $callerid
  143. */
  144. public function setCallerid($callerid) {
  145. $this->callerid = $callerid;
  146. }
  147. /**
  148. * Define a qual grupo pertence esse usuário.
  149. *
  150. * @param string $group name
  151. */
  152. public function setGroup($group) {
  153. $this->group = $group;
  154. }
  155. /**
  156. * Define um numero para o usuário
  157. *
  158. * MUITO CUIDADO: Numeros de usuário devem ser únicos para cada usuário.
  159. *
  160. * @param int $number
  161. */
  162. public function setNumero($number) {
  163. $this->numero = $number;
  164. }
  165. /**
  166. * Define uma senha para o usuário
  167. *
  168. * @param string $password
  169. */
  170. public function setPassword($password) {
  171. $this->senha = $password;
  172. }
  173. /**
  174. * Define um nome de usuário para acesso a interface ou identificação
  175. * simplificada.
  176. *
  177. * Geralmente usa-se o número do usuário.
  178. *
  179. * @param string $username
  180. */
  181. public function setUsername($username) {
  182. $this->username = $username;
  183. }
  184. }