1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2008, Adam Chlipala
4 * This program is free software
; you can redistribute it
and/or
5 * modify it under the terms
of the GNU General Public License
6 * as published by the Free Software Foundation
; either version
2
7 * of the License
, or (at your option
) any later version
.
9 * This program is distributed
in the hope that it will be useful
,
10 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
12 * GNU General Public License for more details
.
14 * You should have received a copy
of the GNU General Public License
15 * along
with this program
; if not
, write to the Free Software
16 * Foundation
, Inc
., 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA
.
19 (* Tailing Apache log
files (locally
) that you are allowed to see
*)
23 val inf
= TextIO.openIn
"/etc/hostname"
25 case TextIO.inputLine inf
of
26 NONE
=> (TextIO.closeIn inf
; raise Fail
"No line in /etc/hostname")
27 | SOME line
=> (TextIO.closeIn inf
; String.substring (line
, 0, size line
- 1))
32 val (f
, args
) = foldl (fn (arg
, (f
, args
)) =>
35 | _
=> (f
, arg
:: args
))
46 | _
=> (print
"Unsupported logfile kind. Use 'access', 'error', or 'rewrite'.\n";
47 OS
.Process
.exit OS
.Process
.failure
)
49 val uid
= Posix
.ProcEnv
.getuid ()
50 val uname
= Posix
.SysDB
.Passwd
.name (Posix
.SysDB
.getpwuid uid
)
52 val proc
= Unix
.execute ("/usr/local/bin/domtool-admin", ["perms", uname
])
53 val inf
= Unix
.textInstreamOf proc
56 case TextIO.inputLine inf
of
59 case String.tokens
Char.isSpace line
of
60 "domain:" :: domains
=> domains
63 val domains
= allowed ()
65 fun inDomains d
= List.exists (fn s
=> s
= d
) domains
71 inDomains (String.concatWith
"." pieces
)
74 val tailArgs
= ["/var/log/apache2/user/"
75 ^
String.substring (uname
, 0, 1)
77 ^
String.substring (uname
, 0, 2)
94 ignore (Unix
.reap proc
);
95 if inDomains vhost
orelse checker (String.fields (fn ch
=> ch
= #
".") vhost
) then
96 Posix
.Process
.exec ("/usr/bin/tail", "/usr/bin/tail" :: tailArgs
)
98 (print
"You're not authorized to view the logs for that vhost.\n";
99 OS
.Process
.exit OS
.Process
.failure
)
101 | _
=> (print
"Invalid arguments\n";
102 OS
.Process
.exit OS
.Process
.failure
)
105 val () = main (CommandLine
.arguments ())