예제 #1
0
/**
 * \brief Given one object (file or URL), upload it.
 *
 * \param $FolderPath - folder path
 * \param $UploadArchive - upload file(absolute path) or url
 * \param $UploadName - uploaded file/dir name
 * \param $UploadDescription - upload description
 *
 * \return 1: error, 0: success
 */
function UploadOne($FolderPath, $UploadArchive, $UploadName, $UploadDescription, $TarSource = NULL)
{
    global $Verbose;
    global $Test;
    global $QueueList;
    global $fossjobs_command;
    global $public_flag;
    global $SysConf;
    if (empty($UploadName)) {
        $text = "UploadName is empty\n";
        echo $text;
        return 1;
    }
    $user_pk = $SysConf['auth']['UserId'];
    /* Get the user record and check the PLUGIN_DB_ level to make sure they have at least write access */
    $UsersRow = GetSingleRec("users", "where user_pk={$user_pk}");
    if ($UsersRow["user_perm"] < PLUGIN_DB_WRITE) {
        print "You have no permission to upload files into FOSSology\n";
        return 1;
    }
    /* Get the folder's primary key */
    $root_folder_fk = $UsersRow["root_folder_fk"];
    global $OptionA;
    /* Should it use bucket names? */
    if ($OptionA) {
        global $bucket_size;
        $FolderPath .= "/" . GetBucketFolder($UploadName, $bucket_size);
    }
    $FolderPk = GetFolder($FolderPath, $root_folder_fk);
    if ($FolderPk == 1) {
        print "  Uploading to folder: 'Software Repository'\n";
    } else {
        print "  Uploading to folder: '{$FolderPath}'\n";
    }
    print "  Uploading as '{$UploadName}'\n";
    if (!empty($UploadDescription)) {
        print "  Upload description: '{$UploadDescription}'\n";
    }
    $Mode = 1 << 3;
    // code for "it came from web upload"
    /* Create the upload for the file */
    if ($Verbose) {
        print "JobAddUpload({$user_pk}, {$UploadName},{$UploadArchive},{$UploadDescription},{$Mode},{$FolderPk}, {$public_flag});\n";
    }
    if (!$Test) {
        $Src = $UploadArchive;
        if (!empty($TarSource)) {
            $Src = $TarSource;
        }
        $UploadPk = JobAddUpload($user_pk, $UploadName, $Src, $UploadDescription, $Mode, $FolderPk, $public_flag);
        print "  UploadPk is: '{$UploadPk}'\n";
    }
    /* Prepare the job: job "wget" */
    if ($Verbose) {
        print "JobAddJob({$user_pk}, wget, {$UploadPk});\n";
    }
    if (!$Test) {
        $jobpk = JobAddJob($user_pk, "wget", $UploadPk);
        if (empty($jobpk) || $jobpk < 0) {
            $text = _("Failed to insert job record");
            echo $text;
            return 1;
        }
    }
    $jq_args = "{$UploadPk} - {$Src}";
    if ($Verbose) {
        print "JobQueueAdd({$jobpk}, wget_agent, {$jq_args}, no, NULL);\n";
    }
    if (!$Test) {
        $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, "no", NULL);
        if (empty($jobqueuepk)) {
            $text = _("Failed to insert task 'wget' into job queue");
            echo $text;
            return 1;
        }
    }
    /* schedule agents */
    global $Plugins;
    if ($Verbose) {
        print "AgentAdd wget_agent and dj2nest.\n";
    }
    if (!$Test) {
        $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
        $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $UploadPk, $ErrorMsg, array("wget_agent"));
        if ($ununpack_jq_pk < 0) {
            echo $ErrorMsg;
            return 1;
        }
        $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
        $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $UploadPk, $ErrorMsg, array());
        if ($adj2nest_jq_pk < 0) {
            echo $ErrorMsg;
            return 1;
        }
    }
    if (!empty($QueueList)) {
        switch ($QueueList) {
            case 'ALL':
            case 'all':
                $Cmd = "{$fossjobs_command} -U '{$UploadPk}'";
                break;
            default:
                $Cmd = "{$fossjobs_command} -U '{$UploadPk}' -A '{$QueueList}'";
                break;
        }
        if ($Verbose) {
            print "CMD={$Cmd}\n";
        }
        if (!$Test) {
            system($Cmd);
        }
    } else {
        /* No other agents other than unpack scheduled, attach to unpack*/
    }
}
예제 #2
0
/**
 * \brief Given one object (file or URL), upload it.
 *
 * \param $FolderPath - folder path
 * \param $UploadArchive - upload file(absolute path) or url
 * \param $UploadName - uploaded file/dir name
 * \param $UploadDescription - upload description
 *
 * \return 1: error, 0: success
 */
function UploadOne($FolderPath, $UploadArchive, $UploadName, $UploadDescription, $TarSource = NULL)
{
    global $Verbose;
    global $Test;
    global $QueueList;
    global $fossjobs_command;
    global $public_flag;
    global $SysConf;
    global $PG_CONN;
    global $VCS;
    global $vcsuser;
    global $vcspass;
    global $TarExcludeList;
    $jobqueuepk = 0;
    if (empty($UploadName)) {
        $text = "UploadName is empty\n";
        echo $text;
        return 1;
    }
    $user_pk = $SysConf['auth']['UserId'];
    $group_pk = $SysConf['auth']['GroupId'];
    /* Get the user record and check the PLUGIN_DB_ level to make sure they have at least write access */
    $UsersRow = GetSingleRec("users", "where user_pk={$user_pk}");
    if ($UsersRow["user_perm"] < PLUGIN_DB_WRITE) {
        print "You have no permission to upload files into FOSSology\n";
        return 1;
    }
    /* Get the folder's primary key */
    $root_folder_fk = $UsersRow["root_folder_fk"];
    global $OptionA;
    /* Should it use bucket names? */
    if ($OptionA) {
        global $bucket_size;
        $FolderPath .= "/" . GetBucketFolder($UploadName, $bucket_size);
    }
    $FolderPk = GetFolder($FolderPath, $root_folder_fk);
    if ($FolderPk == 1) {
        print "  Uploading to folder: 'Software Repository'\n";
    } else {
        print "  Uploading to folder: '{$FolderPath}'\n";
    }
    print "  Uploading as '{$UploadName}'\n";
    if (!empty($UploadDescription)) {
        print "  Upload description: '{$UploadDescription}'\n";
    }
    $Mode = 1 << 3;
    // code for "it came from web upload"
    /* Create the upload for the file */
    if ($Verbose) {
        print "JobAddUpload({$user_pk}, {$group_pk}, {$UploadName},{$UploadArchive},{$UploadDescription},{$Mode},{$FolderPk}, {$public_flag});\n";
    }
    if (!$Test) {
        $Src = $UploadArchive;
        if (!empty($TarSource)) {
            $Src = $TarSource;
        }
        $UploadPk = JobAddUpload($user_pk, $group_pk, $UploadName, $Src, $UploadDescription, $Mode, $FolderPk, $public_flag);
        print "  UploadPk is: '{$UploadPk}'\n";
    }
    /* Prepare the job: job "wget" */
    if ($Verbose) {
        print "JobAddJob({$user_pk}, {$group_pk}, wget, {$UploadPk});\n";
    }
    if (!$Test) {
        $jobpk = JobAddJob($user_pk, $group_pk, "wget", $UploadPk);
        if (empty($jobpk) || $jobpk < 0) {
            $text = _("Failed to insert job record");
            echo $text;
            return 1;
        }
    }
    $jq_args = "{$UploadPk} - {$Src}";
    if ($TarExcludeList) {
        $jq_args .= " " . $TarExcludeList;
    }
    if ($VCS) {
        $jq_args .= " " . $VCS;
    }
    // add flags when upload from version control system
    if ($vcsuser && $vcspass) {
        $jq_args .= " --username {$vcsuser} --password {$vcspass} ";
    }
    if ($Verbose) {
        print "JobQueueAdd({$jobpk}, wget_agent, {$jq_args}, no, NULL);\n";
    }
    if (!$Test) {
        $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, "no", NULL);
        if (empty($jobqueuepk)) {
            $text = _("Failed to insert task 'wget' into job queue");
            echo $text;
            return 1;
        }
    }
    /* schedule agents */
    global $Plugins;
    if ($Verbose) {
        print "AgentAdd wget_agent and dj2nest.\n";
    }
    if (!$Test) {
        $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
        $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $UploadPk, $ErrorMsg, array("wget_agent"));
        if ($ununpack_jq_pk < 0) {
            echo $ErrorMsg;
            return 1;
        }
        $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
        $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $UploadPk, $ErrorMsg, array());
        if ($adj2nest_jq_pk < 0) {
            echo $ErrorMsg;
            return 1;
        }
    }
    if (!empty($QueueList)) {
        switch ($QueueList) {
            case 'ALL':
            case 'all':
                $Cmd = "{$fossjobs_command} -U '{$UploadPk}'";
                break;
            default:
                $Cmd = "{$fossjobs_command} -U '{$UploadPk}' -A '{$QueueList}'";
                break;
        }
        if ($Verbose) {
            print "CMD={$Cmd}\n";
        }
        if (!$Test) {
            system($Cmd);
        }
    } else {
        /* No other agents other than unpack scheduled, attach to unpack*/
    }
    global $OptionS;
    /* Should it run synchronously? */
    if ($OptionS) {
        $working = true;
        $waitCount = 0;
        while ($working && $waitCount++ < 30) {
            sleep(3);
            $SQL = "select * from jobqueue inner join job on job.job_pk = jobqueue.jq_job_fk where job_upload_fk = '{$UploadPk}' and jq_end_bits = 0 and jq_type = 'wget_agent'";
            $result = pg_query($PG_CONN, $SQL);
            DBCheckResult($result, $SQL, __FILE__, __LINE__);
            $row_count = pg_num_rows($result);
            pg_free_result($result);
            if ($row_count == 0) {
                $working = false;
            }
        }
        if ($working) {
            echo "Gave up waiting for copy completion. Is the scheduler running?";
            return 1;
        }
    }
}
// $username = "******";
// $password = "******";
$mbox = imap_open($server, $username, $password, OP_HALFOPEN) or die("unable to connect: " . imap_last_error());
// $list = @imap_getsubscribed($mbox, $server, "*");
$list = imap_getmailboxes($mbox, $server, "*");
// print_r($list);
if (is_array($list)) {
    $folders = array();
    // reverse list to obtain folders in right order
    $list = array_reverse($list);
    foreach ($list as $val) {
        $box = array();
        // cut off serverstring
        $imapid = substr($val->name, strlen($server));
        printf("Evaluating %s\n", $imapid);
        GetFolder($imapid);
        $fhir = explode($val->delimiter, $imapid);
        if (count($fhir) > 1) {
            if (defined('IMAP_FOLDER_PREFIX') && strlen(IMAP_FOLDER_PREFIX) > 0) {
                if (strcasecmp($fhir[0], IMAP_FOLDER_PREFIX) == 0) {
                    //                     printf("Removing prefix\n");
                    // Discard prefix
                    array_shift($fhir);
                }
            }
            if (count($fhir) == 1) {
                $box["mod"] = $fhir[0];
                $box["parent"] = "0";
            } else {
                //                 printf("Subfolder\n");
                getModAndParentNames($fhir, $box["mod"], $imapparent);