예제 #1
0
int main(int argc, char** argv) {
	RSScript ss, *s = &ss;
	rss_init(s, argc, argv);
	
	rss_http_request* req = rss_get_request(s);
	if(!req) return 1;
	
	if(!rss_is_cookie_authed(s)) {
		rss_redirect_hard(s, SPLITERAL("/login.html"));
		rss_free(s);
		exit(0);
	}
	
	rss_set_cookie_authed(s, NULL);
	
	stringptr *x, *y;
	
	if((kv_find(req->formdata, SPLITERAL("list"), (void**) &x))) {
		y = stringptr_replace(x, SPLITERAL("\r"), SPLITERAL(""));
		stringptr_tofile("/tmp/testfile", y);
		stringptr_free(y);
		rss_redirect_soft(s, SPLITERAL("main.cgi"));
	} else
		rss_respond500(s);
	
	rss_free(s);
	return 0;
}
예제 #2
0
파일: butch.c 프로젝트: yasar11732/butch
int create_script(jobtype ptype, pkgstate* state, pkg_exec* item, pkgdata* data) {
	stringptr* temp, *config, tb;
	stringptr* set_cc = SPL("if [ -z \"$CC\" ] ; then\n\tCC=cc\nfi\n");
	
	char* prefix;
	char buf[256];
	int hastarball;
	if(ptype == JT_DOWNLOAD) {
		prefix = "dl";
	} else if (ptype == JT_BUILD) {
		prefix = "build";
	} else
		abort();
	
	item->scripts.filename = stringptr_format("%s/%s_%s.sh", state->cfg.builddir.ptr, prefix, item->name->ptr);
	item->scripts.stdoutfn = stringptr_format("%s/%s_%s.log", state->cfg.logdir.ptr, prefix, item->name->ptr); 
	
	config = make_config(&state->cfg);
	hastarball = get_tarball_filename(data, buf, sizeof(buf));
	
	if(ptype == JT_DOWNLOAD) {
		if(!hastarball) abort(); //bug
		temp = stringptr_concat(SPL("#!/bin/sh\n"),
			config,
			SPL("wget -O $C/"),
			stringptr_fromchar(buf, &tb),
			SPL(" "),
			stringptrlist_get(data->mirrors, rand() % stringptrlist_getsize(data->mirrors)),
			//SPL(" --no-check-certificate"),
			NULL);
		
	} else if (ptype == JT_BUILD) {
		stringptr* buildscr = stringptrlist_tostring(data->buildscript);
		
		if(!hastarball) {
			temp = stringptr_concat(SPL("#!/bin/sh\n"), 
				config,
				set_cc,
				buildscr,
				NULL);
		} else {
			if(data->tardir->size && data->tardir->ptr[0] == '/') 
				// prevent erroneus scripts from trash our fs
				abort();
			
			temp = stringptr_concat(SPL("#!/bin/sh\n"), 
				config,
				set_cc,
				SPL("cd $S/build\n"), 
				SPL("[ -e "),
				data->tardir,
				SPL(" ] && rm -rf "),
				data->tardir,
				SPL("\ntar xf $C/"), 
				stringptr_fromchar(buf, &tb),
				SPL(" || (echo tarball error; exit 1)\ncd $S/build/"),
				data->tardir,
				SPL("\n"),
				buildscr,
				NULL);
		}
		
		stringptr_free(buildscr);
		
	} else abort();

	stringptr_tofile(item->scripts.filename->ptr, temp);
	if(chmod(item->scripts.filename->ptr, 0777) == -1) die(SPL("error setting permission"));
	stringptr_free(config);
	stringptr_free(temp);
	return 1;
}