home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / backftpb.zip / backftp.mex < prev    next >
Text File  |  1996-04-17  |  5KB  |  212 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: Back-ftp
  4. //
  5. // Desc: Back Ftp for Maximus 3.0
  6. //
  7. // Copyright 1995-1996 Alberto Velo
  8. //
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11.  
  12. #include <max.mh>
  13. #include <prm.mh>
  14.  
  15. string: sito,dir,file,userarea,cfg,fftp;
  16. int: ld, haspaid,error;
  17. #define cfg "backftp.usr"  // must be in MAX directory !
  18. #define fftp "backftp.dat" // in Max dir
  19.  
  20. void cls()
  21. {
  22. print ("\f\n" COL_YELLOWONBLUE " --- Back-Ftp for Maximus 3.0 --- \n");
  23. print ("       (c) Alberto Velo, 1995     \n" COL_WHITE);
  24. }
  25.  
  26. int need_money()
  27. {
  28. string: key;
  29. int: nkey, i;
  30. char: c;
  31.  
  32. print("\nHello, " COL_YELLOW, usr.name);
  33. print(COL_WHITE "\n\nPlease wait: checking your account...");
  34. key:= usr.xkeys;
  35. nkey:= strlen(key);
  36.  
  37. for (i := 1; i < (nkey+1); i := i + 1)
  38.     {
  39.     c:= key[i];
  40.     if (c = 'X') haspaid := 1;
  41.     }
  42.  
  43. if (haspaid <> 1) {
  44.         print(COL_LRED "\n\n\aERROR! You don't have access to Back-Ftp !");
  45.         print("\nThis service is reserved to payant users.");
  46.     return (haspaid);
  47.     }
  48. print("\nLevel 1: ok...");
  49. }
  50.  
  51. int area()
  52. {
  53. int: file,ln,pos,i,area;
  54. string: linea,nome,dir,user;
  55. user:= usr.name;
  56. file:= fileexists(cfg);
  57.  
  58. if (file <> 1) return (error:=1);
  59. file:= open(cfg, IOPEN_READ);
  60.  
  61. do
  62. {
  63.      ln:= readln(file,linea);
  64.  for (pos := stridx (linea, pos, '=');
  65.       pos;
  66.       pos := stridx (linea, pos+1, '='))
  67.  {
  68.  i := strfind(linea,user);
  69.  if (i > 0){
  70.          print("\nLevel 2: ok...");
  71.     dir:=  strtrim(substr(linea, pos+1,strlen(linea))," ");
  72.     goto eof;
  73.     }
  74.  }
  75. }
  76. while (ln >= 0);
  77.  
  78. return (error:=1); //Utente non presente in backftp.usr
  79.  
  80. eof:
  81. userarea:= "USER." + dir;
  82. if (area:= fileareaselect(userarea) <> 1) return(error:=2);  // Area misconfigured
  83. print(COL_GREEN "\n\nYour personal area is: " COL_LGREEN,userarea);
  84. print(COL_GREEN "\nThere you will find files retrieved with BackFtp.\n");
  85. }
  86.  
  87. int leggi_dati(int: ld)
  88. {
  89. if (ld=0) 
  90.     {
  91.         input_str(sito,INPUT_NLB_LINE,0,0,COL_WHITE "\nHost name: " COL_YELLOW);
  92.         input_str(dir,INPUT_NLB_LINE,0,0,COL_WHITE "\nDirectory: " COL_YELLOW);
  93.         input_str(file,INPUT_NLB_LINE,0,0,COL_WHITE "\nFile name: " COL_YELLOW);
  94.     }
  95. else if (ld=1)
  96.     {
  97.         input_str(sito,INPUT_NLB_LINE,0,0,COL_WHITE "\nHost name: " COL_YELLOW);
  98.     }
  99. else if (ld=2)
  100.     {
  101.         input_str(dir,INPUT_NLB_LINE,0,0,COL_WHITE "\nDirectory: " COL_YELLOW);
  102.     }
  103. else if (ld=3)
  104.     {
  105.         input_str(file,INPUT_NLB_LINE,0,0,COL_WHITE "\nFile name: " COL_YELLOW);
  106.     }
  107. }
  108.  
  109.  
  110. int prepara_dat(string: sito, string: dir, string: gfile)
  111. {
  112. string: user,localdir;
  113. int: file,dat;
  114. localdir:= farea.downpath;
  115. user:=usr.name;
  116. dat:= fileexists(fftp);
  117. if (dat=1)
  118.     {
  119.     file:= open(fftp, IOPEN_WRITE | IOPEN_APPEND);
  120.     }
  121. else    {
  122.     file:= open(fftp, IOPEN_WRITE | IOPEN_CREATE);
  123.     }
  124.  
  125. writeln(file,"<");
  126. writeln(file,user);
  127. writeln(file,localdir);
  128. writeln(file,sito);
  129. writeln(file,dir);
  130. writeln(file,gfile);
  131. writeln(file,">");
  132. }
  133.  
  134. int main()
  135. {
  136. char: yn, grt;
  137. string: localdir;
  138. cls();
  139. need_money();
  140. if (haspaid <> 1) goto the_end;
  141. area();
  142. if (error = 1 or error=2) {
  143.     print(COL_LRED "\n\nERROR n. ",error," : access not granted.");
  144.     print("\nPlease contact the SysOp and signal the error code.");
  145.     goto the_end;
  146.     }
  147.  
  148. insert:
  149. leggi_dati(ld);
  150.  
  151. if (strlen(sito) = 0) 
  152.     { print(COL_LRED "\nYou MUST tell me where to get the file!\n");
  153.     ld:=1;    
  154.     goto insert;
  155.     }
  156. if (strlen(file) = 0) 
  157.     { print(COL_LRED "\nYou MUST tell me file name!\n");
  158.     ld:=3;
  159.     goto insert;
  160.     }
  161.  
  162. isok:
  163. cls();
  164. print("\n\nYou requested a ftp for: ");
  165. print(COL_WHITE "\n\nHostname  :" COL_YELLOW, sito);
  166. print(COL_WHITE "\nDirectory :" COL_YELLOW, dir);
  167. print(COL_WHITE "\nFile      :" COL_YELLOW, file);
  168.  
  169. print(COL_WHITE "\n\nThese are data you filled in.\nPress '" COL_LMAGENTA "S" COL_WHITE "' if you wish to change hostname, '" COL_LMAGENTA "D" COL_WHITE "' to change directory and '" COL_LMAGENTA "F" COL_WHITE "' for \nfile name.");
  170. print("\nPress '" COL_LMAGENTA "Q" COL_WHITE "' to quit without saving.\n");
  171. print("Press" COL_LMAGENTA " [Enter]" COL_WHITE " or any other key  to accept current data.");
  172. yn := input_ch(CINPUT_DISPLAY | CINPUT_PROMPT, COL_WHITE "\n\nDo you wish to change something ?");
  173.  
  174. if (yn <> 'S' and yn <> 'D' and yn <> 'F' and yn <> 'Q') goto ok;
  175. if (yn= 'S') 
  176.     {
  177.     leggi_dati(1);
  178.     goto isok;
  179.     }
  180. else if (yn= 'D') 
  181.     {
  182.     leggi_dati(2);
  183.     goto isok;
  184.     }
  185. else if (yn= 'F') 
  186.     {
  187.     leggi_dati(3);
  188.     goto isok;
  189.     }
  190. else if (yn= 'Q') 
  191.     {
  192.     cls();
  193.     print(COL_LRED "\nBack-Ftp ABORTED.");
  194.     goto the_end;
  195.     }
  196.  
  197. ok:
  198. cls();
  199. prepara_dat(sito,dir,file);
  200.  
  201. print(COL_YELLOW "\n\nBack-Ftp OK." COL_WHITE);
  202. print("\nYour request has been saved.\nYou will find the reqeusted file in your personal userdir, " COL_GREEN,userarea,COL_WHITE ".");
  203. print("\nYou will be also notified with a Matrix (Netmail) message, informing you'");
  204. print("\nabout the log of the ftp session.");
  205. print(COL_LBLUE "\n\n\t\t",prm_string(PRM_SYSNAME), "'s Back-Ftp");
  206.  
  207. grt := input_ch(CINPUT_PROMPT, COL_WHITE "\n\n   Press a key");
  208.  
  209. the_end:
  210. return 0;
  211. }
  212.