13 #include <sys/types.h>
15 #include <sys/socket.h>
16 #ifdef HAVE_SYS_TIME_H
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
34 #include <sys/utsname.h>
42 * Uncomment to dump an HTTP trace to stderr
43 #define HTTP_TRACING 1
57 #define WEBCIT_WITH_CALENDAR_SERVICE 1
61 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
66 /* Work around RedHat's b0rken OpenSSL includes */
67 #define OPENSSL_NO_KRB5
68 #include <openssl/ssl.h>
69 #include <openssl/err.h>
70 #include <openssl/rand.h>
73 #define CALENDAR_ROOM_NAME "Calendar"
74 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
76 #define SIZ 4096 /* generic buffer size */
78 #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
80 #define SLEEPING 180 /* TCP connection timeout */
81 #define WEBCIT_TIMEOUT 900 /* WebCit session timeout */
82 #define PORT_NUM 2000 /* port number to listen on */
83 #define SERVER "WebCit v6.21" /* who's in da house */
84 #define DEVELOPER_ID 0
86 #define CLIENT_VERSION 621 /* This version of WebCit */
87 #define MINIMUM_CIT_VERSION 655 /* min required Citadel vers */
88 #define DEFAULT_HOST "localhost" /* Default Citadel server */
89 #define DEFAULT_PORT "504"
90 #define LB (1) /* Internal escape chars */
93 #define TARGET "webcit01" /* Target for inline URL's */
94 #define HOUSEKEEPING 15 /* Housekeeping frequency */
95 #define MIN_WORKER_THREADS 5
96 #define MAX_WORKER_THREADS 250
97 #define LISTEN_QUEUE_LENGTH 100 /* listen() backlog queue */
99 #define USERCONFIGROOM "My Citadel Config"
100 #define DEFAULT_MAXMSGS 20
104 * Room flags (from Citadel)
108 #define QR_PERMANENT 1 /* Room does not purge */
109 #define QR_INUSE 2 /* Set if in use, clear if avail */
110 #define QR_PRIVATE 4 /* Set for any type of private room */
111 #define QR_PASSWORDED 8 /* Set if there's a password too */
112 #define QR_GUESSNAME 16 /* Set if it's a guessname room */
113 #define QR_DIRECTORY 32 /* Directory room */
114 #define QR_UPLOAD 64 /* Allowed to upload */
115 #define QR_DOWNLOAD 128 /* Allowed to download */
116 #define QR_VISDIR 256 /* Visible directory */
117 #define QR_ANONONLY 512 /* Anonymous-Only room */
118 #define QR_ANONOPT 1024 /* Anonymous-Option room */
119 #define QR_NETWORK 2048 /* Shared network room */
120 #define QR_PREFONLY 4096 /* Preferred status needed to enter */
121 #define QR_READONLY 8192 /* Aide status required to post */
122 #define QR_MAILBOX 16384 /* Set if this is a private mailbox */
127 #define QR2_SYSTEM 1 /* System room; hide by default */
128 #define QR2_SELFLIST 2 /* Self-service mailing list mgmt */
132 #define UA_GOTOALLOWED 4
133 #define UA_HASNEWMSGS 8
142 struct httprequest *next;
147 struct urlcontent *next;
154 char serv_nodename[32];
155 char serv_humannode[64];
157 char serv_software[64];
159 char serv_bbs_city[64];
160 char serv_sysadm[64];
161 char serv_moreprompt[SIZ];
163 int serv_supports_ldap;
169 * This struct holds a list of rooms for <G>oto operations.
173 char march_name[128];
179 * This struct holds a list of rooms for client display.
183 struct roomlisting *lnext;
184 struct roomlisting *rnext;
194 * Dynamic content for variable substitution in templates
197 struct wcsubst *next;
201 void (*wcs_function)(void);
205 * Values for wcs_type
214 struct wc_attachment {
215 struct wc_attachment *next;
217 char content_type[SIZ];
222 struct message_summary {
233 * One of these is kept for each active Citadel session.
234 * HTTP transactions are bound to one at a time.
237 struct wcsession *next; /* Linked list */
238 int wc_session; /* WebCit session ID */
239 char wc_username[SIZ];
240 char wc_password[SIZ];
241 char wc_roomname[SIZ];
258 char upload_filename[SIZ];
259 char upload_content_type[SIZ];
261 int remember_new_mail;
262 int need_regi; /* This user needs to register. */
263 int need_vali; /* New users require validation. */
264 char cs_inet_email[SIZ]; /* User's preferred Internet addr. */
265 pthread_mutex_t SessionMutex; /* mutex for exclusive access */
266 time_t lastreq; /* Timestamp of most recent HTTP */
267 int killthis; /* Nonzero == purge this session */
268 struct march *march; /* march mode room list */
269 char reply_to[SIZ]; /* reply-to address */
271 long msgarr[10000]; /* for read operations */
273 struct message_summary *summ;
275 int is_wap; /* Client is a WAP gateway */
276 struct urlcontent *urlstrings;
277 int HaveInstantMessages; /* Nonzero if incoming msgs exist */
278 struct wcsubst *vars;
279 char this_page[SIZ]; /* address of current page */
280 char http_host[SIZ]; /* HTTP Host: header */
282 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
284 icalcomponent *cal; /* cal items for display */
285 long cal_msgnum; /* cal msgids for display */
289 struct wc_attachment *first_attachment;
290 char ImportantMessage[SIZ];
291 char last_chat_user[SIZ];
292 int ctdl_pid; /* Session ID on the Citadel server */
293 char httpauth_user[SIZ]; /* only for GroupDAV sessions */
294 char httpauth_pass[SIZ]; /* only for GroupDAV sessions */
298 int gzip_ok; /* Nonzero if Accept-encoding: gzip */
301 #define num_parms(source) num_tokens(source, '|')
303 /* Per-session data */
304 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
305 extern pthread_key_t MyConKey;
307 /* Per-thread SSL context */
309 #define THREADSSL ((SSL *)pthread_getspecific(ThreadSSL))
310 extern pthread_key_t ThreadSSL;
313 struct serv_info serv_info;
314 extern char floorlist[128][SIZ];
315 extern char *axdefs[];
316 extern char *ctdlhost, *ctdlport;
317 extern char *server_cookie;
319 extern int setup_wizard;
320 extern char wizard_filename[];
321 void do_setup_wizard(void);
323 void stuff_to_cookie(char *cookie, int session,
324 char *user, char *pass, char *room);
325 void cookie_to_stuff(char *cookie, int *session,
326 char *user, size_t user_len,
327 char *pass, size_t pass_len,
328 char *room, size_t room_len);
329 char *bmstrstr(char *text, char *pattern,
330 int (*cmpfunc)(const char *, const char *, size_t) );
331 void locate_host(char *, int);
332 void become_logged_in(char *, char *, char *);
334 void display_login(char *mesg);
335 void do_welcome(void);
336 void do_logout(void);
337 void display_main_menu(void);
338 void display_aide_menu(void);
339 void display_advanced_menu(void);
340 void slrp_highest(void);
343 void get_serv_info(char *, char *);
344 int uds_connectsock(char *);
345 int tcp_connectsock(char *, char *);
346 void serv_getln(char *strbuf, int bufsize);
347 void serv_puts(char *string);
349 void who_inner_html(void);
350 void fmout(FILE *fp, char *align);
351 void wDumpContent(int);
352 void serv_printf(const char *format,...);
353 char *bstr(char *key);
354 void urlesc(char *, char *);
355 void urlescputs(char *);
356 void jsesc(char *, char *);
357 void jsescputs(char *);
358 void output_headers( int do_httpheaders,
365 void wprintf(const char *format,...);
366 void output_static(char *what);
367 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks);
368 void escputs(char *strbuf);
370 void escputs1(char *strbuf, int nbsp, int nolinebreaks);
371 void msgesc(char *target, char *strbuf);
372 void msgescputs(char *strbuf);
373 int extract_int(const char *source, int parmnum);
374 long extract_long(const char *source, int parmnum);
375 void stripout(char *str, char leftboundary, char rightboundary);
376 void dump_vars(void);
377 void embed_main_menu(void);
378 void serv_read(char *buf, int bytes);
379 int haschar(char *, char);
380 void readloop(char *oper);
381 void embed_message(void);
382 void text_to_server(char *ptr, int convert_to_html);
383 void display_enter(void);
384 void post_message(void);
385 void confirm_delete_msg(void);
386 void delete_msg(void);
387 void confirm_move_msg(void);
391 void display_page(void);
392 void page_user(void);
394 void display_private(char *rname, int req_pass);
395 void goto_private(void);
396 void zapped_list(void);
397 void display_zap(void);
399 void display_success(char *);
400 void display_entroom(void);
402 void display_editroom(void);
405 void display_whok(void);
406 void do_invt_kick(void);
407 void server_to_text(void);
408 void save_edit(char *description, char *enter_cmd, int regoto);
409 void display_edit(char *description, char *check_cmd,
410 char *read_cmd, char *save_cmd, int with_room_banner);
411 void gotoroom(char *gname);
412 void confirm_delete_room(void);
413 void delete_room(void);
415 void display_graphics_upload(char *, char *, char *);
416 void do_graphics_upload(char *upl_cmd);
417 void serv_read(char *buf, int bytes);
418 void serv_gets(char *strbuf);
419 void serv_write(char *buf, int nbytes);
420 void serv_puts(char *string);
421 void serv_printf(const char *format,...);
422 void load_floorlist(void);
423 void display_reg(int);
424 void display_changepw(void);
426 void display_edit_node(void);
427 void edit_node(void);
428 void display_netconf(void);
429 void display_confirm_delete_node(void);
430 void delete_node(void);
431 void display_add_node(void);
433 void terminate_session(void);
435 void display_siteconfig(void);
436 void siteconfig(void);
437 void display_generic(void);
438 void do_generic(void);
439 void display_menubar(int);
440 void smart_goto(char *);
441 void worker_entry(void);
442 void session_loop(struct httprequest *);
443 void fmt_date(char *buf, time_t thetime, int brief);
444 void fmt_time(char *buf, time_t thetime);
445 void httpdate(char *buf, time_t thetime);
446 void end_webcit_session(void);
447 void page_popup(void);
448 void chat_recv(void);
449 void chat_send(void);
450 void http_redirect(char *);
451 void clear_local_substs(void);
452 void svprintf(char *keyname, int keytype, const char *format,...);
453 void svcallback(char *keyname, void (*fcn_ptr)() );
454 void do_template(void *templatename);
455 int lingering_close(int fd);
456 char *memreadline(char *start, char *buf, int maxlen);
457 int num_tokens (char *source, char tok);
458 void extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
459 void remove_token(char *source, int parmnum, char separator);
460 char *load_mimepart(long msgnum, char *partnum);
461 int pattern2(char *search, char *patn);
462 void do_edit_vcard(long, char *, char *);
463 void edit_vcard(void);
464 void submit_vcard(void);
465 void striplt(char *);
466 void select_user_to_edit(char *message, char *preselect);
467 void delete_user(char *);
468 void display_edituser(char *who, int is_new);
469 void create_user(void);
471 void do_change_view(int);
472 void change_view(void);
474 void do_stuff_to_msgs(void);
475 void load_preferences(void);
476 void save_preferences(void);
477 void get_preference(char *key, char *value, size_t value_len);
478 void set_preference(char *key, char *value, int save_to_server);
480 int is_msg_in_mset(char *mset, long msgnum);
481 char *safestrncpy(char *dest, const char *src, size_t n);
482 void display_addressbook(long msgnum, char alpha);
483 void offer_start_page(void);
484 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext);
485 void change_start_page(void);
486 void output_html(char *);
487 void display_floorconfig(char *);
488 void delete_floor(void);
489 void create_floor(void);
490 void rename_floor(void);
491 void do_listsub(void);
492 void toggle_self_service(void);
494 ssize_t write(int fd, const void *buf, size_t count);
495 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum);
496 void display_calendar(long msgnum);
497 void display_task(long msgnum);
498 void display_note(long msgnum);
499 void do_calendar_view(void);
500 void do_tasks_view(void);
501 void free_calendar_buffer(void);
502 void calendar_summary_view(void);
503 int load_msg_ptrs(char *servcmd, int with_headers);
504 void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen);
505 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
506 void free_attachments(struct wcsession *sess);
507 void set_room_policy(void);
508 void display_inetconf(void);
509 void save_inetconf(void);
510 void generate_uuid(char *);
511 void display_preferences(void);
512 void set_preferences(void);
514 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
515 void display_edit_task(void);
516 void save_task(void);
517 void display_edit_event(void);
518 void save_event(void);
519 void display_icaltimetype_as_webform(struct icaltimetype *, char *);
520 void icaltime_from_webform(struct icaltimetype *result, char *prefix);
521 void icaltime_from_webform_dateonly(struct icaltimetype *result, char *prefix);
522 void display_edit_individual_event(icalcomponent *supplied_vtodo, long msgnum);
523 void save_individual_event(icalcomponent *supplied_vtodo, long msgnum);
524 void respond_to_request(void);
525 void handle_rsvp(void);
526 void ical_dezonify(icalcomponent *cal);
527 void partstat_as_string(char *buf, icalproperty *attendee);
528 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp);
529 void check_attendee_availability(icalcomponent *supplied_vevent);
530 void do_freebusy(char *req);
533 extern char *months[];
535 void read_server_binary(char *buffer, size_t total_len);
536 char *read_server_text(void);
537 int goto_config_room(void);
538 long locate_user_vcard(char *username, long usernum);
539 void sleeeeeeeeeep(int);
540 void http_transmit_thing(char *thing, size_t length, char *content_type,
542 void unescape_input(char *buf);
543 void do_iconbar(void);
544 void display_customize_iconbar(void);
545 void commit_iconbar(void);
546 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
547 void spawn_another_worker_thread(void);
549 void embed_room_banner(char *, int);
550 /* navbar types that can be passed to embed_room_banner */
560 void ssl_lock(int mode, int n, const char *file, int line);
561 int starttls(int sock);
562 extern SSL_CTX *ssl_ctx;
563 int client_read_ssl(char *buf, int bytes, int timeout);
564 void client_write_ssl(char *buf, int nbytes);
569 int ZEXPORT compress_gzip(Bytef * dest, uLongf * destLen,
570 const Bytef * source, uLong sourceLen, int level);
574 void begin_burst(void);
575 void end_burst(void);
577 extern char *ascmonths[];
578 void http_datestring(char *buf, size_t n, time_t xtime);
580 /* Views (from citadel.h) */
581 #define VIEW_BBS 0 /* Traditional Citadel BBS view */
582 #define VIEW_MAILBOX 1 /* Mailbox summary */
583 #define VIEW_ADDRESSBOOK 2 /* Address book view */
584 #define VIEW_CALENDAR 3 /* Calendar view */
585 #define VIEW_TASKS 4 /* Tasks view */
586 #define VIEW_NOTES 5 /* Notes view */
589 /* These should be empty, but we have them for testing */
590 #define DEFAULT_HTTPAUTH_USER ""
591 #define DEFAULT_HTTPAUTH_PASS ""