home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / bbs102e.zip / bbsconfg.cmd < prev    next >
OS/2 REXX Batch file  |  1997-11-16  |  12KB  |  359 lines

  1. /* configure the BBS.INI file */
  2.  
  3.  
  4. parse arg  ddir, tempfile, reqstrg,list,verb ,uri,user, ,
  5.           basedir ,workdir,privset,enmadd,transaction,verbose, ,
  6.          servername,host_nickname,homedir
  7.  
  8. /*if verb="" then do
  9.    say " This SRE-http add-on is NOT meant to be run from the command line."
  10.    exit
  11. end  /* Do */
  12. */
  13.  
  14. /* chekc for needed_privs superuser */
  15. if wordpos('SUPERUSER',upper(privset))=0 then do
  16.     'header add WWW-Authenticate: Basic Realm=<BBS>'  /* challenge */
  17.      return sref_response('unauth', "You do not have Superuser privileges ",tempfile,servername)
  18. end
  19.  
  20. if list<>"" then do
  21.     call setme
  22.    return 0
  23. end  /* Do */
  24.  
  25.  
  26. knowns='FILE_DIR BBS_LOGON_FILE '
  27. knowns=knowns||' BBS_PARAM_DIR USERLOG_DIR INCOMING_DIR BBSCACHE_DIR  IMAGEPATH '
  28. KNOWNS=KNOWNS||' HEADER_FILE FOOTER_FILE ZIP_HEADER_FILE DESCRIPTION_FILE EXCLUSION_FILE '
  29. knowns=knowns||' INCLUSION_MODE_FILE  '
  30. KNOWNS=KNOWNS||' CACHE_FILES CACHE_DURATION CACHE_CHECK UPLOAD_MAXSIZE UPLOAD_MINFREE '
  31. KNOWNS=KNOWNS||' HEADER_TEXT FOOTER_TEXT DESCRIPTION_TEXT DESCRIPTION_TEXT_LENGTH '
  32. KNOWNS=KNOWNS||' DESCRIPTION_TEXT_LENGTH_1LINE AUTO_DESCRIBE ZIP_DESCRIPTOR_FILE '
  33. knowns=knowns||' GET_Z_ZIP_DESCRIPTION '
  34. knowns=knowns||' OWN_UPLOAD_DIR OWN_DOWNLOAD_DIR OWN_DOWNLOAD_FLAG '
  35. KNOWNS=KNOWNS||' TABLE_BORDER DEF_BIN_TEXT_LINKS CELL_SPACING USE_COOKIES DEFAULT_DESCRIPTION DEFAULT_DESCRIPTION_DIR '
  36. KNOWNS=KNOWNS||' DEFAULT_DATEFMT DEFAULT_SORT_BY CONTINUATION_FLAG WRITE_DETAILS UPLOAD_QUICK_CHECK '
  37. KNOWNS=KNOWNS||' DEFAULT_RATIO DEFAULT_BYTE_RATIO BYTES_NEWUSER FILES_NEWUSER MUST_WAIT '
  38. KNOWNS=KNOWNS||' OWN_NAME_PRIVILEGE USE_SERVERNAME BBS_SMTP_GATEWAY ADMIN_EMAIL SEND_ALERT '
  39.  
  40. oldwas=knowns
  41.  
  42. nochangers=' '
  43. lastmod=' '
  44.  
  45.  
  46. /* sets */
  47. set.1='FILE_DIR BBS_PARAM_DIR USERLOG_DIR INCOMING_DIR BBSCACHE_DIR IMAGEPATH '
  48. setmess.1='BBS Directories '
  49.  
  50. set.2='BBS_LOGON_FILE HEADER_FILE FOOTER_FILE ZIP_HEADER_FILE DESCRIPTION_FILE EXCLUSION_FILE INCLUSION_MODE_FILE ZIP_DESCRIPTOR_FILE'
  51. setmess.2='BBS Files (generic and/or directory specific) '
  52.  
  53. /* cache stuff */
  54. set.3='CACHE_FILES CACHE_DURATION CACHE_CHECK '
  55. setmess.3=' BBS Cache Parameters '
  56.  
  57. /* descrription modifiers */
  58. set.4='HEADER_TEXT FOOTER_TEXT DESCRIPTION_TEXT DESCRIPTION_TEXT_LENGTH  DESCRIPTION_TEXT_LENGTH_1LINE '
  59. set.4=set.4||' AUTO_DESCRIBE  GET_Z_ZIP_DESCRIPTION DEFAULT_DESCRIPTION DEFAULT_DESCRIPTION_DIR '
  60. setmess.4=' File Description Modifiers '
  61.  
  62. /* other display modifiers */
  63. set.5='DEFAULT_DATEFMT DEFAULT_SORT_BY USE_SERVERNAME TABLE_BORDER CELL_SPACING DEF_BIN_TEXT_LINKS '
  64. setmess.5=' Other display modifiers '
  65. /* upload stuff */
  66. set.6='UPLOAD_MAXSIZE UPLOAD_MINFREE UPLOAD_QUICK_CHECK  OWN_UPLOAD_DIR OWN_DOWNLOAD_DIR OWN_DOWNLOAD_FLAG '
  67. setmess.6=' Upload/Download Parameters '
  68.  
  69. /* privileges and ratios */
  70. set.7='DEFAULT_RATIO DEFAULT_BYTE_RATIO BYTES_NEWUSER FILES_NEWUSER MUST_WAIT OWN_NAME_PRIVILEGE '
  71. setmess.7='BBS Privileges and Ratios '
  72.  
  73. /* email alert stuff */
  74. set.8='BBS_SMTP_GATEWAY ADMIN_EMAIL SEND_ALERT '
  75. setmess.8=' E-mail Parameters '
  76.  
  77. /* miscellaneious */
  78. /* 'USE_COOKIES WRITE_DETAILS CONTINUATION_FLAG  ' */
  79. setmess.9='Miscellaneous '
  80.  
  81. do io=1 to 9
  82.    set.io.!list=' '
  83. end /* do */
  84.  
  85.  call lineout tempfile, "<html><head><title>SRE-http: Configure BBS  </title>"
  86.  call lineout tempfile, "</head><body>"
  87.  call lineout tempfile,' <h1>Configure BBS </h1> <hr>'
  88.  
  89.  
  90.  bbsini=strip(basedir,'t','\')'\bbs.ini'
  91.  getem=fileread(bbsini,blines,,'E')
  92.  if blines.0=0 then do
  93.       call lineout tempfile,' <h2>Error in BBS configurator </h2> <hr>'
  94.       call lineout tempfile, ' BBS initialization file (' bbsini ') could not be found '
  95.       call lineout tempfile,'</body></html>'
  96.       call lineout tempfile
  97.      'FILE ERASE TYPE text/html NAME' tempfile
  98.       return 'Error in BBS configurator '
  99.  end  /* Do */
  100.  
  101. /* rules:
  102. start with /* or empty line -- is a comment line
  103. end with */ --- strip out ending comment (and retain)
  104. otherwise, check variable name. If not in "to do list", treat as a comment
  105. */
  106.  
  107. do mm=1 to BLINES.0
  108.    aline=strip(blines.mm)
  109.    ALINE=REPLACESTRG(ALINE,'<','<','ALL')
  110.    ALINE=REPLACESTRG(ALINE,'>','>','ALL')
  111.  
  112.    todo.mm.!extra=' '
  113.    if abbrev(aline,'/*')=1 | aline=' ' then do
  114.         t2a=REPLACESTRG(aline,'"','"','ALL')
  115.         todo.mm.!value=t2a
  116.         todo.mm.!var=0
  117.         iterate
  118.     end
  119.  
  120. /* not a comment. Read the variable, and it's own comment at end of line */
  121.     itis=aline
  122.     if right(aline,2)='*/' then do              /* strip out ending comment */
  123.        foo2=lastpos('/*',aline)
  124.        if foo2>0 then do             /* found comment start */
  125.                itis=left(aline,foo2-1)
  126.                t2a=substr(aline,foo2)
  127.                t2a=REPLACESTRG(t2a,'"','"','ALL')
  128.                todo.mm.!extra=t2a
  129.        end  /* Do */
  130.      end
  131.      parse var itis t1 '=' t2
  132.      t1=upper(strip(t1))
  133.  
  134. /* is it the LAST_MODIFIED parameter */
  135.     if t1="LAST_MODIFIED" then do
  136.         todo.mm.!var=-1
  137.         todo.mm.!value=' '
  138.         lastmod=translate(t2,' ','2227'x)
  139.         iterate   /*then skip it */
  140.      end
  141.  
  142. /* is it one of the known parameters? */
  143.      IT1=WORDPOS(T1,KNOWNS)
  144.      IF IT1=0 then DO
  145.        nochangers=nochangers' 't1
  146.        t2a=REPLACESTRG(aline,'"','"','ALL')
  147.        todo.mm.!value=t2a
  148.        todo.mm.!var=0
  149.        iterate
  150.      end  /* Do */
  151.  
  152.      it1=wordpos(t1,oldwas)
  153.      oldwas=delword(oldwas,it1,1)
  154.      t2=strip(t2) ; t2a=t2
  155.      if abbrev(t2,'"')=1 then 
  156.         t2a=strip(t2,,'"')
  157.       if abbrev(t2,"'")=1 then
  158.         t2a=strip(t2,,"'")
  159.      t1=strip(upper(t1))
  160.      todo.mm.!var=t1
  161.      t2a=REPLACESTRG(T2A,'"','"','ALL')
  162.      todo.mm.!value=t2a
  163.  
  164. /* assign to a set ? */
  165.      iu2=0
  166.      do iu=1 to 8
  167.           iu2=wordpos(t1,set.iu)
  168.           if iu2>0 then do
  169.              set.iu.!list=set.iu.!list||' '||mm
  170.              leave
  171.           end  /* Do */
  172.      end /* do */
  173.      if iu2=0 then set.9.!list=set.9.!list||' '||mm
  174.  
  175.  end /* do */
  176.  
  177. call lineout tempfile,' <h3> Modifying parameters in ' bbsini ' </h3>'
  178. call lineout tempfile,' With this FORM you can change most of the parameters in the  BBS initialization file. <br>'
  179. call lineout tempfile,' For a detailed description of these parameters, see <a href="/bbs.doc">BBS.DOC </a><p>'
  180. if lastmod<>' ' then
  181.   call lineout tempfile,' <p> Note: BBS.INI last modified on ' lastmod
  182. call lineout tempfile,' <FORM ACTION="/bbsconfg" METHOD="POST"> '
  183.  
  184.  
  185. do ii=1 to blines.0             /* dump comments */
  186.    if todo.ii.!var=0 | todo.ii.!var=-1 then do
  187.        call lineout tempfile,' <INPUT TYPE="hidden" NAME="var.'ii'" value='todo.ii.!var' >'
  188.        call lineout tempfile,' <INPUT TYPE="hidden" NAME="value.'ii'"  VALUE="'todo.ii.!value'"  >'
  189.        call lineout tempfile,' <INPUT TYPE="hidden" NAME="extra.'ii'"  VALUE=""  >'
  190.    end
  191. end
  192.  
  193. do iset=1 to 9
  194.   islist=strip(set.iset.!list)
  195.   call lineout tempfile,'<h3> ' setmess.iset ' </h3> '
  196.   call lineout tempfile,' <dl> '
  197.   do inset=1 to words(islist)
  198.     ii=strip(word(islist,inset))
  199.     call lineout tempfile,' <INPUT TYPE="hidden" NAME="var.'ii'" value="'todo.ii.!var'" >'
  200.     call lineout tempfile,' <dt> ' todo.ii.!var  ' =  '
  201.     call lineout tempfile,'  <INPUT TYPE="text" NAME="value.'ii'"  VALUE="'todo.ii.!value'" SIZE=30 MAXLENGTH=80 >'
  202.     adesc=strip(todo.ii.!extra)
  203.     if pos('/*',adesc) >0 then
  204.            adesc=substr(delstr(adesc,length(adesc)-1),3)
  205.      call lineout tempfile,' <dd> ' adesc ' <br>'
  206.      call lineout tempfile,' <INPUT TYPE="hidden" NAME="extra.'ii'"  VALUE="'todo.ii.!extra'"  >'
  207.    end
  208.    call lineout tempfile,' </dl> '
  209. end /* do */
  210. call lineout tempfile,' <INPUT TYPE="submit" VALUE="submit">  '
  211. call lineout tempfile,' <INPUT TYPE="hidden" NAME="SETME" value='blines.0' >'
  212. call lineout tempfile,' </form>'
  213.  
  214. call lineout tempfile,' <p>'
  215. call lineout tempfile,' Notes: <ul> '
  216. call lineout tempfile,'<li> The following parameters were <b>not</b> set: <blockquote>' nochangers
  217. call lineout tempfile,' </blockquote> To change them, you will have to edit 'bbsini '<br>'
  218.  
  219. if oldwas<>' ' then do
  220.   call lineout tempfile,' <li> The following parameters should have been, but were <b>not</b>, found in ' bbsini ' <blockquote>'
  221.   call lineout tempfile, oldwas
  222.   call lineout tempfile,'</blockquote>'
  223. end
  224. call lineout tempfile,' </ul>'
  225. call lineout tempfile,'</body></html>'
  226. call lineout tempfile
  227. 'FILE ERASE TYPE text/html NAME' tempfile
  228. return 'BBS configurator sent form'
  229.  
  230.  
  231. /* ------------- */
  232. /* ----------------------------------------------------------------------- */
  233. /* REPLACESTRG: In string astring, find first occurence substring target and
  234. .   replace it with substring putme
  235. .      if no target, return unchanged astring
  236. .      if no putme, then remove target
  237. .      if type=backward, then find/change LAST occurence
  238. .      if type=all, find/change all occurences
  239. .      if exactmatch=yes, then do not capitalize during search (exact match only */
  240. /* ----------------------------------------------------------------------- */
  241.  
  242. replacestrg: procedure
  243.  
  244. exactmatch=0
  245. backward=0 ; doall=0
  246.  
  247. parse arg astring ,  target   , putme , type , exactmatch
  248.  
  249. type = translate(type)
  250. if type="BACKWARD" then backward="YES"
  251. if type="ALL" then doall="YES"
  252.  
  253. iat=1
  254. joelen=length(target)
  255. joelen2=length(putme)
  256.  
  257. doagain:                /* here if doall=yes */
  258.  if exactmatch="YES" then do
  259.     if   backward="YES" then
  260.         joe= lastpos(target,astring)
  261.     else
  262.         joe= pos(target,astring,iat)
  263.  end
  264.  else do
  265.    if   backward="YES" then
  266.         joe= lastpos(translate(target),translate(astring))
  267.     else
  268.         joe= pos(translate(target),translate(astring),iat)
  269.  end
  270.  if joe=0 then
  271.          return astring
  272.  
  273.  astring=delstr(astring,joe,joelen)
  274.  if putme<>' ' then
  275.     astring=insert(putme,astring,joe-1)
  276.  
  277.  if doall="YES" then do
  278.      iat=joe+joelen2
  279.      signal doagain
  280.  end
  281. /* else, all done */
  282.  return astring
  283.  
  284.  
  285. /***********************/
  286. /* Jump here to write results */
  287. setme:
  288. if pos('SETME',list)=0 then do
  289.  call lineout tempfile, "<html><head><title>SRE-http: Configure BBS  </title>"
  290.  call lineout tempfile, "</head><body>"
  291.  call lineout tempfile,' <h2>Configure BBS </h2>'
  292.  call lineout tempfile,' Error: incorrect information. ' 
  293.  call lineout tempfile,'</body></html>'
  294.  call lineout tempfile
  295.  'FILE ERASE TYPE text/html NAME' tempfile
  296.  return 0
  297. end
  298.  
  299.  call lineout tempfile, "<html><head><title>SRE-http: Configure BBS  </title>"
  300.  call lineout tempfile, "</head><body>"
  301.  call lineout tempfile,' <h2>Configure BBS </h2>'
  302.  
  303. do until list=""
  304.    parse var list a1 '&' list
  305.    parse var  a1 avar '=' aval
  306.    if avar='SETME' then do
  307.         ndo=aval
  308.         iterate
  309.    end  /* Do */
  310.    avar=strip(upper(avar))
  311.    aval=translate(aval,' ','+')
  312.    aval=packur(aval)
  313.    ack='!'||avar
  314.    stuff.ack=aval
  315. end /* do */
  316.  
  317. call lineout tempfile,' <h3> BBS initialization file has been modified </h3>'
  318.  
  319. /* rename old bbs.ini file */
  320.  bbsini=strip(basedir,'t','\')'\bbs.ini'
  321.  aa=stream(bbsini,'c','query exists')
  322.  if aa<>"" then do
  323.       newn=dostempname(strip(basedir,'t','\')'\bbsINI.???')
  324.       foo=dosrename(bbsini,newn)
  325.       if foo=1 then
  326.          call lineout tempfile,' Old BBS.INI file has been moved to ' newn
  327.       else
  328.          call lineout tempfile,' Old BBS.INI could <b>not</b> be renamed '
  329.  end  /* Do */
  330.  else do
  331.          call lineout tempfile,' Creating BBS.INI '
  332.  end  /* Do */
  333.  getem=fileread(bbsini,blines,,'E')    
  334.  
  335. mm2=0
  336. do mm=1 to ndo
  337.    if stuff.!var.mm=-1  then iterate
  338.    mm2=mm2+1
  339.    if stuff.!var.mm=0 then do
  340.       newl.mm2=stuff.!value.mm
  341.       iterate
  342.    end
  343.    if datatype(stuff.!value.mm)="NUM"then
  344.       newl.mm2=stuff.!var.mm '=' stuff.!value.mm' ' stuff.!extra.mm
  345.   else
  346.       newl.mm2=stuff.!var.mm "='"||stuff.!value.mm||"' " stuff.!extra.mm
  347.  
  348. end /* do */
  349. mm2=mm2+1
  350. newl.mm2="LAST_MODIFIED='" time('n')' ' date('n') "'"
  351.  
  352. newl.0=mm2
  353. foo=filewrite(bbsini,newl)
  354. call lineout tempfile
  355. 'FILE ERASE TYPE text/html NAME' tempfile
  356.  
  357. return 0
  358.  
  359.