9 namespace Fossology\UI\Page;
13 use Symfony\Component\HttpFoundation\Request;
20 const NAME =
"upload_vcs";
21 const GETURL_PARAM =
'geturl';
23 public function __construct()
25 parent::__construct(self::NAME, array(
26 self::TITLE => _(
"Upload from Version Control System"),
27 self::MENU_LIST =>
"Upload::From Version Control System",
28 self::DEPENDENCIES => array(
"agent_unpack",
"showjobs"),
40 $vars[
'vcstypeField'] =
'vcstype';
41 $vars[
'usernameField'] =
'username';
42 $vars[
'passwdField'] =
'passwd';
43 $vars[
'geturlField'] = self::GETURL_PARAM;
44 $vars[
'branchField'] =
'branch';
45 $vars[
'nameField'] =
'name';
46 return $this->
render(
"upload_vcs.html.twig", $this->mergeWithDefault($vars));
58 $folderId = intval($request->get(self::FOLDER_PARAMETER_NAME));
59 $description = stripslashes($request->get(self::DESCRIPTION_INPUT_NAME));
60 $description = $this->basicShEscaping($description);
62 $getUrlThatMightIncludeSpaces =
trim($request->get(self::GETURL_PARAM));
63 $getUrl = str_replace(
" ",
"%20", $getUrlThatMightIncludeSpaces);
66 return array(
false, _(
"Empty URL") . $getUrl, $description);
68 if (preg_match(
"@^((http)|(https))://([[:alnum:]]+)@i", $getUrl) != 1) {
69 return array(
false, _(
"Invalid URL") . $getUrl, $description);
71 $getUrl = $this->basicShEscaping($getUrl);
73 if ($request->getSession()->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME)
74 != $request->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME)) {
75 $text = _(
"This seems to be a resent file.");
76 return array(
false, $text, $description);
79 if (empty($folderId)) {
80 $text = _(
"Invalid Folder.");
81 return array(
false, $text, $description);
83 $setGlobal = ($request->get(
'globalDecisions')) ? 1 : 0;
85 $public = $request->get(
'public');
88 $Name =
trim($request->get(
'name'));
90 $Name = basename($getUrl);
92 $ShortName = basename($Name);
93 if (empty($ShortName)) {
98 $uploadMode = (1 << 2);
101 $uploadId =
JobAddUpload($userId, $groupId, $ShortName, $getUrl,
102 $description, $uploadMode, $folderId, $publicPermission, $setGlobal);
103 if (empty($uploadId)) {
104 $text = _(
"Failed to insert upload record");
105 return array(
false, $text, $description);
109 $jobpk = JobAddJob($userId, $groupId,
"wget", $uploadId);
110 if (empty($jobpk) || ($jobpk < 0)) {
111 $text = _(
"Failed to insert job record");
112 return array(
false, $text, $description);
115 $VCSType =
trim($request->get(
'vcstype'));
116 $VCSType = $this->basicShEscaping($VCSType);
117 $jq_args =
"$uploadId - $getUrl $VCSType ";
119 $Username =
trim($request->get(
'username'));
120 $Username = $this->basicShEscaping($Username);
121 if (!empty($Username)) {
122 $jq_args .=
"--username $Username ";
125 $Passwd =
trim($request->get(
'passwd'));
126 $Passwd = $this->basicShEscaping($Passwd);
127 if (!empty($Passwd)) {
128 $jq_args .=
"--password $Passwd ";
131 $Branch =
trim(explode(
' ',
trim($request->get(
'branch')))[0]);
132 if (!empty($Branch) && strcasecmp($VCSType,
'git') == 0) {
133 $jq_args .=
"--single-branch --branch '$Branch'";
136 $jobqueuepk =
JobQueueAdd($jobpk,
"wget_agent", $jq_args, NULL, NULL);
137 if (empty($jobqueuepk)) {
138 $text = _(
"Failed to insert task 'wget_agent' into job queue");
139 return array(
false, $text, $description);
142 $unpackplugin = &$Plugins[plugin_find_id(
"agent_unpack") ];
143 $unpackArgs = intval($request->get(
'scm')) == 1 ?
'-I' :
'';
144 $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadId, $ErrorMsg, array(
"wget_agent"), $unpackArgs);
145 if ($ununpack_jq_pk < 0) {
146 return array(
false, _($ErrorMsg), $description);
149 $adj2nestplugin = &$Plugins[plugin_find_id(
"agent_adj2nest") ];
150 $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadId, $ErrorMsg, array());
151 if ($adj2nest_jq_pk < 0) {
152 return array(
false, _($ErrorMsg), $description);
155 $message = $this->postUploadAddJobs($request, $Name, $uploadId, $jobpk);
156 return array(
true, $message, $description, $uploadId);
160 register_plugin(
new UploadVcsPage());
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)
Upload from some Version Conntrol System using the UI.
handleView(Request $request, $vars)
handleUpload(Request $request)
Process the upload request.
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.