示例#1
0
function dec2IP($dec)
{
    $hex = dec2hex($dec);
    if (strlen($hex) == 7) {
        $hex = "0" . $hex;
    }
    $one = hexdec(substr($hex, 0, 2));
    $two = hexdec(substr($hex, 2, 2));
    $three = hexdec(substr($hex, 4, 2));
    $four = hexdec(substr($hex, 6, 2));
    $ip = $one . "." . $two . "." . $three . "." . $four;
    return $ip;
}
示例#2
0
function oid2hex($n)
{
    if (is_int($n)) {
        $oidHex = $n > 127 ? dec2hex(128 | $n / 128) . dec2hex($n % 128) : dec2hex($n);
    } else {
        $oidHex = '';
        $oid = explode('.', $n);
        $n1 = 40 * $oid[0] + $oid[1];
        $oidHex .= dec2hex($n1);
        unset($oid[0], $oid[1]);
        foreach ($oid as $n) {
            $oidHex .= oid2hex((int) $n);
        }
    }
    return $oidHex;
}
示例#3
0
 private function _computeK()
 {
     $hash_input = str_pad($this->_Ahex, strlen($this->_srp->Nhex()), "0", STR_PAD_LEFT) . str_pad($this->_Bhex, strlen($this->_srp->Nhex()), "0", STR_PAD_LEFT);
     $hash_input = pack("H*", $hash_input);
     $this->_uhex = $this->_srp->hash($hash_input);
     $this->_udec = hex2dec($this->_uhex);
     $Stmp = bcpowmod($this->_vdec, $this->_udec, $this->_srp->Ndec());
     // v^u (mod N)
     $Stmp = bcmod(bcmul($Stmp, $this->_Adec), $this->_srp->Ndec());
     //v^u*A (mod N)
     $Stmp = bcpowmod($Stmp, $this->_bdec, $this->_srp->Ndec());
     // (v^u*A)^b (mod N)
     $this->_Sdec = $Stmp;
     $this->_Shex = dec2hex($this->_Sdec);
     $this->_Shex = str_pad($this->_Shex, strlen($this->_srp->Nhex()), "0", STR_PAD_LEFT);
     $this->_Khex = $this->_srp->keyHash(pack("H*", $this->_Shex));
 }
示例#4
0
function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation)
{
    //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
    //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
    logMe("streamContents({$path}, {$include_target}, {$start_time}, {$count}, {$order}, {$exclude_target}, {$continuation})\n");
    header('Content-Type: application/json; charset=UTF-8');
    $feedDAO = FreshRSS_Factory::createFeedDao();
    $arrayFeedCategoryNames = $feedDAO->arrayFeedCategoryNames();
    switch ($path) {
        case 'reading-list':
            $type = 'A';
            break;
        case 'starred':
            $type = 's';
            break;
        case 'feed':
            $type = 'f';
            break;
        case 'label':
            $type = 'c';
            $categoryDAO = new FreshRSS_CategoryDAO();
            $cat = $categoryDAO->searchByName($include_target);
            $include_target = $cat == null ? -1 : $cat->id();
            break;
        default:
            $type = 'A';
            break;
    }
    switch ($exclude_target) {
        case 'user/-/state/com.google/read':
            $state = FreshRSS_Entry::STATE_NOT_READ;
            break;
        default:
            $state = FreshRSS_Entry::STATE_ALL;
            break;
    }
    if (!empty($continuation)) {
        $count++;
        //Shift by one element
    }
    $entryDAO = FreshRSS_Factory::createEntryDao();
    $entries = $entryDAO->listWhere($type, $include_target, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, '', $start_time);
    $items = array();
    foreach ($entries as $entry) {
        $f_id = $entry->feed();
        if (isset($arrayFeedCategoryNames[$f_id])) {
            $c_name = $arrayFeedCategoryNames[$f_id]['c_name'];
            $f_name = $arrayFeedCategoryNames[$f_id]['name'];
        } else {
            $c_name = '_';
            $f_name = '_';
        }
        $item = array('id' => dec2hex($entry->id()), 'crawlTimeMsec' => substr($entry->id(), 0, -3), 'timestampUsec' => $entry->id(), 'published' => $entry->date(true), 'title' => $entry->title(), 'summary' => array('content' => $entry->content()), 'alternate' => array(array('href' => $entry->link())), 'categories' => array('user/-/state/com.google/reading-list', 'user/-/label/' . $c_name), 'origin' => array('streamId' => 'feed/' . $f_id, 'title' => $f_name));
        if ($entry->author() != '') {
            $item['author'] = $entry->author();
        }
        if ($entry->isRead()) {
            $item['categories'][] = 'user/-/state/com.google/read';
        }
        if ($entry->isFavorite()) {
            $item['categories'][] = 'user/-/state/com.google/starred';
        }
        $items[] = $item;
    }
    if (!empty($continuation)) {
        array_shift($items);
        //Discard first element that was already sent in the previous response
    }
    $response = array('id' => 'user/-/state/com.google/reading-list', 'updated' => time(), 'items' => $items);
    if (count($entries) >= $count && !empty($entry)) {
        $response['continuation'] = $entry->id();
    }
    echo json_encode($response), "\n";
    exit;
}
示例#5
0
/**
 * getSignature
 * Get the base64 signature of a dictionary
 * @param array Associative array (i.e. dictionary) of key-value pairs
 * @param string Hexadecimal string of public key
 * @param string Hexadecimal string the private key
 * @return string Base64 encoded signature
 */
function getSignature($dict, $key, $privKey)
{
    // Sort keys alphabetically
    uksort($dict, "strcasecmp");
    // Concatenate all values
    $total = '';
    foreach ($dict as $value) {
        $total .= $value;
    }
    // Escape apostrophes by un-quoting, adding apos, then re-quoting
    // so this turns ' into '\'' ... we have to double-slash for this php.
    // Switch to UTF8 before otherwise escapeshellarg will strip out non-ASCII characters
    $oldlocale = setlocale(LC_CTYPE, 0);
    setlocale(LC_CTYPE, "en_US.UTF-8");
    $fixedApostrophes = escapeshellarg($total);
    // restore localte
    setlocale(LC_CTYPE, $oldlocale);
    // This part is the most expensive below
    // We try to do it with native code first
    $aquatic_root = preg_replace('!((/[A-Za-z._-]+)+)/AquaticPrime\\.php!', '$1', __FILE__);
    ob_start();
    $passthruString = $aquatic_root . "/aquaticprime {$key} {$privKey} {$fixedApostrophes}";
    passthru($passthruString, $err);
    $sig = ob_get_contents();
    ob_end_clean();
    if ($err) {
        error_log("passthrough yielded {$err}: {$passthruString}");
    }
    // If that fails, do it in php
    if ($sig != "") {
        $sig = base64_encode($sig);
    } else {
        // Get the hash
        $hash = sha1(utf8_encode($total));
        // OpenSSL-compatible PKCS1 Padding
        // 128 bytes - 20 bytes hash - 3 bytes extra padding = 105 bytes '0xff'
        $paddedHash = '0001';
        for ($i = 0; $i < 105; $i++) {
            $paddedHash .= 'ff';
        }
        $paddedHash .= '00' . $hash;
        $decryptedSig = hex2dec($paddedHash);
        // Encrypt into a signature
        $sig = powmod($decryptedSig, hex2dec($privKey), hex2dec($key));
        $sig = base64_encode(ap_hex2bin(dec2hex($sig)));
    }
    return $sig;
}
示例#6
0
function computverifier($srp, $user, $pwd, $salt)
{
    // private key
    $innerHash = $srp->hashHex(strToHex($user) . '3a' . strToHex($pwd));
    $privateKey = $srp->hashHex($salt . $innerHash);
    // verifier
    $tmp = dec2hex(bcpowmod($srp->gdec(), hex2dec($privateKey), $srp->Ndec()));
    $verifier = str_pad($tmp, strlen($srp->Nhex()), "0", STR_PAD_LEFT);
    return $verifier;
}
function enterasys_N7_convert_macs($oldmac)
{
    //    print ("==oldmac=[$oldmac] \n");
    $oldmac = substr($oldmac, stripos($oldmac, '.') + 1);
    //		print ("==old___=[$oldmac] \n");
    $oldmac = substr($oldmac, stripos($oldmac, '.'));
    //		print ("==o_____=[$oldmac] \n");
    $piece = explode(".", $oldmac);
    $newmac = '';
    for ($i = 0; $i < 6; $i++) {
        $newmac = $newmac . dec2hex($piece[$i], 2) . ":";
    }
    $newmac = substr($newmac, 0, strlen($newmac) - 1);
    //print ("=newmac=$newmac\n");
    return $newmac;
}
        $conn['port'] = $parts[1];
    }
    $conn['db'] = 'mysql';
    if ($sample['db_max'] != '') {
        $conn['db'] = $sample['db_max'];
    }
    $conn['user'] = '******';
    $conn['password'] = '';
    return $conn;
});
/**
 * This is configuration information for how the actual sql queries are built
 * from the form values.  It shouldn't be necessary to modify any of these
 * values, and you can possibly break reporting functionality by doing so.
 *
 * For more information, see the phpDoc or comments in the MySQLTableReport class.
 */
$conf['reports']['slow_query_log'] = array('join' => array('dimension' => 'USING (`checksum`)'), 'fields' => array('fact' => array('group' => 'group', 'order' => 'order', 'having' => 'having', 'limit' => 'limit', 'first_seen' => 'clear|reldate|ge|where', 'where' => 'raw_where', 'sample' => 'clear|like|where', 'checksum' => 'clear|where', 'reviewed_status' => 'clear|where'), 'dimension' => array('extra_fields' => 'where', 'hostname_max' => 'clear|where', 'ts_min' => 'date_range|reldate|clear|where', 'pivot-hostname_max' => 'clear|pivot|select', 'pivot-checksum' => 'clear|pivot|select')), 'custom_fields' => array('checksum' => 'checksum', 'date' => 'DATE(ts_min)', 'hour' => 'substring(ts_min,1,13)', 'hour_ts' => 'round(unix_timestamp(substring(ts_min,1,13)))', 'minute_ts' => 'round(unix_timestamp(substring(ts_min,1,16)))', 'minute' => 'substring(ts_min,1,16)', 'snippet' => 'LEFT(dimension.sample,20)', 'index_ratio' => 'ROUND(SUM(Rows_examined_sum)/SUM(rows_sent_sum),2)', 'query_time_avg' => 'SUM(Query_time_sum) / SUM(ts_cnt)', 'rows_sent_avg' => 'ROUND(SUM(Rows_sent_sum)/SUM(ts_cnt),0)'), 'callbacks' => array('table' => array('date' => function ($x) {
    $type = '';
    if (date('N', strtotime($x)) >= 6) {
        $type = 'weekend';
    }
    return array($x, $type);
}, 'checksum' => function ($x) {
    return array(dec2hex($x), '');
})));
$conf['reports']['performance_schema'] = array('fields' => array('fact' => array('order' => 'order', 'having' => 'having', 'limit' => 'limit', 'first_seen' => 'date_range|reldate|clear|where', 'where' => 'raw_where', 'DIGEST' => 'clear|where', 'DIGEST_TEXT' => 'clear|like|where', 'group' => 'group')), 'custom_fields' => array('snippet' => 'LEFT(fact.DIGEST_TEXT,20)', 'index_ratio' => 'ROUND(SUM_ROWS_EXAMINED/SUM_ROWS_SENT,2)', 'rows_sent_avg' => 'ROUND(SUM_ROWS_SENT/COUNT_STAR,0)'), 'special_field_names' => array('time' => 'FIRST_SEEN', 'checksum' => 'DIGEST', 'sample' => 'DIGEST_TEXT', 'fingerprint' => 'DIGEST_TEXT'));
$conf['reports']['performance_schema_history'] = array('join' => array('dimension' => 'USING (`DIGEST`)'), 'fields' => array('fact' => array('group' => 'group', 'order' => 'order', 'having' => 'having', 'limit' => 'limit', 'first_seen' => 'clear|reldate|ge|where', 'where' => 'raw_where', 'DIGEST_TEXT' => 'clear|like|where', 'DIGEST' => 'clear|where', 'reviewed_status' => 'clear|where'), 'dimension' => array('extra_fields' => 'where', 'hostname' => 'clear|where', 'FIRST_SEEN' => 'date_range|reldate|clear|where', 'pivot-hostname' => 'clear|pivot|select')), 'custom_fields' => array('date' => 'DATE(fact.FIRST_SEEN)', 'snippet' => 'LEFT(fact.DIGEST_TEXT,20)', 'index_ratio' => 'ROUND(SUM_ROWS_EXAMINED/SUM_ROWS_SENT,2)', 'rows_sent_avg' => 'ROUND(SUM_ROWS_SENT/COUNT_STAR,0)', 'hour' => 'substring(dimension.FIRST_SEEN,1,13)', 'hour_ts' => 'round(unix_timestamp(substring(dimension.FIRST_SEEN,1,13)))', 'minute_ts' => 'round(unix_timestamp(substring(dimension.FIRST_SEEN,1,16)))', 'minute' => 'substring(dimension.FIRST_SEEN,1,16)'), 'special_field_names' => array('time' => 'FIRST_SEEN', 'checksum' => 'DIGEST', 'hostname' => 'hostname', 'sample' => 'DIGEST_TEXT'));
/**
 * end of configuration settings
 */
示例#9
0
文件: ap.inc.php 项目: jschilli/Shine
/**
 * getSignature
 * Get the base64 signature of a dictionary
 * @param array Associative array (i.e. dictionary) of key-value pairs
 * @param string Hexadecimal string of public key
 * @param string Hexadecimal string the private key
 * @return string Base64 encoded signature
 */
function getSignature($dict, $key, $privKey)
{
    // Sort keys alphabetically
    uksort($dict, "strcasecmp");
    // Concatenate all values
    $total = '';
    foreach ($dict as $value) {
        $total .= $value;
    }
    // Get the hash
    $hash = sha1(utf8_encode($total));
    // OpenSSL-compatible PKCS1 Padding
    // 128 bytes - 20 bytes hash - 3 bytes extra padding = 105 bytes '0xff'
    $paddedHash = '0001';
    for ($i = 0; $i < 105; $i++) {
        $paddedHash .= 'ff';
    }
    $paddedHash .= '00' . $hash;
    $decryptedSig = hex2dec($paddedHash);
    // Encrypt into a signature
    $sig = powmod($decryptedSig, hex2dec($privKey), hex2dec($key));
    $sig = base64_encode(hex2bin(dec2hex($sig)));
    return $sig;
}
示例#10
0
function dec2mac($mac)
{
    $mac = dec2hex($mac);
    $mac = str_pad($mac, 12, '0', STR_PAD_LEFT);
    $mac = substr_replace($mac, ':', 10, 0);
    $mac = substr_replace($mac, ':', 8, 0);
    $mac = substr_replace($mac, ':', 6, 0);
    $mac = substr_replace($mac, ':', 4, 0);
    $mac = substr_replace($mac, ':', 2, 0);
    return $mac;
}
示例#11
0
 /**
  * Send a check-in request to google.
  *
  * @return String
  *  The device id of the new device as hex string.
  *
  * @throws CheckinException
  *  If the check-in request fails.
  */
 public function checkin()
 {
     $deviceid = '';
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, 'https://android.clients.google.com/checkin');
     curl_setopt($curl, CURLOPT_POST, TRUE);
     curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
     curl_setopt($curl, CURLOPT_USERAGENT, 'Android-Checkin/2.0 (maguro JRO03L); gzip');
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-protobuffer', 'Content-Encoding: gzip'));
     curl_setopt($curl, CURLOPT_POSTFIELDS, gzencode($this->checkinMessage()));
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_BINARYTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_TIMEOUT, 5);
     // Get result and status code of request.
     $httpresult = curl_exec($curl);
     $httpstatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($httpstatus === 28) {
         throw new CheckinException(_('Failed to check-in device: Request timed out.'));
     } elseif ($httpstatus !== 200) {
         throw new CheckinException(_f('Failed to check-in device: %s', $httpresult));
     }
     if ($httpstatus === 200) {
         $response = new AndroidCheckinResponse($httpresult);
         $deviceid = $response->getAndroidId();
         if (empty($response) || !is_numeric($deviceid)) {
             throw new CheckinException(_('Failed to check-in device: Received no deviceid.'));
         }
     }
     curl_close($curl);
     return dec2hex($deviceid);
 }
示例#12
0
 protected static function hexlen($s, $showPrefix = false)
 {
     $len = strlen($s);
     $prefix = $showPrefix ? '81' : '';
     if ($len > 255) {
         $prefix = '82';
     }
     if ($len > 65535) {
         $prefix = '83';
     }
     return $prefix . dec2hex($len);
 }
示例#13
0
    // allgemeine settings
    //include blocks from template config
    include_once GC_IPATH . 'templates/' . $_POST['Template'] . '/config.php';
    $TPLBlocks = explode(';', $TemplateSettings);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Step 3: Save new Site
if ($Step == "3") {
    //get Template Settings
    include_once GC_IPATH . 'templates/' . $_POST['Template'] . '/config.php';
    $TPLBlocks = explode(';', $TemplateSettings);
    include_once GC_IPATH . 'functions.php';
    include GC_IPATH . '_base/site-index.php';
    //filename
    $filename = extractName($_POST['path']);
    $filehandle = fopen(GC_IPATH . "_base/sites/" . dec2hex($SLastID + 1) . '-' . $filename . '.php', "w");
    //write header
    fwrite($filehandle, "<?php \r\n");
    fwrite($filehandle, '$SSettings = array();' . "\r\n");
    fwrite($filehandle, '$SBlocks = array();' . "\r\n");
    //write settings
    fwrite($filehandle, '$SSettings' . "['template'] = '" . $_POST['Template'] . '/standard.tpl' . "'; \r\n");
    fwrite($filehandle, '$SSettings' . "['title'] = '" . $_POST['title'] . "'; \r\n");
    fwrite($filehandle, '$SSettings' . "['path'] = '" . $_POST['path'] . "'; \r\n");
    //write blocks
    foreach ($TPLBlocks as $BlockEntry) {
        if (empty($_POST[$BlockEntry])) {
            continue;
        }
        fwrite($filehandle, '$SBlocks' . "['" . $BlockEntry . "'] = '" . $_POST[$BlockEntry] . "'; \r\n");
    }
示例#14
0
文件: ap.inc.php 项目: holtwick/Shine
/**
 * getSignature
 * Get the base64 signature of a dictionary
 * @param array Associative array (i.e. dictionary) of key-value pairs
 * @param string Hexadecimal string of public key
 * @param string Hexadecimal string the private key
 * @return string Base64 encoded signature
 */
function getSignature($dict, $key, $privKey)
{
    // Sort keys alphabetically
    uksort($dict, "strcasecmp");
    // Concatenate all values
    $total = '';
    foreach ($dict as $value) {
        $total .= $value;
    }
    // Escape apostrophes by un-quoting, adding apos, then re-quoting
    // so this turns ' into '\'' ... we have to double-slash for this php.
    $fixedApostrophes = str_replace("'", "'\\''", $total);
    // This part is the most expensive below
    // We try to do it with native code first
    ob_start();
    $passthruString = DOC_ROOT . "/includes/aquaticprime {$key} {$privKey} '{$fixedApostrophes}'";
    //passthru($passthruString, $err);
    $sig = ob_get_contents();
    ob_end_clean();
    if (true) {
        // Get the hash
        $hash = sha1(utf8_encode($total));
        // OpenSSL-compatible PKCS1 Padding
        // 128 bytes - 20 bytes hash - 3 bytes extra padding = 105 bytes '0xff'
        $paddedHash = '0001';
        for ($i = 0; $i < 105; $i++) {
            $paddedHash .= 'ff';
        }
        $paddedHash .= '00' . $hash;
        $decryptedSig = hex2dec($paddedHash);
        // Encrypt into a signature
        $sig = powmod($decryptedSig, hex2dec($privKey), hex2dec($key));
        $sig = base64_encode(hex2bin(dec2hex($sig)));
    }
    return $sig;
}
示例#15
0
$wtfdata = array();
if (count($result)) {
    if (preg_match("/^\\d+\$/", $result[0][$group])) {
        $is_datetime = false;
    } else {
        $is_datetime = true;
    }
}
foreach ($result as $row) {
    foreach ($series as $col) {
        $date = $row[$group];
        if ($is_datetime) {
            $parts = strptime($date, "%Y-%m-%d %H:%M:%S");
            $date = mktime($parts['tm_hour'], $parts['tm_min'], $parts['tm_sec'], $parts['tm_mon'] + 1, $parts['tm_mday'], $parts['tm_year'] + 1900);
        }
        $wtfdata[$col][] = array($date, $row[$col]);
    }
}
foreach ($series as $col) {
    // this is intended to capture checksum values when we pivot on checksums
    // and convert them to hex.  Done here because Javascript can't handle large enough
    // int values to convert them w/out loss of precision.
    // this may have some unintended consequences, but it's the easist way to solve the JS
    // limitation for now
    $col_label = $col;
    if (is_numeric($col_label)) {
        $col_label = dec2hex($col_label);
    }
    $finalfingdata[] = array('label' => $col_label, 'data' => $wtfdata[$col]);
}
print json_encode($finalfingdata);
示例#16
0
function convert_color($color, $bHex = false, $default_color = '000000')
{
    $rgb = array();
    if (preg_match('#(([0-9]{1,3}),\\s*([0-9]{1,3}),\\s*([0-9]{1,3})(,\\s*([0-9]{1,3}))?)#i', $color, $m)) {
        $rgb['red'] = $m[2];
        $rgb['green'] = $m[3];
        $rgb['blue'] = $m[4];
    } elseif (preg_match('#^[a-f0-9]{3}|[a-f0-9]{6}$#i', trim($color))) {
        if (strlen($color) == 3) {
            $color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
        }
        $colors = explode(',', substr(chunk_split($color, 2, ','), 0, -1));
        $rgb['red'] = hexdec($colors[0]);
        $rgb['green'] = hexdec($colors[1]);
        $rgb['blue'] = hexdec($colors[2]);
    } else {
        $rgb = css2hex($color, $default_color);
    }
    return $bHex ? dec2hex($rgb['red'], $rgb['green'], $rgb['blue']) : $rgb;
}
    unlink(FULL_CACHE_PATH);
}
$image = false;
if ($FLIR['text'][0] == '@') {
    $FLIR['text'] = '\\' . $FLIR['text'];
}
$bounds = bounding_box($FLIR['text']);
// convertBoundingBox(imagettfbbox($FLIR['size_pts'], 0, $FLIR['font'], $FLIR['text']));
$fulltrim = '';
if ($FStyle['fixBaseline'] != 'true') {
    $bounds['height'] += 200;
    $REAL_HEIGHT_BOUNDS = $bounds;
    $fulltrim = '-trim +repage';
}
$fore_hex = dec2hex($FLIR['color']['red'], $FLIR['color']['green'], $FLIR['color']['blue']);
$bkg_hex = $FLIR['output'] == 'png' ? 'transparent' : '"#' . dec2hex($FLIR['bkgcolor']['red'], $FLIR['bkgcolor']['green'], $FLIR['bkgcolor']['blue']) . '"';
$opacity = '';
if ($FLIR['opacity'] < 100 && $FLIR['opacity'] >= 0) {
    $opacity = strlen($FLIR['opacity']) == 1 ? '0' . $FLIR['opacity'] : (strlen($FLIR['opacity']) > 2 ? substr($FLIR['opacity'], 0, 2) : $FLIR['opacity']);
}
switch ($FStyle['cAlign']) {
    case 'center':
        $align = 'center';
        break;
    default:
        $align = 'west';
        break;
    case 'right':
        $align = 'east';
        break;
}