Ignore:
Timestamp:
2015-05-12T21:47:35+12:00 (9 years ago)
Author:
ak19
Message:

First part of commit for ensuring the user is authenticated when running the scripts used by the online metadata editor. Running metaserver, BuildAndActivate and other GS2Construct.java commands should not be possible from a web browser.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build/GS2PerlConstructor.java

    r29576 r29869  
    3333    public static final int BUILD = 2;
    3434    public static final int ACTIVATE = 3;
     35    public static final int SET_METADATA_SERVER = 4;
    3536
    3637    /**
     
    118119        case ACTIVATE:
    119120            activateCollection();
     121            break;
     122        case SET_METADATA_SERVER:
     123            setMetadataForCollection();
    120124            break;
    121125        default:
     
    202206        command.add("-collectdir");
    203207        command.add(GSFile.collectDir(this.site_home));
     208        command.add("-removeold"); // saves some seconds processing time when this flag's added in explicitly
    204209        command.addAll(extractParameters(this.process_params));
    205210        command.add(this.collection_name);
     
    272277        command.add("-collectdir");
    273278        command.add(GSFile.collectDir(this.site_home));
     279        command.add("-removeold"); // saves some seconds processing time when this flag's added in explicitly
    274280        command.addAll(extractParameters(this.process_params));
    275281        command.add(this.collection_name);
     
    279285
    280286        if (runPerlCommand(command_str))
     287        {
     288            // success!! - need to send the final completed message
     289            sendProcessComplete(new ConstructionEvent(this, GSStatus.COMPLETED, ""));
     290        }// else an error message has already been sent, do nothing     
     291
     292    }
     293
     294
     295    protected void setMetadataForCollection()
     296    {
     297        sendMessage(new ConstructionEvent(this, GSStatus.INFO, "Collection metadata: setMetadata for collection."));
     298
     299        Vector<String> command = new Vector<String>();
     300
     301        String perlPath = GlobalProperties.getProperty("perl.path", "perl");
     302        if (perlPath.charAt(perlPath.length() - 1) != File.separatorChar)
     303        {
     304            perlPath = perlPath + File.separator;
     305        }
     306
     307        String cgi_directory = GlobalProperties.getGSDL3Home() + File.separator + "WEB-INF" + File.separator + "cgi";
     308        command.add(perlPath + "perl");
     309        command.add("-S");
     310        //command.add(GlobalProperties.getGSDL3Home() + File.separator + "WEB-INF" + File.separator + "cgi" + File.separator + "metadata-server.pl");
     311        command.add(cgi_directory + File.separator + "metadata-server.pl");
     312       
     313        // Need to set QUERY_STRING and REQUEST_METHOD=GET in environment
     314        // http://www.cgi101.com/class/ch3/text.html
     315        String[] envvars = {
     316            "QUERY_STRING=" + this.query_string,
     317            "REQUEST_METHOD=GET"
     318        };
     319
     320        String[] command_str = {};
     321        command_str = command.toArray(command_str);
     322
     323        // http://www.cgi101.com/class/ch3/text.html
     324        // setenv QUERY_STRING and REQUEST_METHOD = GET.
     325        if (runPerlCommand(command_str, envvars, new File(cgi_directory)))
     326                   //new File(GlobalProperties.getGSDL3Home() + File.separator + "WEB-INF" + File.separator + "cgi")))
    281327        {
    282328            // success!! - need to send the final completed message
     
    316362
    317363    /** returns true if completed correctly, false otherwise */
    318     protected boolean runPerlCommand(String[] command)
     364    protected boolean runPerlCommand(String[] command) {
     365    return runPerlCommand(command, null, null);
     366    }
     367
     368    protected boolean runPerlCommand(String[] command, String[] envvars, File dir)
    319369    {
    320370        int sepIndex = this.gsdl3home.lastIndexOf(File.separator);
     
    329379        args.add("PERL_PERTURB_KEYS=0");
    330380
     381        if(envvars != null) {
     382            for(int i = 0; i < envvars.length; i++) {
     383            args.add(envvars[i]);
     384            }
     385        }
     386
    331387        for (String a : System.getenv().keySet())
    332388        {
     
    345401            Runtime rt = Runtime.getRuntime();
    346402            sendProcessBegun(new ConstructionEvent(this, GSStatus.ACCEPTED, "starting"));
    347             Process prcs = rt.exec(command, args.toArray(new String[args.size()]));
     403            Process prcs = (dir == null)
     404                ? rt.exec(command, args.toArray(new String[args.size()]))
     405                : rt.exec(command, args.toArray(new String[args.size()]), dir);
    348406
    349407            InputStreamReader eisr = new InputStreamReader(prcs.getErrorStream());
Note: See TracChangeset for help on using the changeset viewer.