This file is indexed.

/usr/share/hplip/doctor.py is in hplip-data 3.14.3-0ubuntu3.4.

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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2012-2020 Hewlett-Packard Development Company, L.P.
#
# 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; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
#
# Author: Amarnath Chitumalla
#

__version__ = '1.0'
__title__ = 'Self Diagnse Utility and Healing Utility'
__mod__ = 'hp-doctor'
__doc__ = """Tool checks for the deprecated, plug-in, dependencies, queues, permission issues and provides self diagnose steps"""


# global import
import getopt
import os
import sys
import getpass

#local import
from base.g import *
from base import utils, tui, module,queues, os_utils, services, smart_install
from installer.core_install import *
from check import DependenciesCheck

USAGE = [(__doc__, "", "name", True),
         ("Usage: %s [OPTIONS]" % __mod__, "", "summary", True),
         utils.USAGE_SPACE,
         utils.USAGE_MODE,
         ("Run in interactive mode:", "-i or --interactive (Default)", "option", False),
         ("Run in graphical UI mode:", "-u or --gui (future use)", "option", False),
         utils.USAGE_SPACE,
         utils.USAGE_OPTIONS,
         utils.USAGE_HELP,
         utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
         ("Non-interactive mode:","-n(Without asking permissions)(future use)","option",False),
         ("Perform the task for the given device id:","-d<device id>(future use)","option",False),
         ("Take options from the file instead of command line:","-f<file> (future use)","option",False)

        ]

##########################global variables ##########################3
MODE = INTERACTIVE_MODE
DEVICE_URI = None
PERFORM_IN_NON_INTERACTIVE_MODE=False
LOG_LEVEL=None
VALID_AUTHENTICATION = False
IS_RESTART_REQ = False
DONOT_CLOSE_TERMINAL=False
SUMMARY_ONLY = False

#################################### functions #########################
def usage(typ='text'):
    if typ == 'text':
        utils.log_title(__title__, __version__)

    utils.format_text(USAGE, typ, __title__, __mod__, __version__)
    clean_exit(2)


def append_options(cmd):
    if MODE == INTERACTIVE_MODE:
        cmd += " -i "
    elif MODE == GUI_MODE:
        cmd += " -u "

    if PERFORM_IN_NON_INTERACTIVE_MODE:
        cmd += " -n "

    if LOG_LEVEL:
        cmd += " -l%s"%LOG_LEVEL

    # Adding quiet mode option..
    cmd += " -s "
    return cmd


def authenticate(core):
    global VALID_AUTHENTICATION
    if not services.running_as_root() and VALID_AUTHENTICATION == False:
        ###TBD
        # if MODE == GUI_MODE:
        #    GUI passwrd query..
        # else:
        if core.passwordObj.getAuthType() == "sudo":
            tui.title("ENTER SUDO PASSWORD")
        else:
            tui.title("ENTER ROOT/SUPERUSER PASSWORD")

        VALID_AUTHENTICATION = core.check_password()
    else:
        VALID_AUTHENTICATION = True

    if not VALID_AUTHENTICATION:
        log.error("3 incorrect attempts. (or) Insufficient permissions(i.e. try with sudo user).\nExiting.")
        clean_exit(3)

    return VALID_AUTHENTICATION


def install_plugin(core):
    plugin_sts = core.get_plugin_status()
    if plugin_sts == PLUGIN_VERSION_MISMATCH:
        ok,user_input =tui.enter_choice("Found Plugin version mismatch. Press 'y' to re-install the plugin(y=yes*, n=no):",['y', 'n'], 'y')
    elif plugin_sts == PLUGIN_FILES_CORRUPTED:
        ok,user_input =tui.enter_choice("Plugins corrupted. Press 'y' to re-install the plugin(y=yes*, n=no):",['y', 'n'], 'y')
    elif plugin_sts == PLUGIN_NOT_INSTALLED:
        ok,user_input =tui.enter_choice("Plugin's are missing. Press 'y' to install the plugin(y=yes*, n=no):",['y', 'n'], 'y')
    elif plugin_sts == PLUGIN_INSTALLED:
        log.info("Plugin's already installed")
        return True
    else:
        log.info("No plug-in printers are configured.")
        return True

    if ok and user_input == 'y':
#        authenticate(core)
        cmd=utils.which('hp-plugin',True)
        if cmd:
            cmd = core.passwordObj.getAuthCmd() %append_options(cmd)
            sts = os_utils.execute(cmd)
            if sts == 0:
                return True
        else:
            log.error("Failed to locate hp-plugin command")
    else:
        log.info(log.bold("Please run 'hp-plugin' command in root mode to install the Plugin's"))
    return False


def deprecated_check(core):
    if core.validate_distro_version():
        log.debug("This distro is supported.")
        log.info("No Deprecated items are found")
    else:
        log.error("This distro (i.e %s  %s) is either deprecated or not yet supported."%(core.distro_name, core.distro_version))
        ok,user_input =tui.enter_choice(log.red("The diagnosis is limited on unsupported platforms. Do you want to continue?(y=yes*, n=no):"),['y', 'n'], 'y')
        if not ok or user_input !='y':
            clean_exit(2)


def display_missing_dependencies(required_dependencies=[],optional_dependencies=[], missing_cmd=[]):
    if len(required_dependencies):
        log.info(log.bold("Missing Required Dependencies"))
        log.info(log.bold('-'*len("Missing Required Dependencies")))
        for packages_to_install in required_dependencies:
           if 'cups' in packages_to_install:
               log.error("'%s' package is missing or '%s' service is not running."%(packages_to_install,'cups'))
           else:
               log.error("'%s' package is missing/incompatible "%packages_to_install)

    if len(optional_dependencies):
        log.info(log.bold("Missing Optional Dependencies"))
        log.info(log.bold('-'*len("Missing Optional Dependencies")))
        for packages_to_install in optional_dependencies:
            log.error("'%s' package is missing/incompatible "%packages_to_install)

    if len(missing_cmd):
        log.info(log.bold("Missing Commands"))
        log.info(log.bold('-'*len("Missing Commands")))
        for cmd in missing_cmd:
            log.error("'%s' is missing"%cmd)


def clean_exit(exit_code=0):
    mod.unlockInstance()

    if DONOT_CLOSE_TERMINAL:
        log.info("\n\nPlease close this terminal manually. ")
        try:
            while 1:
                pass
        except KeyboardInterrupt:
            pass

    sys.exit(exit_code)


#################################### Main #########################
log.set_module(__mod__)
try:
    mod = module.Module(__mod__, __title__, __version__, __doc__, USAGE,
                    (INTERACTIVE_MODE, GUI_MODE),
                    (UI_TOOLKIT_QT3, UI_TOOLKIT_QT4), True, True)

    opts, device_uri, printer_name, mode, ui_toolkit, loc = \
               mod.parseStdOpts('hl:gnid:f:w', ['summary-only','help', 'help-rest', 'help-man', 'help-desc', 'interactive', 'gui', 'lang=','logging=', 'debug'],
                     handle_device_printer=False)

except getopt.GetoptError, e:
    log.error(e.msg)
    usage()

if os.getenv("HPLIP_DEBUG"):
    log.set_level('debug')
    LOG_LEVEL = 'debug'

for o, a in opts:
    if o == '-n':
        MODE = NON_INTERACTIVE_MODE
        PERFORM_IN_NON_INTERACTIVE_MODE = True
        log.warn("NON_INTERACTIVE mode is not yet supported.")
        #TBD
        usage()
    elif o == '-d':
        DEVICE_URI=a
    elif o in ('-u', '--gui'):
        log.warn("GUI is not yet supported.")
        #TBD
        usage()
    elif o == '-f':
        log.warn("Option from file is not yet supported")
        #TBD
        usage()
    elif o in ('-l', '--logging'):
        LOG_LEVEL = a.lower().strip()
        if not log.set_level(LOG_LEVEL):
            usage()
    elif o == '-w':
        DONOT_CLOSE_TERMINAL = True

    elif o == '--summary-only':
        SUMMARY_ONLY = True


try:
    if os.geteuid() == 0:
        log.error("Please run %s as a non-root user"%__mod__)
        sys.exit(1)

    mod.lockInstance('')
    mod.quiet= False
    mod.showTitle()
    log_file = os.path.normpath('%s/hp-doctor.log'%prop.user_dir)

    if os.path.exists(log_file):
        try:
            os.remove(log_file)
        except OSError:
            pass

    log.set_logfile(log_file)
    log.set_where(log.LOG_TO_CONSOLE_AND_FILE)

    log.debug("Upgrade log saved in: %s" % log.bold(log_file))
    log.debug("")

    if PERFORM_IN_NON_INTERACTIVE_MODE and os.geteuid() != 0:
        log.error("Non Interactive mode should be run in root mode.")
        clean_exit(1)

    ui_toolkit = sys_conf.get('configure','ui-toolkit')

    core =  DependenciesCheck(MODE_CHECK,INTERACTIVE_MODE,ui_toolkit)
    core.init()
    log.info(log.bold("\n\nChecking for Deprecated items...."))

    deprecated_check(core)

    log.info(log.bold("\n\nChecking for HPLIP updates...."))
    upgrade_cmd = utils.which('hp-upgrade',True)
    if upgrade_cmd:
        #checking for latest version of HPLIP.
        upgrade_cmd = append_options(upgrade_cmd)
        sts = os_utils.execute(upgrade_cmd)
        if sts != 0:
            log.error("Failed to upgrade latest HPLIP. Is hp-upgrade already running (i.e. foreground or background)?")
    else:
        log.error("Failed to locate hp-upgrade utility")

    ### Dependency check
    log.info(log.bold("\n\nChecking for Dependencies...."))
    if SUMMARY_ONLY:
        num_errors, num_warns = core.validate(DEPENDENCY_RUN_AND_COMPILE_TIME, True)
    else:
        num_errors, num_warns = core.validate(DEPENDENCY_RUN_AND_COMPILE_TIME, False)

    if num_errors or num_warns:

        if core.get_required_deps() or core.get_optional_deps() or core.get_cmd_to_run():
            display_missing_dependencies(core.get_required_deps(),core.get_optional_deps(), core.get_cmd_to_run())
            authenticate(core)
            core.install_missing_dependencies(INTERACTIVE_MODE,core.get_required_deps(),core.get_optional_deps(), core.get_cmd_to_run())

        log.info(log.bold("\n\nChecking Permissions...."))
#        if not core.get_missing_user_grps() and not core.get_disable_selinux_status():
        if not core.get_disable_selinux_status():
            log.info("Permissions are correct.")

#        if core.get_missing_user_grps():
#            log.info(log.bold("Missing User Groups"))
#            log.info(log.bold('-'*len("Missing User Groups")))
#            log.info("%s"%core.get_missing_user_grps())
#            authenticate(core)
#            if core.add_groups_to_user(core.get_missing_user_grps(), core.get_user_grp_cmd()):
#                IS_RESTART_REQ = True

        if core.get_disable_selinux_status():
            log.info(log.bold("SELinux Status"))
            log.info(log.bold('-'*len("SELinux Status")))
            log.info("SELinux is enabled. Needs to be disabled")
            authenticate(core)
            if core.disable_SELinux():
                IS_RESTART_REQ = True

    log.info(log.bold("\n\nChecking for Configured Queues...."))
    queues.main_function(core.passwordObj, MODE,ui_toolkit, False, DEVICE_URI)

    log.info(log.bold("\n\nChecking for HP Properitery Plugin's...."))
    ### Check for Plugin Printers
    install_plugin(core)

    smart_ins_dev_list = smart_install.get_smartinstall_enabled_devices()
    if smart_ins_dev_list:
        log.info(log.bold("\n\nChecking for 'CD-ROM'/'Smart Install' Detected Devices...."))
        url, tool_name = smart_install.get_SmartInstall_tool_info()
        for printer in smart_ins_dev_list:
            log.error("Smart Install is Enabled in '%s' Printer. This needs to be disabled."%printer)
        log.info(log.bold("\nRefer link '%s' to disable Smart Install manually.\n"%(url)))

    comm_err_dev = core.get_communication_error_devs()
    if comm_err_dev:
        log.info(log.bold("\n\nChecking for Printer Status...."))
        for printer in comm_err_dev:
            log.error("'%s' Printer is either Powered-OFF or Failed to communicate."%printer)
            log.info(log.bold("Turn On Printer and re-run %s"%__mod__))

    if IS_RESTART_REQ:
        log.info(log.bold("\nPlease reboot the system before performing any function."))

    log.info(log.bold("\nDiagnose completed...\n"))
    log.info("")
    log.info("")
    log.info("More information on Troubleshooting,How-To's and Support is available on http://hplipopensource.com/hplip-web/index.html")
        
    clean_exit(0)


except KeyboardInterrupt:
    log.error("User exit")
    clean_exit(1)