Skip to content
Snippets Groups Projects
Select Git revision
  • dailybuild_linux-x64
  • dailybuild_win32
  • master default protected
  • sqlite
  • rip_abstraction
  • dailybuild_macos-armv8
  • dd_file_lister_filanem_in_desc_color
  • mode7
  • dd_msg_reader_are_you_there_warning_improvement
  • c23-playing
  • syncterm-1.3
  • syncterm-1.2
  • test-build
  • hide_remote_connection_with_telgate
  • 638-can-t-control-c-during-a-file-search
  • add_body_to_pager_email
  • mingw32-build
  • cryptlib-3.4.7
  • ree/mastermind
  • new_user_dat
  • sbbs320d
  • syncterm-1.6
  • syncterm-1.5
  • syncterm-1.4
  • sbbs320b
  • syncterm-1.3
  • syncterm-1.2
  • syncterm-1.2rc6
  • syncterm-1.2rc5
  • push
  • syncterm-1.2rc4
  • syncterm-1.2rc2
  • syncterm-1.2rc1
  • sbbs319b
  • sbbs318b
  • goodbuild_linux-x64_Sep-01-2020
  • goodbuild_win32_Sep-01-2020
  • goodbuild_linux-x64_Aug-31-2020
  • goodbuild_win32_Aug-31-2020
  • goodbuild_win32_Aug-30-2020
40 results

upload.ssjs

Blame
    • Rob Swindell's avatar
      d1073a21
      A basic HTTP-post handler for uploading files to the filebase · d1073a21
      Rob Swindell authored
      Based on qwk.ssjs
      
      I tested this using:
      wget --auth-no-challenge --post-file=file.ext --http-user=username --http-password=passwd vert.synchro.net/upload.ssjs?filename=file.ext\?desc=description-text
      
      This currently requires an "uploads" directory to be configured by the sysop.
      
      I'm not sure if there's a better/more-standard way for the posted filename or
      content to be included in the request. This is just a sort of proof-of-concept
      as a solution for issue #554. Perhaps an ecbwebv4 page displays a prompt to the
      user for their filename and it redirects to this page. Not sure how that'll
      work.
      d1073a21
      History
      A basic HTTP-post handler for uploading files to the filebase
      Rob Swindell authored
      Based on qwk.ssjs
      
      I tested this using:
      wget --auth-no-challenge --post-file=file.ext --http-user=username --http-password=passwd vert.synchro.net/upload.ssjs?filename=file.ext\?desc=description-text
      
      This currently requires an "uploads" directory to be configured by the sysop.
      
      I'm not sure if there's a better/more-standard way for the posted filename or
      content to be included in the request. This is just a sort of proof-of-concept
      as a solution for issue #554. Perhaps an ecbwebv4 page displays a prompt to the
      user for their filename and it redirects to this page. Not sure how that'll
      work.
    upload.ssjs 2.52 KiB
    // Upload a file via HTTP-POST
    // vi: tabstop=4
    
    require('sbbsdefs.js', 'LEN_FDESC');
    
    "use strict";
    
    function post(query)
    {
    //	log(LOG_INFO, "query: " + JSON.stringify(query));
    	if(!http_request.post_data) {
    		log(LOG_WARNING, "no post data provided");
    		return "500 No post data provided";
    	}
        if(!query.filename) {
            log(LOG_WARNING, "no filename specified");
            return "500 No filename specified";
        }
    	var fname = file_getname(query.filename[0]);
    	if(!check_filename(fname)) {
    		log(LOG_WARNING, "Attempted disallowed filname: " + fname);
    		return "500 Filename not allowed";
    	}
    	var fdesc;
    	if(query.desc)
    		fdesc = query.desc[0];
    	
    	log(LOG_INFO, format("received file (%s): %u bytes"
            ,fname, http_request.post_data.length));
        if(!file_area.upload_dir) {
            log(LOG_ERR, "No upload directory configured");
            return "500 No upload directory configured";
        }
        var dir = file_area.upload_dir;
    	
    	if(!dir.can_upload) {
    		log(LOG_NOTICE, "User can't upload to dir: " + dir.code);
    		return "500 Can't upload here";
    	}
    
    	var filename = dir.path + fname;
    	if(file_exists(filename)) {
    		log(LOG_WARNING, filename + " already exists");
    		return "409 File already exists";
    	}
    
    	var filebase = new FileBase(dir.code);
    	if(!filebase.open()) {
    		log(LOG_ERR, "Failed to open: " + filebase.file);
    		return "500 error opening " + filebase.file;
    	}
    	if(filebase.get(fname)) {
    		log(LOG_WARNING, format("File (%s) already exists in %s", fname, dir.code));
    		return "500 File already uploaded";
    	}
    
    	var file = new File(filename);
    	if(!file.open("wb")) {
    		log(LOG_ERR, "error " + file.error + " opening file: " + file.name);
    		return "409 error creating file";
    	}
    	file.write(http_request.post_data);
    	file.close();
    
    	file = { name: fname, desc: format("%.*s", LEN_FDESC, fdesc), from: user.alias };
    	file.cost = file_size(filename);
    	log(LOG_INFO, "Adding " + file.name + " to " + filebase.file);
    	var result = filebase.add(file);
    	if(result)
    		log(LOG_INFO, format("File (%s) added successfully to: ", file.name) + dir.code);
    	else
    		log(LOG_ERR, "Error " + filebase.last_error + " adding file to: " + dir.code);
    	filebase.close();
    	
    	return result ? "200 bitchen" : "500 error";
    }
    
    function main()
    {
    	if(!user.number) {
    		http_reply.status = "403 Must auth first";
    		return;
    	}
    	switch(http_request.method) {
    		case "POST":
                log(LOG_DEBUG, "http_request = " + JSON.stringify(http_request));
    			http_reply.status = post(http_request.query);
    			break;
    		default:
    			http_reply.status = "404 method not supported";
    			break;
    	}
    }
    
    main();