function jsonifyStats($channel, $limit = 50) { header('content-type: application/json; charset=utf-8'); if (!validateChannel($channel) || !preg_match('/^[0-9]*$/i', $limit)) { die(json_encode("Invalid parameter", JSON_FORCE_OBJECT)); } $obj = array(); if ($channel) { $obj['streams'] = array(); date_default_timezone_set('UTC'); $pastBroadcasts = json_decode(file_get_contents('https://api.twitch.tv/kraken/channels/' . $channel . '/videos?client_id=1edbt02x273wfht9ad4goa4aabv00fw&broadcasts=true&limit=' . $limit), true); if (!is_array($pastBroadcasts)) { die(json_encode("Error with Twitch API", JSON_FORCE_OBJECT)); } $pastBroadcasts = $pastBroadcasts["videos"]; foreach ($pastBroadcasts as $pastBroadcast) { $streamObj = array(); $streamObj["title"] = $pastBroadcast["title"]; $streamObj["id"] = $pastBroadcast["_id"]; //$streamObj["channel"] = $channel; $streamstart = strtotime($pastBroadcast["recorded_at"]); $streamend = strtotime($pastBroadcast["recorded_at"]) + $pastBroadcast["length"]; $streamObj["start"] = $streamstart; $streamObj["end"] = $streamend; $streamObj["duration"] = $pastBroadcast["length"]; // is this really necessary? A: no $result = $this->db->query("select stamp as `time`, count(*) as hits, `type` from highlights where channel = '{$channel}' and stamp >= '" . $streamstart . "' and stamp <= '" . $streamend . "' group by YEAR(FROM_UNIXTIME(stamp)), MONTH(FROM_UNIXTIME(stamp)), DAY(FROM_UNIXTIME(stamp)), HOUR(FROM_UNIXTIME(stamp)), MINUTE(FROM_UNIXTIME(stamp)), `type` order by stamp"); //number of unique highlights $uniquecount = $this->db->getNumRows(); $streamObj["hlcount"] = $uniquecount; $obj['streams'][] = $streamObj; } } else { die(json_encode("No channel specified!", JSON_FORCE_OBJECT)); } spitOutJson($obj); }
<?php require_once "common.php"; if (!isset($_GET['channel'])) { throw404(); } $channel = strtolower($_GET['channel']); if (!validateChannel($channel)) { throw404(); } //if (getUserAccessLevel($_SESSION['channel']) > $USER_ACCESS_LEVEL_NONE) $channelCoebotData = dbGetChannel($channel); if (!$channelCoebotData || $channelCoebotData['isActive'] == false) { if (getUserAccessLevel($channel) >= $USER_ACCESS_LEVEL_OWNER) { printHead("Join CoeBot?"); printNav('', true); ?> <div class="container"> <div class="row"> <div class="col-sm-8 col-sm-offset-2"> <h2 class="text-center">Join CoeBot?</h2> <p class="lead text-center">You haven't joined CoeBot yet! Care to change that?</p> <p class="text-center">Already hit the join button? Your request may still be processing; wait a few seconds and refresh the page.</p> <p class="text-center"> <a class="btn btn-primary btn-lg" href="/botaction.php?a=join&bot=coebot&channel=<?php echo $channel; ?> "> Join <?php echo $channel;
function getChannelFromQuery($query) { //if (count($query) < 3) return false; $authArr = getAuthArray($query); $chan = $authArr[0]; // this check is crucial!!! huge server vulnerability if this check is removed if (!validateChannel($chan)) { return false; } return $chan; }
<?php require_once 'common.php'; if (!isset($_GET['channel']) || !isset($_GET['var'])) { die("Your URL is missing a required parameter."); } $channel = $_GET['channel']; $varName = $_GET['var']; $refresh = isset($_GET['refresh']) ? $_GET['refresh'] : "5000"; if (!validateChannel($channel) || !preg_match('/^[A-Z0-9\\-_]{1,64}$/i', $varName) || !preg_match('/^[0-9]+$/i', $refresh)) { die('One of the parameters in your URL is invalid.'); } function printOptionalParam($param, $format = "%s") { if (isset($_GET[$param]) && $_GET[$param] != "") { printf($format, htmlspecialchars($_GET[$param])); } } // $varRow = dbGetVar($channel, $varName); // $ct = ($varRow && isset($varRow['value'])) ? $varRow['value'] : "?"; // if (isset($_GET['format']) && $_GET['format'] == "text") { // header('Content-type: text/plain'); // die($ct); // } ?> <!doctype html> <html id="html" class="<?php printOptionalParam('themes'); ?> "> <head>
function logUserIn($channel, $uid) { if (!validateChannel($channel)) { return false; } $_SESSION['loggedIn'] = true; $_SESSION['channel'] = $channel; $_SESSION['uid'] = $uid; return true; }
<?php require_once 'common.php'; if (!isset($_GET['channel']) || !isset($_GET['command'])) { die("lern2parameters"); } $channel = $_GET['channel']; $command = $_GET['command']; if (!validateChannel($channel) || preg_match('/^[A-Z0-9\\-_]$/i', $command)) { die('git gud skrub'); } $json_data = file_get_contents('configs/' . $channel . '.json'); $data = json_decode($json_data); $cmdObj = (object) array("count" => "?"); foreach ($data->commands as $struct) { if ($command == $struct->key) { $cmdObj = $struct; break; } } $ct = $cmdObj->count; $isUpdated = false; if (isset($_COOKIE['lastcmdct_' . $command]) && $_COOKIE['lastcmdct_' . $command] != $ct) { $isUpdated = true; } $devMode = isset($_GET['dev']); setcookie("lastcmdct_" . $command, $ct); header('Content-type: text/html'); header('refresh: 5; url=http://coebot.tv/showvar.php?channel=coestar&var=rip-uncharted2&themes=blood+guude&label=deaths'); ?> <html>
function getChannelWithAuthOrDie($userAccessLevel, $useJson = false) { $channel = getParam('channel'); if (!validateChannel($channel)) { respondMessage("invalid parameter (channel)"); return NULL; } if (getUserAccessLevel($channel) < $userAccessLevel) { respondMessage("not authorized"); return NULL; } return $channel; }