Exemplo n.º 1
0
 /**
  * \brief Process the upload request.
  * \param $Folder
  * \param  $GetURL
  * \param  $Desc
  * \param  $Name
  * \param  $Accept
  * \param  $Reject
  * \param  $Level
  * \param $public_perm public permission on the upload
  * Returns NULL on success, string on failure.
  */
 function Upload($Folder, $GetURL, $Desc, $Name, $Accept, $Reject, $Level, $public_perm)
 {
     global $SysConf;
     /* See if the URL looks valid */
     if (empty($Folder)) {
         $text = _("Invalid folder");
         return $text;
     }
     $GetURL = trim($GetURL);
     if (empty($GetURL)) {
         $text = _("Invalid URL");
         return $text;
     }
     if (preg_match("@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $GetURL) != 1) {
         $text = _("Invalid URL");
         return "{$text}: " . htmlentities($GetURL);
     }
     if (preg_match("@[[:space:]]@", $GetURL) != 0) {
         $text = _("Invalid URL (no spaces permitted)");
         return "{$text}: " . htmlentities($GetURL);
     }
     if (empty($Name)) {
         $Name = basename($GetURL);
     }
     $ShortName = basename($Name);
     if (empty($ShortName)) {
         $ShortName = $Name;
     }
     /* Create an upload record. */
     $Mode = 1 << 2;
     // code for "it came from wget"
     $user_pk = $SysConf['auth']['UserId'];
     $uploadpk = JobAddUpload($user_pk, $ShortName, $GetURL, $Desc, $Mode, $Folder, $public_perm);
     if (empty($uploadpk)) {
         $text = _("Failed to insert upload record");
         return $text;
     }
     /* Set default values */
     if (empty($Level) && !is_numeric($Level) || $Level < 0) {
         $Level = 1;
     }
     /* first trim, then get rid of whitespaces before and after each comma letter */
     $Accept = preg_replace('/\\s*,\\s*/', ',', trim($Accept));
     $Reject = preg_replace('/\\s*,\\s*/', ',', trim($Reject));
     /* Create the job: job "wget" */
     $jobpk = JobAddJob($user_pk, "wget", $uploadpk);
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to insert job record");
         return $text;
     }
     $jq_args = "{$uploadpk} - {$GetURL} -l {$Level} ";
     if (!empty($Accept)) {
         $jq_args .= "-A {$Accept} ";
     }
     if (!empty($Reject)) {
         // reject the files index.html*
         $jq_args .= "-R {$Reject},index.html* ";
     } else {
         $jq_args .= "-R index.html* ";
     }
     $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, NULL, NULL);
     if (empty($jobqueuepk)) {
         $text = _("Failed to insert task 'wget_agent' into job queue");
         return $text;
     }
     global $Plugins;
     /* schedule agents */
     $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
     $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array("wget_agent"));
     if ($ununpack_jq_pk < 0) {
         return $ErrorMsg;
     }
     $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
     $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array());
     if ($adj2nest_jq_pk < 0) {
         return $ErrorMsg;
     }
     AgentCheckBoxDo($jobpk, $uploadpk);
     $msg = "";
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     if (empty($status)) {
         $msg .= _("Is the scheduler running? ");
     }
     $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadpk}";
     $text = _("The upload");
     $text1 = _("has been queued. It is");
     $msg .= "{$text} {$Name} {$text1} ";
     $keep = "<a href='{$Url}'>upload #" . $uploadpk . "</a>.\n";
     print displayMessage($msg, $keep);
     return NULL;
 }
Exemplo n.º 2
0
 /**
  * @brief Process the upload request.
  */
 protected function handleUpload(Request $request)
 {
     global $MODDIR;
     global $SYSCONFDIR;
     global $Plugins;
     $folderId = intval($request->get(self::FOLDER_PARAMETER_NAME));
     $description = stripslashes($request->get(self::DESCRIPTION_INPUT_NAME));
     $description = $this->basicShEscaping($description);
     $getUrlThatMightIncludeSpaces = trim($request->get(self::GETURL_PARAM));
     $getUrl = str_replace(" ", "%20", $getUrlThatMightIncludeSpaces);
     if (empty($getUrl)) {
         return array(false, _("Empty URL") . $getUrl, $description);
     }
     if (preg_match("@^((http)|(https))://([[:alnum:]]+)@i", $getUrl) != 1) {
         return array(false, _("Invalid URL") . $getUrl, $description);
     }
     $getUrl = $this->basicShEscaping($getUrl);
     if ($request->getSession()->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME) != $request->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME)) {
         $text = _("This seems to be a resent file.");
         return array(false, $text, $description);
     }
     if (empty($folderId)) {
         $text = _("Invalid Folder.");
         return array(false, $text, $description);
     }
     $public = $request->get('public');
     $publicPermission = $public == self::PUBLIC_ALL ? Auth::PERM_READ : Auth::PERM_NONE;
     $Name = trim($request->get('name'));
     if (empty($Name)) {
         $Name = basename($getUrl);
     }
     $ShortName = basename($Name);
     if (empty($ShortName)) {
         $ShortName = $Name;
     }
     /* Create an upload record. */
     $uploadMode = 1 << 2;
     // code for "it came from wget"
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     $uploadId = JobAddUpload($userId, $groupId, $ShortName, $getUrl, $description, $uploadMode, $folderId, $publicPermission);
     if (empty($uploadId)) {
         $text = _("Failed to insert upload record");
         return array(false, $text, $description);
     }
     /* Create the job: job "wget" */
     $jobpk = JobAddJob($userId, $groupId, "wget", $uploadId);
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to insert job record");
         return array(false, $text, $description);
     }
     $VCSType = trim($request->get('vcstype'));
     $VCSType = $this->basicShEscaping($VCSType);
     $jq_args = "{$uploadId} - {$getUrl} {$VCSType} ";
     $Username = trim($request->get('username'));
     $Username = $this->basicShEscaping($Username);
     if (!empty($Username)) {
         $jq_args .= "--username {$Username} ";
     }
     $Passwd = trim($request->get('passwd'));
     $Passwd = $this->basicShEscaping($Passwd);
     if (!empty($Passwd)) {
         $jq_args .= "--password {$Passwd}";
     }
     $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, NULL, NULL);
     if (empty($jobqueuepk)) {
         $text = _("Failed to insert task 'wget_agent' into job queue");
         return array(false, $text, $description);
     }
     /* schedule agents */
     $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
     $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadId, $ErrorMsg, array("wget_agent"));
     if ($ununpack_jq_pk < 0) {
         return array(false, _($ErrorMsg), $description);
     }
     $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
     $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadId, $ErrorMsg, array());
     if ($adj2nest_jq_pk < 0) {
         return array(false, _($ErrorMsg), $description);
     }
     AgentCheckBoxDo($jobpk, $uploadId);
     $msg = "";
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     if (empty($status)) {
         $msg .= _("Is the scheduler running? ");
     }
     $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadId}";
     $text = _("The upload");
     $text1 = _("has been queued. It is");
     $msg .= "{$text} {$Name} {$text1} ";
     $keep = "<a href='{$Url}'>upload #" . $uploadId . "</a>.\n";
     return array(true, $msg . $keep, $description);
 }
Exemplo n.º 3
0
 /**
  * @brief Process the upload request.
  */
 protected function handleUpload(Request $request)
 {
     global $Plugins;
     define("UPLOAD_ERR_INVALID_FOLDER_PK", 100);
     define("UPLOAD_ERR_RESEND", 200);
     $uploadErrors = array(UPLOAD_ERR_INVALID_FOLDER_PK => _("Invalid Folder."), UPLOAD_ERR_RESEND => _("This seems to be a resent file."));
     $folderId = intval($request->get(self::FOLDER_PARAMETER_NAME));
     $description = stripslashes($request->get(self::DESCRIPTION_INPUT_NAME));
     $description = $this->basicShEscaping($description);
     if ($request->getSession()->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME) != $request->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME)) {
         return array(false, $uploadErrors[UPLOAD_ERR_RESEND], $description);
     }
     if (empty($folderId)) {
         return array(false, $uploadErrors[UPLOAD_ERR_INVALID_FOLDER_PK], $description);
     }
     $public = $request->get('public');
     $publicPermission = $public == self::PUBLIC_ALL ? Auth::PERM_READ : Auth::PERM_NONE;
     $sourceFiles = trim($request->get(self::SOURCE_FILES_FIELD));
     $sourceFiles = $this->basicShEscaping($sourceFiles);
     $host = $request->get('host') ?: "localhost";
     if (preg_match('/[^a-z.0-9]/i', $host)) {
         $text = _("The given host is not valid.");
         return array(false, $text, $description);
     }
     if (!$this->check_if_host_is_allowed($host)) {
         $text = _("You are not allowed to upload from the chosen host.");
         return array(false, $text, $description);
     }
     $shortName = basename($sourceFiles);
     if (empty($shortName)) {
         $shortName = $sourceFiles;
     }
     if (strcmp($host, "localhost")) {
         $shortName = $host . ':' . $shortName;
     }
     $sourceFiles = $this->normalize_path($sourceFiles, $host);
     $sourceFiles = str_replace('|', '\\|', $sourceFiles);
     $sourceFiles = str_replace(' ', '\\ ', $sourceFiles);
     $sourceFiles = str_replace("\t", "\\t", $sourceFiles);
     if ($sourceFiles == FALSE) {
         $text = _("failed to normalize/validate given path");
         return array(false, $text, $description);
     }
     if ($this->check_by_whitelist($sourceFiles) === FALSE) {
         $text = _("no suitable prefix found in the whitelist") . ", " . _("you are not allowed to upload this file");
         return array(false, $text, $description);
     }
     if (!$this->path_is_pattern($sourceFiles) && !$this->remote_file_exists($sourceFiles, $host)) {
         $text = _("'{$sourceFiles}' does not exist.\n");
         return array(false, $text, $description);
     }
     if (!$this->path_is_pattern($sourceFiles) && !$this->remote_file_permission($sourceFiles, $host, "r")) {
         $text = _("Have no READ permission on '{$sourceFiles}'.\n");
         return array(false, $text, $description);
     }
     if (!$this->path_is_pattern($sourceFiles) && is_file($sourceFiles) && filesize($sourceFiles) <= 0) {
         $text = _("You can not upload an empty file.\n");
         return array(false, $text, $description);
     }
     /* Create an upload record. */
     $uploadMode = 1 << 3;
     // code for "it came from web upload"
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     $uploadId = JobAddUpload($userId, $groupId, $shortName, $sourceFiles, $description, $uploadMode, $folderId, $publicPermission);
     if (empty($uploadId)) {
         $text = _("Failed to insert upload record");
         return array(false, $text, $description);
     }
     /* Prepare the job: job "wget" */
     $jobpk = JobAddJob($userId, $groupId, "wget", $uploadId);
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to insert upload record");
         return array(false, $text, $description);
     }
     $jq_args = "{$uploadId} - {$sourceFiles}";
     $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, "no", NULL, $host);
     if (empty($jobqueuepk)) {
         $text = _("Failed to insert task 'wget' into job queue");
         return array(false, $text, $description);
     }
     $ErrorMsg = "";
     /* schedule agents */
     $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
     $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadId, $ErrorMsg, array("wget_agent"));
     if ($ununpack_jq_pk < 0) {
         return array(false, $text, _($ErrorMsg));
     }
     $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
     $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadId, $ErrorMsg, array());
     if ($adj2nest_jq_pk < 0) {
         return array(false, $text, _($ErrorMsg));
     }
     AgentCheckBoxDo($jobpk, $uploadId);
     $message = "";
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     if (empty($status)) {
         $message .= _("Is the scheduler running? ");
     }
     $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadId}";
     $message .= "The file {$sourceFiles} has been uploaded. ";
     $keep = "It is <a href='{$Url}'>upload #" . $uploadId . "</a>.\n";
     return array(true, $message . $keep, $description);
 }
 /**
  * \brief Process the upload request.  Call the upload by the Name passed in or by
  * the filename if no name is supplied.
  *
  * \param $FolderPk - folder fk to load into
  * \param $SourceFiles - files to upload, file, tar, directory, etc...
  * \param $GroupNames - flag for indicating if group names were requested.
  *        passed on as -A option to cp2foss.
  * \param $Desc - optional description for the upload
  * \param $Name - optional Name for the upload
  * \param $public_perm public permission on the upload
  *
  * \return NULL on success, string on failure.
  */
 function Upload($FolderPk, $SourceFiles, $GroupNames, $Desc, $Name, $HostName, $public_perm)
 {
     global $Plugins;
     global $SysConf;
     $FolderPath = FolderGetName($FolderPk);
     $SourceFiles = trim($SourceFiles);
     // $FolderPath = str_replace('\\','\\\\',$FolderPath);
     // $FolderPath = str_replace('"','\"',$FolderPath);
     $FolderPath = str_replace('`', '\\`', $FolderPath);
     $FolderPath = str_replace('$', '\\$', $FolderPath);
     if (!empty($Desc)) {
         // $Desc = str_replace('\\','\\\\',$Desc);
         // $Desc = str_replace('"','\"',$Desc);
         $Desc = str_replace('`', '\\`', $Desc);
         $Desc = str_replace('$', '\\$', $Desc);
     }
     if (!empty($Name)) {
         // $Name = str_replace('\\','\\\\',$Name);
         // $Name = str_replace('"','\"',$Name);
         $Name = str_replace('`', '\\`', $Name);
         $Name = str_replace('$', '\\$', $Name);
     } else {
         $Name = $SourceFiles;
     }
     // $SourceFiles = str_replace('\\','\\\\',$SourceFiles);
     // $SourceFiles = str_replace('"','\"',$SourceFiles);
     $SourceFiles = str_replace('`', '\\`', $SourceFiles);
     $SourceFiles = str_replace('$', '\\$', $SourceFiles);
     $SourceFiles = str_replace('|', '\\|', $SourceFiles);
     $SourceFiles = str_replace(' ', '\\ ', $SourceFiles);
     $SourceFiles = str_replace("\t", "\\\t", $SourceFiles);
     /* Add the job to the queue */
     // create the job
     $ShortName = basename($Name);
     if (empty($ShortName)) {
         $ShortName = $Name;
     }
     $wildcardpath = strstr($SourceFiles, '*');
     /** check if the file/directory is existed (the path does not include wildcards) */
     if (empty($wildcardpath) && !$this->remote_file_exists($SourceFiles, $HostName)) {
         $text = _("'{$SourceFiles}' does not exist.\n");
         return $text;
     }
     /** check if has the read permission */
     if (empty($wildcardpath) && !$this->remote_file_permission($SourceFiles, $HostName, "r")) {
         $text = _("Have no READ permission on '{$SourceFiles}'.\n");
         return $text;
     }
     // Create an upload record.
     $jobq = NULL;
     $Mode = 1 << 3;
     // code for "it came from web upload"
     $user_pk = $SysConf['auth']['UserId'];
     $uploadpk = JobAddUpload($user_pk, $ShortName, $SourceFiles, $Desc, $Mode, $FolderPk, $public_perm);
     /* Prepare the job: job "wget" */
     $jobpk = JobAddJob($user_pk, "wget", $uploadpk);
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to insert job record");
         return $text;
     }
     $jq_args = "{$uploadpk} - {$SourceFiles}";
     $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, "no", NULL, $HostName);
     if (empty($jobqueuepk)) {
         $text = _("Failed to insert task 'wget' into job queue");
         return $text;
     }
     /* schedule agents */
     $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
     $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array("wget_agent"));
     if ($ununpack_jq_pk < 0) {
         return $ErrorMsg;
     }
     $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
     $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array());
     if ($adj2nest_jq_pk < 0) {
         return $ErrorMsg;
     }
     AgentCheckBoxDo($jobpk, $uploadpk);
     $msg = "";
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     if (empty($status)) {
         $msg .= _("Is the scheduler running? ");
     }
     $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadpk}";
     $msg .= "The file {$SourceFiles} has been uploaded. ";
     $keep = "It is <a href='{$Url}'>upload #" . $uploadpk . "</a>.\n";
     print displayMessage($msg, $keep);
     return NULL;
 }
Exemplo n.º 5
0
 /**
  * \brief Process the upload request.
  * \param $Folder
  * \param $VCSType
  * \param $GetURL
  * \param $Desc
  * \param $Name
  * \param $Username
  * \param $Passwd 
  * \param $public_perm public permission on the upload
  * Returns NULL on success, string on failure.
  */
 function Upload($Folder, $VCSType, $GetURL, $Desc, $Name, $Username, $Passwd, $public_perm)
 {
     global $SysConf;
     /* See if the URL looks valid */
     if (empty($Folder)) {
         $text = _("Invalid folder");
         return $text;
     }
     $GetURL = trim($GetURL);
     if (empty($GetURL)) {
         $text = _("Invalid URL");
         return $text;
     }
     if (preg_match("@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $GetURL) != 1) {
         $text = _("Invalid URL");
         return "{$text}: " . htmlentities($GetURL);
     }
     if (preg_match("@[[:space:]]@", $GetURL) != 0) {
         $text = _("Invalid URL (no spaces permitted)");
         return "{$text}: " . htmlentities($GetURL);
     }
     if (empty($Name)) {
         $Name = basename($GetURL);
     }
     $ShortName = basename($Name);
     if (empty($ShortName)) {
         $ShortName = $Name;
     }
     /* Create an upload record. */
     $Mode = 1 << 2;
     // code for "it came from wget"
     $user_pk = $SysConf['auth']['UserId'];
     $uploadpk = JobAddUpload($user_pk, $ShortName, $GetURL, $Desc, $Mode, $Folder, $public_perm);
     if (empty($uploadpk)) {
         $text = _("Failed to insert upload record");
         return $text;
     }
     /* Create the job: job "wget" */
     $jobpk = JobAddJob($user_pk, "wget", $uploadpk);
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to insert job record");
         return $text;
     }
     $jq_args = "{$uploadpk} - {$GetURL} {$VCSType} ";
     if (!empty($Username)) {
         $jq_args .= "--username {$Username} ";
     }
     if (!empty($Passwd)) {
         $jq_args .= "--password {$Passwd}";
     }
     $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, NULL, NULL);
     if (empty($jobqueuepk)) {
         $text = _("Failed to insert task 'wget_agent' into job queue");
         return $text;
     }
     global $Plugins;
     /* schedule agents */
     $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
     $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array("wget_agent"));
     if ($ununpack_jq_pk < 0) {
         return $ErrorMsg;
     }
     $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
     $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array());
     if ($adj2nest_jq_pk < 0) {
         return $ErrorMsg;
     }
     AgentCheckBoxDo($jobpk, $uploadpk);
     $msg = "";
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     if (empty($status)) {
         $msg .= _("Is the scheduler running? ");
     }
     $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadpk}";
     $text = _("The upload");
     $text1 = _("has been queued. It is");
     $msg .= "{$text} {$Name} {$text1} ";
     $keep = "<a href='{$Url}'>upload #" . $uploadpk . "</a>.\n";
     print displayMessage($msg, $keep);
     return NULL;
 }
Exemplo n.º 6
0
 /**
  * \brief Process the upload request.
  *
  * \param $folder_pk
  * \param $TempFile path to temporary (upload) file
  * \param $Desc optional upload description.
  * \param $Name original name of the file on the client machine.
  * \param $public_perm public permission on the upload
  * \return NULL on success, error string on failure.
  */
 function Upload($folder_pk, $TempFile, $Desc, $Name, $public_perm)
 {
     global $MODDIR;
     global $SysConf;
     global $SYSCONFDIR;
     define("UPLOAD_ERR_EMPTY", 5);
     define("UPLOAD_ERR_INVALID_FOLDER_PK", 100);
     $upload_errors = array(UPLOAD_ERR_OK => _("No errors."), UPLOAD_ERR_INI_SIZE => _("Larger than upload_max_filesize ") . ini_get('upload_max_filesize'), UPLOAD_ERR_FORM_SIZE => _("Larger than form MAX_FILE_SIZE."), UPLOAD_ERR_PARTIAL => _("Partial upload."), UPLOAD_ERR_NO_FILE => _("No file."), UPLOAD_ERR_NO_TMP_DIR => _("No temporary directory."), UPLOAD_ERR_CANT_WRITE => _("Can't write to disk."), UPLOAD_ERR_EXTENSION => _("File upload stopped by extension."), UPLOAD_ERR_EMPTY => _("File is empty or you don't have permission to read the file."), UPLOAD_ERR_INVALID_FOLDER_PK => _("Invalid Folder."));
     $UploadFile = $_FILES['getfile'];
     $UploadError = @$UploadFile['error'];
     /* Additional error checks */
     if ($UploadFile['size'] == 0 && $UploadFile['error'] == 0) {
         $UploadFile['error'] = UPLOAD_ERR_EMPTY;
     }
     if (empty($folder_pk)) {
         $UploadFile['error'] = UPLOAD_ERR_INVALID_FOLDER_PK;
     }
     if ($UploadFile['error'] != UPLOAD_ERR_OK) {
         return $upload_errors[$UploadFile['error']];
     }
     $originName = @$UploadFile['name'];
     if (empty($Name)) {
         $Name = basename($originName);
     }
     $ShortName = basename($Name);
     if (empty($ShortName)) {
         $ShortName = $Name;
     }
     // for odd case where $Name is '/'
     /* Create an upload record. */
     $Mode = 1 << 3;
     // code for "it came from web upload"
     $user_pk = $SysConf['auth']['UserId'];
     $uploadpk = JobAddUpload($user_pk, $ShortName, $originName, $Desc, $Mode, $folder_pk, $public_perm);
     if (empty($uploadpk)) {
         $text = _("Failed to insert upload record");
         return $text;
     }
     /* move the temp file */
     $UploadedFile = "{$TempFile}" . "-uploaded";
     if (!move_uploaded_file($TempFile, "{$UploadedFile}")) {
         $text = _("Could not save uploaded file");
         return $text;
     }
     if (!chmod($UploadedFile, 0660)) {
         $text = _("ERROR! could not update permissions on downloaded file");
         return $text;
     }
     /* Run wget_agent locally to import the file. */
     $Prog = "{$MODDIR}/wget_agent/agent/wget_agent -C -g fossy -k {$uploadpk} '{$UploadedFile}' -c '{$SYSCONFDIR}'";
     $wgetOut = array();
     $wgetLast = exec($Prog, $wgetOut, $wgetRtn);
     unlink($UploadedFile);
     /* Create Job */
     $job_pk = JobAddJob($user_pk, $ShortName, $uploadpk);
     global $Plugins;
     $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
     $Dependencies = array();
     $adj2nestplugin->AgentAdd($job_pk, $uploadpk, $ErrorMsg, $Dependencies);
     AgentCheckBoxDo($job_pk, $uploadpk);
     if ($wgetRtn == 0) {
         $Msg = "";
         /** check if the scheudler is running */
         $status = GetRunnableJobList();
         if (empty($status)) {
             $Msg .= _("Is the scheduler running? ");
         }
         $text = _("The file");
         $text1 = _("has been uploaded. It is");
         $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadpk}";
         $Msg .= "{$text} {$Name} {$text1} ";
         $keep = '<a href=' . $Url . '>upload #' . $uploadpk . "</a>.\n";
         print displayMessage($Msg, $keep);
         return NULL;
     } else {
         $ErrMsg = GetArrayVal(0, $wgetOut);
         if (empty($ErrMsg)) {
             $ErrMsg = _("File upload failed.  Error:") . $wgetRtn;
         }
         return $ErrMsg;
     }
     return NULL;
 }