4 * Uncomment to dump an HTTP trace to stderr
19 #define WEBCIT_WITH_CALENDAR_SERVICE 1
23 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
28 /* Work around RedHat's b0rken OpenSSL includes */
29 #define OPENSSL_NO_KRB5
30 #include <openssl/ssl.h>
31 #include <openssl/err.h>
32 #include <openssl/rand.h>
35 #define CALENDAR_ROOM_NAME "Calendar"
36 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
38 #define SIZ 4096 /* generic buffer size */
40 #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
42 #define SLEEPING 180 /* TCP connection timeout */
43 #define WEBCIT_TIMEOUT 900 /* WebCit session timeout */
44 #define PORT_NUM 2000 /* port number to listen on */
45 #define SERVER "WebCit v6.20" /* who's in da house */
46 #define DEVELOPER_ID 0
48 #define CLIENT_VERSION 620 /* This version of WebCit */
49 #define MINIMUM_CIT_VERSION 640 /* min required Citadel vers */
50 #define DEFAULT_HOST "localhost" /* Default Citadel server */
51 #define DEFAULT_PORT "504"
52 #define LB (1) /* Internal escape chars */
55 #define TARGET "webcit01" /* Target for inline URL's */
56 #define HOUSEKEEPING 15 /* Housekeeping frequency */
57 #define MIN_WORKER_THREADS 5
58 #define MAX_WORKER_THREADS 250
59 #define LISTEN_QUEUE_LENGTH 100 /* listen() backlog queue */
61 #define USERCONFIGROOM "My Citadel Config"
62 #define DEFAULT_MAXMSGS 20
66 * Room flags (from Citadel)
70 #define QR_PERMANENT 1 /* Room does not purge */
71 #define QR_INUSE 2 /* Set if in use, clear if avail */
72 #define QR_PRIVATE 4 /* Set for any type of private room */
73 #define QR_PASSWORDED 8 /* Set if there's a password too */
74 #define QR_GUESSNAME 16 /* Set if it's a guessname room */
75 #define QR_DIRECTORY 32 /* Directory room */
76 #define QR_UPLOAD 64 /* Allowed to upload */
77 #define QR_DOWNLOAD 128 /* Allowed to download */
78 #define QR_VISDIR 256 /* Visible directory */
79 #define QR_ANONONLY 512 /* Anonymous-Only room */
80 #define QR_ANONOPT 1024 /* Anonymous-Option room */
81 #define QR_NETWORK 2048 /* Shared network room */
82 #define QR_PREFONLY 4096 /* Preferred status needed to enter */
83 #define QR_READONLY 8192 /* Aide status required to post */
84 #define QR_MAILBOX 16384 /* Set if this is a private mailbox */
89 #define QR2_SYSTEM 1 /* System room; hide by default */
90 #define QR2_SELFLIST 2 /* Self-service mailing list mgmt */
94 #define UA_GOTOALLOWED 4
95 #define UA_HASNEWMSGS 8
104 struct httprequest *next;
109 struct urlcontent *next;
116 char serv_nodename[32];
117 char serv_humannode[64];
119 char serv_software[64];
121 char serv_bbs_city[64];
122 char serv_sysadm[64];
123 char serv_moreprompt[SIZ];
125 int serv_supports_ldap;
131 * This struct holds a list of rooms for <G>oto operations.
135 char march_name[128];
141 * This struct holds a list of rooms for client display.
145 struct roomlisting *lnext;
146 struct roomlisting *rnext;
156 * Dynamic content for variable substitution in templates
159 struct wcsubst *next;
163 void (*wcs_function)(void);
167 * Values for wcs_type
176 struct wc_attachment {
177 struct wc_attachment *next;
179 char content_type[SIZ];
185 * One of these is kept for each active Citadel session.
186 * HTTP transactions are bound to one at a time.
189 struct wcsession *next; /* Linked list */
190 int wc_session; /* WebCit session ID */
191 char wc_username[SIZ];
192 char wc_password[SIZ];
193 char wc_roomname[SIZ];
210 char upload_filename[SIZ];
211 char upload_content_type[SIZ];
213 int remember_new_mail;
214 int need_regi; /* This user needs to register. */
215 int need_vali; /* New users require validation. */
216 char cs_inet_email[SIZ]; /* User's preferred Internet addr. */
217 pthread_mutex_t SessionMutex; /* mutex for exclusive access */
218 time_t lastreq; /* Timestamp of most recent HTTP */
219 int killthis; /* Nonzero == purge this session */
220 struct march *march; /* march mode room list */
221 char reply_to[SIZ]; /* reply-to address */
222 long msgarr[10000]; /* for read operations */
223 int is_wap; /* Client is a WAP gateway */
224 struct urlcontent *urlstrings;
225 int HaveInstantMessages; /* Nonzero if incoming msgs exist */
226 struct wcsubst *vars;
227 char this_page[SIZ]; /* address of current page */
228 char http_host[SIZ]; /* HTTP Host: header */
230 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
232 icalcomponent *cal; /* cal items for display */
233 long cal_msgnum; /* cal msgids for display */
237 struct wc_attachment *first_attachment;
238 char ImportantMessage[SIZ];
239 char last_chat_user[SIZ];
240 int ctdl_pid; /* Session ID on the Citadel server */
241 char httpauth_user[SIZ]; /* only for GroupDAV sessions */
242 char httpauth_pass[SIZ]; /* only for GroupDAV sessions */
246 int gzip_ok; /* Nonzero if Accept-encoding: gzip */
249 #define num_parms(source) num_tokens(source, '|')
251 /* Per-session data */
252 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
253 extern pthread_key_t MyConKey;
255 /* Per-thread SSL context */
257 #define THREADSSL ((SSL *)pthread_getspecific(ThreadSSL))
258 extern pthread_key_t ThreadSSL;
261 struct serv_info serv_info;
262 extern char floorlist[128][SIZ];
263 extern char *axdefs[];
264 extern char *ctdlhost, *ctdlport;
265 extern char *server_cookie;
267 extern int setup_wizard;
268 extern char wizard_filename[];
269 void do_setup_wizard(void);
271 void stuff_to_cookie(char *cookie, int session,
272 char *user, char *pass, char *room);
273 void cookie_to_stuff(char *cookie, int *session,
274 char *user, size_t user_len,
275 char *pass, size_t pass_len,
276 char *room, size_t room_len);
277 char *bmstrstr(char *text, char *pattern,
278 int (*cmpfunc)(const char *, const char *, size_t) );
279 void locate_host(char *, int);
280 void become_logged_in(char *, char *, char *);
282 void display_login(char *mesg);
283 void do_welcome(void);
284 void do_logout(void);
285 void display_main_menu(void);
286 void display_aide_menu(void);
287 void display_advanced_menu(void);
288 void slrp_highest(void);
291 void get_serv_info(char *, char *);
292 int uds_connectsock(char *);
293 int tcp_connectsock(char *, char *);
294 void serv_getln(char *strbuf, int bufsize);
295 void serv_puts(char *string);
297 void who_inner_html(void);
298 void fmout(FILE *fp, char *align);
299 void wDumpContent(int);
300 void serv_printf(const char *format,...);
301 char *bstr(char *key);
302 void urlesc(char *, char *);
303 void urlescputs(char *);
304 void jsesc(char *, char *);
305 void jsescputs(char *);
306 void output_headers( int do_httpheaders,
313 void wprintf(const char *format,...);
314 void output_static(char *what);
315 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks);
316 void escputs(char *strbuf);
318 void escputs1(char *strbuf, int nbsp, int nolinebreaks);
319 void msgesc(char *target, char *strbuf);
320 void msgescputs(char *strbuf);
321 int extract_int(const char *source, int parmnum);
322 long extract_long(const char *source, int parmnum);
323 void stripout(char *str, char leftboundary, char rightboundary);
324 void dump_vars(void);
325 void embed_main_menu(void);
326 void serv_read(char *buf, int bytes);
327 int haschar(char *, char);
328 void readloop(char *oper);
329 void text_to_server(char *ptr, int convert_to_html);
330 void display_enter(void);
331 void post_message(void);
332 void confirm_delete_msg(void);
333 void delete_msg(void);
334 void confirm_move_msg(void);
338 void display_page(void);
339 void page_user(void);
341 void display_private(char *rname, int req_pass);
342 void goto_private(void);
343 void zapped_list(void);
344 void display_zap(void);
346 void display_success(char *);
347 void display_entroom(void);
349 void display_editroom(void);
352 void display_whok(void);
353 void do_invt_kick(void);
354 void server_to_text(void);
355 void save_edit(char *description, char *enter_cmd, int regoto);
356 void display_edit(char *description, char *check_cmd,
357 char *read_cmd, char *save_cmd, int with_room_banner);
358 void gotoroom(char *gname);
359 void confirm_delete_room(void);
360 void delete_room(void);
362 void display_graphics_upload(char *, char *, char *);
363 void do_graphics_upload(char *upl_cmd);
364 void serv_read(char *buf, int bytes);
365 void serv_gets(char *strbuf);
366 void serv_write(char *buf, int nbytes);
367 void serv_puts(char *string);
368 void serv_printf(const char *format,...);
369 void load_floorlist(void);
370 void display_reg(int);
371 void display_changepw(void);
373 void display_edit_node(void);
374 void edit_node(void);
375 void display_netconf(void);
376 void display_confirm_delete_node(void);
377 void delete_node(void);
378 void display_add_node(void);
380 void terminate_session(void);
382 void display_siteconfig(void);
383 void siteconfig(void);
384 void display_generic(void);
385 void do_generic(void);
386 void display_menubar(int);
387 void smart_goto(char *);
388 void worker_entry(void);
389 void session_loop(struct httprequest *);
390 void fmt_date(char *buf, time_t thetime, int brief);
391 void fmt_time(char *buf, time_t thetime);
392 void httpdate(char *buf, time_t thetime);
393 void end_webcit_session(void);
394 void page_popup(void);
395 void chat_recv(void);
396 void chat_send(void);
397 void http_redirect(char *);
398 void clear_local_substs(void);
399 void svprintf(char *keyname, int keytype, const char *format,...);
400 void svcallback(char *keyname, void (*fcn_ptr)() );
401 void do_template(void *templatename);
402 int lingering_close(int fd);
403 char *memreadline(char *start, char *buf, int maxlen);
404 int num_tokens (char *source, char tok);
405 void extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
406 void remove_token(char *source, int parmnum, char separator);
407 char *load_mimepart(long msgnum, char *partnum);
408 int pattern2(char *search, char *patn);
409 void do_edit_vcard(long, char *, char *);
410 void edit_vcard(void);
411 void submit_vcard(void);
412 void striplt(char *);
413 void select_user_to_edit(char *message, char *preselect);
414 void delete_user(char *);
415 void display_edituser(char *who, int is_new);
416 void create_user(void);
418 void do_change_view(int);
419 void change_view(void);
421 void do_stuff_to_msgs(void);
422 void load_preferences(void);
423 void save_preferences(void);
424 void get_preference(char *key, char *value, size_t value_len);
425 void set_preference(char *key, char *value, int save_to_server);
427 int is_msg_in_mset(char *mset, long msgnum);
428 char *safestrncpy(char *dest, const char *src, size_t n);
429 void display_addressbook(long msgnum, char alpha);
430 void offer_start_page(void);
431 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext);
432 void change_start_page(void);
433 void output_html(char *);
434 void display_floorconfig(char *);
435 void delete_floor(void);
436 void create_floor(void);
437 void rename_floor(void);
438 void do_listsub(void);
439 void toggle_self_service(void);
441 ssize_t write(int fd, const void *buf, size_t count);
442 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum);
443 void display_calendar(long msgnum);
444 void display_task(long msgnum);
445 void display_note(long msgnum);
446 void do_calendar_view(void);
447 void do_tasks_view(void);
448 void free_calendar_buffer(void);
449 void calendar_summary_view(void);
450 int load_msg_ptrs(char *servcmd);
451 void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen);
452 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
453 void free_attachments(struct wcsession *sess);
454 void set_room_policy(void);
455 void display_inetconf(void);
456 void save_inetconf(void);
457 void generate_uuid(char *);
458 void display_preferences(void);
459 void set_preferences(void);
461 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
462 void display_edit_task(void);
463 void save_task(void);
464 void display_edit_event(void);
465 void save_event(void);
466 void display_icaltimetype_as_webform(struct icaltimetype *, char *);
467 void icaltime_from_webform(struct icaltimetype *result, char *prefix);
468 void icaltime_from_webform_dateonly(struct icaltimetype *result, char *prefix);
469 void display_edit_individual_event(icalcomponent *supplied_vtodo, long msgnum);
470 void save_individual_event(icalcomponent *supplied_vtodo, long msgnum);
471 void respond_to_request(void);
472 void handle_rsvp(void);
473 void ical_dezonify(icalcomponent *cal);
474 void partstat_as_string(char *buf, icalproperty *attendee);
475 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp);
476 void check_attendee_availability(icalcomponent *supplied_vevent);
477 void do_freebusy(char *req);
480 extern char *months[];
482 void read_server_binary(char *buffer, size_t total_len);
483 char *read_server_text(void);
484 int goto_config_room(void);
485 long locate_user_vcard(char *username, long usernum);
486 void sleeeeeeeeeep(int);
487 void http_transmit_thing(char *thing, size_t length, char *content_type,
489 void unescape_input(char *buf);
490 void do_iconbar(void);
491 void display_customize_iconbar(void);
492 void commit_iconbar(void);
493 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
494 void spawn_another_worker_thread(void);
496 void embed_room_banner(char *, int);
497 /* navbar types that can be passed to embed_room_banner */
507 void ssl_lock(int mode, int n, const char *file, int line);
508 int starttls(int sock);
509 extern SSL_CTX *ssl_ctx;
510 int client_read_ssl(char *buf, int bytes, int timeout);
511 void client_write_ssl(char *buf, int nbytes);
516 int ZEXPORT compress_gzip(Bytef * dest, uLongf * destLen,
517 const Bytef * source, uLong sourceLen, int level);
521 void begin_burst(void);
522 void end_burst(void);
524 extern char *ascmonths[];
525 void http_datestring(char *buf, size_t n, time_t xtime);
528 /* Views (from citadel.h) */
529 #define VIEW_BBS 0 /* Traditional Citadel BBS view */
530 #define VIEW_MAILBOX 1 /* Mailbox summary */
531 #define VIEW_ADDRESSBOOK 2 /* Address book view */
532 #define VIEW_CALENDAR 3 /* Calendar view */
533 #define VIEW_TASKS 4 /* Tasks view */
534 #define VIEW_NOTES 5 /* Notes view */
537 /* These should be empty, but we have them for testing */
538 #define DEFAULT_HTTPAUTH_USER ""
539 #define DEFAULT_HTTPAUTH_PASS ""