HEX
Server: Apache
System: Linux msm5694.mjhst.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: camjab_ssh (1000)
PHP: 5.3.29
Disabled: NONE
Upload Files
File: /home/httpd/html/baretube.com/admin/functions.awempire.php
<?
//Extract data for blacklabel API
if(file_exists($basepath."/admin/modules/awempire_blacklabel/config/blacklabel.json")) { 
	$blacklabel = json_decode(file_get_contents($basepath . '/admin/modules/awempire_blacklabel/config/blacklabel.json'), true);
}

/**
 *  aweBlacklabelDisplayThumbs - A summary has for this function has not yet been written.
 *  
 *  @param [in] $category Main category. girls or boys
 *  @param [in] $substring Search string for a particular type of model
 *  @param [in] $amount Number of performers to display, default 5
 *  @return void
 *  
 */
function aweBlacklabelDisplayThumbs($category = 'girls', $substring = '',$amount = 5) { 
	global $blacklabel;
	global $headers;
	global $basepath;
	global $template_path;
	global $basehttp; 
	//prepare translation api usage
	if($blacklabel['blacklabel_use_translation_api']) { 
		$thisUserApiTranslation = 1;
	} else { 
		$thisUserApiTranslation = 0;
	}

	$performers = aweBlacklabelCurlRequest('performers',"?category=".$category."&searchText=".$substring."&pageSize=".$amount."&useApiTranslation=".$thisUserApiTranslation);
	if(!is_array($performers['data']['performers']) || count($performers['data']['performers']) == 0 ) { 
		echo "No live performers found.";
	} else { 
		foreach($performers['data']['performers'] as $row) { 
			
			include("$template_path/awe_blacklabel/template.content_item_aweblacklabel.php");
		}
	}
}

/**
 *  aweBlacklabelCurlRequest - Wrapper for AWEmpire blacklabel API curl requests
 *  
 *  @param [in] $endpoint Endpoint to use
 *  @param [in] $queryString Querystring to append to endpoint. ex: "?category=girls&searchText=lesbian"
 *  @return array
 *  
 */
function aweBlacklabelCurlRequest($endpoint, $queryString = '') { 
	global $blacklabel;
	global $headers;
	global $basepath; 
	if($blacklabel['blacklabel_language']) { 
		$language = $blacklabel['blacklabel_language']; 
	} else { 
		$language = 'en';
	}
	
	if(substr($_SESSION['X-Session-Id'],0,1) == 'm') { 
		$language = "$language/member"; 
	}
	
	if($_SESSION['username']) { 
		$thisUser = $_SESSION['username']; 
	} else { 
		$thisUser = "Guest"; 
	}
	$logToFile = date('Y-m-d H:i:s').": ".$thisUser." - ".$_SESSION['X-Session-Id']." (GET REQUEST | ".$blacklabel['blacklabel_whitelabel_url'].'/'.$language.'/api/v1/'.$endpoint." | $queryString)\n";
	file_put_contents("$basepath/cache/awelog.txt",$logToFile, FILE_APPEND); 
	
	
	$debug = false; 
	if($debug) { 
		$tmp = array('Accept: application/json',
			'X-Application-Secret: '.$blacklabel['blacklabel_apikey'],
			'X-Client-Ip: '.$_SERVER['REMOTE_ADDR'].'',
			'X-User-Agent: '.$_SERVER['HTTP_USER_AGENT'].'',
			'X-Session-Id: '.$_SESSION['X-Session-Id'].'');
		$ep = $blacklabel['blacklabel_whitelabel_url'].'/'.$language.'/api/v1/'.$endpoint.$queryString;
		print_r($tmp);
		echo $ep."\n";
	}
	
	$curl = curl_init();
	curl_setopt_array($curl, array(
		CURLOPT_URL => $blacklabel['blacklabel_whitelabel_url'].'/'.$language.'/api/v1/'.$endpoint.$queryString,
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_FOLLOWLOCATION => 1,
		CURLOPT_TIMEOUT => 3,
		CURLOPT_HEADER => 0, 
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => 'GET',
		CURLOPT_HTTPHEADER => array(
			'Accept: application/json',
			'X-Application-Secret: '.$blacklabel['blacklabel_apikey'],
			'X-Client-Ip: '.$_SERVER['REMOTE_ADDR'].'',
			'X-User-Agent: '.$_SERVER['HTTP_USER_AGENT'].'',
			'X-Session-Id: '.$_SESSION['X-Session-Id'].'',
		),
	));
	$response = curl_exec($curl);
	
	//var_dump($response);
	curl_close($curl);
	if (!$err && $response) {
		$response = json_decode($response,true);
		
		if($response['errors'][0]['code'] == 401) { 
			echo "<strong>401 ERROR - Your API Key is most likely incorrect</strong>"; 
		} else { 
			return $response; 
		}
	}
}

/**
 *  aweBlacklabelCurlRequestPost - Same as aweBlacklabelCurlRequest but sends POST
 *  
 *  @param [in] Endpoint to use
 *  @param [in] $postData array of post data.
 *  @return array
 *  
 */
function aweBlacklabelCurlRequestPost($endpoint, $postData = array()) { 
	global $blacklabel;
	global $basepath; 
	if($blacklabel['blacklabel_language']) { 
		$language = $blacklabel['blacklabel_language']; 
	} else { 
		$language = 'en';
	}
	
	
	if(substr($_SESSION['X-Session-Id'],0,1) == 'm' || $forceMember) { 
		$language = "$language/member"; 
	}
	
	if($_SESSION['username']) { 
		$thisUser = $_SESSION['username']; 
	} else { 
		$thisUser = "Guest"; 
	}
	$logToFile = date('Y-m-d H:i:s').": ".$thisUser." - ".$_SESSION['X-Session-Id']." (GET REQUEST | ".$blacklabel['blacklabel_whitelabel_url'].'/'.$language.'/api/v1/'.$endpoint." | $queryString)\n";
	file_put_contents("$basepath/cache/awelog.txt",$logToFile, FILE_APPEND); 
	
	//echo $language;
	$curl = curl_init();
	if($endpoint == 'users') { 
		//send without X-Session-Id to circumvent issue with API returning guest status
		curl_setopt_array($curl, array(
			CURLOPT_URL => $blacklabel['blacklabel_whitelabel_url'].'/'.$language.'/api/v1/'.$endpoint,
			CURLOPT_POST => true,
			CURLOPT_POSTFIELDS => json_encode($postData),
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_ENCODING => '',
			CURLOPT_FOLLOWLOCATION => 0,
			CURLOPT_TIMEOUT => 3,
			CURLOPT_HEADER => 1, 
			CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
			CURLOPT_HTTPHEADER => array(
				'Accept: application/json',
				'X-Application-Secret: '.$blacklabel['blacklabel_apikey'],
				'X-Client-Ip: '.$_SERVER['REMOTE_ADDR'].'',
				'X-User-Agent: '.$_SERVER['HTTP_USER_AGENT'].''
			),
		));
	} else { 
		curl_setopt_array($curl, array(
			CURLOPT_URL => $blacklabel['blacklabel_whitelabel_url'].'/'.$language.'/api/v1/'.$endpoint,
			CURLOPT_POST => true,
			CURLOPT_POSTFIELDS => json_encode($postData),
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_ENCODING => '',
			CURLOPT_FOLLOWLOCATION => 0,
			CURLOPT_TIMEOUT => 3,
			CURLOPT_HEADER => 1, 
			CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
			CURLOPT_HTTPHEADER => array(
				'Accept: application/json',
				'X-Application-Secret: '.$blacklabel['blacklabel_apikey'],
				'X-Client-Ip: '.$_SERVER['REMOTE_ADDR'].'',
				'X-User-Agent: '.$_SERVER['HTTP_USER_AGENT'].'',
				'X-Session-Id: '.$_SESSION['X-Session-Id'].'',
			),
		));
	}
	$response = curl_exec($curl);
	$err = curl_error($curl);
	
	$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
	$header = substr($response, 0, $header_size);
	$body = substr($response, $header_size);

	$headers = get_headers_from_curl_response($header);
	if($headers['X-Session-Id']) { 
		$_SESSION['X-Session-Id'] = $headers['X-Session-Id'];
	}
	
	$response = $body; 
	
	
	curl_close($curl);
	if (!$err && $response) {
		$response = json_decode($response,true);
		if($response['errors'][0]['code'] == 401) { 
			echo "<strong>401 ERROR - Your API Key is most likely incorrect</strong>"; 
		} else { 
			return $response; 
		}
	}
}

function aweBlacklabelHeaderCallback($ch, $header_line)
{ 
    global $headers;
    $headers[] = $header_line;
    return strlen($header_line);
}

function get_headers_from_curl_response($response)
{
    $headers = array();
    $header_text = substr($response, 0, strpos($response, "\r\n\r\n"));
    foreach (explode("\r\n", $header_text) as $i => $line)
        if ($i === 0)
            $headers['http_code'] = $line;
        else
        {
            list ($key, $value) = explode(': ', $line);
            $headers[$key] = $value;
        }

    return $headers;
}


/**
 *  fetchLiveVideoList - Fetches live json feed from AWEmpire Videos API
 *  
 *  @param [in] $limit Max Number Of Results
 *  @param [in] $category Category as per AWEmpire Documentation
 *  @param [in] $tags Tags as per AWEmpire Documentation
 *  @param [in] $cobrandId CobrandId as per AWEmpire Documentation
 *  @param [in] $site Siteid as per AWEmpire Documentation
 *  @return Return description
 *  
 */
function fetchLiveVideoList($limit = 10, $category = 'girls', $tags = "", $cobrandId = "", $site = "") {
	global $AWEmpirePSID;
	global $AWEmpireAccessKey;
	global $AWEmpirePrimaryColor;
	global $AWEmpireLabelColor;
	//set defaults
	if(isset($_SERVER["HTTP_CF_CONNECTING_IP"])){
		$ipAddress = $_SERVER["HTTP_CF_CONNECTING_IP"];
	} else{
		$ipAddress = $_SERVER['REMOTE_ADDR'];
	}
	
	 $data = file_get_contents("https://pt.ptawe.com/api/video-promotion/v1/list?category=girl&clientIp=".$ipAddress."&limit=".$limit."&pageIndex=1&psid=".$AWEmpirePSID."&accessKey=".$AWEmpireAccessKey."&primaryColor=".$AWEmpirePrimaryColor."&labelColor=".$AWEmpireLabelColor."&cobrandId=".$cobrandId."&site=".$site."&tags=".$tags."&mitigable=true");
	$json = json_decode($data,true);
	
	if(!is_array($json)) { 
		echo "An error has occured while fetching the feed. ".$data;
		return false;
	} else { 
		$counter = 0;
		foreach($json['data']['videos'] as $i) { 
			$result[$counter]['id'] = $i['id'];
			$result[$counter]['title'] = $i['title']; 
			$result[$counter]['length'] = $i['duration']; 
			$result[$counter]['keywords'] = implode(",",$i['tags']);
			$result[$counter]['thumbnail'] = $i['thumbImage']; 
			$result[$counter]['submitter'] = $i['uploader']; 
			$result[$counter]['rating'] = rand(75,100); 
			$result[$counter]['views'] = rand(100,10000); 
			if($i['quality'] == 'sd') { //fake the movie height for hd tags on templates, which are typically based on if statement using $rrow[movie_height]
				$result[$counter]['movie_height'] = '480';
			} else { 
				$result[$counter]['movie_height'] = '720';
			}
			$counter++; 
		}
		return $result;
	}
}	

/**
 *  showAweVideos - Displays the data from fetchLiveVideoList in template
 *  
 *  @param [in] $template Template file being used
 *  @param [in] $limit Max number of results, passed to fetchLiveVideoList
 *  @param [in] $tags Tags, passed to fetchLiveVideoList
 *  @param [in] $category Category, passed to fetchLiveVideoList
 *  @param [in] $cobrandId Cobrandid, passed to fetchLiveVideoList
 *  @param [in] $site Siteid, passed to fetchLiveVideoList
 *  @return Return description
 *  
 */
function showAweVideos($template = 'template.content_item.php', $limit = 10, $tags = "", $category = 'girls', $cobrandId = "", $site = "") {
	global $basehttp;
    global $basepath;
    global $gallery_url;
    global $template_path;
    global $thumb_url;
    global $thumbwidth;
    global $thumbheight;
    global $picthumbwidth;
    global $picthumbheight;
    global $bad;
    global $good;
    global $results_per_row;
    global $template_url;
    global $currentLang;
    global $dblink;
    global $config;
	
	$farray = fetchLiveVideoList($limit, $category, $tags, $cobrandId, $site); //fetch data;
	
    if (is_array($farray)) {
        $i = 0;
        $j = 0;
        $maxRes = count($farray);
        foreach ($farray as $row) {
            if ($results_per_row > 0) {
                $i++;
                $rest = $i % $results_per_row;
                if ($rest == 0) {
                    $class = ' last';
                } else {
                    $class = '';
                }
            }

            if ($slider) {
                if ($j % $slider_per_page == 0) {
                    echo '<div class="window">';
                }
            }
            include($template_path . '/' . $template);
            if ($slider) {
                if (($j + 1) % $slider_per_page == 0 || $j == ($maxRes - 1)) {
                    echo '</div>';
                }
            }
            ++$j;
        }
    }	
}

/**
 *  getAweDetails - Gets details of a single AWEmpire Video
 *  
 *  @param [in] $id id number of video
 *  @return Return description
 *  
 */
function getAweDetails($id) { 
	global $AWEmpirePSID;
	global $AWEmpireAccessKey;
	global $AWEmpirePrimaryColor;
	global $AWEmpireLabelColor;
	if(isset($_SERVER["HTTP_CF_CONNECTING_IP"])){
		$ipAddress = $_SERVER["HTTP_CF_CONNECTING_IP"];
	} else{
		$ipAddress = $_SERVER['REMOTE_ADDR'];
	}
	$data = file_get_contents("https://pt.ptawe.com/api/video-promotion/v1/details/".$id."?clientIp=".$ipAddress."&psid=".$AWEmpirePSID."&accessKey=".$AWEmpireAccessKey.""); 
	$json = json_decode($data,true);

	$i = $json['data']; 
	$result['id'] = $i['id'];
	$result['title'] = $i['title']; 
	$result['length'] = $i['duration']; 
	$result['keywords'] = implode(",",$i['tags']);
	$result['thumbnail'] = $i['thumbImage']; 
	$result['submitter'] = $i['uploader']; 
	$result['rating'] = rand(75,100); 
	$result['views'] = rand(100,10000); 
	$result['embed'] = "<div data-awe-container-id=\"jasminPlayer\"></div><script src=\"".str_replace("{CONTAINER}","jasminPlayer",$i['playerEmbedUrl'])."\"></script>";
	if($i['quality'] == 'sd') { //fake the movie height for hd tags on templates, which are typically based on if statement using $rrow[movie_height]
		$result['movie_height'] = '480';
	} else { 
		$result['movie_height'] = '720';
	}

	return $result; 
}