[luci] initscript: remove trailing whitespaces
by Jan Pokorný
commit 1952b4db437928133f7ac2a9a8c69d966a4330ae
Author: Jan Pokorny <jpokorny(a)redhat.com>
Date: Fri Aug 26 15:29:02 2011 +0200
initscript: remove trailing whitespaces
Signed-off-by: Jan Pokorny <jpokorny(a)redhat.com>
input_files/initscript/initscript.in | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/input_files/initscript/initscript.in b/input_files/initscript/initscript.in
index cbb3423..f22e7e5 100755
--- a/input_files/initscript/initscript.in
+++ b/input_files/initscript/initscript.in
@@ -319,7 +319,7 @@ load_database() {
return 1
fi
- if [ ! -r "$db_dump_file" ]; then
+ if [ ! -r "$db_dump_file" ]; then
$ECHOFUNC "The database backup in \`$db_dump_file' cannot be read." >&2
return 1
fi
@@ -375,7 +375,7 @@ load_database() {
fi
ret_code=1
fi
-
+
restorecon -R -- "$DB_DIR" "$BACKUP_DIR" >&/dev/null
return $ret_code
}
12 years, 10 months
[luci] initscript: make distinction of status/non-status action retval
by Jan Pokorný
commit 8fd8434e78d36d649fa8599cb4b717bd88d750a1
Author: Jan Pokorny <jpokorny(a)redhat.com>
Date: Fri Aug 26 11:54:33 2011 +0200
initscript: make distinction of status/non-status action retval
Functionally the same at the moment (due to 'entry_check' returning
solely 4 to signal a failure), but the fact that 'status' action is
unique wrt. its return value should not get lost:
status action [1]: program or service status is unknown
non-status actions [2]: user had insufficient privilege
The change ensures that return values are as expected even if
'entry_check' modified to return various values to signal a failure.
[1] http://fedoraproject.org/wiki/Packaging:SysVInitScript#Exit_Codes_for_the...
[2] http://fedoraproject.org/wiki/Packaging:SysVInitScript#Exit_Codes_for_non...
Signed-off-by: Jan Pokorny <jpokorny(a)redhat.com>
input_files/initscript/initscript.in | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/input_files/initscript/initscript.in b/input_files/initscript/initscript.in
index 414d8c5..cbb3423 100755
--- a/input_files/initscript/initscript.in
+++ b/input_files/initscript/initscript.in
@@ -489,7 +489,7 @@ case "$1" in
$1
;;
backup-db)
- entry_check || exit 4
+ entry_check || exit $?
status &>/dev/null
if [ $? -eq 0 ]; then
$ECHOFUNC "The database backup operation can proceed only when @SERVICENAME@ is stopped. Stop @SERVICENAME@, then try again." >&2
@@ -500,7 +500,7 @@ case "$1" in
exit $?
;;
restore-db)
- entry_check || exit 4
+ entry_check || exit $?
status &>/dev/null
if [ $? -eq 0 ]; then
$ECHOFUNC "The database restore operation can proceed only when @SERVICENAME@ is stopped. Stop @SERVICENAME@, then try again." >&2
@@ -511,7 +511,7 @@ case "$1" in
exit $?
;;
list-backups)
- entry_check || exit 4
+ entry_check || exit $?
list_database_dumps
exit $?
;;
12 years, 10 months
[luci] Change calls to 'echo' to $ECHOFUNC for the database backup and restore functionality added to the i
by Ryan McCabe
commit 61c6a03d627b832e1b5dbdf472b48f41fc0522f4
Author: Ryan McCabe <rmccabe(a)redhat.com>
Date: Sat Aug 20 14:41:35 2011 -0400
Change calls to 'echo' to $ECHOFUNC for the database
backup and restore functionality added to the init script
input_files/initscript/initscript.in | 26 +++++++++++++-------------
1 files changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/input_files/initscript/initscript.in b/input_files/initscript/initscript.in
index 135e5e1..414d8c5 100755
--- a/input_files/initscript/initscript.in
+++ b/input_files/initscript/initscript.in
@@ -291,20 +291,20 @@ dump_database() {
if [ -e "$output_file" ]; then
if [ "$2" != "--force" ] && [ "$2" != "-f" ]; then
- echo "A file named \`$output_file' already exists. Pass the additional argument of --force to overwrite it." >&2
+ $ECHOFUNC "A file named \`$output_file' already exists. Pass the additional argument of --force to overwrite it." >&2
return 1
fi
fi
$sqlite_bin "$DB_FILE" '.dump' > "$output_file"
if [ $? -ne 0 ]; then
- echo "Failed to create \`$output_file' properly." >&2
+ $ECHOFUNC "Failed to create \`$output_file' properly." >&2
rm -f -- "$output_file"
return 1
fi
chown $DAEMON_USER:$DAEMON_GROUP "$output_file" \
&& chmod -- $BACKUP_PERMS "$output_file"
if [ $? -ne 0 ]; then
- echo "Unable to change ownership/attributes of the $PKG_NAME database backup file (\`$output_file')." >&2
+ $ECHOFUNC "Unable to change ownership/attributes of the $PKG_NAME database backup file (\`$output_file')." >&2
rm -f -- "$output_file" >&/dev/null
return 1
fi
@@ -315,32 +315,32 @@ dump_database() {
load_database() {
db_dump_file=$1
if [ ! "$db_dump_file" ]; then
- echo "No database backup file was specified. Run \`$0 list-backups' to get a list of known existing backup files." >&2
+ $ECHOFUNC "No database backup file was specified. Run \`$0 list-backups' to get a list of known existing backup files." >&2
return 1
fi
if [ ! -r "$db_dump_file" ]; then
- echo "The database backup in \`$db_dump_file' cannot be read." >&2
+ $ECHOFUNC "The database backup in \`$db_dump_file' cannot be read." >&2
return 1
fi
tmp_db="$(mktemp --tmpdir=$DB_DIR)"
if [ $? -ne 0 ]; then
- echo "Unable to create a temporary file in \`$DB_DIR'." >&2
+ $ECHOFUNC "Unable to create a temporary file in \`$DB_DIR'." >&2
return 1
fi
$sqlite_bin $tmp_db ".read $db_dump_file"
if [ $? -ne 0 ] || [ ! -s "$tmp_db" ]; then
# sqlite will return 0 even if you feed it non-sql input. In the case
# of bad input, the database file will have size 0.
- echo "Unable to restore the database from the backup file \`$db_dump_file'" >&2
+ $ECHOFUNC "Unable to restore the database from the backup file \`$db_dump_file'" >&2
rm -f -- "$tmp_db" >&/dev/null
return 1
fi
chown $DAEMON_USER:$DAEMON_GROUP "$tmp_db" \
&& chmod -- $DB_PERMS "$tmp_db"
if [ $? -ne 0 ]; then
- echo "Unable to change ownership/attributes of the $PKG_NAME database file (\`$tmp_db')." >&2
+ $ECHOFUNC "Unable to change ownership/attributes of the $PKG_NAME database file (\`$tmp_db')." >&2
rm -f -- "$tmp_db" >&/dev/null
return 1
fi
@@ -357,7 +357,7 @@ load_database() {
mv -n -- "$DB_FILE" "$old_db_name"
if [ $? -ne 0 ]; then
# it appeared out of nowhere
- echo "Unable to move the existing database file to \`$old_db_name'." >&2
+ $ECHOFUNC "Unable to move the existing database file to \`$old_db_name'." >&2
rm -f -- "$tmp_db" >&/dev/null
return 1
fi
@@ -368,10 +368,10 @@ load_database() {
if [ $? -ne 0 ]; then
rm -f -- "$tmp_db" >&/dev/null
if [ $old_exists -eq 1 ]; then
- echo "Unable to move the newly created database file to \`$DB_FILE'. Trying to restore database from \`$old_db_name'." >&2
+ $ECHOFUNC "Unable to move the newly created database file to \`$DB_FILE'. Trying to restore database from \`$old_db_name'." >&2
mv -- "$old_db_name" "$DB_FILE"
else
- echo "Unable to move the newly created database file to \`$DB_FILE'." >&2
+ $ECHOFUNC "Unable to move the newly created database file to \`$DB_FILE'." >&2
fi
ret_code=1
fi
@@ -492,7 +492,7 @@ case "$1" in
entry_check || exit 4
status &>/dev/null
if [ $? -eq 0 ]; then
- echo "The database backup operation can proceed only when @SERVICENAME@ is stopped. Stop @SERVICENAME@, then try again." >&2
+ $ECHOFUNC "The database backup operation can proceed only when @SERVICENAME@ is stopped. Stop @SERVICENAME@, then try again." >&2
exit 1
fi
shift
@@ -503,7 +503,7 @@ case "$1" in
entry_check || exit 4
status &>/dev/null
if [ $? -eq 0 ]; then
- echo "The database restore operation can proceed only when @SERVICENAME@ is stopped. Stop @SERVICENAME@, then try again." >&2
+ $ECHOFUNC "The database restore operation can proceed only when @SERVICENAME@ is stopped. Stop @SERVICENAME@, then try again." >&2
exit 1
fi
shift
12 years, 10 months
[luci] Make users confirm node deletion
by Ryan McCabe
commit 817909e9b32596c2fa6ab1005d25455ccfc63a0e
Author: Ryan McCabe <rmccabe(a)redhat.com>
Date: Sat Aug 20 14:33:30 2011 -0400
Make users confirm node deletion
luci/public/js/node.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++
luci/templates/node.html | 10 +++++--
2 files changed, 72 insertions(+), 3 deletions(-)
---
diff --git a/luci/public/js/node.js b/luci/public/js/node.js
index 0a5a0fa..7c2a306 100644
--- a/luci/public/js/node.js
+++ b/luci/public/js/node.js
@@ -1,3 +1,68 @@
+$(function() {
+ $('#confirm_remove_node_dialog').dialog({
+ modal: true,
+ autoOpen: false,
+ draggable: false,
+ resizable: false,
+ buttons: {
+ "Proceed": function() {
+ $(this).dialog("close");
+ },
+ "Cancel": function() {
+ $(this).dialog("close");
+ }
+ }
+ });
+
+ $(".confirm_link").click(function(e) {
+ e.preventDefault();
+ var targetUrl = $(this).attr("href");
+
+ $("#confirm_remove_node_dialog").dialog({
+ buttons : {
+ "Proceed": function() {
+ window.location.href = targetUrl;
+ $(this).dialog("close");
+ },
+ "Cancel" : function() {
+ $(this).dialog("close");
+ }
+ }
+ });
+ $("#confirm_remove_node_dialog").dialog("open");
+ });
+
+ $("[type=submit],[type=image]").bind("click", function(e) {
+ $(this).attr("trigger_elem", "True");
+ });
+
+ $(".confirm_form").submit(function(e) {
+ var cur_form = this;
+
+ var trigger_elem = $("[trigger_elem=True]").get(0);
+ if (trigger_elem.id != 'tb_delete') {
+ return true;
+ }
+
+ e.preventDefault();
+ var ret = $("#confirm_remove_node_dialog").dialog({
+ buttons : {
+ "Proceed": function() {
+ $(this).dialog("close");
+ $(cur_form).append('<input type="hidden" name="MultiAction" value="Delete"/>');
+ cur_form.submit();
+ return true;
+ },
+ "Cancel" : function() {
+ $(this).dialog("close");
+ return false;
+ }
+ }
+ });
+ $("#confirm_remove_node_dialog").dialog("open");
+ });
+});
+
function add_fenceinst(parent_id, fence_type, fence_device) {
var form_jelem = $(document.getElementById(parent_id));
if (!form_jelem) {
diff --git a/luci/templates/node.html b/luci/templates/node.html
index e1097c1..65dd8ff 100644
--- a/luci/templates/node.html
+++ b/luci/templates/node.html
@@ -52,7 +52,7 @@
</div>
</py:if>
- <form action="${tg.url('%snodes_cmd' % tmpl_context.cluster_url)}" method="post">
+ <form action="${tg.url('%snodes_cmd' % tmpl_context.cluster_url)}" class="confirm_form" method="post">
<div class="sectionblock">
<xi:include href="submenu.html"/>
<div id="toolbar">
@@ -60,7 +60,7 @@
<input type="submit" name="MultiAction" value="${_('Reboot')}" class="toolbar_button MultiAction" id="tb_reboot" disabled="disabled"/>
<input type="submit" name="MultiAction" value="${_('Join Cluster')}" class="toolbar_button MultiAction" id="tb_join" disabled="disabled"/>
<input type="submit" name="MultiAction" value="${_('Leave Cluster')}" class="toolbar_button MultiAction" id="tb_leave" disabled="disabled"/>
- <input type="submit" name="MultiAction" value="${_('Delete')}" class="toolbar_button MultiAction" id="tb_delete" disabled="disabled"/>
+ <input type="submit" name="MultiAction" value="${_('Delete')}" class="confirm_form toolbar_button MultiAction" id="tb_delete" disabled="disabled"/>
</div>
<!--! OVERVIEW SECTION. -->
@@ -219,7 +219,7 @@
<a href="${tg.url('%snodes_cmd?command=Join+Cluster&name=%s' % (tmpl_context.cluster_url, name))}" id="dh_join" title="join"><span class="hide">join</span></a>
<a href="${tg.url('%snodes_cmd?command=Leave+Cluster&name=%s' % (tmpl_context.cluster_url, name))}" id="dh_leave" title="leave cluster"><span class="hide">leave cluster</span></a>
<py:if test="details['clustered'] != 'true'">
- <a href="${tg.url('%snodes_cmd?command=Delete&name=%s' % (tmpl_context.cluster_url, name))}" id="dh_delete" title="delete"><span class="hide">delete</span></a>
+ <a class="confirm_link" href="${tg.url('%snodes_cmd?command=Delete&name=%s' % (tmpl_context.cluster_url, name))}" id="dh_delete" title="delete"><span class="hide">delete</span></a>
</py:if>
<py:if test="details['clustered'] == 'true'">
<a href="javascript:void(0)" id="dh_delete" title="node must be stopped first"><span class="hide">delete</span></a>
@@ -511,6 +511,10 @@
</div>
</div>
<div class="hidden">
+ <div id="confirm_remove_node_dialog" title="Confirm deletion">
+ <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Removing a cluster node from the cluster is a destructive operation that cannot be undone.</p>
+ </div>
+
<div id="create_fencemethod_dialog">
<form name="create_fence_method" method="post" action="${tg.url('%snodes_fence_cmd?command=AddFenceMethod' % tmpl_context.cluster_url)}">
<input type="hidden" name="node" value="${name}"/>
12 years, 10 months
[luci] Fix transient traceback when displaying the cluster list
by Ryan McCabe
commit f966b3934a8baa1b1589f980b027b4b193677ca3
Author: Ryan McCabe <rmccabe(a)redhat.com>
Date: Sat Aug 20 14:31:55 2011 -0400
Fix transient traceback when displaying the
cluster list
luci/lib/db_helpers.py | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
---
diff --git a/luci/lib/db_helpers.py b/luci/lib/db_helpers.py
index a28f75e..680a211 100644
--- a/luci/lib/db_helpers.py
+++ b/luci/lib/db_helpers.py
@@ -190,6 +190,9 @@ def get_cluster_list_full():
cluster_list = {}
db_objs = get_cluster_list()
+ if not db_objs:
+ return cluster_list
+
for i in db_objs:
cluster_name = i.name
rc = get_agent_for_cluster(cluster_name)
12 years, 10 months
[luci] Remove messages generated in the post_login and post_logout handlers
by Ryan McCabe
commit 0409d619f4f2eebbd09bd3e33f8162c4219b8dcd
Author: Ryan McCabe <rmccabe(a)redhat.com>
Date: Sat Aug 20 14:31:20 2011 -0400
Remove messages generated in the post_login and
post_logout handlers
luci/controllers/root.py | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
---
diff --git a/luci/controllers/root.py b/luci/controllers/root.py
index 7e3adcf..6bfceb9 100644
--- a/luci/controllers/root.py
+++ b/luci/controllers/root.py
@@ -135,9 +135,7 @@ class RootController(BaseController):
"""
if not request.identity:
login_counter = request.environ['repoze.who.logins'] + 1
- redirect(url('/login', came_from=came_from, __logins=login_counter))
- userid = request.identity['repoze.who.userid']
- flash(_('Welcome back, %s!') % userid)
+ redirect('/login', came_from=came_from, __logins=login_counter)
redirect(came_from)
@expose()
@@ -147,5 +145,4 @@ class RootController(BaseController):
goodbye as well.
"""
- flash(_('We hope to see you soon!'))
redirect(came_from)
12 years, 10 months
[luci] Create a local database object for users after they authenticate successfully
by Ryan McCabe
commit 178cab31d06b6d8ee787170cc5f6148673156a8f
Author: Ryan McCabe <rmccabe(a)redhat.com>
Date: Sat Aug 20 14:29:56 2011 -0400
Create a local database object for users
after they authenticate successfully
luci/lib/plugin_sasl2auth.py | 20 +++++++++++++++++++-
1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/luci/lib/plugin_sasl2auth.py b/luci/lib/plugin_sasl2auth.py
index 7716b73..0e0158c 100644
--- a/luci/lib/plugin_sasl2auth.py
+++ b/luci/lib/plugin_sasl2auth.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2009-2010 Red Hat, Inc.
+# Copyright (C) 2009-2011 Red Hat, Inc.
#
# This program is free software; you can redistribute
# it and/or modify it under the terms of version 2 of the
@@ -9,6 +9,11 @@ from zope.interface import implements
from repoze.who.interfaces import IAuthenticator, IMetadataProvider
from repoze.who.utils import resolveDotted
+
+from luci.model import DBSession
+from luci.model.auth import User
+import transaction
+
from luci import sasl2auth
class Sasl2AuthPlugin(object):
@@ -33,6 +38,19 @@ class Sasl2AuthPlugin(object):
identity['login'], identity['password'], self.server_fqdn,
self.user_realm, self.iplocalport, self.ipremoteport
):
+ username = identity['login']
+ db_user = User.by_user_name(username)
+ if not db_user:
+ db_user = User(
+ user_name=username,
+ display_name=username,
+ email_address='',
+ )
+ try:
+ DBSession.add(db_user)
+ transaction.commit()
+ except Exception, e:
+ DBSession.rollback()
return identity['login']
return None
12 years, 10 months
[luci] Add back in the post_login and post_logout hooks to avoid "Wrong credentials" messages
by Ryan McCabe
commit 311230cdf7f5ee74381ef2917aaf9756fe332b23
Author: Ryan McCabe <rmccabe(a)redhat.com>
Date: Sat Aug 20 14:27:10 2011 -0400
Add back in the post_login and post_logout hooks
to avoid "Wrong credentials" messages
input_files/config.tmpl/config.tmpl.in | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/input_files/config.tmpl/config.tmpl.in b/input_files/config.tmpl/config.tmpl.in
index 5d71781..5ed192f 100644
--- a/input_files/config.tmpl/config.tmpl.in
+++ b/input_files/config.tmpl/config.tmpl.in
@@ -186,8 +186,8 @@ login_form_url= /login
login_handler_path = /login_handler
logout_handler_path = /logout_handler
rememberer_name = auth_tkt
-post_login_url =
-post_logout_url =
+post_login_url = /post_login
+post_logout_url = /post_logout
[plugin:auth_tkt]
use = @PKGNAME@.initwrappers:auth_tkt_make_plugin
12 years, 10 months
[luci] Reset the forms in lightbox dialogs when they're closed
by Ryan McCabe
commit 3a0f651585500e230e7e95c8375f42e16584c718
Author: Ryan McCabe <rmccabe(a)redhat.com>
Date: Sat Aug 20 14:25:33 2011 -0400
Reset the forms in lightbox dialogs when they're closed
luci/public/js/shared.js | 9 +++++++++
luci/templates/add_existing.html | 4 ++--
luci/templates/add_node.html | 2 +-
luci/templates/create_cluster.html | 2 +-
luci/templates/failover.html | 2 +-
luci/templates/fence.html | 2 +-
luci/templates/node.html | 6 +++---
luci/templates/resource.html | 2 +-
luci/templates/service.html | 2 +-
9 files changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/luci/public/js/shared.js b/luci/public/js/shared.js
index 0aa2595..4bbd36a 100644
--- a/luci/public/js/shared.js
+++ b/luci/public/js/shared.js
@@ -104,3 +104,12 @@ function update_multi_action(checkbox_obj) {
}
}
}
+
+/* From jquery.form.js */
+function reset_form(form_elem) {
+ $(form_elem).each(function() {
+ if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
+ this.reset();
+ }
+ });
+}
diff --git a/luci/templates/add_existing.html b/luci/templates/add_existing.html
index 0564027..8a6d54e 100644
--- a/luci/templates/add_existing.html
+++ b/luci/templates/add_existing.html
@@ -21,7 +21,7 @@
</div>
<input type="button" class="button formsubmit blue" value="Connect" onclick="add_existing_async(this.form)" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#add_existing_dialog').dialog('close')" />
+ onclick="$('#add_existing_dialog').dialog('close');reset_form(this.form)" />
</form>
</div>
</div>
@@ -54,7 +54,7 @@
<div class="row">
<input type="submit" class="button formsubmit blue" value="Add Cluster" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#add_existing_dialog').dialog('close')" />
+ onclick="$('#add_existing_dialog').dialog('close');reset_form(this.form)" />
</div>
</form>
</div>
diff --git a/luci/templates/add_node.html b/luci/templates/add_node.html
index 14f81a7..71607c1 100644
--- a/luci/templates/add_node.html
+++ b/luci/templates/add_node.html
@@ -51,7 +51,7 @@
<div class="row">
<input type="submit" class="button formsubmit blue" value="Add Nodes" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#add_nodes_dialog').dialog('close')" />
+ onclick="$('#add_nodes_dialog').dialog('close');reset_form(this.form)" />
</div>
</form>
<div class="hidden">
diff --git a/luci/templates/create_cluster.html b/luci/templates/create_cluster.html
index 31beb05..5a0095c 100644
--- a/luci/templates/create_cluster.html
+++ b/luci/templates/create_cluster.html
@@ -50,7 +50,7 @@
<div class="row">
<input type="submit" class="button formsubmit blue" value="Create Cluster" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#create_cluster_dialog').dialog('close')" />
+ onclick="$('#create_cluster_dialog').dialog('close');reset_form(this.form)" />
</div>
</form>
<div class="hidden">
diff --git a/luci/templates/failover.html b/luci/templates/failover.html
index 171ef87..b22c47d 100644
--- a/luci/templates/failover.html
+++ b/luci/templates/failover.html
@@ -308,7 +308,7 @@
</table>
<input type="submit" class="button formsubmit blue" value="Create" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#create_fdom_dialog').dialog('close')"/>
+ onclick="$('#create_fdom_dialog').dialog('close');reset_form(this.form)"/>
</form>
</div>
</div>
diff --git a/luci/templates/fence.html b/luci/templates/fence.html
index 82534dd..fd426ff 100644
--- a/luci/templates/fence.html
+++ b/luci/templates/fence.html
@@ -195,7 +195,7 @@
<input py:if="expertMode" type="hidden" name="expert_mode" value="1"/>
<input type="submit" value="Submit" class="button formsubmit blue" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#create_fencedev_dialog').dialog('close')" />
+ onclick="$('#create_fencedev_dialog').dialog('close');reset_form(this.form)" />
</div>
</form>
</div>
diff --git a/luci/templates/node.html b/luci/templates/node.html
index 7e0edc0..e1097c1 100644
--- a/luci/templates/node.html
+++ b/luci/templates/node.html
@@ -403,7 +403,7 @@
<div class="row">
<input type="submit" value="Submit" class="button formsubmit blue" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#edit_fencedev_dialog_${instance_id}').dialog('close')" />
+ onclick="$('#edit_fencedev_dialog_${instance_id}').dialog('close');reset_form(this.form)" />
</div>
</form>
</div>
@@ -505,7 +505,7 @@
<div class="row">
<input type="submit" value="Submit" class="button formsubmit blue" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#create_fencedev_dialog').dialog('close')" />
+ onclick="$('#create_fencedev_dialog').dialog('close');reset_form(this.form)" />
</div>
</form>
</div>
@@ -518,7 +518,7 @@
<div class="row">
<input type="submit" value="Submit" class="button formsubmit blue" />
<input type="button" class="button formsubmit silver" value="Cancel"
- onclick="$('#create_fencemethod_dialog').dialog('close')" />
+ onclick="$('#create_fencemethod_dialog').dialog('close');reset_form(this.form)" />
</div>
</form>
</div>
diff --git a/luci/templates/resource.html b/luci/templates/resource.html
index 8b30666..5c07db5 100644
--- a/luci/templates/resource.html
+++ b/luci/templates/resource.html
@@ -132,7 +132,7 @@
<input py:if="expertMode" type="hidden" name="expert_mode" value="1"/>
<input type="submit" class="formsubmit button blue" value="Submit"/>
<input type="button" class="formsubmit button silver" value="Cancel"
- onclick="$('#add_resource_dialog').dialog('close')" />
+ onclick="$('#add_resource_dialog').dialog('close');reset_form(this.form)" />
</div>
</form>
</div>
diff --git a/luci/templates/service.html b/luci/templates/service.html
index 68aeabe..bd14eb0 100644
--- a/luci/templates/service.html
+++ b/luci/templates/service.html
@@ -276,7 +276,7 @@
<input type="button" class="formsubmit button blue" value="Submit"
onclick="submit_svc_form(this.form)"/>
<input type="button" class="formsubmit button silver" value="Cancel"
- onclick="$('#add_service_dialog').dialog('close')" />
+ onclick="$('#add_service_dialog').dialog('close');reset_form(this.form)" />
</div>
<input type="hidden" name="action" value="create"/>
<input type="hidden" name="res_count" value="0"/>
12 years, 10 months
[luci] Add database backup and restore functionality to the luci init file.
by Ryan McCabe
commit 1c7ed45089572b0ff471e8394d93e8a3847fc334
Author: Ryan McCabe <rmccabe(a)redhat.com>
Date: Sat Aug 20 14:24:48 2011 -0400
Add database backup and restore functionality to the
luci init file.
input_files/initscript/initscript.in | 141 +++++++++++++++++++++++++++++++++-
1 files changed, 138 insertions(+), 3 deletions(-)
---
diff --git a/input_files/initscript/initscript.in b/input_files/initscript/initscript.in
index c4c4511..135e5e1 100755
--- a/input_files/initscript/initscript.in
+++ b/input_files/initscript/initscript.in
@@ -37,6 +37,7 @@ prog="@SERVICENAME@"
config="@BASECONFIG@"
sysconfig="@SYSCONFIG@"
exec="@LAUNCHER@"
+sqlite_bin="/usr/bin/sqlite3"
# Defaults that can be overridden by the content of $sysconfig
@@ -62,6 +63,10 @@ PORT=@PORT@
STATE_DIR="@STATEDIR@"
DB_FILE="@DBFILE@"
+DB_DIR="$(dirname $DB_FILE)"
+BACKUP_DIR="$(dirname $DB_FILE)"
+DB_PERMS=0640
+BACKUP_PERMS=0640
RUNTIMEDATA_DIR="@RUNTIMEDATADIR@"
CACHE_DIR="@CACHEDIR@"
@@ -159,7 +164,7 @@ prepare_config() {
prepare_db() {
touch "$DB_FILE"
chown $DAEMON_USER:$DAEMON_GROUP "$DB_FILE" \
- && chmod 0640 "$DB_FILE"
+ && chmod -- $DB_PERMS "$DB_FILE"
if [ $? -ne 0 ]; then
rm -f -- "$DB_FILE" &>/dev/null
$ECHOFUNC "Unable to change ownership/attributes of the $PKG_NAME database file (\`$DB_FILE')." >&2
@@ -272,8 +277,111 @@ initialize() {
fi
}
+list_database_dumps() {
+ /bin/ls -1 -- $BACKUP_DIR/@SERVICENAME(a)-backup*.db 2>/dev/null
+ return 0
+}
+
+dump_database() {
+ if [ -n "$1" ]; then
+ output_file="$1"
+ else
+ output_file="$BACKUP_DIR/@SERVICENAME@-backup$(/bin/date +%Y%m%d%H%M%S).db"
+ fi
+
+ if [ -e "$output_file" ]; then
+ if [ "$2" != "--force" ] && [ "$2" != "-f" ]; then
+ echo "A file named \`$output_file' already exists. Pass the additional argument of --force to overwrite it." >&2
+ return 1
+ fi
+ fi
+ $sqlite_bin "$DB_FILE" '.dump' > "$output_file"
+ if [ $? -ne 0 ]; then
+ echo "Failed to create \`$output_file' properly." >&2
+ rm -f -- "$output_file"
+ return 1
+ fi
+ chown $DAEMON_USER:$DAEMON_GROUP "$output_file" \
+ && chmod -- $BACKUP_PERMS "$output_file"
+ if [ $? -ne 0 ]; then
+ echo "Unable to change ownership/attributes of the $PKG_NAME database backup file (\`$output_file')." >&2
+ rm -f -- "$output_file" >&/dev/null
+ return 1
+ fi
+ restorecon -R -- "$DB_DIR" "$BACKUP_DIR" >&/dev/null
+ return 0
+}
+
+load_database() {
+ db_dump_file=$1
+ if [ ! "$db_dump_file" ]; then
+ echo "No database backup file was specified. Run \`$0 list-backups' to get a list of known existing backup files." >&2
+ return 1
+ fi
+
+ if [ ! -r "$db_dump_file" ]; then
+ echo "The database backup in \`$db_dump_file' cannot be read." >&2
+ return 1
+ fi
+
+ tmp_db="$(mktemp --tmpdir=$DB_DIR)"
+ if [ $? -ne 0 ]; then
+ echo "Unable to create a temporary file in \`$DB_DIR'." >&2
+ return 1
+ fi
+ $sqlite_bin $tmp_db ".read $db_dump_file"
+ if [ $? -ne 0 ] || [ ! -s "$tmp_db" ]; then
+ # sqlite will return 0 even if you feed it non-sql input. In the case
+ # of bad input, the database file will have size 0.
+ echo "Unable to restore the database from the backup file \`$db_dump_file'" >&2
+ rm -f -- "$tmp_db" >&/dev/null
+ return 1
+ fi
+ chown $DAEMON_USER:$DAEMON_GROUP "$tmp_db" \
+ && chmod -- $DB_PERMS "$tmp_db"
+ if [ $? -ne 0 ]; then
+ echo "Unable to change ownership/attributes of the $PKG_NAME database file (\`$tmp_db')." >&2
+ rm -f -- "$tmp_db" >&/dev/null
+ return 1
+ fi
+
+ old_exists=0
+ if [ -e "$DB_FILE" ]; then
+ old_exists=1
+ bknum=0
+ while [ -e "$DB_FILE".$bknum ]; do
+ bknum=$(($bknum+1))
+ done
+ old_db_name="$DB_FILE".$bknum
+
+ mv -n -- "$DB_FILE" "$old_db_name"
+ if [ $? -ne 0 ]; then
+ # it appeared out of nowhere
+ echo "Unable to move the existing database file to \`$old_db_name'." >&2
+ rm -f -- "$tmp_db" >&/dev/null
+ return 1
+ fi
+ fi
+
+ ret_code=0
+ mv -- "$tmp_db" "$DB_FILE"
+ if [ $? -ne 0 ]; then
+ rm -f -- "$tmp_db" >&/dev/null
+ if [ $old_exists -eq 1 ]; then
+ echo "Unable to move the newly created database file to \`$DB_FILE'. Trying to restore database from \`$old_db_name'." >&2
+ mv -- "$old_db_name" "$DB_FILE"
+ else
+ echo "Unable to move the newly created database file to \`$DB_FILE'." >&2
+ fi
+ ret_code=1
+ fi
+
+ restorecon -R -- "$DB_DIR" "$BACKUP_DIR" >&/dev/null
+ return $ret_code
+}
+
start_server() {
- # TODO: Can be the dependency on running saslauthd solved in a better way?
+ # TODO: Can the dependency on saslauthd running be solved in a better way?
# LSB header doesn't seem to help there.
/sbin/service saslauthd start || return 1
@@ -380,8 +488,35 @@ case "$1" in
entry_check || exit 4
$1
;;
+ backup-db)
+ entry_check || exit 4
+ status &>/dev/null
+ if [ $? -eq 0 ]; then
+ echo "The database backup operation can proceed only when @SERVICENAME@ is stopped. Stop @SERVICENAME@, then try again." >&2
+ exit 1
+ fi
+ shift
+ dump_database $*
+ exit $?
+ ;;
+ restore-db)
+ entry_check || exit 4
+ status &>/dev/null
+ if [ $? -eq 0 ]; then
+ echo "The database restore operation can proceed only when @SERVICENAME@ is stopped. Stop @SERVICENAME@, then try again." >&2
+ exit 1
+ fi
+ shift
+ load_database $*
+ exit $?
+ ;;
+ list-backups)
+ entry_check || exit 4
+ list_database_dumps
+ exit $?
+ ;;
*)
- echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|try-restart}"
+ echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|try-restart|backup-db|restore-db|list-backups}"
exit 2
esac
exit $?
12 years, 10 months