diff options
author | Mario Vavti <mario@mariovavti.com> | 2017-08-19 14:31:47 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2017-08-19 14:31:47 +0200 |
commit | 4cafa6280d6e1a8e550246a27e807c4768e06f9a (patch) | |
tree | 3eb0b741acbb37543307d672fa5e2052573a5128 /util | |
parent | b18f3f4f7adb8f4d49dac1bb4b8b6c21255cbecb (diff) | |
parent | b4880343524aab6b4583c6815d94a5dfe61dd042 (diff) | |
download | volse-hubzilla-4cafa6280d6e1a8e550246a27e807c4768e06f9a.tar.gz volse-hubzilla-4cafa6280d6e1a8e550246a27e807c4768e06f9a.tar.bz2 volse-hubzilla-4cafa6280d6e1a8e550246a27e807c4768e06f9a.zip |
Merge remote-tracking branch 'mike/master' into dev
Diffstat (limited to 'util')
-rwxr-xr-x | util/dcp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/util/dcp b/util/dcp new file mode 100755 index 000000000..86c25259f --- /dev/null +++ b/util/dcp @@ -0,0 +1,73 @@ +#!/usr/bin/env php +<?php + +// file import to DAV utility + +if(!file_exists('include/cli_startup.php')) { + echo 'Run dcp from the top level Hubzilla web directory, as util/dcp <args>' . PHP_EOL; + exit(1); +} + +require_once('include/cli_startup.php'); +require_once('include/attach.php'); + +cli_startup(); + +$srcfile = $argv[1]; +$dstfile = $argv[2]; + +if($argc != 3) { + echo "Usage: " . $argv[0] . ' source destination' . "\n"; + echo 'Always run from the toplevel web directory.' . "\n"; + echo 'destination should begin with store/$nickname/desired/path/filename or $nickname/desired/path/filename' . "\n"; + echo 'destination must end with the destination filename (not a directory name).' . "\n"; + echo 'Example: util/dcp /etc/motd store/joe/etc/motd' . "\n"; + exit; +} + + + + if(strpos($dstfile,'store/') === 0) + $dstfile = substr($dstfile,6); + + $nick = substr($dstfile,0,strpos($dstfile,'/')); + + $dstfile = substr($dstfile,strlen($nick)+1); + + $channel = channelx_by_nick($nick); + if(! $channel) + return; + + + $arr = [ + 'pathname' => dirname($dstfile), + 'allow_cid' => $channel['channel_allow_cid'], + 'allow_gid' => $channel['channel_allow_gid'], + 'deny_cid' => $channel['channel_deny_cid'], + 'deny_gid' => $channel['channel_deny_gid'], + ]; + + $folder = ''; + if(dirname($dstfile)) { + $x = attach_mkdirp($channel,$channel['channel_hash'],$arr); + if($x['success']) + $folder = $x['data']['hash']; + } + + $arr = [ + 'src' => $srcfile, + 'filename' => basename($srcfile), + 'hash' => random_string(), + 'allow_cid' => $channel['channel_allow_cid'], + 'allow_gid' => $channel['channel_allow_gid'], + 'deny_cid' => $channel['channel_deny_cid'], + 'deny_gid' => $channel['channel_deny_gid'], + 'preserve_original' => true, + ]; + + if($folder) + $arr['folder'] = $folder; + + attach_store($channel,$channel['channel_hash'],'import',$arr); + + |