cryptonas/plugins/shutdown/shutdown.py

75 lines
2.1 KiB
Python
Raw Normal View History

#
# Copyright 2006 sense.lab e.V.
#
# This file is part of the CryptoBox.
#
# The CryptoBox 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.
#
# The CryptoBox 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 the CryptoBox; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
__revision__ = "$Id"
import cryptobox.plugins.base
2006-11-06 17:05:00 +01:00
REDIRECT_DELAY = 120
2006-11-06 17:05:00 +01:00
class shutdown(cryptobox.plugins.base.CryptoBoxPlugin):
2006-11-06 17:05:00 +01:00
plugin_capabilities = [ "system" ]
plugin_visibility = [ "preferences", "menu" ]
request_auth = False
2006-11-06 17:05:00 +01:00
rank = 90
def do_action(self, type=None):
2006-11-06 17:05:00 +01:00
if not type:
return "form_shutdown"
elif type == "shutdown":
if self.__do_shutdown("shutdown"):
2006-11-06 17:05:00 +01:00
self.hdf["Data.Success"] = "Plugins.shutdown.Shutdown"
return "progress_shutdown"
else:
self.hdf["Data.Warning"] = "Plugins.shutdown.ShutdownFailed"
return "form_shutdown"
elif type == "reboot":
if self.__do_shutdown("reboot"):
2006-11-06 17:05:00 +01:00
self.hdf["Data.Success"] = "Plugins.shutdown.Reboot"
self.hdf["Data.Redirect.URL"] = "/"
2006-11-06 17:05:00 +01:00
self.hdf["Data.Redirect.Delay"] = REDIRECT_DELAY
return "progress_reboot"
else:
self.hdf["Data.Warning"] = "Plugins.shutdown.RebootFailed"
return "form_shutdown"
else:
return "form_shutdown"
def get_status(self):
2006-11-06 17:05:00 +01:00
return "the box is up'n'running"
def __do_shutdown(self, action):
2006-11-06 17:05:00 +01:00
import subprocess
import os
proc = subprocess.Popen(
shell = False,
args = [
self.cbox.prefs["Programs"]["super"],
self.cbox.prefs["Programs"]["CryptoBoxRootActions"],
"plugin",
os.path.join(self.plugin_dir, "root_action.py"),
2006-11-06 17:05:00 +01:00
action])
proc.wait()
return proc.returncode == 0