userinfo, 6) || is_member_of($vbulletin->userinfo,2)); function streamFile() { set_time_limit(4000); $chunks = explode("/",$_REQUEST["file"]); $file = array_pop($chunks); $fs = filesize($_REQUEST["file"]); $mime = mime_content_type($_REQUEST["file"]); if(!$mime || $mime=="text/plain") $mime = trim(exec('file -bi ' . escapeshellarg ($_REQUEST["file"]))); else if(!$mime || $mime=="text/plain") $mime = "application/octet-stream"; //echo($file . " == " . $fs); //echo("Content-Type: " . $mime); //header("Content-Disposition: attachment; filename=$file"); //header("Content-Type: application/octet-stream"); //header("Content-Type: text/plain"); header("Content-Type: " . $mime); header("Content-Length: ".$fs); header("Pragma: no-cache"); header("Expires: 0"); $fp=fopen($_REQUEST["file"],"rb"); //print fread($fp,$fs); //echo fread($fp, $fs); while(!feof($fp)) echo fread($fp, 8192); fclose($fp); exit(); } function watermark($uri) { $_GET["imgfile"] = $uri; $_GET["w"] = '100%'; $_GET["h"] = '100%'; include("gallery/img_resize.php"); } function resize($uri,$w,$h) { $_GET["imgfile"] = $uri; $_GET["w"] = $w; $_GET["h"] = $h; include("gallery/img_resize.php"); } function auth_user() { $realm = mt_rand( 1, 1000000000 ); header('WWW-Authenticate: Basic realm="Realm ID='.$realm.']"'); header('HTTP/1.0 401 Unauthorized'); //header("Location: /forum/vba_index.php?page=multimedia"); die(""); //die("window.location='/gallery'"); } function authenticate() { global $vbulletin; $pref = $vbulletin->config['Misc']['cookieprefix']; $u = $_SERVER['PHP_AUTH_USER']; $p = $_SERVER['PHP_AUTH_PW']; $hp = md5($p); $vbulletin->GPC['vb_login_username'] = $u; $vbulletin->GPC['vb_login_password'] = $p; $vbulletin->GPC['vb_login_md5password'] = $hp; // can the user login? $strikes = verify_strike_status($vbulletin->GPC['vb_login_username']); if ($vbulletin->GPC['vb_login_username'] == '') { return false; } if (!verify_authentication($vbulletin->GPC['vb_login_username'], $vbulletin->GPC['vb_login_password'], $vbulletin->GPC['vb_login_md5password'], $vbulletin->GPC['vb_login_md5password_utf'], $vbulletin->GPC['cookieuser'], true)) { ($hook = vBulletinHook::fetch_hook('login_failure')) ? eval($hook) : false; // check password exec_strike_user($vbulletin->userinfo['username']); $vbulletin->userinfo = array( 'userid' => 0, 'usergroupid' => 1 ); return false; } exec_unstrike_user($vbulletin->GPC['username']); // create new session process_new_login($vbulletin->GPC['logintype'], $vbulletin->GPC['cookieuser'], $vbulletin->GPC['cssprefs']); setcookie($pref . "userid",$vbulletin->userinfo['userid'],time()+60*60*24*30); return true; } $pref = $vbulletin->config['Misc']['cookieprefix']; $chunks = explode("/",$_REQUEST["file"]); $file = array_pop($chunks); $cat = array_pop($chunks); if(!is_numeric($cat)) $cat = array_pop($chunks); if($cat!=520 && $cat!=539) { if (!$is_logged_in && !isset($_SERVER['PHP_AUTH_USER'])) { auth_user(); } else if (!$is_logged_in && !authenticate()) { auth_user(); } else if (isset($_GET['action']) && $_GET['action'] == "logout") { auth_user(); } else if($vbulletin->userinfo['userid'] && !$_COOKIE[$pref.'userid']) { setcookie($pref."userid",$vbulletin->userinfo['userid'],time()+60*60*24*30); } } //chdir($basedir . "/gallery"); chdir($basedir); if(is_numeric($cat)) { $photoid = $db->query_first("SELECT id FROM pp_photos WHERE cat=" . $cat . " and bigimage='".$file."'"); if($photoid && $photoid["id"]) { $ugnoview = $db->query_first("SELECT ugnoview FROM pp_categories WHERE id=" . $cat); $can_view = $cat==539; //false; if($ugnoview && $ugnoview["ugnoview"]) { $grps = explode(",",$ugnoview["ugnoview"]); $myGroups = array($vbulletin->userinfo["usergroupid"]); if($vbulletin->userinfo["membergroupids"]) array_push($myGroups,explode($vbulletin->userinfo["membergroupids"])); foreach($myGroups as $group) { if(!array_search($group,$grps)) { $can_view = true; break; } } } if(!$can_view) { header("Location: /gallery/showphoto.php?photo=".$photoid["id"]); exit; } else if(preg_match("/resize\/(\d*)x(\d*)\/(.*)/",$_REQUEST['file'],$matches)) { resize("gallery/files/".$matches[3],$matches[1],$matches[2]); //header("Location: /gallery/img_resize.php?imgfile=files/".$matches[3]."&w=".$matches[1]."&h=".$matches[2]); exit; } else if(preg_match("/(data|files)\/([^\/]*\/.*\.(jpg|jpeg|gif|png))/i",$_REQUEST['file'],$matches)) { watermark("gallery/files/".$matches[2]); exit; } else if(!file_exists($_REQUEST['file'])) { header("Location: /gallery/showphoto.php?photo=".$photoid["id"]); exit; } else { streamFile(); //header("Location: /gallery/".$_REQUEST['file']); } } } if(preg_match("/resize\/(\d*)x(\d*)\/(.*)/",$_REQUEST['file'],$matches)) { //header("Location: /gallery/img_resize.php?imgfile=files/".$matches[3]."&w=".$matches[1]."&h=".$matches[2]); resize("gallery/files/".$matches[3],$matches[1],$matches[2]); } else if(preg_match("/(data|files)\/([^\/]*\/.*\.(jpg|jpeg|gif|png))/i",$_REQUEST['file'],$matches)) { watermark("gallery/files/".$matches[2]); exit; } else if(preg_match("/forum\/imagehosting\/(.*\.(jpg|jpeg|gif|png))/i",$_REQUEST['file'],$matches)) { watermark("forum/imagehosting/".$matches[1]); exit; } else if(file_exists($_REQUEST['file'])) { streamFile(); } else { header("Location: /forum/vba_index.php?page=multimedia"); } ?>