Changeset 1432


Ignore:
Timestamp:
2000-08-20T20:44:06+12:00 (24 years ago)
Author:
sjboddie
Message:

Lots of changes - mostly to get collectoraction working

Location:
trunk/gsdl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/lib/cfgread.cpp

    r1421 r1432  
    6969  }
    7070  fileout << "\n";
     71  return 0;
    7172}
    7273
  • trunk/gsdl/src/recpt/authenaction.cpp

    r1402 r1432  
    242242      arg_er.clear();
    243243   
     244    // needs to be decoded for use within forms
     245    decode_cgi_arg (arg_er);   
     246
    244247    // redirect to this action
    245248    args_a = "a";
  • trunk/gsdl/src/recpt/collectoraction.cpp

    r1425 r1432  
    3434#include "fileutil.h"
    3535#include "cfgread.h"
     36#include "gsdltools.h"
    3637
    3738#if !defined (__WIN32__)
     
    4445  recpt = NULL;
    4546  do_mkcol = false;
     47  clone_failed = false;
    4648
    4749  cgiarginfo arg_ainfo;
     
    110112  argsinfo.addarginfo (NULL, arg_ainfo);
    111113
     114  // set when cloning option has changed
     115  arg_ainfo.shortname = "bc1clonechanged";
     116  arg_ainfo.longname = "collector specific";
     117  arg_ainfo.multiplechar = false;
     118  arg_ainfo.defaultstatus = cgiarginfo::weak;
     119  arg_ainfo.argdefault = "0";
     120  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
     121  argsinfo.addarginfo (NULL, arg_ainfo);
     122
    112123  arg_ainfo.shortname = "bc1inputdir1";
    113124  arg_ainfo.longname = "collector specific";
     
    160171  arg_ainfo.argdefault = "0";
    161172  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
     173  argsinfo.addarginfo (NULL, arg_ainfo);
     174
     175  arg_ainfo.shortname = "bc1dodelete";
     176  arg_ainfo.longname = "collector specific";
     177  arg_ainfo.multiplechar = false;
     178  arg_ainfo.defaultstatus = cgiarginfo::weak;
     179  arg_ainfo.argdefault = "0";
     180  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
     181  argsinfo.addarginfo (NULL, arg_ainfo);
     182
     183  // will be set if we arrived at the "configure collection" page
     184  // via the "changing an existing collection" page
     185  arg_ainfo.shortname = "bc1econf";
     186  arg_ainfo.longname = "collector specific";
     187  arg_ainfo.multiplechar = false;
     188  arg_ainfo.defaultstatus = cgiarginfo::weak;
     189  arg_ainfo.argdefault = "0";
     190  arg_ainfo.savedarginfo = cgiarginfo::must;
     191  argsinfo.addarginfo (NULL, arg_ainfo);
     192
     193  // will be set if we arrived at the "source data" page
     194  // via the "changing an existing collection" page
     195  arg_ainfo.shortname = "bc1esrce";
     196  arg_ainfo.longname = "collector specific";
     197  arg_ainfo.multiplechar = false;
     198  arg_ainfo.defaultstatus = cgiarginfo::weak;
     199  arg_ainfo.argdefault = "0";
     200  arg_ainfo.savedarginfo = cgiarginfo::must;
    162201  argsinfo.addarginfo (NULL, arg_ainfo);
    163202}
     
    200239
    201240  if (args["cp"] != "intro") {
    202     // authenticate the user if authentication is avaiable
     241    // authenticate the user if authentication is available
    203242    args["uan"] = 1;
    204243    args["ug"] = "colbuilder";
     
    215254      args["bc1dirname"] = get_directory_name (args["bc1fullname"]);
    216255      do_mkcol = true;
    217 
    218256    } else {
    219257      // "collection information" has been changed after collection was made
     
    230268  }
    231269 
     270  if (args["bc1clonechanged"] == "1") {
     271    // cloning option has been changed on "source data" page. if it was turned
     272    // on we want to create a new collect.cfg file using the bc1clonecol cfg file
     273    // as a model (we'll save the old file as collect.cfg.org). if cloning was
     274    // turned off we'll revert to using the collect.cfg.org file (which will need
     275    // updating in case the bc1 arguments have been altered since cloning was
     276    // turned on).
     277    update_cfgfile_clone (args, logout);
     278  }
     279
    232280  return true;
     281}
     282
     283void collectoraction::update_cfgfile_clone (cgiargsclass &args, ostream &logout) {
     284
     285  text_t cfgfile = filename_cat(gsdlhome, "collect", args["bc1dirname"], "etc", "collect.cfg");
     286  text_t cfgfile_org = cfgfile + ".org";
     287
     288  if (args["bc1clone"] == "1") {
     289    // cloning was turned on
     290
     291    text_t cfgfile_clone = filename_cat(gsdlhome, "collect", args["bc1clonecol"], "etc", "collect.cfg");
     292    if (file_exists (cfgfile_clone)) {
     293      // if .org file doesn't exist already create it
     294      if (!file_exists (cfgfile_org)) {
     295    file_copy (cfgfile, cfgfile_org);
     296      }
     297      // copy clone collections cfg file to new collection
     298      file_copy (cfgfile_clone, cfgfile);
     299      // update the new cfg file
     300      update_cfgfile_partial (args, logout);
     301     
     302    } else {
     303      // can't clone non-existant collection
     304      clone_failed = true;
     305    }
     306
     307  } else {
     308    // cloning has been turned off having been on at some point. the .org file
     309    // should exist, if it doesn't we'll bail out and leave the user with the
     310    // cloned copy
     311    if (file_exists (cfgfile_org)) {
     312      // copy original back again and update it with any recent changes
     313      file_copy (cfgfile_org, cfgfile);
     314      update_cfgfile_partial (args, logout);
     315    }
     316  }
    233317}
    234318
     
    247331    while (read_cfg_line(cfg_in, cfgline) >= 0) {
    248332      if (cfgline.size () >= 2) {
    249     if (cfgline[0] == "creator") {
     333    if (cfgline[0] == "creator" || cfgline[0] == "maintainer") {
    250334      cfgline[1] = args["bc1contactemail"];
    251335    } else if (cfgline[0] == "collectionmeta") {
     
    262346
    263347    // now write cfg file back out
     348#ifdef __WIN32__
     349    ofstream cfg_out (cfgfilec, ios::binary);
     350#else
    264351    ofstream cfg_out (cfgfilec);
     352#endif
    265353    if (cfg_out) {
    266354      // lock the file
     
    285373
    286374    } else {
    287       logout << "collectoraction::update_cfgfile_partial: unable to open " 
     375      logout << "collectoraction::update_cfgfile_partial: unable to open "
    288376         << cfgfilec << " for output\n";
    289377    }
    290378
    291379  } else {
    292     logout << "collectoraction::update_cfgfile_partial: unable to open " 
     380    logout << "collectoraction::update_cfgfile_partial: unable to open "
    293381       << cfgfilec << " for input\n";
    294382  }
     
    302390  text_t cfgfile = filename_cat(gsdlhome, "collect", args["bc1dirname"], "etc", "collect.cfg");
    303391  char *cfgfilec = cfgfile.getcstr();
     392#ifdef __WIN32__
     393  ofstream cfg_out (cfgfilec, ios::binary);
     394#else
    304395  ofstream cfg_out (cfgfilec);
     396#endif
    305397 
    306398  if (cfg_out) {
     
    405497  }
    406498
    407   text_t &currentname = args["bc1clonecol"];
    408   text_t fullnamemenu;
    409   bool first = true;
     499  text_t &current_page = args["cp"];
     500  text_t currentname = args["bc1dirname"];
     501  if (current_page == "srce") currentname = args["bc1clonecol"];
     502
     503  text_tarray dirnames;
     504  text_tarray fullnames;
     505  vector<bool> write_protected;
     506  int selected_index = 0;
     507  int index = 0;
    410508
    411509  recptprotolistclass::iterator rprotolist_here = protos->begin();
     
    422520    text_tset metadata;
    423521    metadata.insert ("collectionname");
    424 
    425522    while (collist_here != collist_end) {
    426 
    427523      ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
    428524      if (cinfo != NULL) {
     
    431527          // get collection name from the collection cfg file
    432528          collectionname = cinfo->collectionmeta["collectionname"];
    433 
    434529        } else if (get_info ("collection", *collist_here, metadata, false,
    435530                 (*rprotolist_here).p, response, logout)) {
     
    437532          collectionname = response.docInfo[0].metadata["collectionname"].values[0];
    438533        }
    439      
    440         if (first) fullnamemenu = "<select name=\"bc1clonecol\">\n";
    441         fullnamemenu += "<option value=\"" + *collist_here;
    442         fullnamemenu.push_back ('"');
    443         if (*collist_here == currentname) fullnamemenu += " selected";
    444         fullnamemenu.push_back ('>');
    445         fullnamemenu += collectionname;
    446 
     534        dirnames.push_back(*collist_here);
     535        fullnames.push_back(collectionname);
    447536        // check to see if the "collection" is writable
    448         text_t cfg_fname = filename_cat(gsdlhome, "collect", *collist_here, "etc", "collect.cfg");
    449         if (!file_writable(cfg_fname)) fullnamemenu += " <b>(write protected)</b>";
    450 
    451         fullnamemenu += "\n";
     537        if (collection_protected (*collist_here)) write_protected.push_back(true);
     538        else write_protected.push_back(false);
     539        if (*collist_here == currentname) selected_index = index;       
    452540       
    453         first = false;
     541        index ++;
    454542      }
    455543      collist_here ++;
     
    459547    rprotolist_here ++;
    460548  }
    461   if (!first) {
    462     fullnamemenu += "</select>\n";
    463     disp.setmacro ("fullnamemenu", "collector", fullnamemenu);
    464   }
     549
     550  bool have_one = false;
     551  text_t fullnamemenu = "<select name=\"bc1dirname\">\n";
     552  if (current_page == "srce") fullnamemenu = "<select name=\"bc1clonecol\">\n";
     553  for (int i = 0; i < index; i ++) {
     554    // don't want write protected collections in list on "change existing
     555    // collection" page
     556    if (write_protected[i] && current_page == "existing") continue;
     557    have_one = true;
     558    fullnamemenu += "<option value=\"" + dirnames[i] + "\"";
     559    if (i == selected_index) fullnamemenu += " selected";
     560    fullnamemenu.push_back ('>');
     561    fullnamemenu += fullnames[i];
     562    if (write_protected[i]) fullnamemenu += " <b>(write protected)</b>";
     563  }
     564  fullnamemenu += "</select>\n";
     565  if (have_one) disp.setmacro ("fullnamemenu", "collector", fullnamemenu);
    465566}
    466567
     
    506607  // _collectorbar_
    507608  // _pagescriptextra_
    508   // _fullnamemenu_ -- if displaying the "source data" page
     609  // _fullnamemenu_ -- if displaying the "source data" page or the "changing existing
     610  //                   collection" page
    509611  // _cfgfile_ -- if displaying the "configure collection" page
    510612
    511613  text_t &collector_page = args["cp"];
     614  int esrce = args["bc1esrce"].getint();
     615  int econf = args["bc1econf"].getint();
    512616
    513617  // set _pagescriptextra_ macro to _cpagescriptextra_
     
    541645
    542646  } else if (collector_page == "srce") {
    543     collectorbar += get_button (collector_page, "yellow", "info", true);
     647    if (esrce == 1) {
     648      // if we came from the "change an existing collection" page previous button(s)
     649      // are disabled
     650      collectorbar += get_button (collector_page, "grey", "info", false);
     651    } else {
     652      collectorbar += get_button (collector_page, "yellow", "info", true);
     653    }
    544654    collectorbar += "<td>_icongreyarrow_</td>\n";
    545655    collectorbar += get_button (collector_page, "yellow", "srce", false);
     
    553663
    554664  } else if (collector_page == "conf") {
    555     collectorbar += get_button (collector_page, "yellow", "info", true);
    556     collectorbar += "<td>_icongreyarrow_</td>\n";
    557     collectorbar += get_button (collector_page, "yellow", "srce", true);
     665    // disable appropriate buttons if we came from "change an existing collection"
     666    // page
     667    if (esrce == 1 || econf == 1) {
     668      collectorbar += get_button (collector_page, "grey", "info", false);
     669    } else {
     670      collectorbar += get_button (collector_page, "yellow", "info", true);
     671    }
     672    collectorbar += "<td>_icongreyarrow_</td>\n";
     673    if (econf == 1) {
     674      collectorbar += get_button (collector_page, "grey", "srce", false);
     675    } else {
     676      collectorbar += get_button (collector_page, "yellow", "srce", true);
     677    }
    558678    collectorbar += "<td>_icongreyarrow_</td>\n";
    559679    collectorbar += get_button (collector_page, "yellow", "conf", false);
     
    572692  disp.setmacro ("collectorbar", "collector", collectorbar);
    573693
    574   if (collector_page == "srce") set_fullnamemenu (disp, args, protos, logout);
    575   if (collector_page == "conf") set_cfgfile (disp, args["bc1dirname"], logout);
     694  if (collector_page == "srce" || collector_page == "existing")
     695    set_fullnamemenu (disp, args, protos, logout);
     696  if (collector_page == "conf")
     697    set_cfgfile (disp, args["bc1dirname"], logout);
    576698}
    577699
     
    579701                 browsermapclass * /*browsers*/, displayclass &disp,
    580702                 outconvertclass &outconvert, ostream &textout,
    581                  ostream &/*logout*/) {
     703                 ostream &logout) {
    582704
    583705  text_t &collector_page = args["cp"];
    584   text_t error;
     706  text_t &collection = args["bc1dirname"];
     707  text_t message;
    585708
    586709  if (do_mkcol) {
     
    591714    mkcol_cmd += " -title \"" + args["bc1fullname"] + "\"";
    592715    mkcol_cmd += " -about \"" + carriage_replace (args["bc1aboutdesc"], 0) + "\" ";
    593     mkcol_cmd += args["bc1dirname"];
     716    mkcol_cmd += collection;
    594717    char *mkcol_cmdc = mkcol_cmd.getcstr();
    595718    system (mkcol_cmdc);
     
    597720   
    598721    // make sure it went ok
    599     text_t cfgfile = filename_cat (gsdlhome, "collect", args["bc1dirname"],
     722    text_t cfgfile = filename_cat (gsdlhome, "collect", collection,
    600723                   "etc", "collect.cfg");
    601     if (!file_writable (cfgfile)) error = "mkcolfail";
     724    if (!file_writable (cfgfile)) message = "mkcolfail";
     725    do_mkcol = false; // reset for fast-cgi
    602726  }
    603727
    604728  if (collector_page == "bild") {
    605729    // do the work (download, import, build)
     730    text_t tmpdir = filename_cat (gsdlhome, "tmp", collection + ".bld");
     731
    606732    text_t build_cmd = "perl " + filename_cat (gsdlhome, "bin", "script", "build");
     733    build_cmd += " -append -remove_import";
     734    build_cmd += " -out \"" + tmpdir + "\"";
    607735    if (!args["bc1inputdir1"].empty()) {
    608736      build_cmd += " -download \"" + args["bc1inputdir1"] + "\"";
     
    618746    }
    619747    build_cmd.push_back (' ');
    620     build_cmd += args["bc1dirname"];
     748    build_cmd += collection;
    621749
    622750#if !defined (__WIN32__)
     
    633761  }
    634762
    635   if (error.empty()) {
     763  if (args["bc1dodelete"] == "1") {
     764    // delete bcidirname collection
     765    if (collection_protected (collection)) {
     766      message = "delinvalid";
     767
     768    } else {
     769
     770      text_t delete_cmd = "perl " + filename_cat (gsdlhome, "bin", "script", "delcol.pl");
     771      delete_cmd += " -f " + collection;
     772      char *delete_cmdc = delete_cmd.getcstr();
     773      int rv = system (delete_cmdc);
     774      delete delete_cmdc;
     775      if (rv != 0) {
     776    // deletion failed -- permissions?
     777    message = "delpermission";
     778      } else {
     779    message = "delsuccess";
     780      }
     781    }
     782  }
     783
     784  if (clone_failed) {
     785    // clone_failed is set from check_cgiargs if an attempt was made
     786    // to clone an invalid collection
     787    message = "clonefail";
     788    clone_failed = false;
     789  }
     790 
     791  if (message.empty()) {
    636792    textout << outconvert << disp << ("_collector:header_\n")
    637793        << ("_collector:" + collector_page + "content_\n")
     
    639795  } else {
    640796    textout << outconvert << disp << ("_collector:header_\n")
    641         << ("_collector:" + error + "content_\n")
     797        << ("_collector:" + message + "content_\n")
    642798        << ("_collector:footer_\n");
    643799  }
     
    738894  return shortname;
    739895}
     896
     897// tests if collection is write protected (currently just checks if
     898// collect.cfg file is writable
     899bool collectoraction::collection_protected (const text_t &collection) {
     900  text_t cfgfile = filename_cat(gsdlhome, "collect", collection, "etc", "collect.cfg");
     901  if (file_writable(cfgfile)) return false;
     902  return true;
     903}
  • trunk/gsdl/src/recpt/collectoraction.h

    r1425 r1432  
    4040
    4141  bool do_mkcol;
     42  bool clone_failed;
    4243
    4344  text_t get_button (const text_t &thispage, const text_t &color,
     
    4950  void set_cfgfile (displayclass &disp, const text_t &dirname, ostream &logout);
    5051
     52  void update_cfgfile_clone (cgiargsclass &args, ostream &logout);
     53
    5154  void update_cfgfile_partial (cgiargsclass &args, ostream &logout);
    5255
     
    5659
    5760  text_t get_directory_name (const text_t &fullname);
     61
     62  bool collection_protected (const text_t &collection);
    5863
    5964public:
Note: See TracChangeset for help on using the changeset viewer.