';
file_put_contents($GLOBALS['config']['CONFIG_FILE'], $data);
$page = 'content';
}
return $page;
}
function checkSecure() {
}
function logout() {
}
function getCurrentDir($bc) {
$currentDir = end(str_split($bc, 8));
return $currentDir;
}
function genToken() {
$token = sha1(uniqid(rand(), true).'_'.mt_rand());
$_SESSION['token'] = $token;
$_SESSION['tokenTime'] = time();
return $token;
}
function verifToken($token) {
if ($token !== $_SESSION['token'] || $_SESSION['tokenTime'] <= time() - 24000) {
ban();
die('So Long, and Thanks for All the Fish.');
}
}
function checkIfBan() {
require 'cache/logs/banUser.php';
$userIp = $_SERVER['REMOTE_ADDR'];
if (isset($banList[$userIp]) && $banList[$userIp]['nbBan'] >= $GLOBALS['config']['maxErrorBeforeBan'] && $banList[$userIp]['lastBan'] + $GLOBALS['config']['banTime'] > time()) {
return true;
} elseif (isset($banList[$userIp]) && $banList[$userIp]['lastBan'] + $GLOBALS['config']['banTime'] < time()) {
unban();
return false;
} else {
return false;
}
}
function ban() {
require $GLOBALS['config']['IPBANS_FILENAME'];
$userIp = $_SERVER['REMOTE_ADDR'];
if (isset($banList[$userIp])) {
$banList[$userIp]['lastBan'] = time();
$banList[$userIp]['nbBan']++;
} else {
$banList[$userIp]['lastBan'] = time();
$banList[$userIp]['nbBan'] = 1;
}
file_put_contents($GLOBALS['config']['IPBANS_FILENAME'], "");
}
function unBan() {
require $GLOBALS['config']['IPBANS_FILENAME'];
$userIp = $_SERVER['REMOTE_ADDR'];
unset($banList[$userIp]);
file_put_contents($GLOBALS['config']['IPBANS_FILENAME'], "");
}
function n_print($data, $name = '') {
$aBackTrace = debug_backtrace();
echo '
', $name, '
';
echo '
';
}
function addDir($dir, $breadcrumb, $fullListDir) {
if (empty($dir)) {
return 'error';
}
$dirHash = substr(sha1($dir.microtime(true)), 0, 8);
$fullListDir[$dirHash] = $dir;
$path = chunk_split($breadcrumb, 8, '/');
file_put_contents($GLOBALS['config']['LISTDIR'], "");
if (mkdir('videos/'.$path.'/'.$dirHash)) {
return array(
'result' => 'success',
'fullListDir' => $fullListDir
);
} else {
return 'error';
}
}
function renDir($dir, $breadcrumb, $fullListDir) {
if (empty($dir)) {
return;
}
$currentDir = getCurrentDir($breadcrumb);
$dirHash = substr(sha1($dir.microtime(true)), 0, 8);
$fullListDir[$dirHash] = $dir;
$path = chunk_split($breadcrumb, 8, '/');
if (rename('videos/'.$path, 'videos/'.substr($path, 0, -9).'/'.$dirHash)) {
unset($fullListDir[$currentDir]);
file_put_contents($GLOBALS['config']['LISTDIR'], "");
$breadcrumb = substr($path, 0, -9).$dirHash;
return array(
'result' => 'success',
'bc' => str_replace('/', '', $breadcrumb),
'fullListDir' => $fullListDir
);
} else {
return 'error';
}
}
function addVideo($ci, $fullListFile) {
$nameHash = substr(sha1($ci['name'].$ci['url']), 0, 10);
$url = escapeshellcmd($ci['url']);
$path = chunk_split($ci['bc'], 8, '/');
$data = $nameHash.' '.$url.' '.$path."\n";
file_put_contents($GLOBALS['config']['TMPDIR'].'/'.$nameHash.'.hash', $data);
$fullListFile[$nameHash] = array(
'title' => $ci['name'],
'url' => $ci['url'],
'desc' => $ci['desc'],
'via' => $ci['via'],
'licence' => $ci['licence']
);
file_put_contents($GLOBALS['config']['LISTFILE'], "");
}
function deleteVideo($bc, $file) {
$path = $GLOBALS['config']['VIDEODIR'].'/'.chunk_split($bc, 8, '/');
$pathAndFile = $path.$file;
if (file_exists($pathAndFile) && !is_dir($pathAndFile) && $file === $_SESSION['video'].'.jpg') {
$listFile = (glob($path.$_SESSION['video']."*"));
foreach ($listFile as $value) {
unlink($value);
}
} else {
return 'Error, cannot delete this file.';
}
}
function updateFileTitle($hash, $title) {
global $fullListFile;
$fullListFile[$hash]['title'] = $title;
chdir($_SERVER['DOCUMENT_ROOT']);
file_put_contents($GLOBALS['config']['LISTFILE'], "");
}
function listCurrentDir($breadcrumb) {
chdir($breadcrumb);
return glob("*", GLOB_ONLYDIR);
}
function makeBreadcrumb($bc, $fullListDir) {
$bcToArray = str_split($bc, 8);
$nbBc = count($bcToArray);
for ($i = 0; $i < $nbBc; $i++) {
$hrefBc .= $bcToArray[$i];
$breadcrumb[$hrefBc] = $fullListDir[$bcToArray[$i]];
}
return $breadcrumb;
}
function listVideo($breadcrumb) {
return glob("*.jpg");
}
function parseVideoDescription($file, $fullInfo = false) {
$value = json_decode(file_get_contents($file));
}
function getVideoInfo($file, $dir, $fullListFile) {
$file = substr($file, 0, 10);
$postInfo = $fullListFile[$file];
$path = chunk_split($dir, 8, '/');
$descFile = glob("videos/".$path.$file."*.json");
$jsonInfo = json_decode(file_get_contents($descFile[0]));
$time = gmdate('H\hi\ms\s', $jsonInfo -> duration);
$info = array(
'hash' => $file,
'title' => $postInfo['title'],
'originalTitle' => htmlentities($jsonInfo -> stitle),
'url' => $postInfo['url'],
'desc' => $postInfo['desc'],
'originalDesc' => htmlentities($jsonInfo -> description),
'uploadDate' => htmlentities($jsonInfo -> upload_date),
'format' => htmlentities($jsonInfo -> format),
'ext' => htmlentities($jsonInfo -> ext),
'duration' => htmlentities($time),
'via' => $postInfo['via'],
'licence' => $postInfo['licence']
);
return $info;
}
function editVideoDescription() {
}
function testCache() {
}
function makeCache() {
}
function getThumbnail($path, $value) {
if (file_exists(getcwd().'/'.$value.'/thumb.jpg')) {
return $path.$value.'/thumb.jpg';
} else {
return;
}
}
function login($ci) {
if (hash('sha256', $ci['loginName'].$GLOBALS['loginName']['salt']) === $GLOBALS['loginName']['loginName'] && $GLOBALS['loginName']['password'] === hash('sha256', $ci['loginPass'].$GLOBALS['loginName']['salt'])) {
$_SESSION['log'] = true;
return true;
} else {
return false;
}
}
function defineThumb($bc, $file) {
$path = chunk_split($bc, 8, '/');
if (file_exists($GLOBALS['config']['VIDEODIR'].'/'.$path.$file)) {
copy($GLOBALS['config']['VIDEODIR'].'/'.$path.$file, $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb.jpg');
}
}
function addThumbnail($bc) {
if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
echo 'Error on upload file.';
}
if ($_FILES['file']['error'] > 0) {
$msgError = array(
'1' => 'Le fichier excède le poids autorisé par la directive upload_max_filesize de php.ini',
'2' => 'Le fichier excède le poids autorisé par le champ MAX_FILE_SIZE s\'il a été donné',
'3' => 'Thumbnail are partially upload',
'4' => 'Thumbnail are not upload'
);
echo $msgError[$_FILES["file"]["error"]];
}
$tmpName = $_FILES["file"]["tmp_name"];
if ((int) extension_loaded('fileinfo') === 1) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $tmpName);
finfo_close($finfo);
} else {
echo 'Please active fileinfo extension';
}
$permitImage = array(
'image/gif',
'image/jpg',
'image/jpeg',
'image/pjpeg',
'image/png'
);
if (!in_array($type, $permitImage)) {
echo 'This type '.$type.' file is not permit. Convert it and retry.';
}
$path = chunk_split($bc, 8, '/');
if (!move_uploaded_file($_FILES['file']['tmp_name'], $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb'.'.tmp')) {
echo 'Error on move file to final destination.';
} else {
convertToJpeg($path, $type);
}
}
function convertToJpeg($path, $type) {
$pathAndNameFile = $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb'.'.tmp';
if ($type == 'image/jpeg') {
$image = imagecreatefromjpeg($pathAndNameFile);
}
if ($type == 'image/png') {
$image = imagecreatefrompng($pathAndNameFile);
}
if ($type == 'image/gif') {
$image = imagecreatefromgif($pathAndNameFile);
}
imagejpeg($image, $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb'.'.jpg', 100);
imagedestroy($image);
unlink($pathAndNameFile);
}
if (!empty($ci['ac']) && $ci['ac'] === 'login' && !empty($ci['op']) && (int)$ci['op'] === 2) {
verifToken($ci['token']);
if (login($ci) === true) {
unset($ci['op'], $ci['ac']);
}
}
if (isset($ci['ac']) && !empty($ci['ac'])) {
if ($ci['ac'] === 'renDir' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$renDir = renDir($ci['renDir'], $ci['bc'], $fullListDir);
$ci['bc'] = $renDir['bc'];
$fullListDir = $renDir['fullListDir'];
}
if ($ci['ac'] === 'newDir' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addDir = addDir($ci['newDir'], $ci['bc'], $fullListDir);
$fullListDir = $addDir['fullListDir'];
}
if ($ci['ac'] === 'addVideo' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addVideo = addVideo($ci, $fullListFile);
}
if ($ci['ac'] === 'addThumbnail' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addThumbnail = addThumbnail($ci['bc']);
}
if ($ci['ac'] === 'view' && !empty($ci['op']) && (int)$ci['op'] === 4) {
verifToken($ci['token']);
if ($_SESSION['log'] !== true) {
die('Tinker say : You can keep your magic, I have laser beams! ');
}
$deleteVideo = deleteVideo($ci['bc'], $ci['file']);
}
if ($ci['ac'] === 'view' && !empty($ci['op']) && (int)$ci['op'] === 3) {
verifToken($ci['token']);
if ($_SESSION['log'] !== true) {
die('Tinker say : Pew Pew Pew Pew Pew Pew Pew Pew Pew Pew Pew Pew');
}
$defineThumb = defineThumb($ci['bc'], $ci['file']);
}
}
?>
SoViGall - Personal Video Gallery
Exec time : '.round((microtime(TRUE) - $startTime), 5).'';
?>