commit 20c0dbbcce59f2496bb3bcd75fb1e2cf456a40d1 Author: Knah Tsaeb Date: Fri Jul 12 17:25:57 2013 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1624d7b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +data +tmp +videos +.project \ No newline at end of file diff --git a/bin/.htaccess b/bin/.htaccess new file mode 100644 index 0000000..2c73686 --- /dev/null +++ b/bin/.htaccess @@ -0,0 +1 @@ +Deny from All \ No newline at end of file diff --git a/bin/cronTask.sh b/bin/cronTask.sh new file mode 100644 index 0000000..d776b22 --- /dev/null +++ b/bin/cronTask.sh @@ -0,0 +1,31 @@ +#!/bin/bash/ +finalDest=/srv/http/mytube.local/videos/ +tempDest=/srv/http/mytube.local/tmp/ +threads=3 # nb cpu core - 1 +cd $tempDest + +nbProcessLauch=$(ps -e | grep -v grep | grep youtube-dl | wc -l) + +if [ $nbProcessLauch != 0 ] +then + echo 'bye' + exit +fi + +for file in $tempDest*.hash +do + if [[ -f $file ]]; + then + while read urlHash url destination + do + youtube-dl -R 0 -q -c --write-thumbnail --write-info-json --recode-video webm --no-check-certificate -f 46/37/45/22/44/35/34/5 -o "$urlHash.%(ext)s" "$url" + sleep 5 + if [ ! -f $urlHash.*.part ] + then + rm $file + sleep 1 + mv $urlHash* $finalDest$destination + fi + done < $file + fi +done diff --git a/inc/.htaccess b/inc/.htaccess new file mode 100644 index 0000000..2c73686 --- /dev/null +++ b/inc/.htaccess @@ -0,0 +1 @@ +Deny from All \ No newline at end of file diff --git a/inc/addVideo.php b/inc/addVideo.php new file mode 100644 index 0000000..a2d2c10 --- /dev/null +++ b/inc/addVideo.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/inc/content.php b/inc/content.php new file mode 100644 index 0000000..6d9445c --- /dev/null +++ b/inc/content.php @@ -0,0 +1,176 @@ + +
+ Login + + + + + + + + + +
+'; +} + +if (!empty($ci['ac']) && $ci['ac'] === 'newDir') { + if (!empty($ci['op']) && (int)$ci['op'] === 1) { + verifToken($ci['token']); + $addDir = addDir($ci['newDir'], $ci['bc'], $fullListDir); + } else { + echo '
+
+ + New directory + + + + + + + + +
+
'; + } +} +if (!empty($ci['ac']) && $ci['ac'] === 'addVideo') { + if (!empty($ci['op']) && (int)$ci['op'] === 1) { + verifToken($ci['token']); + $addVideo = addVideo($ci, $fullListFile); + } else { + echo '
+
+ + New video + + + + + + + + + + + + + + + + +
+
'; + } +} +if (!empty($ci['ac']) && $ci['ac'] === 'view') { + if (!empty($ci['op']) && (int)$ci['op'] === 1) { + verifToken($ci['token']); + } else { + $videoInfo = getVideoInfo($ci['file'], $ci['bc'], $fullListFile); + } +} +if (empty($ci['bc'])) { + $path = 'videos/'; +} else { + $splitBc = chunk_split($ci['bc'], 8, '/'); + $path = 'videos/'.$splitBc; + $breadcrumb = makeBreadcrumb($ci['bc'], $fullListDir); + $nbBread = count($breadcrumb); +} + +$listCurrentDir = listCurrentDir($path); +$listCurrentFile = listVideo($path); +echo ''; +echo '
'; +if (!empty($listCurrentDir)) { + foreach ($listCurrentDir as $value) { + if (file_exists($value.'.folder')) { + echo '', $path.$value, '', $fullListDir[$value], ' '; + } else { + echo '', $fullListDir[$value], ' '; + } + } +} +if (!empty($listCurrentFile) && $ci['ac'] !== 'view') { + foreach ($listCurrentFile as $value) { + echo '', $path.$value, '', $fullListFile[str_replace('.jpg', '', $value)]['title'], ''; + } +} + +if ($ci['ac'] === 'view' && !empty($listCurrentFile)) { + if (!empty($videoInfo)) { + echo '
'; + echo '

', $videoInfo['title'], ' (', $videoInfo['originalTitle'], ')

'; + echo ''; + } + + echo ' + + + + + + + + + + + + + + + + + + + + + + + +
Title', $videoInfo['title'], ' (', $videoInfo['originalTitle'], ')
Description', $videoInfo['desc'], '
Original description', $videoInfo['originalDesc'], '
Url', $videoInfo['url'], '
Date', $videoInfo['uploadDate'], '
Via', $videoInfo['via'], '
Licence', $videoInfo['licence'], '
+
'; +} +echo '
'; +?> diff --git a/inc/install.php b/inc/install.php new file mode 100644 index 0000000..8b93427 --- /dev/null +++ b/inc/install.php @@ -0,0 +1,14 @@ +
+
+ Install + + + + + + + + + +
+
\ No newline at end of file diff --git a/inc/topMenu.php b/inc/topMenu.php new file mode 100644 index 0000000..c4b63f8 --- /dev/null +++ b/inc/topMenu.php @@ -0,0 +1,12 @@ +

Home

+ \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..8d5f05b --- /dev/null +++ b/index.php @@ -0,0 +1,291 @@ + +'; + file_put_contents($GLOBALS['config']['CONFIG_FILE'], $data); + $page = 'content'; + } + return $page; +} + +function checkSecure() { +} + +function logout() { +} + +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 ' +
'; + echo ' + + ', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], ' + '; + echo '
',         htmlentities(print_r($data, 1)), '
'; + echo ' +
+
'; +} + +function addDir($dir, $breadcrumb, $fullListDir) { + if (empty($dir)) { + return 'error'; + } + $dirHash = substr(sha1($dir), 0, 8); + $fullListDir[$dirHash] = $dir; + $path = chunk_split($breadcrumb, 8, '/'); + file_put_contents($GLOBALS['config']['LISTDIR'], ""); + if (mkdir('videos/'.$path.'/'.$dirHash)) { + return 'success'; + } else { + return 'error'; + } +} + +function addVideo($ci, $fullListFile) { + $nameHash = substr(sha1($ci['name']), 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 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 renameDir() { +} + +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])); + + $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(round(($jsonInfo -> duration / 60), 2)), + 'via' => $postInfo['via'], + 'licence' => $postInfo['licence'] + ); + return $info; +} + +function editVideoDescription() { +} + +function testCache() { +} + +function makeCache() { + +} + +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; + } +} + +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']); + } +} +?> + + + + + Please find a fucking apps name + + + + Exec time : '.round((microtime(TRUE) - $startTime), 5).'

'; + ?> + + \ No newline at end of file diff --git a/lib/cronTask.sh b/lib/cronTask.sh new file mode 100644 index 0000000..d776b22 --- /dev/null +++ b/lib/cronTask.sh @@ -0,0 +1,31 @@ +#!/bin/bash/ +finalDest=/srv/http/mytube.local/videos/ +tempDest=/srv/http/mytube.local/tmp/ +threads=3 # nb cpu core - 1 +cd $tempDest + +nbProcessLauch=$(ps -e | grep -v grep | grep youtube-dl | wc -l) + +if [ $nbProcessLauch != 0 ] +then + echo 'bye' + exit +fi + +for file in $tempDest*.hash +do + if [[ -f $file ]]; + then + while read urlHash url destination + do + youtube-dl -R 0 -q -c --write-thumbnail --write-info-json --recode-video webm --no-check-certificate -f 46/37/45/22/44/35/34/5 -o "$urlHash.%(ext)s" "$url" + sleep 5 + if [ ! -f $urlHash.*.part ] + then + rm $file + sleep 1 + mv $urlHash* $finalDest$destination + fi + done < $file + fi +done diff --git a/lib/flowplayer-3.2.1.swf b/lib/flowplayer-3.2.1.swf new file mode 100644 index 0000000..db34bd1 Binary files /dev/null and b/lib/flowplayer-3.2.1.swf differ diff --git a/style.css b/style.css new file mode 100644 index 0000000..81d0ee4 --- /dev/null +++ b/style.css @@ -0,0 +1,43 @@ +*{ + color:#dfdfdf; +} + +body { + background-color: #1E1915; +} + +#listFile a { + width: 170px; + height: 170px; + display: block; + border: 2px solid #dfdfdf; + float:left; + margin:0.3em; + padding:0.3em; + text-decoration: none; + text-align:center; + overflow: hidden; + text-overflow: "..."; +} + +#listFile img { + width : 100%; +vertical-align: middle; +} + +#time { + clear :both; +} + +#viewFile { + text-align:center; +} + +#viewFile table { + width : 60%; + margin : 0 auto; +} + +input[type="submit"] { + color : #1E1915; +} \ No newline at end of file