32 const NAME =
"upload_file";
33 const FOLDER_PARAMETER_NAME =
'folder';
35 const DESCRIPTION_INPUT_NAME =
'descriptionInputName';
36 const DESCRIPTION_VALUE =
'descriptionValue';
37 const UPLOAD_FORM_BUILD_PARAMETER_NAME =
'uploadformbuild';
38 const PUBLIC_ALL =
'public';
39 const PUBLIC_GROUPS =
'protected';
48 public function __construct($name, $parameters = array())
50 parent::__construct($name, $parameters);
52 $this->folderDao = $this->
getObject(
'dao.folder');
53 $this->uploadDao = $this->
getObject(
'dao.upload');
54 $this->logger = $this->
getObject(
'logger');
56 abstract protected function handleUpload(Request $request);
57 abstract protected function handleView(Request $request, $vars);
59 protected function handle(Request $request)
62 $this->folderDao->ensureTopLevelFolder();
66 if ($request->isMethod(Request::METHOD_POST)) {
67 list($success, $message, $description) = $this->handleUpload($request);
69 $vars[
'message'] = $message;
70 $vars[
'descriptionInputValue'] = $description ?:
"";
71 $vars[
'descriptionInputName'] = self::DESCRIPTION_INPUT_NAME;
72 $vars[
'folderParameterName'] = self::FOLDER_PARAMETER_NAME;
73 $vars[
'upload_max_filesize'] = ini_get(
'upload_max_filesize');
74 $vars[
'agentCheckBoxMake'] =
'';
77 $folderStructure = $this->folderDao->getFolderStructure($rootFolder->getId());
79 $vars[
'folderStructure'] = $folderStructure;
80 $vars[
'baseUrl'] = $request->getBaseUrl();
81 $vars[
'moduleName'] = $this->
getName();
82 $vars[self::FOLDER_PARAMETER_NAME] = $request->get(self::FOLDER_PARAMETER_NAME);
85 $vars[
'parmAgentContents'] = array();
86 $vars[
'parmAgentFoots'] = array();
87 foreach ($parmAgentList as $parmAgent) {
89 $vars[
'parmAgentContents'][] = $agent->renderContent($vars);
90 $vars[
'parmAgentFoots'][] = $agent->renderFoot($vars);
93 $session = $request->getSession();
94 $session->set(self::UPLOAD_FORM_BUILD_PARAMETER_NAME, time().
':'.$_SERVER[
'REMOTE_ADDR']);
95 $vars[
'uploadFormBuild'] = $session->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME);
96 $vars[
'uploadFormBuildParameterName'] = self::UPLOAD_FORM_BUILD_PARAMETER_NAME;
99 $skip = array(
"agent_unpack",
"agent_adj2nest",
"wget_agent");
102 return $this->handleView($request, $vars);
105 protected function postUploadAddJobs(Request $request, $fileName, $uploadId, $jobId = null, $wgetDependency =
false)
110 if ($jobId === null) {
111 $jobId = JobAddJob($userId, $groupId, $fileName, $uploadId);
114 $unpackArgs = intval($request->get(
'scm')) == 1 ?
'-I' :
'';
115 $adj2nestDependencies = array();
116 if ($wgetDependency) {
117 $adj2nestDependencies = array(array(
'name'=>
'agent_unpack',
'args'=>$unpackArgs,AgentPlugin::PRE_JOB_QUEUE=>array(
'wget_agent')));
120 $adj2nestplugin->AgentAdd($jobId, $uploadId, $dummy, $adj2nestDependencies, null, (empty($adj2nestDependencies) ? $unpackArgs :
''));
128 $agentList = array_merge($plainAgentList, $parmAgentList);
132 foreach ($parmAgentList as $parmAgent) {
134 $agent->scheduleAgent($jobId, $uploadId, $errorMsg, $request, $agentList);
138 $message = empty($status) ? _(
"Is the scheduler running? ") :
"";
139 $jobUrl =
Traceback_uri() .
"?mod=showjobs&upload=$uploadId";
140 $message .= _(
"The file") .
" " . $fileName .
" " . _(
"has been uploaded. It is") .
141 ' <a href=' . $jobUrl .
'>upload #' . $uploadId .
"</a>.\n";
142 if ($request->get(
'public')==self::PUBLIC_GROUPS) {
143 $this->
getObject(
'dao.upload.permission')->makeAccessibleToAllGroupsOf($uploadId, $userId);
160 while ($pos < strlen($str) &&
161 ($pos = strpos($str,$char,$pos)) !==
false) {
162 foreach (range(($pos++) -1, 1, -2) as $tpos) {
163 if ($tpos > 0 && $str[$tpos] !==
'\\') {
166 if ($tpos > 1 && $str[$tpos - 1] !==
'\\') {
201 || strpos($path,
'..') !==
false;
216 if (strpos($path,
'/') ===
false || $path ===
'/') {
220 $bpath = basename($path);
225 if (strcmp($host,
"localhost") === 0) {
228 $bpath . ($appendix ==
'' ?
235 return $path . ($appendix ==
'' ?
240 $rpath = realpath($path);
241 if ($rpath ===
false) {
244 return $rpath . ($appendix ==
'' ?
250 function basicShEscaping($str)
252 $str = str_replace(
'\\',
'\\\\', $str);
253 $str = str_replace(
'"',
'\"', $str);
254 $str = str_replace(
'`',
'\`', $str);
255 $str = str_replace(
'$',
'\$', $str);
266 $deciderKey = array_search(
'agent_decider', $parmList);
267 $reuserKey = array_search(
'agent_reuser', $parmList);
268 if ($deciderKey !==
false && $reuserKey !==
false) {
269 $temp = $parmList[$deciderKey];
270 $parmList[$deciderKey] = $parmList[$reuserKey];
271 $parmList[$reuserKey] = $temp;
GetRunnableJobList()
Get runnable job list, the process is below:
AgentSchedule($jobId, $uploadId, $agents)
Schedule all given agents.
checkedAgents()
read the UI form and return array of user selected agents Because input comes from the user...
Traceback_uri()
Get the URI without query to this location.
static getUserId()
Get the current user's id.
normalize_path($path, $host="localhost", $appendix="")
normalizes an path and returns FALSE on errors
AgentCheckBoxMake($upload_pk, $SkipAgents=array(), $specified_username="")
Generate a checkbox list of available agents.
path_can_escape($path)
checks, whether a path contains substrings, which could enable it to escape his prefix ...
path_is_pattern($path)
checks, whether a path is a pattern from the perspective of a shell
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
rearrangeDependencies(&$parmList)
list_t type structure used to keep various lists. (e.g. there are multiple lists).
static getGroupId()
Get the current user's group id.
str_contains_notescaped_char($str, $char)
checks, whether a string contains some special character without escaping