Compare commits
3 Commits
b02d2ac1c1
...
50259400b4
| Author | SHA1 | Date | |
|---|---|---|---|
| 50259400b4 | |||
| 061c8afa2c | |||
| ab0dd508dc |
|
|
@ -10,28 +10,40 @@ $data["message"] = "";
|
||||||
$data["validated"] = $validated;
|
$data["validated"] = $validated;
|
||||||
$data["filename"] = "";
|
$data["filename"] = "";
|
||||||
|
|
||||||
if ( !$validated ) {
|
function sendResponse() {
|
||||||
$data["error"] = true;
|
global $data;
|
||||||
$data["message"] = "Clients must validate accounts";
|
header('Content-Type: application/json');
|
||||||
header('Content-Type: application/json');
|
echo json_encode($data);
|
||||||
echo json_encode($data);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset($_REQUEST['comic']) ) {
|
|
||||||
$comicfull = realpath(COMICSDIR . base64_decode($_REQUEST['comic']));
|
|
||||||
$data["filename"] = basename($comicfull);
|
|
||||||
if ( $comicfull === false ) exit();
|
|
||||||
if ( substr($comicfull, 0, strlen(COMICSDIR)) != COMICSDIR ) exit();
|
|
||||||
$comic = substr($comicfull, strlen(COMICSDIR));
|
|
||||||
$comicoutputurl = "comics" . str_replace("#", "", $comic) . "/";
|
|
||||||
$comicoutputfull = "../" . EXTRACTSDIR . str_replace("#", "", $comic) . "/";
|
|
||||||
} else {
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !$validated ) {
|
||||||
|
$data["error"] = true;
|
||||||
|
$data["message"] = "Clients must validate accounts";
|
||||||
|
sendResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !isset($_REQUEST['comic']) ) {
|
||||||
|
$data["error"] = true;
|
||||||
|
$data["message"] = "Malformed request";
|
||||||
|
sendResponse();
|
||||||
|
}
|
||||||
|
$comicreq = base64_decode($_REQUEST['comic']);
|
||||||
|
$comicfile = basename($comicreq);
|
||||||
|
$comicpath = dirname($comicreq);
|
||||||
|
$comicfull = realpath(COMICSDIR . $comicreq);
|
||||||
|
if ( $comicfull === false ) {
|
||||||
|
$data["error"] = true;
|
||||||
|
$data["message"] = "Requested comic not found";
|
||||||
|
sendResponse();
|
||||||
|
}
|
||||||
|
$data["filename"] = $comicfile;
|
||||||
|
$comic = safeFileName(substr($comicfull, strlen(COMICSDIR)));
|
||||||
|
$comicoutputurl = "comics" . $comicpath . "/" . safeFileName($comicfile) . "/";
|
||||||
|
$comicoutputfull = "../" . EXTRACTSDIR . $comicpath . "/" . safeFileName($comicfile) . "/";
|
||||||
|
|
||||||
$ext = strtolower(substr($comicfull, -3));
|
$ext = strtolower(substr($comicfull, -3));
|
||||||
$_SESSION['comfile'] = basename($comicfull);
|
$_SESSION['comfile'] = $comicfile;
|
||||||
session_write_close();
|
session_write_close();
|
||||||
|
|
||||||
// Get the current page for this comic or 0 (zero) if never opened
|
// Get the current page for this comic or 0 (zero) if never opened
|
||||||
|
|
@ -48,20 +60,21 @@ if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
|
||||||
$data["startindex"] = $currentpage;
|
$data["startindex"] = $currentpage;
|
||||||
|
|
||||||
$extracted = false;
|
$extracted = false;
|
||||||
|
$files = array();
|
||||||
if ( !is_dir($comicoutputfull) ) {
|
if ( !is_dir($comicoutputfull) ) {
|
||||||
mkdir($comicoutputfull, 0755, true);
|
mkdir($comicoutputfull, 0755, true);
|
||||||
} else {
|
} else {
|
||||||
touch($comicoutputfull);
|
touch($comicoutputfull);
|
||||||
$extracted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$files = array();
|
|
||||||
if ( $extracted ) {
|
|
||||||
$contents = glob($comicoutputfull . "*");
|
$contents = glob($comicoutputfull . "*");
|
||||||
foreach ( $contents as $i ) {
|
foreach ( $contents as $i ) {
|
||||||
$files[] = basename($i);
|
$files[] = basename($i);
|
||||||
}
|
}
|
||||||
} else {
|
if ( count($files) != 0 ) {
|
||||||
|
$extracted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !$extracted ) {
|
||||||
$magic = file_get_contents($comicfull, false, null, 0, 4);
|
$magic = file_get_contents($comicfull, false, null, 0, 4);
|
||||||
if ( substr($magic, 0, 2) === "PK" ) {
|
if ( substr($magic, 0, 2) === "PK" ) {
|
||||||
$comtype = "cbz";
|
$comtype = "cbz";
|
||||||
|
|
@ -81,7 +94,7 @@ if ( $extracted ) {
|
||||||
if ( (substr($imgname, 0, 8) == "__MACOSX") || (substr($imgname, 0, 2) == "._") ) continue;
|
if ( (substr($imgname, 0, 8) == "__MACOSX") || (substr($imgname, 0, 2) == "._") ) continue;
|
||||||
$myext = strtolower(pathinfo($imgname)['extension']);
|
$myext = strtolower(pathinfo($imgname)['extension']);
|
||||||
if ( ! in_array($myext, VALIDIMAGETYPES) ) continue;
|
if ( ! in_array($myext, VALIDIMAGETYPES) ) continue;
|
||||||
$imgname = str_replace("#", "", $imgname);
|
$imgname = safeFileName($imgname);
|
||||||
$imgcontents = $zip->getFromIndex($i);
|
$imgcontents = $zip->getFromIndex($i);
|
||||||
$written = file_put_contents($comicoutputfull . $imgname, $imgcontents);
|
$written = file_put_contents($comicoutputfull . $imgname, $imgcontents);
|
||||||
if ( $written ) $files[] = $imgname;
|
if ( $written ) $files[] = $imgname;
|
||||||
|
|
@ -96,7 +109,7 @@ if ( $extracted ) {
|
||||||
} else {
|
} else {
|
||||||
$entries = $rar->getEntries();
|
$entries = $rar->getEntries();
|
||||||
foreach ( $entries as $entry ) {
|
foreach ( $entries as $entry ) {
|
||||||
$outfile = str_replace("#", "", basename($entry->getName()));
|
$outfile = safeFileName(basename($entry->getName()));
|
||||||
if ( ! isset(pathinfo($outfile)['extension']) ) continue;
|
if ( ! isset(pathinfo($outfile)['extension']) ) continue;
|
||||||
if ( (substr($outfile, 0, 8) == "__MACOSX") || (substr($outfile, 0, 2) == "._") ) continue;
|
if ( (substr($outfile, 0, 8) == "__MACOSX") || (substr($outfile, 0, 2) == "._") ) continue;
|
||||||
$myext = strtolower(pathinfo($outfile)['extension']);
|
$myext = strtolower(pathinfo($outfile)['extension']);
|
||||||
|
|
@ -109,7 +122,8 @@ if ( $extracted ) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$data["error"] = true;
|
$data["error"] = true;
|
||||||
$data["message"] = "Error invalid comic file format";
|
$data["message"] = "Invalid comic file format";
|
||||||
|
sendResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,8 +142,6 @@ foreach ( $files as $file ) {
|
||||||
|
|
||||||
$data["images"] = $images;
|
$data["images"] = $images;
|
||||||
$data["captions"] = $captions;
|
$data["captions"] = $captions;
|
||||||
header('Content-Type: application/json');
|
sendResponse();
|
||||||
echo json_encode($data);
|
|
||||||
exit();
|
|
||||||
|
|
||||||
// vim: set ts=3 sw=3 et:
|
// vim: set ts=3 sw=3 et:
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ function getAdultComics() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function safeFileName($file = "") {
|
function safeFileName($file = "") {
|
||||||
$to_remove = array("<", ">", "#", "\"", "/", "\\", "*", "?", "|");
|
$to_remove = array("<", ">", "#", "\"", "/", "\\", "*", "?", "|", "'");
|
||||||
return str_replace($to_remove, '', $file);
|
return str_replace($to_remove, "", $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeThumb($item = "") {
|
function makeThumb($item = "") {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user