8 namespace Fossology\UI\Page;
11 use Symfony\Component\HttpFoundation\Request;
15 const NAME =
'upload_url';
17 const NAME_PARAM =
'name';
18 const ACCEPT_PARAM =
'accept';
19 const REJECT_PARAM =
'reject';
20 const GETURL_PARAM =
'geturl';
21 const LEVEL_PARAM =
'level';
23 public function __construct()
25 parent::__construct(self::NAME, array(
26 self::TITLE => _(
"Upload from URL"),
27 self::MENU_LIST =>
"Upload::From URL",
28 self::DEPENDENCIES => array(
"agent_unpack",
"showjobs"),
33 protected function handleUpload(Request $request)
35 $folderId = intval($request->get(self::FOLDER_PARAMETER_NAME));
36 $description = stripslashes($request->get(self::DESCRIPTION_INPUT_NAME));
37 $description = $this->basicShEscaping($description);
39 $getUrlThatMightIncludeSpaces =
trim($request->get(self::GETURL_PARAM));
40 $getURL = str_replace(
" ",
"%20", $getUrlThatMightIncludeSpaces);
43 return array(
false, _(
"Invalid URL"), $description);
45 if (preg_match(
"@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $getURL) != 1) {
46 return array(
false, _(
"Invalid URL"), $description);
48 $getURL = $this->basicShEscaping($getURL);
50 $name = $request->get(self::NAME_PARAM);
52 $name = basename($getURL);
54 $shortName = basename($name);
55 if (empty($shortName)) {
63 $setGlobal = ($request->get(
'globalDecisions')) ? 1 : 0;
64 $public = $request->get(
'public');
67 $uploadId =
JobAddUpload($userId, $groupId, $shortName, $getURL, $description, $mode, $folderId, $publicPermission, $setGlobal);
68 if (empty($uploadId)) {
69 $text = _(
"Failed to insert upload record");
70 return array(
false, $text, $description);
73 $level = intval($request->get(self::LEVEL_PARAM));
79 $accept = preg_replace(
'/\s*,\s*/',
',',
trim($request->get(self::ACCEPT_PARAM)));
80 $accept = $this->basicShEscaping($accept);
81 $reject = preg_replace(
'/\s*,\s*/',
',',
trim($request->get(self::REJECT_PARAM)));
82 $reject = $this->basicShEscaping($reject);
85 $jobId = JobAddJob($userId, $groupId,
"wget", $uploadId);
86 if (empty($jobId) || ($jobId < 0)) {
87 return array(
false, _(
"Failed to insert job record"), $description);
90 $jqArgs =
"$uploadId - $getURL -l $level ";
91 if (! empty($accept)) {
92 $jqArgs .=
"-A $accept ";
94 $jqArgs .= empty($reject) ?
"-R index.html* " :
"-R $reject,index.html* ";
96 $jobqueueId =
JobQueueAdd($jobId,
"wget_agent", $jqArgs, NULL, NULL);
97 if (empty($jobqueueId)) {
99 "Failed to insert task 'wget_agent' into job queue", $description);
102 $message = $this->postUploadAddJobs($request, $shortName, $uploadId, $jobId,
true);
103 return array(
true, $message, $description, $uploadId);
106 protected function handleView(Request $request, $vars)
108 $vars[
'geturlField'] = self::GETURL_PARAM;
109 $vars[
'nameField'] = self::NAME_PARAM;
110 $vars[
'acceptField'] = self::ACCEPT_PARAM;
111 $vars[
'rejectField'] = self::REJECT_PARAM;
112 $vars[
'levelField'] = self::LEVEL_PARAM;
113 return $this->
render(
"upload_url.html.twig", $this->mergeWithDefault($vars));
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.
render($templateName, $vars=null, $headers=null)
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
JobAddUpload($userId, $groupId, $job_name, $filename, $desc, $UploadMode, $folder_pk, $public_perm=Auth::PERM_NONE, $setGlobal=0)
Insert a new upload record, and update the foldercontents table.
char * trim(char *ptext)
Trimming whitespace.