8 namespace Fossology\UI\Page;
17 use Symfony\Component\HttpFoundation\Request;
21 const NAME =
"upload_file";
22 const FOLDER_PARAMETER_NAME =
'folder';
24 const DESCRIPTION_INPUT_NAME =
'descriptionInputName';
25 const DESCRIPTION_VALUE =
'descriptionValue';
26 const UPLOAD_FORM_BUILD_PARAMETER_NAME =
'uploadformbuild';
27 const PUBLIC_ALL =
'public';
28 const PUBLIC_GROUPS =
'protected';
39 public function __construct($name, $parameters = array())
41 parent::__construct($name, $parameters);
43 $this->folderDao = $this->
getObject(
'dao.folder');
44 $this->uploadDao = $this->
getObject(
'dao.upload');
45 $this->logger = $this->
getObject(
'logger');
46 $this->userDao = $this->
getObject(
'dao.user');
48 abstract protected function handleUpload(Request $request);
49 abstract protected function handleView(Request $request, $vars);
51 protected function handle(Request $request)
54 $this->folderDao->ensureTopLevelFolder();
58 if ($request->isMethod(Request::METHOD_POST)) {
59 list($success, $message, $description) = $this->handleUpload($request);
61 $vars[
'message'] = $message;
62 $vars[
'descriptionInputValue'] = $description ?:
"";
63 $vars[
'descriptionInputName'] = self::DESCRIPTION_INPUT_NAME;
64 $vars[
'folderParameterName'] = self::FOLDER_PARAMETER_NAME;
65 $vars[
'upload_max_filesize'] = ini_get(
'upload_max_filesize');
66 $vars[
'agentCheckBoxMake'] =
'';
69 $UserRec = $this->userDao->getUserByPk($userId);
70 if (!empty($UserRec[
'upload_visibility'])) {
71 $vars[
'uploadVisibility'] = $UserRec[
'upload_visibility'];
73 $vars[
'uploadVisibility'] = $SysConf[
'SYSCONFIG'][
'UploadVisibility'];
76 if ($rootFolder == NULL) {
79 $folderStructure = $this->folderDao->getFolderStructure($rootFolder->getId());
81 $vars[
'folderStructure'] = $folderStructure;
82 $vars[
'baseUrl'] = $request->getBaseUrl();
83 $vars[
'moduleName'] = $this->
getName();
84 $vars[self::FOLDER_PARAMETER_NAME] = $request->get(self::FOLDER_PARAMETER_NAME);
87 $vars[
'parmAgentContents'] = array();
88 $vars[
'parmAgentFoots'] = array();
89 foreach ($parmAgentList as $parmAgent) {
91 $vars[
'parmAgentContents'][] = $agent->renderContent($vars);
92 $vars[
'parmAgentFoots'][] = $agent->renderFoot($vars);
95 $session = $request->getSession();
96 $session->set(self::UPLOAD_FORM_BUILD_PARAMETER_NAME, time().
':'.$_SERVER[
'REMOTE_ADDR']);
97 $vars[
'uploadFormBuild'] = $session->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME);
98 $vars[
'uploadFormBuildParameterName'] = self::UPLOAD_FORM_BUILD_PARAMETER_NAME;
101 $skip = array(
"agent_unpack",
"agent_adj2nest",
"wget_agent");
104 return $this->handleView($request, $vars);
107 protected function postUploadAddJobs(Request $request, $fileName, $uploadId, $jobId =
null, $wgetDependency =
false)
112 if ($jobId ===
null) {
113 $jobId = JobAddJob($userId, $groupId, $fileName, $uploadId);
116 $unpackArgs = intval($request->get(
'scm')) == 1 ?
'-I' :
'';
117 $adj2nestDependencies = array();
118 if ($wgetDependency) {
119 $adj2nestDependencies = array(array(
'name'=>
'agent_unpack',
'args'=>$unpackArgs,AgentPlugin::PRE_JOB_QUEUE=>array(
'wget_agent')));
122 $adj2nestplugin->AgentAdd($jobId, $uploadId, $dummy, $adj2nestDependencies,
123 null,
null, (empty($adj2nestDependencies) ? $unpackArgs :
''));
131 $agentList = array_merge($plainAgentList, $parmAgentList);
135 foreach ($parmAgentList as $parmAgent) {
137 $agent->scheduleAgent($jobId, $uploadId, $errorMsg, $request, $agentList);
141 $message = empty($status) ? _(
"Is the scheduler running? ") :
"";
142 $jobUrl =
Traceback_uri() .
"?mod=showjobs&upload=$uploadId";
143 $message .= _(
"The file") .
" " . $fileName .
" " . _(
"has been uploaded. It is") .
144 ' <a href=' . $jobUrl .
'>upload #' . $uploadId .
"</a>.\n";
145 if ($request->get(
'public')==self::PUBLIC_GROUPS) {
146 $this->
getObject(
'dao.upload.permission')->makeAccessibleToAllGroupsOf($uploadId, $userId);
163 while ($pos < strlen($str) &&
164 ($pos = strpos($str,$char,$pos)) !==
false) {
165 foreach (range(($pos++) -1, 1, -2) as $tpos) {
166 if ($tpos > 0 && $str[$tpos] !==
'\\') {
169 if ($tpos > 1 && $str[$tpos - 1] !==
'\\') {
204 || strpos($path,
'..') !==
false;
219 if (strpos($path,
'/') ===
false || $path ===
'/') {
223 $bpath = basename($path);
228 if (strcmp($host,
"localhost") === 0) {
231 $bpath . ($appendix ==
'' ?
238 return $path . ($appendix ==
'' ?
243 $rpath = realpath($path);
244 if ($rpath ===
false) {
247 return $rpath . ($appendix ==
'' ?
253 function basicShEscaping($str)
255 $str = str_replace(
'\\',
'\\\\', $str);
256 $str = str_replace(
'"',
'\"', $str);
257 $str = str_replace(
'`',
'\`', $str);
258 $str = str_replace(
'$',
'\$', $str);
269 $deciderKey = array_search(
'agent_decider', $parmList);
270 $reuserKey = array_search(
'agent_reuser', $parmList);
271 if ($deciderKey !==
false && $reuserKey !==
false) {
272 $temp = $parmList[$deciderKey];
273 $parmList[$deciderKey] = $parmList[$reuserKey];
274 $parmList[$reuserKey] = $temp;
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
static getGroupId()
Get the current user's group id.
path_is_pattern($path)
checks, whether a path is a pattern from the perspective of a shell
path_can_escape($path)
checks, whether a path contains substrings, which could enable it to escape his prefix
str_contains_notescaped_char($str, $char)
checks, whether a string contains some special character without escaping
rearrangeDependencies(&$parmList)
normalize_path($path, $host="localhost", $appendix="")
normalizes an path and returns FALSE on errors
AgentSchedule($jobId, $uploadId, $agents)
Schedule all given agents.
checkedAgents($agents=null)
read the UI form and return array of user selected agents Because input comes from the user,...
AgentCheckBoxMake($upload_pk, $SkipAgents=array(), $specified_username="")
Generate a checkbox list of available agents.
Traceback_uri()
Get the URI without query to this location.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
GetRunnableJobList()
Get runnable job list, the process is below:
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
list_t type structure used to keep various lists. (e.g. there are multiple lists).