This file is indexed.

/usr/sbin/powernap-action is in powernap 2.18-0ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/python
#
#    powernap-action - enable or disable actions when running powernap
#                      Available actions at /usr/lib/powernap/actions.
#                      Enabled actions at /etc/powernap/actions.d.
#
#    Copyright (C) 2010 Canonical Ltd.
#
#    Authors: Andres Rodriguez <andreserl@ubuntu.com>
#
#    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, version 3 of the License.
#
#    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.  If not, see <http://www.gnu.org/licenses/>.

import os, sys, commands
from optparse import OptionParser

global PKG
PKG = "powernap"
PM_ACTIONS_DIR = "/etc/pm/power.d"


# If not running as root, exit program and display message
if not os.geteuid()==0:
    sys.exit("This utility may only be run by the root user.")

# Check if action exists.
def action_exists(action):
    path = "%s/%s" % (PM_ACTIONS_DIR, action)
    if os.path.exists(path):
        return True
    else:
        return False

# Check if action is enabled.
def is_action_enabled(action):
    path = "%s/%s" % (PM_ACTIONS_DIR, action)
    if os.access(path, os.X_OK):
        return True
    else:
        return False

def do_action_enable(action):
    src = "%s/%s" % (PM_ACTIONS_DIR, action)
    info("enabling action [%s]..." % action)
    os.chmod(src, 0755)

def do_action_disable(action):
    path = "%s/%s" % (PM_ACTIONS_DIR, action)
    info("disabling action [%s]..." % action)
    #TODO: Not only remove, but undo changes if possible!!
    os.chmod(path, 0644)

def list_available_actions():
    #TODO: Display the actions and show which ones are enabled or disabled.
    try:
        actionslist = os.listdir(PM_ACTIONS_DIR)
        for action in actionslist:
            path = "%s/%s" % (PM_ACTIONS_DIR, action)
            (status, output) = commands.getstatusoutput("%s help" % path)
            if os.access(path, os.X_OK):
                print "[enabled]  %-20s - %s" % (action, output)
            else:
                print "[disabled] %-20s - %s" % (action, output)
    except:
        error("Could not retrieve list of available actions")

def get_action_status():
    print "obtaining status of"

def info(str):
    print("INFO: %s" % str)

def error(str):
    print("ERROR: %s" % str)
    sys.exit(1)

if __name__ == '__main__':
    hasOptions = False
    # Option Parser
    usage = "usage: %prog <parameters>\n\
            \n\
    %prog is a utility that allows to enable and disable available PowerNap\n\
    actions.\n\
    \n\
    %prog --enable [action]\n\
    %prog --disable [action]\n\
    %prog --list"

    parser = OptionParser(usage)
    parser.add_option('-e', '--enable', action='store', type='string', dest='enable',
                      help='enable available PowerNap actions', metavar='ACTION')
    parser.add_option('-d', '--disable', action='store', type='string', dest='disable',
                      help='disable available PowerNap actions', metavar='ACTION')
    parser.add_option('-l', '--list', action='store_true', dest='list', help='Lists available actions')

    (opt, args) = parser.parse_args()

    if opt.list and opt.enable:
        error("Options -l (--list) and -e (--enable) are mutually exclusive")
        sys.exit(1)

    if opt.list and opt.disable:
        error("Options -l (--list) and -d (--disable) are mutually exclusive")

    if opt.enable and opt.disable:
        error("Options -e (--enable) and -d (--disable) are mutually exclusive")
        sys.exit(1)

    if opt.enable:
        hasOptions = True
        # Check if action exists, if not, exit
        if not action_exists(opt.enable):
            error("[%s] does not exist, exiting..." % opt.enable)
            sys.exit(1)

        # If action is not enabled, enable it, otherwise do nothing.
        if not is_action_enabled(opt.enable):
            do_action_enable(opt.enable)
        else:
            info("[%s] is already enabled, skipping..." % opt.enable)

    if opt.disable:
        hasOptions = True
        # Check if action exists, if not, exit
        if not action_exists(opt.disable):
            error("[%s] does not exist, exiting..." % opt.disable)
            sys.exit(1)

        # If action is enabled, disable it, otherwise do nothing.
	if is_action_enabled(opt.disable):
            do_action_disable(opt.disable)
        else:
            info("[%s] is already disabled, skipping..." % opt.disable)

    if opt.list:
        hasOptions = True
        list_available_actions()

    if not hasOptions:
        print parser.get_usage()