Example #1
0
 function post()
 {
     // logger('file upload: ' . print_r($_REQUEST,true));
     $channel = $_REQUEST['channick'] ? get_channel_by_nick($_REQUEST['channick']) : null;
     if (!$channel) {
         logger('channel not found');
         killme();
     }
     $_REQUEST['source'] = 'file_upload';
     if ($channel['channel_id'] != local_channel()) {
         $_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']);
         $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']);
         $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']);
         $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']);
     }
     if ($_REQUEST['filename']) {
         $_REQUEST['allow_cid'] = perms2str($_REQUEST['contact_allow']);
         $_REQUEST['allow_gid'] = perms2str($_REQUEST['group_allow']);
         $_REQUEST['deny_cid'] = perms2str($_REQUEST['contact_deny']);
         $_REQUEST['deny_gid'] = perms2str($_REQUEST['group_deny']);
         $r = attach_mkdir($channel, get_observer_hash(), $_REQUEST);
     } else {
         $r = attach_store($channel, get_observer_hash(), '', $_REQUEST);
     }
     goaway(z_root() . '/' . $_REQUEST['return_url']);
 }
Example #2
0
/**
 * @brief Create directory (recursive).
 *
 * @param array $channel channel array of owner
 * @param string $observer_hash hash of current observer
 * @param array $arr parameter array to fulfil request
 * - Required:
 *  * \e string \b pathname
 *  * \e string \b folder hash of parent directory, empty string for root directory
 * - Optional:
 *  * \e string \b allow_cid
 *  * \e string \b allow_gid
 *  * \e string \b deny_cid
 *  * \e string \b deny_gid
 * @return array
 */
function attach_mkdirp($channel, $observer_hash, $arr = null)
{
    $ret = array('success' => false);
    $channel_id = $channel['channel_id'];
    $sql_options = '';
    $basepath = 'store/' . $channel['channel_address'];
    logger('attach_mkdirp: basepath: ' . $basepath);
    if (!is_dir($basepath)) {
        os_mkdir($basepath, STORAGE_DEFAULT_PERMISSIONS, true);
    }
    if (!perm_is_allowed($channel_id, $observer_hash, 'write_storage')) {
        $ret['message'] = t('Permission denied.');
        return $ret;
    }
    if (!$arr['pathname']) {
        $ret['message'] = t('Empty pathname');
        return $ret;
    }
    $paths = explode('/', $arr['pathname']);
    if (!$paths) {
        $ret['message'] = t('Empty path');
        return $ret;
    }
    $current_parent = '';
    foreach ($paths as $p) {
        if (!$p) {
            continue;
        }
        $arx = array('filename' => $p, 'folder' => $current_parent, 'force' => 1);
        if (array_key_exists('allow_cid', $arr)) {
            $arx['allow_cid'] = $arr['allow_cid'];
        }
        if (array_key_exists('deny_cid', $arr)) {
            $arx['deny_cid'] = $arr['deny_cid'];
        }
        if (array_key_exists('allow_gid', $arr)) {
            $arx['allow_gid'] = $arr['allow_gid'];
        }
        if (array_key_exists('deny_gid', $arr)) {
            $arx['deny_gid'] = $arr['deny_gid'];
        }
        $x = attach_mkdir($channel, $observer_hash, $arx);
        if ($x['success']) {
            $current_parent = $x['data']['hash'];
        } else {
            $ret['message'] = $x['message'];
            return $ret;
        }
    }
    if (isset($x)) {
        $ret['success'] = true;
        $ret['data'] = $x['data'];
    }
    return $ret;
}
Example #3
0
 /**
  * @brief Creates a new subdirectory.
  *
  * @param string $name the directory to create
  * @return void
  */
 public function createDirectory($name)
 {
     logger('create directory ' . $name, LOGGER_DEBUG);
     if (!$this->auth->owner_id || !perm_is_allowed($this->auth->owner_id, $this->auth->observer, 'write_storage')) {
         throw new DAV\Exception\Forbidden('Permission denied.');
     }
     $r = q("SELECT * FROM channel WHERE channel_id = %d AND channel_removed = 0 LIMIT 1", intval($this->auth->owner_id));
     if ($r) {
         require_once 'include/attach.php';
         $result = attach_mkdir($r[0], $this->auth->observer, array('filename' => $name, 'folder' => $this->folder_hash));
         if ($result['success']) {
             $sync = attach_export_data($r[0], $result['data']['hash']);
             logger('createDirectory: attach_export_data returns $sync:' . print_r($sync, true), LOGGER_DEBUG);
             if ($sync) {
                 build_sync_packet($r[0]['channel_id'], array('file' => array($sync)));
             }
         } else {
             logger('error ' . print_r($result, true), LOGGER_DEBUG);
         }
     }
 }
Example #4
0
 /**
  * @brief Creates a new subdirectory.
  *
  * @param string $name the directory to create
  * @return void
  */
 public function createDirectory($name)
 {
     logger($name, LOGGER_DEBUG);
     if (!$this->auth->owner_id || !perm_is_allowed($this->auth->owner_id, $this->auth->observer, 'write_storage')) {
         throw new DAV\Exception\Forbidden('Permission denied.');
     }
     $r = q("SELECT * FROM channel WHERE channel_id = %d AND channel_removed = 0 LIMIT 1", intval($this->auth->owner_id));
     if ($r) {
         $result = attach_mkdir($r[0], $this->auth->observer, array('filename' => $name, 'folder' => $this->folder_hash));
         if (!$result['success']) {
             logger('error ' . print_r($result, true), LOGGER_DEBUG);
         }
     }
 }