mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-16 21:18:00 +00:00
added new config: ALT_FOLDER for on/offsite backups and mounted folders. closes #54
This commit is contained in:
@@ -111,7 +111,10 @@ class Backblaze
|
|||||||
curl_close ($session); // Clean up
|
curl_close ($session); // Clean up
|
||||||
$data = json_decode($server_output,true); // Tell me about the rabbits, George!
|
$data = json_decode($server_output,true); // Tell me about the rabbits, George!
|
||||||
$this->ulURL = $data['uploadUrl'];
|
$this->ulURL = $data['uploadUrl'];
|
||||||
|
//var_dump("upload url at load: ".$data['uploadUrl']);
|
||||||
$this->ulToken = $data['authorizationToken'];
|
$this->ulToken = $data['authorizationToken'];
|
||||||
|
|
||||||
|
//var_dump($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function download($hash)
|
function download($hash)
|
||||||
|
|||||||
@@ -87,3 +87,11 @@ define('SHOW_ERRORS', false);
|
|||||||
//define('BACKBLAZE_AUTODOWNLOAD', true); //if true, will download images from backblaze if not found local
|
//define('BACKBLAZE_AUTODOWNLOAD', true); //if true, will download images from backblaze if not found local
|
||||||
//define('BACKBLAZE_AUTOUPLOAD', true); //if true, will upload images to backblaze when they are uploaded to pictshare
|
//define('BACKBLAZE_AUTOUPLOAD', true); //if true, will upload images to backblaze when they are uploaded to pictshare
|
||||||
//define('BACKBLAZE_AUTODELETE', true); //if true, will delete images from backblaze if they are deleted from pictshare
|
//define('BACKBLAZE_AUTODELETE', true); //if true, will delete images from backblaze if they are deleted from pictshare
|
||||||
|
|
||||||
|
//If you have a NAS or some cifs or nfs mounted drive, you can specify this here as a folder
|
||||||
|
//if a requested hash is not found locally, its looked up on this location. This allows for mounted external spaces
|
||||||
|
//or just backups on a second drive.
|
||||||
|
//Also new hashes will be uploaded there (just the originals, not resizes)
|
||||||
|
//value should be a path **without tailing slash**!
|
||||||
|
|
||||||
|
define('ALT_FOLDER','/mnt');
|
||||||
@@ -94,6 +94,16 @@ class PictshareModel extends Model
|
|||||||
}
|
}
|
||||||
$data['hash']=$el;
|
$data['hash']=$el;
|
||||||
}
|
}
|
||||||
|
else if(defined('ALT_FOLDER') && ALT_FOLDER && $this->couldThisBeAnImage($el)) //check alternative folder for the hash
|
||||||
|
{
|
||||||
|
$altname=ALT_FOLDER.DS.$el;
|
||||||
|
//var_dump($altname);
|
||||||
|
if(file_exists($altname))
|
||||||
|
{
|
||||||
|
$this->uploadImageFromURL($altname,$el);
|
||||||
|
$data['hash'] = $el;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(BACKBLAZE === true && $this->couldThisBeAnImage($el) && BACKBLAZE_AUTODOWNLOAD ===true) //looks like it might be a hash but didn't find it here. Let's see
|
else if(BACKBLAZE === true && $this->couldThisBeAnImage($el) && BACKBLAZE_AUTODOWNLOAD ===true) //looks like it might be a hash but didn't find it here. Let's see
|
||||||
{
|
{
|
||||||
$b = new Backblaze();
|
$b = new Backblaze();
|
||||||
@@ -211,6 +221,16 @@ class PictshareModel extends Model
|
|||||||
|
|
||||||
rmdir($base_path);
|
rmdir($base_path);
|
||||||
|
|
||||||
|
//delete from alt folder if configured
|
||||||
|
if(defined('ALT_FOLDER') && ALT_FOLDER)
|
||||||
|
{
|
||||||
|
$altname=ALT_FOLDER.DS.$hash;
|
||||||
|
if(file_exists($altname))
|
||||||
|
{
|
||||||
|
unlink($altname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//delete from backblaze if configured
|
//delete from backblaze if configured
|
||||||
if(BACKBLAZE===true && BACKBLAZE_AUTODELETE===true)
|
if(BACKBLAZE===true && BACKBLAZE_AUTODELETE===true)
|
||||||
{
|
{
|
||||||
@@ -444,7 +464,7 @@ class PictshareModel extends Model
|
|||||||
return $this->isTypeAllowed($this->getTypeOfFile($url));
|
return $this->isTypeAllowed($this->getTypeOfFile($url));
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadImageFromURL($url)
|
function uploadImageFromURL($url,$forcehash=false)
|
||||||
{
|
{
|
||||||
$type = $this->getTypeOfFile($url);
|
$type = $this->getTypeOfFile($url);
|
||||||
$type = $this->isTypeAllowed($type);
|
$type = $this->isTypeAllowed($type);
|
||||||
@@ -466,12 +486,12 @@ class PictshareModel extends Model
|
|||||||
$dup_id = $this->isDuplicate($url);
|
$dup_id = $this->isDuplicate($url);
|
||||||
if($dup_id)
|
if($dup_id)
|
||||||
{
|
{
|
||||||
$hash = $dup_id;
|
$hash = $forcehash?$forcehash:$dup_id;
|
||||||
$url = ROOT.DS.'upload'.DS.$hash.DS.$hash;
|
$url = ROOT.DS.'upload'.DS.$hash.DS.$hash;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$hash = $this->getNewHash($type);
|
$hash = $forcehash?$forcehash:$this->getNewHash($type);
|
||||||
$this->saveSHAOfFile($url,$hash);
|
$this->saveSHAOfFile($url,$hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,6 +517,15 @@ class PictshareModel extends Model
|
|||||||
fclose($fh);
|
fclose($fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(defined('ALT_FOLDER') && ALT_FOLDER)
|
||||||
|
{
|
||||||
|
$altname=ALT_FOLDER.DS.$hash;
|
||||||
|
if(!file_exists($altname))
|
||||||
|
{
|
||||||
|
copy($file,$altname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(BACKBLAZE===true && BACKBLAZE_AUTOUPLOAD===true)
|
if(BACKBLAZE===true && BACKBLAZE_AUTOUPLOAD===true)
|
||||||
{
|
{
|
||||||
$b = new Backblaze();
|
$b = new Backblaze();
|
||||||
@@ -512,6 +541,8 @@ class PictshareModel extends Model
|
|||||||
{
|
{
|
||||||
$code = getRandomString(32);
|
$code = getRandomString(32);
|
||||||
$file = ROOT.DS.'upload'.DS.'deletecodes'.DS.$code;
|
$file = ROOT.DS.'upload'.DS.'deletecodes'.DS.$code;
|
||||||
|
if(!is_dir(ROOT.DS.'upload'.DS.'deletecodes'))
|
||||||
|
mkdir(ROOT.DS.'upload'.DS.'deletecodes');
|
||||||
if(file_exists($file)) continue;
|
if(file_exists($file)) continue;
|
||||||
file_put_contents($file,$hash);
|
file_put_contents($file,$hash);
|
||||||
return $code;
|
return $code;
|
||||||
|
|||||||
65
tools/altfolder_copy.php
Normal file
65
tools/altfolder_copy.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Alternative folder upload
|
||||||
|
* This tool copies all raw images/videos/gifs to the defined ALT_FOLDER location
|
||||||
|
* This will create a copy in the location. The location can be a mounted external server like CIFS or sshfs
|
||||||
|
* This will allow you to store a backup of your images on some other server
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(php_sapi_name() !== 'cli') exit('This script can only be called via CLI');
|
||||||
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
||||||
|
define('DS', DIRECTORY_SEPARATOR);
|
||||||
|
define('ROOT', dirname(__FILE__).DS.'..');
|
||||||
|
include_once(ROOT.DS.'inc/config.inc.php');
|
||||||
|
include_once(ROOT.DS.'inc/core.php');
|
||||||
|
|
||||||
|
if(!defined('ALT_FOLDER') || !ALT_FOLDER)
|
||||||
|
die("[X] Error: You should define the ALT_FOLDER config in your inc/config.inc.php first");
|
||||||
|
|
||||||
|
$pm = new PictshareModel();
|
||||||
|
|
||||||
|
if(in_array('sim',$argv))
|
||||||
|
{
|
||||||
|
echo "[!!!!] SIMULATION MODE. Nothing will be uploaded [!!!!] \n\n";
|
||||||
|
$sim = true;
|
||||||
|
}
|
||||||
|
else $sim = false;
|
||||||
|
|
||||||
|
|
||||||
|
//gather local data
|
||||||
|
echo "[i] Looping through local files\n";
|
||||||
|
|
||||||
|
$dir = ROOT.DS.'upload'.DS;
|
||||||
|
$dh = opendir($dir);
|
||||||
|
$localfiles = array();
|
||||||
|
while (false !== ($hash = readdir($dh))) {
|
||||||
|
$img = $dir.$hash.DS.$hash;
|
||||||
|
if(!file_exists($img)) continue;
|
||||||
|
$type = pathinfo($img, PATHINFO_EXTENSION);
|
||||||
|
$type = $pm->isTypeAllowed($type);
|
||||||
|
if($type)
|
||||||
|
{
|
||||||
|
++$allhashes;
|
||||||
|
//$localfiles[] = $hash;
|
||||||
|
if(file_exists(ALT_FOLDER.DS.$hash))
|
||||||
|
{
|
||||||
|
echo " [!] Skipping $hash because it already exists in ".ALT_FOLDER."\n";
|
||||||
|
++$skips;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++$copied;
|
||||||
|
echo "[i] Copying $hash\t to ".ALT_FOLDER.DS.$hash." \r";
|
||||||
|
if($sim===false)
|
||||||
|
copy($img,ALT_FOLDER.DS.$hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\n[i] Done\n";
|
||||||
|
echo "\n----------- STATS ----------\n\n";
|
||||||
|
echo " All files found:\t$allhashes\n";
|
||||||
|
echo " Copied files:\t$copied\n";
|
||||||
|
echo " Skipped files:\t$skips\n";
|
||||||
4
upload/deletecodes/.gitignore
vendored
4
upload/deletecodes/.gitignore
vendored
@@ -1,4 +0,0 @@
|
|||||||
# Ignore everything in this directory
|
|
||||||
*
|
|
||||||
# Except this file
|
|
||||||
!.gitignore
|
|
||||||
Reference in New Issue
Block a user