/** * Create log record * * @param string $cmd command name * @param array $result command result * @param array $args command arguments from client * @param elFinder $elfinder elFinder instance * @return void|true * @author Dmitry (dio) Levashov **/ public function log($cmd, $result, $args, $elfinder) { $log = $cmd . ' [' . date('d.m H:s') . "]\n"; if (!empty($result['error'])) { $log .= "\tERROR: " . implode(' ', $result['error']) . "\n"; } if (!empty($result['warning'])) { $log .= "\tWARNING: " . implode(' ', $result['warning']) . "\n"; } if (!empty($result['removed'])) { foreach ($result['removed'] as $file) { // removed file contain additional field "realpath" $log .= "\tREMOVED: " . $file['realpath'] . "\n"; //preg_match('/[^\/]+$/', $file['realpath'], $file); //$log .= $file[0]; } } if (!empty($result['added'])) { foreach ($result['added'] as $file) { $log .= "\tADDED: " . $elfinder->realpath($file['hash']) . "\n"; } } if (!empty($result['changed'])) { foreach ($result['changed'] as $file) { $log .= "\tCHANGED: " . $elfinder->realpath($file['hash']) . "\n"; } } $this->write($log); }
/** * Create log record * * @param string $cmd command name * @param array $result command result * @param array $args command arguments from client * @param elFinder $elfinder elFinder instance * @return void|true * @author Dmitry (dio) Levashov **/ public function log($cmd, $result, $args, $elfinder) { if ($cmd === 'netmount' && is_object($this->xoopsUser) && !empty($result['sync'])) { if ($uid = $this->xoopsUser->getVar('uid')) { $uid = intval($uid); $table = $this->db->prefix($this->mydirname.'_userdat'); $netVolumes = mysql_real_escape_string(serialize($_SESSION[_MD_XELFINDER_NETVOLUME_SESSION_KEY])); $sql = 'SELECT `id` FROM `'.$table.'` WHERE `key`=\'netVolumes\' AND `uid`='.$uid; if ($res = $this->db->query($sql)) { if ($this->db->getRowsNum($res) > 0) { $sql = 'UPDATE `'.$table.'` SET `data`="'.$netVolumes.'", `mtime`='.time().' WHERE `key`=\'netVolumes\' AND `uid`='.$uid; } else { $sql = 'INSERT `'.$table.'` SET `key`=\'netVolumes\', `uid` = '.$uid.', `data`="'.$netVolumes.'", `mtime`='.time(); } $this->db->queryF($sql); } } } $log = $cmd.' ['.date('d.m H:s')."]\n"; if (!empty($result['error'])) { $log .= "\tERROR: ".implode(' ', $result['error'])."\n"; } if (!empty($result['warning'])) { $log .= "\tWARNING: ".implode(' ', $result['warning'])."\n"; } if (!empty($result['removed'])) { foreach ($result['removed'] as $file) { // removed file contain additional field "realpath" $log .= "\tREMOVED: ".$elfinder->realpath($file['hash'])."\n"; } } if (!empty($result['added'])) { foreach ($result['added'] as $file) { $log .= "\tADDED: ".$elfinder->realpath($file['hash'])."\n"; } } if (!empty($result['changed'])) { foreach ($result['changed'] as $file) { $log .= "\tCHANGED: ".$elfinder->realpath($file['hash'])."\n"; } } $this->write($log); }
/** * Create log record * * @param string $cmd command name * @param array $result command result * @param array $args command arguments from client * @param elFinder $elfinder elFinder instance * @return void|true * @author Dmitry (dio) Levashov **/ public function log($cmd, &$result, $args, $elfinder) { $log = $cmd . ' [' . date('d.m H:s') . "]\n"; if ($cmd === 'netmount' && is_object($this->xoopsUser) && (!empty($result['sync']) || !empty($result['added']))) { if ($uid = $this->xoopsUser->getVar('uid')) { $uid = intval($uid); $table = $this->db->prefix($this->mydirname . '_userdat'); $netVolumes = $this->db->quoteString(serialize($_SESSION[_MD_XELFINDER_NETVOLUME_SESSION_KEY])); $sql = 'SELECT `id` FROM `' . $table . '` WHERE `key`=\'netVolumes\' AND `uid`=' . $uid; if ($res = $this->db->query($sql)) { if ($this->db->getRowsNum($res) > 0) { $sql = 'UPDATE `' . $table . '` SET `data`=' . $netVolumes . ', `mtime`=' . time() . ' WHERE `key`=\'netVolumes\' AND `uid`=' . $uid; } else { $sql = 'INSERT `' . $table . '` SET `key`=\'netVolumes\', `uid` = ' . $uid . ', `data`=' . $netVolumes . ', `mtime`=' . time(); } $this->db->queryF($sql); } } } if (!empty($result['error'])) { $log .= "\tERROR: " . implode(' ', $result['error']) . "\n"; } if (!empty($result['warning'])) { $log .= "\tWARNING: " . implode(' ', $result['warning']) . "\n"; } if (!empty($result['removed'])) { foreach ($result['removed'] as $file) { // removed file contain additional field "realpath" $log .= "\tREMOVED: " . $elfinder->realpath($file['hash']) . "\n"; } } if (!empty($result['added'])) { foreach ($result['added'] as $file) { $log .= "\tADDED: " . $elfinder->realpath($file['hash']) . "\n"; } } if (!empty($result['changed'])) { foreach ($result['changed'] as $file) { $log .= "\tCHANGED: " . $elfinder->realpath($file['hash']) . "\n"; } } if (!empty($result['added']) && in_array($cmd, array('mkdir', 'mkfile', 'put', 'upload', 'extract'))) { $mail = false; if (is_object($this->xoopsUser)) { if ($this->isAdmin) { $mail = in_array(XOOPS_GROUP_ADMIN, $this->config['mail_notify_group']); } else { $mail = array_intersect($this->config['mail_notify_group'], $this->mygids); } } else { $mail = $this->config['mail_notify_guest']; } //$log .= "\n\$mail=".($mail? 'On' : 'Off')."\n"; if ($mail) { $config_handler = xoops_gethandler('config'); $xoopsConfig = $config_handler->getConfigsByCat(XOOPS_CONF); $sep = "\n" . str_repeat('-', 40) . "\n"; $self = XOOPS_MODULE_URL . '/' . $this->mydirname . '/connector.php'; if (is_object($this->xoopsUser)) { $uname = $this->xoopsUser->uname('n'); $uid = $this->xoopsUser->uid(); } else { $uname = $xoopsConfig['anonymous']; $uid = 0; } $date = date('c'); $head = <<<EOD USER: {$uname} UID: {$uid} IP: {$_SERVER['REMOTE_ADDR']} CMD: {$cmd} DATE: {$date} EOD; $msg = array(); foreach ($result['added'] as $file) { $url = 'unknown'; if (!empty($file['url'])) { $url = $file['url'] != 1 ? $file['url'] : 'ondemand'; } else { $url = $self . '?cmd=file&target=' . $file['hash']; } $dl = $self . '?cmd=file&download=1&target=' . $file['hash']; $hash = $file['hash']; $path = $elfinder->realpath($file['hash']); $name = $file['name']; $manager = XOOPS_MODULE_URL . '/' . $this->mydirname . '/manager.php#elf_' . $file['phash']; $msg[] = <<<EOD HASH: {$hash} PATH: {$path} NAME: {$name} URL: {$url} DOWNLOAD: {$dl} MANAGER: {$manager} EOD; } $sitename = $xoopsConfig['sitename']; $modname = $this->xoopsModule->getVar('name'); $subject = '[' . $modname . '] Cmd: "' . $cmd . '" Report'; $message = join($sep, $msg); if (strtoupper(_CHARSET) !== 'UTF-8') { ini_set('default_charset', _CHARSET); if (version_compare(PHP_VERSION, '5.6', '<')) { ini_set('mbstring.internal_encoding', _CHARSET); } else { @ini_set('mbstring.internal_encoding', ''); } $message = mb_convert_encoding($message, _CHARSET, 'UTF-8'); } $xoopsMailer = getMailer(); $xoopsMailer->useMail(); $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); $xoopsMailer->setFromName($sitename . ':' . $modname); $xoopsMailer->setSubject($subject); $xoopsMailer->setBody($head . $sep . $message); $xoopsMailer->setToEmails($xoopsConfig['adminmail']); $xoopsMailer->send(); $xoopsMailer->reset(); if (strtoupper(_CHARSET) !== 'UTF-8') { ini_set('mbstring.internal_encoding', 'UTF-8'); } } } $this->write($log); if (in_array($cmd, array('mkdir', 'mkfile', 'put', 'paste', 'upload', 'extract', 'resize'))) { if (!empty($result['changed'])) { if (($target = $result['changed'][0]['phash']) && ($volume = $elfinder->getVolume($target))) { if ($parents = $volume->parents($target, true)) { $result['changed'] = array_merge($result['changed'], $parents); } } } } }
public function action_finder($input) { global $prefs, $user; if ($this->parentIds === null) { $ids = TikiLib::lib('filegal')->getGalleriesParentIds(); $this->parentIds = array('galleries' => array(), 'files' => array()); foreach ($ids as $id) { if ($id['parentId'] > 0) { $this->parentIds['galleries'][(int) $id['galleryId']] = (int) $id['parentId']; } } $tiki_files = TikiDb::get()->table('tiki_files'); $this->parentIds['files'] = $tiki_files->fetchMap('fileId', 'galleryId', array()); } // turn off some elfinder commands here too (stops the back-end methods being accessible) $disabled = array('mkfile', 'edit', 'archive', 'resize'); // done so far: 'rename', 'rm', 'duplicate', 'upload', 'copy', 'cut', 'paste', 'mkdir', 'extract', // check for a "userfiles" gallery - currently although elFinder can support more than one root, it always starts in the first one $opts = array('debug' => true, 'roots' => array()); $rootDefaults = array('driver' => 'TikiFiles', 'disabled' => $disabled, 'accessControl' => array($this, 'elFinderAccess'), 'uploadMaxSize' => ini_get('upload_max_filesize'), 'accessControlData' => array('deepGallerySearch' => $input->deepGallerySearch->int(), 'parentIds' => $this->parentIds)); // gallery to start in $startGallery = $input->defaultGalleryId->int(); // 'startPath' not functioning with multiple roots as yet (https://github.com/Studio-42/elFinder/issues/351) // so work around it for now with startRoot $opts['roots'][] = array_merge(array('path' => $this->fileController->defaultGalleryId), $rootDefaults); $startRoot = 0; if (!empty($user) && $prefs['feature_use_fgal_for_user_files'] == 'y') { if ($startGallery && $startGallery == $prefs['fgal_root_user_id'] && !Perms::get('file gallery', $startGallery)->admin_trackers) { $startGallery = (int) TikiLib::lib('filegal')->get_user_file_gallery(); } $userRootId = $prefs['fgal_root_user_id']; if ($startGallery != $userRootId) { $gal_info = TikiLib::lib('filegal')->get_file_gallery_info($startGallery); if ($gal_info['type'] == 'user') { $startRoot = count($opts['roots']); } } else { $startRoot = count($opts['roots']); } $opts['roots'][] = array_merge(array('path' => $userRootId), $rootDefaults); } if ($startGallery) { $opts['startRoot'] = $startRoot; $d = $opts['roots'][$startRoot]['path'] == $startGallery ? '' : 'd_'; // needs to be the cached name in elfinder (with 'd_' in front) unless it's the root id $opts['roots'][$startRoot]['startPath'] = $d . $startGallery; } /* thumb size not working due to css issues - tried this in setup/javascript.php but needs extensive css overhaul to get looking right if ($prefs['fgal_elfinder_feature'] === 'y') { $tmbSize = (int) $prefs['fgal_thumb_max_size'] / 2; TikiLib::lib('header')->add_css(".elfinder-cwd-icon {width:{$tmbSize}px; height:{$tmbSize}px;}"); // def 48 $tmbSize += 4; // def 52 TikiLib::lib('header')->add_css(".elfinder-cwd-view-icons .elfinder-cwd-file-wrapper {width:{$tmbSize}px; height:{$tmbSize}px;}"); $tmbSize += 28; $tmbSizeW = $tmbSize + 40; // def 120 x 80 TikiLib::lib('header')->add_css(".elfinder-cwd-view-icons .elfinder-cwd-file {width: {$tmbSizeW}px;height: {$tmbSize}px;}"); } */ // run elFinder $elFinder = new elFinder($opts); $connector = new elFinderConnector($elFinder); if ($input->cmd->text() === 'tikiFileFromHash') { // intercept tiki only commands $fileId = $elFinder->realpath($input->hash->text()); $filegallib = TikiLib::lib('filegal'); $info = $filegallib->get_file(str_replace('f_', '', $fileId)); $info['wiki_syntax'] = $filegallib->getWikiSyntax($info['galleryId'], $info); return $info; } // elfinder needs "raw" $_GET or $_POST if ($_SERVER["REQUEST_METHOD"] == 'POST') { $_POST = $input->asArray(); } else { $_GET = $input->asArray(); } $connector->run(); // deals with response return array(); }