Changeset 2401 for trunk/gsdl/src


Ignore:
Timestamp:
2001-05-11T15:58:47+12:00 (23 years ago)
Author:
sjboddie
Message:

Made some changes to the collector so that paths/URLs/ftp addresses are
checked (pinged for HTTP/FTP) when leaving the "source data" page.
Functionality is complete I think but the interface still needs a
little work.

Location:
trunk/gsdl/src/recpt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/collectoraction.cpp

    r2379 r2401  
    5252  disabled = true;
    5353  do_mkcol = false;
     54  badsources = false;
     55  failedsources.erase(failedsources.begin(), failedsources.end());
    5456  gsdlosc = NULL;
    5557  gsdlhomec = NULL;
     
    140142  argsinfo.addarginfo (NULL, arg_ainfo);
    141143
    142   arg_ainfo.shortname = "bc1inputdir1";
    143   arg_ainfo.longname = "collector specific";
    144   arg_ainfo.multiplechar = true;
    145   arg_ainfo.defaultstatus = cgiarginfo::weak;
    146   arg_ainfo.argdefault = "";
    147   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    148   argsinfo.addarginfo (NULL, arg_ainfo);
    149 
    150   arg_ainfo.shortname = "bc1inputdir2";
    151   arg_ainfo.longname = "collector specific";
    152   arg_ainfo.multiplechar = true;
    153   arg_ainfo.defaultstatus = cgiarginfo::weak;
    154   arg_ainfo.argdefault = "";
    155   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    156   argsinfo.addarginfo (NULL, arg_ainfo);
    157 
    158   arg_ainfo.shortname = "bc1inputdir3";
    159   arg_ainfo.longname = "collector specific";
    160   arg_ainfo.multiplechar = true;
    161   arg_ainfo.defaultstatus = cgiarginfo::weak;
    162   arg_ainfo.argdefault = "";
    163   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    164   argsinfo.addarginfo (NULL, arg_ainfo);
    165 
    166   arg_ainfo.shortname = "bc1inputdir4";
    167   arg_ainfo.longname = "collector specific";
    168   arg_ainfo.multiplechar = true;
    169   arg_ainfo.defaultstatus = cgiarginfo::weak;
    170   arg_ainfo.argdefault = "";
    171   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    172   argsinfo.addarginfo (NULL, arg_ainfo);
    173 
    174144  // only set when one of the fields was changed in
    175145  // the "collection info" page
     
    226196  arg_ainfo.argdefault = "0";
    227197  arg_ainfo.savedarginfo = cgiarginfo::must;
     198  argsinfo.addarginfo (NULL, arg_ainfo);
     199
     200  arg_ainfo.shortname = "bc1filenum";
     201  arg_ainfo.longname = "collector specific";
     202  arg_ainfo.multiplechar = true;
     203  arg_ainfo.defaultstatus = cgiarginfo::weak;
     204  arg_ainfo.argdefault = "1";
     205  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     206  argsinfo.addarginfo (NULL, arg_ainfo);
     207
     208  arg_ainfo.shortname = "bc1httpnum";
     209  arg_ainfo.longname = "collector specific";
     210  arg_ainfo.multiplechar = true;
     211  arg_ainfo.defaultstatus = cgiarginfo::weak;
     212  arg_ainfo.argdefault = "1";
     213  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     214  argsinfo.addarginfo (NULL, arg_ainfo);
     215
     216  arg_ainfo.shortname = "bc1ftpnum";
     217  arg_ainfo.longname = "collector specific";
     218  arg_ainfo.multiplechar = true;
     219  arg_ainfo.defaultstatus = cgiarginfo::weak;
     220  arg_ainfo.argdefault = "1";
     221  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     222  argsinfo.addarginfo (NULL, arg_ainfo);
     223
     224  arg_ainfo.shortname = "bc1fileinput";
     225  arg_ainfo.longname = "collector specific";
     226  arg_ainfo.multiplechar = true;
     227  arg_ainfo.multiplevalue = true;
     228  arg_ainfo.defaultstatus = cgiarginfo::weak;
     229  arg_ainfo.argdefault = "";
     230  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     231  argsinfo.addarginfo (NULL, arg_ainfo);
     232
     233  arg_ainfo.shortname = "bc1httpinput";
     234  arg_ainfo.longname = "collector specific";
     235  arg_ainfo.multiplechar = true;
     236  arg_ainfo.multiplevalue = true;
     237  arg_ainfo.defaultstatus = cgiarginfo::weak;
     238  arg_ainfo.argdefault = "";
     239  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     240  argsinfo.addarginfo (NULL, arg_ainfo);
     241
     242  arg_ainfo.shortname = "bc1ftpinput";
     243  arg_ainfo.longname = "collector specific";
     244  arg_ainfo.multiplechar = true;
     245  arg_ainfo.multiplevalue = true;
     246  arg_ainfo.defaultstatus = cgiarginfo::weak;
     247  arg_ainfo.argdefault = "";
     248  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     249  argsinfo.addarginfo (NULL, arg_ainfo);
     250
     251  // will be set when we've just come from the "source data" page
     252  arg_ainfo.shortname = "bc1fromsrce";
     253  arg_ainfo.longname = "collector specific";
     254  arg_ainfo.multiplechar = false;
     255  arg_ainfo.defaultstatus = cgiarginfo::weak;
     256  arg_ainfo.argdefault = "0";
     257  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
    228258  argsinfo.addarginfo (NULL, arg_ainfo);
    229259}
     
    323353    enum source_t {default_arg, compressed_arg, cgi_arg, program_arg};
    324354    text_tmap saved_args;
    325     saved_args["bc1inputdir1"] = "";
    326     saved_args["bc1inputdir2"] = "";
    327     saved_args["bc1inputdir3"] = "";
    328     saved_args["bc1inputdir4"] = "";
    329355    saved_args["bc1fullname"] = "";
    330356    saved_args["bc1contactemail"] = "";
    331357    saved_args["bc1aboutdesc"] = "";
    332358    saved_args["bc1clone"] = "";
     359    saved_args["bc1clonecol"] = "";
     360    saved_args["bc1filenum"] = "";
     361    saved_args["bc1httpnum"] = "";
     362    saved_args["bc1ftpnum"] = "";
     363    saved_args["bc1fileinput"] = "";
     364    saved_args["bc1httpinput"] = "";
     365    saved_args["bc1ftpinput"] = "";
    333366
    334367    // update the argdb database with any arguments that were set
     
    465498      }
    466499      delete fbldc;
     500    }
     501  }
     502
     503  if (args["bc1fromsrce"] == "1") {
     504
     505    // we've just come from the "source data" page so we need to check that
     506    // input sources are valid
     507    if (!check_sources(args, logout)) {
     508      args["p"] = "srce";
    467509    }
    468510  }
     
    701743}
    702744
    703 // set the _fullnamemenu_ macro (and _warnindex_ if we're on the "srce" page)
     745// set the _fullnamemenu_ macro (and _warnindex_ and _selectedindex_ if
     746// we're on the "srce" page)
    704747void collectoraction::set_fullnamemenu (displayclass &disp, cgiargsclass &args,
    705748                    recptprotolistclass *protos, ostream &logout) {
     
    719762  text_tarray fullnames;
    720763  vector<bool> write_protected;
     764  bool is_selected = false;
    721765  int selected_index = 0;
    722766  int index = 0;
     
    727771    if ((*rprotolist_here).p != NULL) {
    728772
    729       // don't include z39.50 collection
     773      // don't include z39.50 collections
    730774      comerror_t err = noError;
    731775      if ((*rprotolist_here).p->get_protocol_name (err) == "z3950proto") {
     
    760804        else write_protected.push_back(false);
    761805
    762         if (*collist_here == currentname) selected_index = index;       
     806        if (*collist_here == currentname) {
     807          is_selected = true;
     808          selected_index = index;       
     809        }
    763810        index ++;
    764811      }
     
    773820  text_t warnindex;
    774821  text_t fullnamemenu = "<select name=\"bc1dirname\">\n";
    775   if (current_page == "srce") fullnamemenu = "<select name=\"bc1clonecol\" onChange=\"menuchange();\">\n";
     822  if (current_page == "srce") {
     823    fullnamemenu = "<select name=\"bc1clonecol\" onChange=\"menuchange();\">\n";
     824    fullnamemenu += "<option value=defaultstructure";
     825    if (!is_selected) fullnamemenu += " selected>";
     826    else fullnamemenu.push_back('>');
     827    fullnamemenu += "default structure\n";
     828  }
    776829  for (int i = 0; i < index; i ++) {
    777830    // don't want write protected collections in list on "change existing
     
    779832    if (write_protected[i] && current_page == "existing") continue;
    780833    fullnamemenu += "<option value=\"" + dirnames[i] + "\"";
    781     if (i == selected_index) fullnamemenu += " selected";
     834    if ((i == 0 && !is_selected && current_page != "srce") ||
     835    (is_selected && i == selected_index)) {
     836      fullnamemenu += " selected";
     837      selected_index++;
     838      is_selected = false;
     839    }
    782840    fullnamemenu.push_back ('>');
    783841    fullnamemenu += fullnames[i];
     
    787845    // (if creating clone collection list)
    788846    if (current_page == "srce") {
    789       if (!first) warnindex.push_back(',');
     847      if (first) warnindex += "0,";
     848      else warnindex.push_back(',');
    790849      if (uses_weird_plugin (dirnames[i])) {
    791850    warnindex += text_t (1);
     
    798857  fullnamemenu += "</select>\n";
    799858
    800   if (!first) {
    801     disp.setmacro ("fullnamemenu", "collector", fullnamemenu);
    802     if (current_page == "srce")
    803       disp.setmacro ("warnindex", "collector", warnindex);
    804   }
     859  disp.setmacro ("fullnamemenu", "collector", fullnamemenu);
     860  if (current_page == "srce") {
     861    disp.setmacro ("warnindex", "collector", warnindex);
     862    disp.setmacro ("selectedindex", "collector", text_t(selected_index));
     863  }
     864}
     865
     866// set _filelist_, _httplist_, _ftplist_ and _badsources_ macros
     867void collectoraction::set_inputsourceboxes (displayclass &disp, cgiargsclass &args,
     868                        ostream &logout) {
     869 
     870  if (badsources) disp.setmacro ("badsources", "collector", "1");
     871
     872  int numfileboxes = args["bc1filenum"].getint();
     873  int numhttpboxes = args["bc1httpnum"].getint();
     874  int numftpboxes = args["bc1ftpnum"].getint();
     875
     876  text_t filelist = get_source_box(args["bc1fileinput"], numfileboxes, "file");
     877  text_t httplist = get_source_box(args["bc1httpinput"], numhttpboxes, "http");
     878  text_t ftplist = get_source_box(args["bc1ftpinput"], numftpboxes, "ftp");
     879
     880  disp.setmacro("filelist", "collector", dm_safe(filelist));
     881  disp.setmacro("httplist", "collector", dm_safe(httplist));
     882  disp.setmacro("ftplist", "collector", dm_safe(ftplist));
     883
     884  // reset badsources and failedsources variables
     885  badsources = false;
     886  failedsources.erase(failedsources.begin(), failedsources.end());
     887}
     888
     889text_t collectoraction::get_source_box (text_t inputarg, int numboxes, text_t boxtype) {
     890
     891  text_tarray files;
     892  // this relies on filenames/URLs/ftp addresses not being able to contain
     893  // commas
     894  splitchar (inputarg.begin(), inputarg.end(), ',', files);
     895
     896  text_t rv = "<table border=0>\n";
     897  for (int i = 0; i < numboxes; i++) {
     898    rv += "<tr><td><input type=text name=\"bc1" + boxtype + "input\" value=\"";
     899    if (i < files.size()) {
     900      rv += files[i];
     901    }
     902    rv += "\" size=50></td>";
     903    if (badsources) {
     904      if ((i < files.size()) && (!files[i].empty())) {
     905    if (failedsources[files[i]] == "1") {
     906      rv += "<td width=40>no</td>";
     907    } else {
     908      rv += "<td width=40>yes</td>";
     909    }
     910      } else {
     911    rv += "<td width=40></td>";
     912      }
     913    }
     914    if (i+1 == numboxes) {
     915      rv += "<td><a href=\"javascript:more('" + boxtype + "')\">more</a></td></tr>\n";
     916    } else {
     917      rv += "<td></td></tr>\n";
     918    }
     919  }
     920  rv += "</table>\n";
     921 
     922  return rv;
    805923}
    806924
     
    836954   
    837955    // define it as a macro
    838     disp.setmacro("cfgfile","collector",dm_safe(cfgtext));
     956    disp.setmacro("cfgfile", "collector", dm_safe(cfgtext));
    839957
    840958  } else {
     
    8871005  // _gsdlhome_ - the gsdlhome path (dm_safe)
    8881006
     1007  // _filelist_ -- these three display "input source" text boxes
     1008  // _httplist_ -- for the "source data" page
     1009  // _ftplist_  --
     1010
     1011  // _badsources_ -- will be set to "1" if we've come from the
     1012  //                 "source data" page and there's a problem
     1013  //                 with the input sources
     1014
    8891015  text_t &collector_page = args["p"];
    8901016  int esrce = args["bc1esrce"].getint();
     
    10301156  if (collector_page == "bildstatus")
    10311157    set_statusline (disp, args, logout);
     1158  if (collector_page == "srce") {
     1159    set_inputsourceboxes (disp, args, logout);
     1160  }
    10321161
    10331162  disp.setmacro ("gsdlhome", "collector", dm_safe(gsdlhome));
     
    15071636  }
    15081637
    1509   if (!args["bc1inputdir1"].empty())
    1510     options += " -download \"" + args["bc1inputdir1"] + "\"";
    1511   if (!args["bc1inputdir2"].empty())
    1512     options += " -download \"" + args["bc1inputdir2"] + "\"";
    1513   if (!args["bc1inputdir3"].empty())
    1514     options += " -download \"" + args["bc1inputdir3"] + "\"";
    1515   if (!args["bc1inputdir4"].empty())
    1516     options += " -download \"" + args["bc1inputdir4"] + "\"";
     1638  text_tarray files;
     1639  text_t filevals = args["bc1fileinput"];
     1640  // this relies on filenames not being able to contain commas
     1641  splitchar (filevals.begin(), filevals.end(), ',', files);
     1642  text_tarray::const_iterator here = files.begin();
     1643  text_tarray::const_iterator end = files.end();
     1644  while (here != end) {
     1645    options += " -download \"" + *here + "\"";
     1646    here ++;
     1647  }
     1648  text_tarray https;
     1649  text_t httpvals = args["bc1httpinput"];
     1650  // this relies on URLs not being able to contain commas
     1651  splitchar (httpvals.begin(), httpvals.end(), ',', https);
     1652  here = https.begin();
     1653  end = https.end();
     1654  while (here != end) {
     1655    options += " -download \"" + *here + "\"";
     1656    here ++;
     1657  }
     1658  text_tarray ftps;
     1659  text_t ftpvals = args["bc1ftpinput"];
     1660  // this relies on ftp addresses not being able to contain commas
     1661  splitchar (ftpvals.begin(), ftpvals.end(), ',', ftps);
     1662  here = ftps.begin();
     1663  end = ftps.end();
     1664  while (here != end) {
     1665    options += " -download \"" + *here + "\"";
     1666    here ++;
     1667  }
    15171668
    15181669  if (logevents) {
     
    17071858  return header;
    17081859}
     1860
     1861bool collectoraction::check_sources (cgiargsclass &args, ostream &logout) {
     1862
     1863  bool found = false;
     1864
     1865  // check local filesystem for file:// sources
     1866  text_tarray files;
     1867  text_t filevals = args["bc1fileinput"];
     1868  // this relies on filenames not being able to contain commas
     1869  splitchar (filevals.begin(), filevals.end(), ',', files);
     1870  text_tarray::const_iterator here = files.begin();
     1871  text_tarray::const_iterator end = files.end();
     1872  while (here != end) {
     1873    text_t file = format_url(*here);
     1874    if (!file_exists(file) && !directory_exists(file)) {
     1875      failedsources[*here] = "1";
     1876      badsources = true;
     1877    }
     1878    found = true;
     1879    here ++;
     1880  }
     1881
     1882  // ping http:// sources
     1883  files.erase(files.begin(), files.end());
     1884  text_t httpvals = args["bc1httpinput"];
     1885  // this relies on URLs not being able to contain commas
     1886  splitchar (httpvals.begin(), httpvals.end(), ',', files);
     1887  here = files.begin();
     1888  end = files.end();
     1889  while (here != end) {
     1890    if (gsdl_system ("perl -S ping.pl -quiet http://" + format_url(*here), true, logout)) {
     1891      failedsources[*here] = "1";
     1892      badsources = true;
     1893    }
     1894    found = true;
     1895    here++;
     1896  }
     1897
     1898  // ping ftp:// sources
     1899  files.erase(files.begin(), files.end());
     1900  text_t ftpvals = args["bc1ftpinput"];
     1901  // this relies on FTP addresses not being able to contain commas
     1902  splitchar (ftpvals.begin(), ftpvals.end(), ',', files);
     1903  here = files.begin();
     1904  end = files.end();
     1905  while (here != end) {
     1906    if (gsdl_system ("perl -S ping.pl -quiet ftp://" + format_url(*here), true, logout)) {
     1907      failedsources[*here] = "1";
     1908      badsources = true;
     1909    }
     1910    found = true;
     1911    here++;
     1912  }
     1913
     1914  // set badsources if there weren't any sources at all
     1915  if (!found) badsources = true;
     1916
     1917  if (badsources) return false;
     1918  return true;
     1919}
     1920
     1921// format_url simply strips "http://", "ftp://", or "file://" off the
     1922// beginning of url if they're there
     1923text_t collectoraction::format_url (const text_t &url) {
     1924  text_t::const_iterator begin = url.begin();
     1925  text_t::const_iterator end = url.end();
     1926
     1927  if (url.size() >= 7) {
     1928    text_t prefix = substr(begin, begin+7);
     1929    if (prefix == "http://" || prefix == "file://") {
     1930      return substr(begin+7, end);
     1931    }
     1932  }
     1933  if (url.size() >= 6) {
     1934    if (substr(begin, begin+6) == "ftp://") {
     1935      return substr(begin+6, end);
     1936    }
     1937  }
     1938  return url;
     1939}
  • trunk/gsdl/src/recpt/collectoraction.h

    r1778 r2401  
    4545  bool do_mkcol;
    4646
     47  bool badsources;
     48  text_tmap failedsources;
     49
    4750  text_t get_button (const text_t &thispage, const text_t &color,
    4851             const text_t &type, bool enabled);
     
    5053  void set_fullnamemenu (displayclass &disp, cgiargsclass &args,
    5154             recptprotolistclass *protos, ostream &logout);
     55
     56  void set_inputsourceboxes (displayclass &disp, cgiargsclass &args,
     57                 ostream &logout);
     58
     59  text_t get_source_box (text_t inputarg, int numboxes, text_t boxtype);
    5260
    5361  void set_cfgfile (displayclass &disp, cgiargsclass &args, ostream &logout);
     
    8896  text_t get_event_header (cgiargsclass &args);
    8997
     98  bool check_sources (cgiargsclass &args, ostream &logout);
     99
     100  text_t format_url (const text_t &url);
     101
    90102public:
    91103  collectoraction ();
Note: See TracChangeset for help on using the changeset viewer.