Package: didiwiki / 0.5-13

50_accesslog.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
From: Carlo Mandelli <camandel@gmail.com>
Subject: Adds access log to didiwiki using syslog

diff -urNad didiwiki-0.5~/src/didi.h didiwiki-0.5/src/didi.h
--- didiwiki-0.5~/src/didi.h	2009-07-23 14:34:34.000000000 +0200
+++ didiwiki-0.5/src/didi.h	2009-07-23 14:34:34.000000000 +0200
@@ -76,6 +76,7 @@
 #include <sys/stat.h>
 #include <dirent.h>
 #include <getopt.h>
+#include <syslog.h>
 
 #endif
 
diff -urNad didiwiki-0.5~/src/http.c didiwiki-0.5/src/http.c
--- didiwiki-0.5~/src/http.c	2009-07-23 14:34:34.000000000 +0200
+++ didiwiki-0.5/src/http.c	2009-07-23 14:35:15.000000000 +0200
@@ -30,6 +30,7 @@
   char             *uri;
   char             *path_info;
   char             *query_string;
+  char             *ip_src;
 };
 
 struct HttpResponse 
@@ -170,6 +171,11 @@
   return req->query_string;
 }
 
+char*
+http_request_get_ip_src(HttpRequest *req)
+{
+  return req->ip_src;
+}
 
 /*
  * This routine handles a single HTTP request which is coming in on
@@ -182,7 +188,7 @@
   char              *token, *content_type, *post_data, *z;
   int                i, len;
   struct sockaddr_in remoteName;
-  int                size = sizeof(struct sockaddr_in);
+  socklen_t          size = sizeof(struct sockaddr_in);
   char               request_line[2048];     /* A single line of input. */
   HttpRequest       *req = NULL;
 
@@ -225,8 +231,10 @@
   if (&token[i])
     req->query_string = strdup(&token[i]);
 
-  if( getpeername(fileno(stdin), (struct sockaddr*)&remoteName, &size) >=0 )
+  if( getpeername(fileno(stdin), (struct sockaddr*)&remoteName, &size) >=0 ) {
     putenv(util_mprintf("REMOTE_ADDR=%s", inet_ntoa(remoteName.sin_addr)));
+    req->ip_src = inet_ntoa(remoteName.sin_addr);
+  }
 
   /* Get all the optional fields that follow the first line.
   */
@@ -448,7 +456,7 @@
   int                listener;      /* The server socket */
   int                connection;    /* A socket for each connection */
   fd_set             readfds;       /* Set of file descriptors for select() */
-  int                lenaddr;       /* Length of the inaddr structure */
+  socklen_t          lenaddr;       /* Length of the inaddr structure */
   int                child;         /* PID of the child process */
   int                nchildren = 0; /* Number of child processes */
   struct timeval     delay;         /* How long to wait inside select() */
@@ -488,6 +496,10 @@
   fprintf(stderr,"Success! \n");
   
   fprintf(stderr,"DidiWiki Started. Please point your browser at http://localhost:%i\n", iPort);
+
+  /* log starting information */
+  openlog("didiwiki", 0, 0);
+  syslog(LOG_LOCAL0|LOG_INFO, "started with PID %d", getpid());
   
   listen(listener,10);
   
diff -urNad didiwiki-0.5~/src/http.h didiwiki-0.5/src/http.h
--- didiwiki-0.5~/src/http.h	2009-07-23 14:26:34.000000000 +0200
+++ didiwiki-0.5/src/http.h	2009-07-23 14:34:34.000000000 +0200
@@ -23,6 +23,8 @@
 char*
 http_request_get_query_string(HttpRequest *req);
 
+char*
+http_request_get_ip_src(HttpRequest *req);
 
 HttpResponse*
 http_response_new(HttpRequest *req);
diff -urNad didiwiki-0.5~/src/wiki.c didiwiki-0.5/src/wiki.c
--- didiwiki-0.5~/src/wiki.c	2009-07-23 14:34:34.000000000 +0200
+++ didiwiki-0.5/src/wiki.c	2009-07-23 14:34:34.000000000 +0200
@@ -1001,13 +1001,19 @@
       /* TODO: dont blindly write wikitext data to disk */
       if ( (wikitext = http_request_param_get(req, "wikitext")) != NULL)
 	{
-	  file_write(page, wikitext);	      
+	  file_write(page, wikitext);
+
+      /* log modified page name and IP address */
+      syslog(LOG_LOCAL0|LOG_INFO, "page %s modified from %s", page ,http_request_get_ip_src(req));
 	}
 
       if (access(page, R_OK) == 0) 	/* page exists */
 	{
 	  wikitext = file_read(page);
-	  
+
+	  /* log read page name and IP address */
+      syslog(LOG_LOCAL0|LOG_INFO, "page %s viewed from %s", page, http_request_get_ip_src(req));
+
 	  if (!strcmp(command, "edit"))
 	    {
 	      /* print edit page */