(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
-(* The [CgiExit] exception should be folded back into the base
- * mod_caml code at some point. It just causes the 'run' function to
- * return at that point safely. (XXX)
- *)
-exception CgiExit
+(* The "host object". *)
+type host_t = { hostname : string;
+ edit_anon : bool;
+ view_anon : bool }
(* The "user object". *)
type user_t = Anonymous (* Not logged in. *)
| User of int * string * permissions_t list
(* Userid, name, permissions. *)
(* The "user object". *)
type user_t = Anonymous (* Not logged in. *)
| User of int * string * permissions_t list
(* Userid, name, permissions. *)
-let can_edit edit_anon = test_permission edit_anon CanEdit
-let can_manage_users = test_permission false CanManageUsers
-let can_manage_contacts = test_permission false CanManageContacts
-
-(* The "host object". *)
-type host_t = { hostname : string;
- edit_anon : bool; }
+let can_edit host = test_permission host CanEdit
+let can_manage_users host = test_permission host CanManageUsers
+let can_manage_contacts host = test_permission host CanManageContacts
+let can_manage_site host = test_permission host CanManageSite
+let can_edit_global_css host = test_permission host CanEditGlobalCSS
let hostname = try Request.hostname r
with Not_found -> failwith "No ``Host:'' header in request" in
let hostname = String.lowercase hostname in
let sth =
dbh#prepare_cached
let hostname = try Request.hostname r
with Not_found -> failwith "No ``Host:'' header in request" in
let hostname = String.lowercase hostname in
let sth =
dbh#prepare_cached
- "select h.id, h.canonical_hostname, h.edit_anon
+ "select h.id, h.canonical_hostname, h.edit_anon, h.view_anon
from hostnames hn, hosts h
where hn.name = ? and hn.hostid = h.id" in
sth#execute [`String hostname];
try
(match sth#fetch1 () with
from hostnames hn, hosts h
where hn.name = ? and hn.hostid = h.id" in
sth#execute [`String hostname];
try
(match sth#fetch1 () with
- [ `Int id; `String hostname; `Bool edit_anon ] ->
- id, hostname, edit_anon
+ [ `Int id; `String hostname;
+ `Bool edit_anon; `Bool view_anon ] ->
+ id, hostname, edit_anon, view_anon
let sth =
dbh#prepare_cached
"select u.id, u.name, u.can_edit, u.can_manage_users,
let sth =
dbh#prepare_cached
"select u.id, u.name, u.can_edit, u.can_manage_users,
from usercookies uc, users u
where uc.cookie = ? and uc.userid = u.id and u.hostid = ?" in
sth#execute [`String cookie; `Int hostid];
(match sth#fetch1 () with
[ `Int userid; `String name;
`Bool can_edit; `Bool can_manage_users;
from usercookies uc, users u
where uc.cookie = ? and uc.userid = u.id and u.hostid = ?" in
sth#execute [`String cookie; `Int hostid];
(match sth#fetch1 () with
[ `Int userid; `String name;
`Bool can_edit; `Bool can_manage_users;
- `Bool can_manage_contacts ] ->
+ `Bool can_manage_contacts; `Bool can_manage_site;
+ `Bool can_edit_global_css ] ->
+ (* Every logged in user can view. *)
+ let perms = [CanView] in
+ let perms =
+ if can_edit then CanEdit :: perms
+ else perms in
- (if can_edit then [ CanEdit ] else []) @
- (if can_manage_users then [ CanManageUsers ] else []) @
- (if can_manage_contacts then [ CanManageContacts ] else [])
- in
+ if can_manage_users then CanManageUsers :: perms
+ else perms in
+ let perms =
+ if can_manage_contacts then CanManageContacts :: perms
+ else perms in
+ let perms =
+ if can_manage_site then CanManageSite :: perms
+ else perms in
+ let perms =
+ if can_edit_global_css then CanEditGlobalCSS :: perms
+ else perms in
- try
- run r q dbh hostid host user
- with
- CgiExit -> ()
- ) else
- error ~back_button:true
- ~title:"Access denied"
- q "You do not have permission to access this part of the site."
+ run r q dbh hostid host user
+ ) else (
+ if user = Anonymous then
+ q#redirect ("http://" ^ hostname ^ "/_login")
+ else
+ error ~back_button:true
+ ~title:"Access denied"
+ q "You do not have permission to access this part of the site."
+ )