This file is indexed.

/usr/share/cherokee/admin/server.py is in cherokee-admin 1.2.101-1.

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
#!/usr/bin/env python

# -*- coding: utf-8 -*-
#
# Cherokee-admin
#
# Authors:
#      Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

# System
import os
import sys
import stat
import socket
import signal
import thread

# Import CTK
sys.path.append (os.path.abspath (os.path.realpath(__file__) + '/../CTK'))
import CTK
import OWS_Login
import market.Distro

# Cherokee imports
import config_version
from configured import *
import PageError


def init (scgi_port, cfg_file):
    # Translation support
    CTK.i18n.install ('cherokee', LOCALEDIR, unicode=True)

    # Ensure SIGCHLD is set. It needs to receive the signal in order
    # to detect when its child processes finish.
    if signal.getsignal (signal.SIGCHLD) == signal.SIG_IGN:
        signal.signal (signal.SIGCHLD, signal.SIG_DFL)

    # Move to the server directory
    pathname, scriptname = os.path.split(sys.argv[0])
    os.chdir(os.path.abspath(pathname))

    # Let the user know what is going on
    version = VERSION
    pid     = os.getpid()

    if scgi_port.isdigit():
        print _("Server %(version)s running.. PID=%(pid)d Port=%(scgi_port)s") % (locals())
    else:
        print _("Server %(version)s running.. PID=%(pid)d Socket=%(scgi_port)s") % (locals())

    # Read configuration file
    CTK.cfg.file = cfg_file
    CTK.cfg.load()

    # Update config tree if required
    config_version.config_version_update_cfg (CTK.cfg)

    # Init CTK
    if scgi_port.isdigit():
        # Ensure that 'localhost' can be resolved
        try:
            socket.getaddrinfo ("localhost", int(scgi_port))
        except socket.gaierror:
            print >> sys.stderr, "[FATAL ERROR]: The 'localhost' host name cannot be resolved.\n"
            sys.exit(1)

        CTK.init (host="localhost", port=int(scgi_port), sec_cookie=True, sec_submit=True)

    else:
        # Remove the unix socket if it already exists
        try:
            mode = os.stat (scgi_port)[stat.ST_MODE]
            if stat.S_ISSOCK(mode):
                print "Removing an old '%s' unix socket.." %(scgi_port)
                os.unlink (scgi_port)
        except OSError:
            pass

        CTK.init (unix_socket=scgi_port, sec_cookie=True, sec_submit=True)

    # At this moment, CTK must be forced to work as a syncronous
    # server. All the initial tests (config file readable, correct
    # installation, etc) must be performed in the safest possible way,
    # ensuring that race conditions don't cause trouble. It will be
    # upgraded to asyncronous mode just before the mainloop is reached
    CTK.set_synchronous (True)

def debug_set_up():
    def debug_callback (sig, frame):
        import code, traceback

        d = {'_frame':frame}       # Allow access to frame object.
        d.update(frame.f_globals)  # Unless shadowed by global
        d.update(frame.f_locals)

        i = code.InteractiveConsole(d)
        message  = "Signal recieved : entering python shell.\nTraceback:\n"
        message += ''.join(traceback.format_stack(frame))
        i.interact(message)

    def trace_callback (sig, stack):
        import traceback, threading

        id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
        for threadId, stack in sys._current_frames().items():
            print '\n# Thread: %s(%d)' %(id2name[threadId], threadId)
            for filename, lineno, name, line in traceback.extract_stack(stack):
                print 'File: "%s", line %d, in %s' %(filename, lineno, name)
                if line:
                    print '  %s' % (line.strip())

    print "DEBUG: SIGUSR1 invokes the console.."
    print "       SIGUSR2 prints a backtrace.."
    signal.signal (signal.SIGUSR1, debug_callback)
    signal.signal (signal.SIGUSR2, trace_callback)


def download_distro_index():
    def thread_func():
        # First instance will trigger the update
        index = market.Distro.Index()

    thread.start_new_thread (thread_func, ())


if __name__ == "__main__":
    # Read the arguments
    try:
        scgi_port = sys.argv[1]
        cfg_file  = sys.argv[2]
    except:
        print _("Incorrect parameters: PORT CONFIG_FILE")
        raise SystemExit

    # Debugging mode
    if '-x' in sys.argv:
        debug_set_up()

    # Init
    init (scgi_port, cfg_file)

    # Ancient config file
    def are_vsrvs_num():
        tmp = [True] + [x.isdigit() for x in CTK.cfg.keys('vserver')]
        return reduce (lambda x,y: x and y, tmp)

    if not are_vsrvs_num():
        CTK.publish (r'', PageError.AncientConfig, file=cfg_file)

        while not are_vsrvs_num():
            CTK.step()

        CTK.unpublish (r'')

    # Check config file and set up
    if os.path.exists (cfg_file) and os.path.isdir (cfg_file):
        CTK.publish (r'', PageError.NotWritable, file=cfg_file)

        while os.path.isdir (cfg_file):
            CTK.step()

        CTK.unpublish (r'')

    if not os.path.exists (cfg_file):
        import PageNewConfig
        CTK.publish (r'', PageNewConfig.Render)

        while not os.path.exists (cfg_file):
            CTK.step()

        CTK.unpublish (r'')
        CTK.cfg.file = cfg_file
        CTK.cfg.load()

    if not os.access (cfg_file, os.W_OK):
        CTK.publish (r'', PageError.NotWritable, file=cfg_file)

        while not os.access (cfg_file, os.W_OK):
            CTK.step()

        CTK.unpublish (r'')

    for path in (CHEROKEE_WORKER, CHEROKEE_SERVER, CHEROKEE_ICONSDIR):
        if not os.path.exists (path):
            CTK.publish (r'', PageError.ResourceMissing, path=CHEROKEE_WORKER)

            while not os.path.exists (path):
                CTK.step()

            CTK.unpublish (r'')

    # OWS related checks
    if not os.path.isdir (CHEROKEE_OWS_DIR):
        try: os.makedirs (CHEROKEE_OWS_DIR, 0755)
        except OSError: pass

    if not os.path.isdir (CHEROKEE_OWS_ROOT):
        try: os.makedirs (CHEROKEE_OWS_ROOT, 0755)
        except OSError: pass

    if not os.access (CHEROKEE_OWS_DIR,  os.W_OK) or \
       not os.access (CHEROKEE_OWS_ROOT, os.W_OK):
        CTK.publish (r'', PageError.OWSDirectory)
        while not os.access (CHEROKEE_OWS_DIR,  os.W_OK) or \
              not os.access (CHEROKEE_OWS_ROOT, os.W_OK):
            CTK.step()

            if not os.path.isdir (CHEROKEE_OWS_DIR):
                try: os.makedirs (CHEROKEE_OWS_DIR, 0755)
                except OSError: pass

            if not os.path.isdir (CHEROKEE_OWS_ROOT):
                try: os.makedirs (CHEROKEE_OWS_ROOT, 0755)
                except OSError: pass

        CTK.unpublish (r'')

    # Add the OWS plug-in directory
    CTK.add_plugin_dir (CHEROKEE_OWS_DIR)

    # Set up the error page
    import PageException
    CTK.error.page = PageException.Page

    # Launch the SystemStats ASAP
    import SystemStats
    SystemStats.get_system_stats()

    # Import the Pages
    import PageIndex
    import PageGeneral
    import PageVServers
    import PageVServer
    import PageRule
    import PageEntry
    import PageSources
    import PageSource
    import PageAdvanced
    import PageNewConfig
    import PageHelp
    import PageStatus
    import market

    # Wizards 2.0 (TMP!)
    wizards2_path = os.path.realpath (__file__ + "/../wizards2")
    if os.path.exists (wizards2_path):
        import wizards2

    # Init translation
    if CTK.cfg['admin!lang']:
        PageIndex.language_set (CTK.cfg.get_val('admin!lang'))

    # Let's get asyncronous..
    CTK.set_synchronous (False)

    # Log into OWS if feature is enabled
    ## do_OWS_login()
    download_distro_index()

    # Run forever
    CTK.run()

    # Kill lingering processes
    try:
        # Parent
        cherokee_admin_pid = os.getppid()
        os.kill (cherokee_admin_pid, signal.SIGTERM)

        # Itself
        os.killpg (0, signal.SIGTERM)
    except OSError:
        pass