/**
  * \brief get the job list for the specified operation
  * \param $type operation type, the job list is different 
  *        according to the type of the operation
  * \return job list as array of <option> elements
  **/
 function JobListOption($type)
 {
     $job_list_option = "";
     $job_array = array();
     if (empty($type)) {
         return '';
     } else {
         if ('status' == $type || 'verbose' == $type || 'priority' == $type) {
             /* you can select scheduler besides jobs for 'status' and 'verbose',
                for 'priority', only jobs to select */
             if ('priority' != $type) {
                 $job_list_option .= "<option value='0'>scheduler</option>";
             }
             $job_array = GetRunnableJobList();
         }
     }
     /* get job list from the table jobqueque */
     if ('pause' == $type) {
         $job_array = GetJobList("tart");
     }
     if ('restart' == $type) {
         $job_array = GetJobList("Paused");
     }
     for ($i = 0; $i < sizeof($job_array); $i++) {
         $job_id = $job_array[$i];
         $job_list_option .= "<option value='{$job_id}'>{$job_id}</option>";
     }
     return $job_list_option;
 }
Ejemplo n.º 2
0
 /**
  * \brief get the job list for the operation 'status'
  * \return job list
  **/
 function JobListOption()
 {
     $job_list_option = "<option value='0'>scheduler</option>";
     $operation = GetParm('operation', PARM_TEXT);
     if ("stop" === $operation) {
         return $job_list_option;
     }
     $job_array = GetRunnableJobList();
     /* get all job list */
     for ($i = 0; $i < sizeof($job_array); $i++) {
         $job_id = $job_array[$i];
         $job_list_option .= "<option value='{$job_id}'>{$job_id}</option>";
     }
     return $job_list_option;
 }
Ejemplo n.º 3
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $folderId = intval($request->get('folder'));
     if (empty($folderId)) {
         $folderId = FolderGetTop();
     }
     $uploadId = intval($request->get('upload'));
     $agents = $request->get('agents') ?: '';
     if (!empty($uploadId) && !empty($agents) && is_array($agents)) {
         $rc = $this->agentsAdd($uploadId, $agents, $request);
         if (empty($rc)) {
             $status = GetRunnableJobList();
             $scheduler_msg = empty($status) ? _("Is the scheduler running? ") : '';
             $url = Traceback_uri() . "?mod=showjobs&upload={$uploadId}";
             $text = _("Your jobs have been added to job queue.");
             $linkText = _("View Jobs");
             $msg = "{$scheduler_msg}" . "{$text} <a href=\"{$url}\">{$linkText}</a>";
             $vars['message'] = $msg;
         } else {
             $text = _("Scheduling of Agent(s) failed: ");
             $vars['message'] = $text . $rc;
         }
     }
     $vars['uploadScript'] = ActiveHTTPscript("Uploads");
     $vars['agentScript'] = ActiveHTTPscript("Agents");
     $vars['folderId'] = $folderId;
     $vars['folderListOptions'] = FolderListOption(-1, 0, 1, $folderId);
     $vars['folderListUploads'] = FolderListUploads_perm($folderId, Auth::PERM_WRITE);
     $vars['baseUri'] = Traceback_uri();
     $vars['uploadId'] = $uploadId;
     $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents");
     $out = '<ol>';
     $parmAgentFoots = '';
     foreach ($parmAgentList as $parmAgent) {
         $agent = plugin_find($parmAgent);
         $out .= "<br/><b>" . $agent->AgentName . ":</b><br/>";
         $out .= $agent->renderContent($vars);
         $parmAgentFoots .= $agent->renderFoot($vars);
     }
     $out .= '</ol>';
     $vars['out'] = $out;
     $vars['outFoot'] = '<script language="javascript"> ' . $parmAgentFoots . '</script>';
     return $this->render('agent_adder.html.twig', $this->mergeWithDefault($vars));
 }
Ejemplo n.º 4
0
 /**
  * \brief Display the loaded menu and plugins.
  */
 public function Output()
 {
     global $Plugins;
     global $PG_CONN;
     $UploadPk = GetParm("upload", PARM_INTEGER);
     $Agent = GetParm("agent", PARM_STRING);
     if (empty($UploadPk) || empty($Agent)) {
         return new Response('missing parameter', Response::HTTP_BAD_REQUEST, array('Content-type' => 'text/plain'));
     }
     $sql = "SELECT upload_pk, upload_filename FROM upload WHERE upload_pk = '{$UploadPk}'";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     if (pg_num_rows($result) < 1) {
         $errMsg = __FILE__ . ":" . __LINE__ . " " . _("Upload") . " " . $UploadPk . " " . _("not found");
         return new Response($errMsg, Response::HTTP_BAD_REQUEST, array('Content-type' => 'text/plain'));
     }
     $UploadRow = pg_fetch_assoc($result);
     $ShortName = $UploadRow['upload_filename'];
     pg_free_result($result);
     $user_pk = Auth::getUserId();
     $group_pk = Auth::getGroupId();
     $job_pk = JobAddJob($user_pk, $group_pk, $ShortName, $UploadPk);
     $Dependencies = array();
     $P =& $Plugins[plugin_find_id($Agent)];
     $rv = $P->AgentAdd($job_pk, $UploadPk, $ErrorMsg, $Dependencies);
     if ($rv <= 0) {
         $text = _("Scheduling of Agent(s) failed: ");
         return new Response($text . $rv . $ErrorMsg, Response::HTTP_BAD_REQUEST, array('Content-type' => 'text/plain'));
     }
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     $scheduler_msg = "";
     if (empty($status)) {
         $scheduler_msg .= _("Is the scheduler running? ");
     }
     $URL = Traceback_uri() . "?mod=showjobs&upload={$UploadPk}";
     /* Need to refresh the screen */
     $text = _("Your jobs have been added to job queue.");
     $LinkText = _("View Jobs");
     $msg = "{$scheduler_msg}" . "{$text} <a href={$URL}>{$LinkText}</a>";
     $this->vars['message'] = $msg;
     return new Response($msg, Response::HTTP_OK, array('Content-type' => 'text/plain'));
 }
Ejemplo n.º 5
0
 /**
  * @brief get the job list for the specified operation
  * @param string $type operation type
  * @return array job list of option elements
  **/
 function jobListOption($type)
 {
     if (empty($type)) {
         return array();
     }
     $job_array = array();
     if ('status' == $type || 'verbose' == $type || 'priority' == $type) {
         $job_array = GetRunnableJobList();
         if ('priority' != $type) {
             $job_array[0] = "scheduler";
         }
     }
     if ('pause' == $type) {
         $job_array = GetJobList("Started");
     }
     if ('restart' == $type) {
         $job_array = GetJobList("Paused");
     }
     return $job_array;
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
 protected function postUploadAddJobs(Request $request, $fileName, $uploadId, $jobId = null, $wgetDependency = false)
 {
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     if ($jobId === null) {
         $jobId = JobAddJob($userId, $groupId, $fileName, $uploadId);
     }
     $dummy = "";
     $adj2nestDependencies = array();
     if ($wgetDependency) {
         $adj2nestDependencies = array(array('name' => 'agent_unpack', AgentPlugin::PRE_JOB_QUEUE => array('wget_agent')));
     }
     $adj2nestplugin = \plugin_find('agent_adj2nest');
     $adj2nestplugin->AgentAdd($jobId, $uploadId, $dummy, $adj2nestDependencies);
     $checkedAgents = checkedAgents();
     AgentSchedule($jobId, $uploadId, $checkedAgents);
     $errorMsg = '';
     $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents");
     $plainAgentList = MenuHook::getAgentPluginNames("Agents");
     $agentList = array_merge($plainAgentList, $parmAgentList);
     foreach ($parmAgentList as $parmAgent) {
         $agent = plugin_find($parmAgent);
         $agent->scheduleAgent($jobId, $uploadId, $errorMsg, $request, $agentList);
     }
     $status = GetRunnableJobList();
     $message = empty($status) ? _("Is the scheduler running? ") : "";
     $jobUrl = Traceback_uri() . "?mod=showjobs&upload={$uploadId}";
     $message .= _("The file") . " " . $fileName . " " . _("has been uploaded. It is") . ' <a href=' . $jobUrl . '>upload #' . $uploadId . "</a>.\n";
     if ($request->get('public') == self::PUBLIC_GROUPS) {
         $this->getObject('dao.upload.permission')->makeAccessibleToAllGroupsOf($uploadId, $userId);
     }
     return $message;
 }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
0
 /**
  * \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;
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
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;
 }