|
|
1.1 root 1: /* js_file_area.c */
2:
3: /* Synchronet JavaScript "File Area" Object */
4:
1.1.1.2 ! root 5: /* $Id: js_file_area.c,v 1.48 2011/08/06 21:11:31 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
1.1.1.2 ! root 11: * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: #ifdef JAVASCRIPT
41:
42: #ifdef BUILD_JSDOCS
43:
44: static char* file_area_prop_desc[] = {
1.1.1.2 ! root 45: "minimum amount of available disk space (in kilobytes) required for user uploads to be allowed"
1.1 root 46: ,"file area settings (bitfield) - see <tt>FM_*</tt> in <tt>sbbsdefs.js</tt> for details"
47: ,NULL
48: };
49:
50:
51: static char* lib_prop_desc[] = {
52: "index into lib_list array (or -1 if not in array) <i>(introduced in v3.12)</i>"
53: ,"unique number for this library"
54: ,"library name"
55: ,"library description"
56: ,"library access requirements"
57: ,"library link (for HTML index)"
58: ,NULL
59: };
60:
61: static char* dir_prop_desc[] = {
62:
63: "index into dir_list array (or -1 if not in array) <i>(introduced in v3.12)</i>"
64: ,"unique number for this directory"
65: ,"library index <i>(introduced in v3.12)</i>"
66: ,"library number"
67: ,"library name <i>(introduced in v3.12)</i>"
68: ,"directory internal code"
69: ,"directory name"
70: ,"directory description"
71: ,"directory file storage location"
72: ,"directory access requirements"
73: ,"directory upload requirements"
74: ,"directory download requirements"
75: ,"directory exemption requirements"
76: ,"directory operator requirements"
77: ,"allowed file extensions (comma delimited)"
78: ,"upload semaphore file"
79: ,"directory data storage location"
80: ,"toggle options (bitfield)"
81: ,"sequential (slow storage) device number"
82: ,"sort order (see <tt>SORT_*</tt> in <tt>sbbsdefs.js</tt> for valid values)"
83: ,"configured maximum number of files"
84: ,"configured maximum age (in days) of files before expiration"
85: ,"percent of file size awarded uploader in credits upon file upload"
86: ,"percent of file size awarded uploader in credits upon subsequent downloads"
87: ,"directory link (for HTML index)"
88: ,"user has sufficient access to upload files"
89: ,"user has sufficient access to download files"
90: ,"user is exempt from download credit costs"
91: ,"user has operator access to this directory"
92: ,"directory is for offline storage <i>(introduced in v3.14)</i>"
93: ,"directory is for uploads only <i>(introduced in v3.14)</i>"
94: ,"directory is for uploads to sysop only <i>(introduced in v3.14)</i>"
95: ,NULL
96: };
97: #endif
98:
99:
100: JSObject* DLLCALL js_CreateFileAreaObject(JSContext* cx, JSObject* parent, scfg_t* cfg
1.1.1.2 ! root 101: ,user_t* user, client_t* client, char* html_index_file)
1.1 root 102: {
103: char vpath[MAX_PATH+1];
104: JSObject* areaobj;
105: JSObject* alllibs;
106: JSObject* alldirs;
107: JSObject* libobj;
108: JSObject* dirobj;
109: JSObject* lib_list;
110: JSObject* dir_list;
111: JSString* js_str;
112: jsval val;
113: jsuint lib_index;
114: jsuint dir_index;
115: uint l,d;
1.1.1.2 ! root 116: BOOL is_op;
1.1 root 117:
118: /* Return existing object if it's already been created */
119: if(JS_GetProperty(cx,parent,"file_area",&val) && val!=JSVAL_VOID)
120: areaobj = JSVAL_TO_OBJECT(val);
121: else
122: areaobj = JS_DefineObject(cx, parent, "file_area", NULL
123: , NULL, JSPROP_ENUMERATE|JSPROP_READONLY);
124: if(areaobj==NULL)
125: return(NULL);
126:
127: /* file_area.properties */
128: if(!JS_NewNumberValue(cx,cfg->min_dspace,&val))
129: return(NULL);
130: if(!JS_SetProperty(cx, areaobj, "min_diskspace", &val))
131: return(NULL);
132:
133: if(!JS_NewNumberValue(cx,cfg->file_misc,&val))
134: return(NULL);
135: if(!JS_SetProperty(cx, areaobj, "settings", &val))
136: return(NULL);
137:
138: /* file_area.lib[] */
139: if((alllibs=JS_NewObject(cx, NULL, NULL, areaobj))==NULL)
140: return(NULL);
141:
142: val=OBJECT_TO_JSVAL(alllibs);
143: if(!JS_SetProperty(cx, areaobj, "lib", &val))
144: return(NULL);
145:
146: /* file_area.dir[] */
147: if((alldirs=JS_NewObject(cx, NULL, NULL, areaobj))==NULL)
148: return(NULL);
149:
150: val=OBJECT_TO_JSVAL(alldirs);
151: if(!JS_SetProperty(cx, areaobj, "dir", &val))
152: return(NULL);
153:
154: if(html_index_file==NULL)
155: html_index_file="";
156:
157: #ifdef BUILD_JSDOCS
158: js_DescribeSyncObject(cx,areaobj,"File Transfer Areas",310);
159: #endif
160:
161: /* file_area.lib_list[] */
162: if((lib_list=JS_NewArrayObject(cx, 0, NULL))==NULL)
163: return(NULL);
164:
165: val=OBJECT_TO_JSVAL(lib_list);
166: if(!JS_SetProperty(cx, areaobj, "lib_list", &val))
167: return(NULL);
168:
169: for(l=0;l<cfg->total_libs;l++) {
170:
171: if((libobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
172: return(NULL);
173:
174: val=OBJECT_TO_JSVAL(libobj);
175: lib_index=-1;
1.1.1.2 ! root 176: if(user==NULL || chk_ar(cfg,cfg->lib[l]->ar,user,client)) {
1.1 root 177:
178: if(!JS_GetArrayLength(cx, lib_list, &lib_index))
179: return(NULL);
180:
181: if(!JS_SetElement(cx, lib_list, lib_index, &val))
182: return(NULL);
183: }
184:
185: /* Add as property (associative array element) */
186: if(!JS_DefineProperty(cx, alllibs, cfg->lib[l]->sname, val
187: ,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
188: return(NULL);
189:
190: val=INT_TO_JSVAL(lib_index);
191: if(!JS_SetProperty(cx, libobj, "index", &val))
192: return(NULL);
193:
194: val=INT_TO_JSVAL(l);
195: if(!JS_SetProperty(cx, libobj, "number", &val))
196: return(NULL);
197:
198: if((js_str=JS_NewStringCopyZ(cx, cfg->lib[l]->sname))==NULL)
199: return(NULL);
200: val=STRING_TO_JSVAL(js_str);
201: if(!JS_SetProperty(cx, libobj, "name", &val))
202: return(NULL);
203:
204: if((js_str=JS_NewStringCopyZ(cx, cfg->lib[l]->lname))==NULL)
205: return(NULL);
206: val=STRING_TO_JSVAL(js_str);
207: if(!JS_SetProperty(cx, libobj, "description", &val))
208: return(NULL);
209:
210: if((js_str=JS_NewStringCopyZ(cx, cfg->lib[l]->arstr))==NULL)
211: return(NULL);
212: val=STRING_TO_JSVAL(js_str);
213: if(!JS_SetProperty(cx, libobj, "ars", &val))
214: return(NULL);
215:
216: sprintf(vpath,"/%s/%s",cfg->lib[l]->sname,html_index_file);
217: if((js_str=JS_NewStringCopyZ(cx, vpath))==NULL)
218: return(NULL);
219: val=STRING_TO_JSVAL(js_str);
220: if(!JS_SetProperty(cx, libobj, "link", &val))
221: return(NULL);
222:
223: #ifdef BUILD_JSDOCS
224: js_DescribeSyncObject(cx,libobj,"File Transfer Libraries (current user has access to)",310);
225: #endif
226:
227: /* dir_list[] */
228: if((dir_list=JS_NewArrayObject(cx, 0, NULL))==NULL)
229: return(NULL);
230:
231: val=OBJECT_TO_JSVAL(dir_list);
232: if(!JS_SetProperty(cx, libobj, "dir_list", &val))
233: return(NULL);
234:
235: for(d=0;d<cfg->total_dirs;d++) {
236: if(cfg->dir[d]->lib!=l)
237: continue;
238:
239: if((dirobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL)
240: return(NULL);
241:
242: val=OBJECT_TO_JSVAL(dirobj);
243: dir_index=-1;
1.1.1.2 ! root 244: if(user==NULL || chk_ar(cfg,cfg->dir[d]->ar,user,client)) {
1.1 root 245:
246: if(!JS_GetArrayLength(cx, dir_list, &dir_index))
247: return(NULL);
248:
249: if(!JS_SetElement(cx, dir_list, dir_index, &val))
250: return(NULL);
251: }
252:
253: /* Add as property (associative array element) */
254: if(!JS_DefineProperty(cx, alldirs, cfg->dir[d]->code, val
255: ,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE))
256: return(NULL);
257:
258: if(d==cfg->user_dir
259: && !JS_DefineProperty(cx, areaobj, "user_dir", val
260: ,NULL,NULL,JSPROP_READONLY))
261: return(NULL);
262:
263: if(d==cfg->sysop_dir
264: && !JS_DefineProperty(cx, areaobj, "sysop_dir", val
265: ,NULL,NULL,JSPROP_READONLY))
266: return(NULL);
267:
268: if(d==cfg->upload_dir
269: && !JS_DefineProperty(cx, areaobj, "upload_dir", val
270: ,NULL,NULL,JSPROP_READONLY))
271: return(NULL);
272:
273: if(d==cfg->lib[l]->offline_dir
274: && !JS_DefineProperty(cx, libobj, "offline_dir", val
275: ,NULL,NULL,JSPROP_READONLY))
276: return(NULL);
277:
278: val=INT_TO_JSVAL(dir_index);
279: if(!JS_SetProperty(cx, dirobj, "index", &val))
280: return(NULL);
281:
282: val=INT_TO_JSVAL(d);
283: if(!JS_SetProperty(cx, dirobj, "number", &val))
284: return(NULL);
285:
286: val=INT_TO_JSVAL(lib_index);
287: if(!JS_SetProperty(cx, dirobj, "lib_index", &val))
288: return(NULL);
289:
290: val=INT_TO_JSVAL(cfg->dir[d]->lib);
291: if(!JS_SetProperty(cx, dirobj, "lib_number", &val))
292: return(NULL);
293:
294: if((js_str=JS_NewStringCopyZ(cx, cfg->lib[cfg->dir[d]->lib]->sname))==NULL)
295: return(NULL);
296: val=STRING_TO_JSVAL(js_str);
297: if(!JS_SetProperty(cx, dirobj, "lib_name", &val))
298: return(NULL);
299:
300: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->code))==NULL)
301: return(NULL);
302: val=STRING_TO_JSVAL(js_str);
303: if(!JS_SetProperty(cx, dirobj, "code", &val))
304: return(NULL);
305:
306: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->sname))==NULL)
307: return(NULL);
308: val=STRING_TO_JSVAL(js_str);
309: if(!JS_SetProperty(cx, dirobj, "name", &val))
310: return(NULL);
311:
312: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->lname))==NULL)
313: return(NULL);
314: val=STRING_TO_JSVAL(js_str);
315: if(!JS_SetProperty(cx, dirobj, "description", &val))
316: return(NULL);
317:
318: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->path))==NULL)
319: return(NULL);
320: val=STRING_TO_JSVAL(js_str);
321: if(!JS_SetProperty(cx, dirobj, "path", &val))
322: return(NULL);
323:
324: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->arstr))==NULL)
325: return(NULL);
326: if(!JS_DefineProperty(cx, dirobj, "ars", STRING_TO_JSVAL(js_str)
327: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY))
328: return(NULL);
329:
330: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->ul_arstr))==NULL)
331: return(NULL);
332: if(!JS_DefineProperty(cx, dirobj, "upload_ars", STRING_TO_JSVAL(js_str)
333: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY))
334: return(NULL);
335:
336: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->dl_arstr))==NULL)
337: return(NULL);
338: if(!JS_DefineProperty(cx, dirobj, "download_ars", STRING_TO_JSVAL(js_str)
339: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY))
340: return(NULL);
341:
342: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->ex_arstr))==NULL)
343: return(NULL);
344: if(!JS_DefineProperty(cx, dirobj, "exempt_ars", STRING_TO_JSVAL(js_str)
345: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY)) /* exception here: Oct-15-2006 */
346: return(NULL); /* ChangeScope->calloc() */
347:
348: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->op_arstr))==NULL)
349: return(NULL);
350: if(!JS_DefineProperty(cx, dirobj, "operator_ars", STRING_TO_JSVAL(js_str)
351: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY))
352: return(NULL);
353:
354: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->exts))==NULL)
355: return(NULL);
356: val=STRING_TO_JSVAL(js_str);
357: if(!JS_SetProperty(cx, dirobj, "extensions", &val))
358: return(NULL);
359:
360: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->upload_sem))==NULL)
361: return(NULL);
362: val=STRING_TO_JSVAL(js_str);
363: if(!JS_SetProperty(cx, dirobj, "upload_sem", &val))
364: return(NULL);
365:
366: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->data_dir))==NULL)
367: return(NULL);
368: val=STRING_TO_JSVAL(js_str);
369: if(!JS_SetProperty(cx, dirobj, "data_dir", &val))
370: return(NULL);
371:
372: if(!JS_NewNumberValue(cx,cfg->dir[d]->misc,&val))
373: return(NULL);
374: if(!JS_SetProperty(cx, dirobj, "settings", &val))
375: return(NULL);
376:
377: val=INT_TO_JSVAL(cfg->dir[d]->seqdev);
378: if(!JS_SetProperty(cx, dirobj, "seqdev", &val))
379: return(NULL);
380:
381: val=INT_TO_JSVAL(cfg->dir[d]->sort);
382: if(!JS_SetProperty(cx, dirobj, "sort", &val))
383: return(NULL);
384:
385: val=INT_TO_JSVAL(cfg->dir[d]->maxfiles);
386: if(!JS_SetProperty(cx, dirobj, "max_files", &val))
387: return(NULL);
388:
389: val=INT_TO_JSVAL(cfg->dir[d]->maxage);
390: if(!JS_SetProperty(cx, dirobj, "max_age", &val))
391: return(NULL);
392:
393: val=INT_TO_JSVAL(cfg->dir[d]->up_pct);
394: if(!JS_SetProperty(cx, dirobj, "upload_credit_pct", &val))
395: return(NULL);
396:
397: val=INT_TO_JSVAL(cfg->dir[d]->dn_pct);
398: if(!JS_SetProperty(cx, dirobj, "download_credit_pct", &val))
399: return(NULL);
400:
401: sprintf(vpath,"/%s/%s/%s"
402: ,cfg->lib[l]->sname
403: ,cfg->dir[d]->code_suffix
404: ,html_index_file);
405: if((js_str=JS_NewStringCopyZ(cx, vpath))==NULL)
406: return(NULL);
407: val=STRING_TO_JSVAL(js_str);
408: if(!JS_SetProperty(cx, dirobj, "link", &val))
409: return(NULL);
410:
1.1.1.2 ! root 411: if(user!=NULL
! 412: && (user->level>=SYSOP_LEVEL
! 413: || (cfg->dir[d]->op_ar[0]!=0
! 414: && chk_ar(cfg,cfg->dir[d]->op_ar,user,client))))
! 415: is_op=TRUE;
! 416: else
! 417: is_op=FALSE;
! 418:
1.1 root 419: if(user==NULL
1.1.1.2 ! root 420: || ((is_op || user->exempt&FLAG('U') || chk_ar(cfg,cfg->dir[d]->ul_ar,user,client)) && !(user->rest&FLAG('U'))))
1.1 root 421: val=JSVAL_TRUE;
422: else
423: val=JSVAL_FALSE;
424: if(!JS_SetProperty(cx, dirobj, "can_upload", &val))
425: return(NULL);
426:
427: if(user==NULL
1.1.1.2 ! root 428: || (chk_ar(cfg,cfg->dir[d]->dl_ar,user,client) && !(user->rest&FLAG('D'))))
1.1 root 429: val=JSVAL_TRUE;
430: else
431: val=JSVAL_FALSE;
432: if(!JS_SetProperty(cx, dirobj, "can_download", &val))
433: return(NULL);
434:
1.1.1.2 ! root 435: if(is_download_free(cfg,d,user,client))
1.1 root 436: val=JSVAL_TRUE;
437: else
438: val=JSVAL_FALSE;
439: if(!JS_SetProperty(cx, dirobj, "is_exempt", &val))
440: return(NULL);
441:
1.1.1.2 ! root 442: if(is_op)
1.1 root 443: val=JSVAL_TRUE;
444: else
445: val=JSVAL_FALSE;
446: if(!JS_SetProperty(cx, dirobj, "is_operator", &val))
447: return(NULL);
448:
449: val=BOOLEAN_TO_JSVAL(d==cfg->lib[l]->offline_dir);
450: if(!JS_SetProperty(cx, dirobj, "is_offline", &val))
451: return(NULL);
452:
453: val=BOOLEAN_TO_JSVAL(d==cfg->upload_dir);
454: if(!JS_SetProperty(cx, dirobj, "is_upload", &val))
455: return(NULL);
456:
457: val=BOOLEAN_TO_JSVAL(d==cfg->sysop_dir);
458: if(!JS_SetProperty(cx, dirobj, "is_sysop", &val))
459: return(NULL);
460:
461: #ifdef BUILD_JSDOCS
462: js_CreateArrayOfStrings(cx, dirobj, "_property_desc_list", dir_prop_desc, JSPROP_READONLY);
463: js_DescribeSyncObject(cx,dirobj,"File Transfer Directories (current user has access to)",310);
464: #endif
465: }
466:
467: #ifdef BUILD_JSDOCS
468: js_CreateArrayOfStrings(cx, libobj, "_property_desc_list", lib_prop_desc, JSPROP_READONLY);
469: #endif
470: }
471:
472: #ifdef BUILD_JSDOCS
473: js_CreateArrayOfStrings(cx, areaobj, "_property_desc_list", file_area_prop_desc, JSPROP_READONLY);
474:
475: js_DescribeSyncObject(cx,alllibs,"Associative array of all libraries (use name as index)",312);
476: JS_DefineProperty(cx,alllibs,"_dont_document",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY);
477:
478: js_DescribeSyncObject(cx,alldirs,"Associative array of all directories (use internal code as index)",311);
479: JS_DefineProperty(cx,alldirs,"_dont_document",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY);
480: #endif
481:
482: return(areaobj);
483: }
484:
485: #endif /* JAVSCRIPT */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.