force_password_change boolean DEFAULT false NOT NULL,
can_import_mail boolean DEFAULT false NOT NULL,
email_notify boolean DEFAULT true NOT NULL,
- invite text
+ invite text,
+ can_edit_macros boolean DEFAULT false NOT NULL
);
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: create_macro.ml,v 1.1 2006/07/26 16:26:43 rich Exp $
+ *
+ * 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 Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_ok
+open Cocanwiki_strings
+
+let name_re = Pcre.regexp "^\\w+$"
+
+let run r (q : cgi) dbh hostid _ _ =
+ let name = trim (q#param "name") in
+ let content = q#param "content" in
+
+ if name = "" then (
+ error ~back_button:true ~title:"Name field missing"
+ dbh hostid q "You must name your macro.";
+ return ()
+ );
+
+ if not (Pcre.pmatch ~rex:name_re name) then (
+ error ~back_button:true ~title:"Name field invalid"
+ dbh hostid q "Name field can only contain letters and numbers.";
+ return ()
+ );
+
+ (* XXX Check it doesn't already exist. *)
+
+ (* Update the database. *)
+ PGSQL(dbh) "insert into macros (hostid, name, content)
+ values ($hostid, $name, $content)";
+
+ (* Finish off. *)
+ PGOCaml.commit dbh;
+
+ let buttons = [ ok_button "/_bin/edit_macros.cmo" ] in
+ ok ~title:"Macro created" ~buttons dbh hostid q
+ "That macro was created."
+
+let () =
+ register_script ~restrict:[CanEditMacros] run
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: create_macro_form.ml,v 1.1 2006/07/26 16:26:43 rich Exp $
+ *
+ * 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 Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+
+let run r (q : cgi) dbh hostid _ _ =
+ let template = get_template dbh hostid "create_macro_form.html" in
+
+ q#template template
+
+let () =
+ register_script ~restrict:[CanEditMacros] run
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: delete_macro.ml,v 1.1 2006/07/26 16:26:43 rich Exp $
+ *
+ * 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 Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_ok
+
+let run r (q : cgi) dbh hostid { hostname = hostname } _ =
+ (* Cancel? *)
+ if q#param_true "cancel" then
+ q#redirect ("http://" ^ hostname ^ "/_bin/edit_macros.cmo");
+
+ (* We can delete multiple macros from this script, which is
+ * quite unusual.
+ *)
+ let names = q#param_all "name" in
+ if names = [] then
+ q#redirect ("http://" ^ hostname ^ "/_bin/edit_macros.cmo");
+
+ (* Delete them. *)
+ PGSQL(dbh) "delete from macros where hostid = $hostid and name in $@names";
+
+ (* Finish off. *)
+ PGOCaml.commit dbh;
+
+ ok ~title:"Macro deleted" ~buttons:[ok_button "/_bin/edit_macros.cmo"]
+ dbh hostid q "That macro was deleted."
+
+let () =
+ register_script ~restrict:[CanEditMacros] run
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: delete_macro_form.ml,v 1.1 2006/07/26 16:26:43 rich Exp $
+ *
+ * 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 Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+
+let run r (q : cgi) dbh hostid { hostname = hostname } _ =
+ let template = get_template dbh hostid "delete_macro_form.html" in
+
+ (* We can delete multiple macros from this script, which is
+ * quite unusual.
+ *)
+ let names = q#param_all "name" in
+ if names = [] then
+ q#redirect ("http://" ^ hostname ^ "/_bin/edit_macros.cmo");
+
+ let rows = PGSQL(dbh)
+ "select name, content from macros
+ where hostid = $hostid and name in $@names
+ order by name" in
+
+ let table =
+ List.map (
+ fun (name, content) ->
+ [ "name", Template.VarString name;
+ "content", Template.VarString content ]
+ ) rows in
+ template#table "deletes" table;
+
+ let table =
+ List.map (fun name ->
+ [ "name", Template.VarString name ]) names in
+ template#table "names" table;
+
+ q#template template
+
+let () =
+ register_script ~restrict:[CanEditMacros] run
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: edit_macro.ml,v 1.1 2006/07/26 16:26:43 rich Exp $
+ *
+ * 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 Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_ok
+open Cocanwiki_strings
+
+let run r (q : cgi) dbh hostid _ _ =
+ let name = q#param "name" in
+ let content = q#param "content" in
+
+ (* Update the database. *)
+ PGSQL(dbh) "update macros set content = $content
+ where hostid = $hostid and name = $name";
+
+ (* Finish off. *)
+ PGOCaml.commit dbh;
+
+ let buttons = [ ok_button "/_bin/edit_macros.cmo" ] in
+ ok ~title:"Macro edited" ~buttons
+ dbh hostid q "The macro was edited."
+
+let () =
+ register_script ~restrict:[CanEditMacros] run
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: edit_macro_form.ml,v 1.1 2006/07/26 16:26:43 rich Exp $
+ *
+ * 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 Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+
+let run r (q : cgi) dbh hostid _ _ =
+ let template = get_template dbh hostid "edit_macro_form.html" in
+
+ let name = q#param "name" in
+
+ (* Get details from the database. *)
+ let rows = PGSQL(dbh) "select content from macros
+ where hostid = $hostid and name = $name" in
+ let content = List.hd rows in
+
+ template#set "name" name;
+ template#set "content" content;
+
+ q#template template
+
+let () =
+ register_script ~restrict:[CanEditMacros] run
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: edit_macros.ml,v 1.1 2006/07/26 16:26:43 rich Exp $
+ *
+ * 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 Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+
+let run r (q : cgi) dbh hostid _ _ =
+ let template = get_template dbh hostid "edit_macros.html" in
+
+ (* Get a list of the macros for this host. *)
+ let macros =
+ PGSQL(dbh) "select name from macros where hostid = $hostid order by 1" in
+
+ let macros = List.map (
+ fun name ->
+ [ "name", Template.VarString name ]
+ ) macros in
+ template#table "macros" macros;
+
+ q#template template
+
+let () =
+ register_script ~restrict:[CanEditMacros] run
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: host_menu.ml,v 1.9 2006/03/27 19:10:29 rich Exp $
+ * $Id: host_menu.ml,v 1.10 2006/07/26 16:26:43 rich Exp $
*
* 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
let can_manage_users = can_manage_users host user in
let can_manage_contacts = can_manage_contacts host user in
let can_edit_global_css = can_edit_global_css host user in
+ let can_edit_macros = can_edit_macros host user in
let can_manage_site = can_manage_site host user in
template#conditional "can_manage_users" can_manage_users;
template#conditional "can_manage_contacts" can_manage_contacts;
template#conditional "can_edit_global_css" can_edit_global_css;
+ template#conditional "can_edit_macros" can_edit_macros;
template#conditional "can_manage_site" can_manage_site;
if can_manage_site then (
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki.ml,v 1.11 2006/07/26 13:19:51 rich Exp $
+ * $Id: cocanwiki.ml,v 1.12 2006/07/26 16:26:44 rich Exp $
*
* 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
*)
type permissions_t = CanView | CanEdit | CanManageUsers | CanManageContacts
| CanManageSite | CanEditGlobalCSS | CanImportMail
+ | CanEditMacros
(* User preferences and other settings (some cannot be changed by the user). *)
type prefs_t = {
let can_manage_site host = test_permission host CanManageSite
let can_edit_global_css host = test_permission host CanEditGlobalCSS
let can_import_mail host = test_permission host CanImportMail
+let can_edit_macros host = test_permission host CanEditMacros
let get_uri_from_request r =
try
"select u.id, u.name, u.can_edit, u.can_manage_users,
u.can_manage_contacts, u.can_manage_site,
u.can_edit_global_css, u.can_import_mail,
+ u.can_edit_macros,
u.email, u.email_notify
from usercookies uc, users u
where uc.cookie = $cookie
| [userid, name, can_edit, can_manage_users,
can_manage_contacts, can_manage_site,
can_edit_global_css, can_import_mail,
+ can_edit_macros,
email, email_notify] ->
(* Every logged in user can view. *)
let perms = [CanView] in
let perms =
if can_import_mail then CanImportMail :: perms
else perms in
+ let perms =
+ if can_edit_macros then CanEditMacros :: perms
+ else perms in
(* Preferences. *)
let prefs = { email = email;
email_notify = email_notify; } in
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Create a macro</title>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+<link rel="alternate stylesheet" href="/_css/easytoread.css" type="text/css" title="High contrast, big fonts"/>
+</head><body>
+
+<h1><span>Create a macro</span></h1>
+
+<form method="post" action="/_bin/create_macro.cmo">
+<table class="left_table">
+<tr>
+<th> Macro name: <br/> <small>Must be letters and numbers only</small> </th>
+<td> <input name="name" value="" size="32" /> </td>
+</tr>
+
+<tr>
+<th> Content: </th>
+<td> <textarea name="content" cols="50" rows="10"></textarea> </td>
+</tr>
+
+<tr>
+<td></td>
+<td> <input type="submit" value=" Create macro "/> </td>
+</tr>
+</table>
+</form>
+
+::include(footer.html)::
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Delete macro</title>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+<link rel="alternate stylesheet" href="/_css/easytoread.css" type="text/css" title="High contrast, big fonts"/>
+</head><body>
+
+<h1><span>Delete macro</span></h1>
+
+<p>
+Are you sure you want to delete the macro shown below?
+</p>
+
+<table class="top_table">
+<tr><th> Name </th> <th> Content </th></tr>
+::table(deletes)::<tr><td> ::name_html:: </td> <td> ::content_html:: </td></tr>::end::
+</table>
+
+<form method="post" action="/_bin/delete_macro.cmo">
+::table(names)::<input type="hidden" name="name" value="::name::"/>::end::
+<input type="submit" name="doit" value=" Delete "/>
+<input type="submit" name="cancel" value=" Cancel "/>
+</form>
+
+::include(footer.html)::
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Edit macro: ::name_html::</title>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+<link rel="alternate stylesheet" href="/_css/easytoread.css" type="text/css" title="High contrast, big fonts"/>
+</head><body>
+
+<h1><span>Edit macro: ::name_html::</span></h1>
+
+<form method="post" action="/_bin/edit_macro.cmo">
+<input type="hidden" name="name" value="::name_html_tag::"/>
+<table class="left_table">
+<tr>
+<th> Macro name: </th>
+<td> ::name_html::</td>
+</tr>
+
+<tr>
+<th> Content: </th>
+<td>
+<textarea name="content" cols="50" rows="10">::content_html_textarea::</textarea> </td>
+</tr>
+
+<tr>
+<td></td>
+<td> <input type="submit" value=" Edit macro "/> </td>
+</tr>
+</table>
+</form>
+
+::include(footer.html)::
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Macros</title>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+<link rel="alternate stylesheet" href="/_css/easytoread.css" type="text/css" title="High contrast, big fonts"/>
+</head><body>
+
+<h1><span>Macros</span></h1>
+
+<table class="top_table">
+<tr>
+ <th> Name </th>
+ <th> </th>
+</tr>
+::table(macros)::
+<tr>
+ <td> <a href="/_bin/edit_macro_form.cmo?name=::name_url::">::name_html::</a> </td>
+ <td>
+ <a href="/_bin/edit_macro_form.cmo?name=::name_url::">Edit</a> |
+ <a href="/_bin/delete_macro_form.cmo?name=::name_url::">Delete</a>
+ </td>
+</tr>
+::end::
+</table>
+
+<p>
+<a href="/_bin/create_macro_form.cmo">Add a new macro ...</a>
+
+<p>
+<a href="/_bin/host_menu.cmo">Back to sitewide settings</a>
+</p>
+
+::include(footer.html)::
+</body>
+</html>
\ No newline at end of file
<li> <a href="/_bin/edit_host_css_form.cmo">Edit global stylesheet</a> </li>
::end::
+::if(can_edit_macros)::
+<li> <a href="/_bin/edit_macros.cmo">Edit macros</a> </li>
+::end::
+
</ul>
::if(can_manage_site)::