function generateReallyUniqueBaseId($tries) { $mdb = $this->mdb; $i = 0; $baseid = ''; while ($i < $tries) { $baseid = randomHex(32); $check = $mdb->queryFirstRow("SELECT baseid FROM base WHERE baseid = %s", $baseid); if ($check === NULL) { break; } $i++; $baseid = ''; } return $baseid; }
function streamPlaylist($favorite_id) { global $cfg, $db; createHiddenDir(NJB_HOME_DIR . 'stream/'); $m3u = 'stream/netjukebox_' . randomHex() . '.m3u'; $m3u_content = '#EXTM3U' . "\n"; $query = mysql_query('SELECT stream_url FROM favoriteitem WHERE favorite_id = ' . (int) $favorite_id . ' AND stream_url != "" ORDER BY position'); while ($favoriteitem = mysql_fetch_assoc($query)) { $m3u_content .= $favoriteitem['stream_url'] . "\n"; } $m3u_content .= '#EXT-X-ENDLIST' . "\n"; if (file_put_contents(NJB_HOME_DIR . $m3u, $m3u_content) === false) { message(__FILE__, __LINE__, 'error', '[b]Failed to write file:[/b][br]' . NJB_HOME_DIR . $m3u); } header('Location: ' . NJB_HOME_URL . $m3u); exit; }
function cacheGetDir($id, $profile) { global $cfg, $db; if (strpos($id, '_')) { $id = substr($id, 0, strpos($id, '_')); } $query = mysql_query('SELECT relative_file FROM cache WHERE profile = ' . (int) $profile . ' AND SUBSTRING_INDEX(id, "_", 1) = "' . mysql_real_escape_string($id) . '"'); $cache = mysql_fetch_assoc($query); $relative_dir = substr($cache['relative_file'], 0, strrpos($cache['relative_file'], '/')) . '/'; $dir = NJB_HOME_DIR . $relative_dir; if ($cache['relative_file'] != '' && is_dir($dir)) { return $dir; } elseif ($cache['relative_file'] != '') { cacheCreateRoot(); if (@mkdir($dir, 0777) == false) { message(__FILE__, __LINE__, 'error', '[b]Failed to create directory:[/b][br]' . $dir); } return $dir; } else { $random = randomHex(); $relative_dir = 'cache/' . substr($random, 0, 1) . '/' . substr($random, 1, 1) . '/' . $random . '/'; $dir = NJB_HOME_DIR . $relative_dir; cacheCreateRoot(); if (@mkdir($dir, 0777) == false) { message(__FILE__, __LINE__, 'error', '[b]Failed to create directory:[/b][br]' . $dir); } mysql_query('INSERT INTO cache (id, profile, create_time, idle_time, relative_file) VALUES ( "' . mysql_real_escape_string($id) . '_pinpoint", ' . (int) $profile . ', ' . (int) time() . ', ' . (int) time() . ', "' . mysql_real_escape_string($relative_dir) . 'dummy.pinpoint")'); return $dir; } }
function sendTo($endpoint, $api, $payload, &$error) { global $thisEntity; // Encode the payload: $payload = base64_encode($payload); // Create a request ID: $id = randomHex(20) . '@' . time() . '000'; // Build the protected header: $pHeader = base64_encode('{"id":"' . $id . '","pubsig":"' . base64_encode(sign($id)) . '"}'); // Build the message: $message = '{"header":{"entity":"' . $thisEntity['Endpoint'] . '"},"protected":"' . $pHeader . '","payload":"' . $payload . '","signature":"' . base64_encode(sign($pHeader . '.' . $payload)) . '"}'; // Post it off: $postError; $response = post('https://' . $endpoint . '/v1/' . $api, $message, $postError); if ($postError) { $error = $postError; return null; } return $response; }
function randomSessionID() { return randomHex(64); }
function randomKey() { $key = substr(randomHex(), 0, 30); $key .= substr(randomHex(), 0, 30); $key = base64_encode(pack('H*', $key)); $key = str_replace('+', '-', $key); // modified Base64 for URL $key = str_replace('/', '_', $key); return $key; }