This file is indexed.

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

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

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
# -*- coding: utf-8 -*-
#
# Cherokee-admin
#
# Authors:
#      Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2010 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.
#

import CTK
import Handler
import Cherokee
import Balancer
import validations

from util import *
from consts import *

URL_APPLY = '/plugin/proxy/apply'
HELPS     = [('modules_handlers_proxy', N_("Reverse Proxy"))]

NOTE_REUSE_MAX       = N_("Maximum number of connections per server that the proxy can try to keep opened.")
NOTE_ALLOW_KEEPALIVE = N_("Allow the server to use Keep-alive connections with the back-end servers.")
NOTE_PRESERVE_HOST   = N_("Preserve the original \"Host:\" header sent by the client. (Default: No)")
NOTE_PRESERVE_SERVER = N_("Preserve the \"Server:\" header sent by the back-end server. (Default: No)")
NOTE_ERROR_HANDLER   = N_("Use the VServer error handler, whenever an error response is received from a back-end server. (Default: No)")

VALS = [
    ('.+?!reuse_max', validations.is_number_gt_0),
]


def commit():
    # New Rewrite
    for e in ('in_rewrite_request', 'out_rewrite_request'):
        key   = CTK.post.pop ('tmp!new!%s!key'%(e))
        regex = CTK.post.pop ('tmp!new!%s!regex'%(e))
        subst = CTK.post.pop ('tmp!new!%s!substring'%(e))

        if regex:
            next = CTK.cfg.get_next_entry_prefix ('%s!%s'%(key, e))
            CTK.cfg['%s!regex'%(next)]     = regex
            CTK.cfg['%s!substring'%(next)] = subst
            return CTK.cfg_reply_ajax_ok()

    # New Header
    for e in ('in_header_add', 'out_header_add'):
        key    = CTK.post.pop ('tmp!new!%s!key'%(e))
        header = CTK.post.pop ('tmp!new!%s!header'%(e))
        value  = CTK.post.pop ('tmp!new!%s!value'%(e))

        if header and value:
            CTK.cfg['%s!%s!%s'%(key, e, header)] = value
            return CTK.cfg_reply_ajax_ok()

    # New Hide
    for e in ('in_header_hide', 'out_header_hide'):
        key  = CTK.post.pop ('tmp!new!%s!key'%(e))
        hide = CTK.post.pop ('tmp!new!%s!hide'%(e))

        if hide:
            next = CTK.cfg.get_next_entry_prefix ('%s!%s'%(key, e))
            CTK.cfg[next] = hide
            return CTK.cfg_reply_ajax_ok()

    # Modification
    return CTK.cfg_apply_post()


class URL_Rewrite (CTK.Container):
    class Content (CTK.Container):
        def __init__ (self, refresh, key):
            CTK.Container.__init__ (self)

            keys = CTK.cfg.keys(key)
            if keys:
                table = CTK.Table()
                table.set_header(1)
                table += [CTK.RawHTML(x) for x in (_('Regular Expression'), _('Substitution'))]

                for k in CTK.cfg.keys(key):
                    regex = CTK.TextCfg ('%s!%s!regex'%(key,k), False)
                    subst = CTK.TextCfg ('%s!%s!substring'%(key,k), False)
                    remove = CTK.ImageStock('del')
                    remove.bind('click', CTK.JS.Ajax (URL_APPLY, data={'%s!%s'%(key,k): ''},
                                                          complete = refresh.JS_to_refresh()))
                    table += [regex, subst, remove]

                submit = CTK.Submitter (URL_APPLY)
                submit += table

                self += CTK.Indenter (submit)

    def __init__ (self, key, key_entry):
        CTK.Container.__init__ (self)

        # List
        refresh = CTK.Refreshable ({'id': 'proxy_%s'%(key_entry)})
        refresh.register (lambda: self.Content(refresh, '%s!%s'%(key, key_entry)).Render())
        self += refresh

        # New
        new_regex  = CTK.TextCfg('tmp!new!%s!regex'%(key_entry), False, {'class': 'noauto'})
        new_subst  = CTK.TextCfg('tmp!new!%s!substring'%(key_entry), True, {'class': 'noauto'})
        add_button = CTK.SubmitterButton(_('Add'))

        table = CTK.Table()
        table.set_header(1)
        table += [CTK.RawHTML(x) for x in (_('Add RegEx'), _('Substitution'))]
        table += [new_regex, new_subst, add_button]

        submit = CTK.Submitter (URL_APPLY)
        submit += CTK.Indenter (table)
        submit += CTK.Hidden ('tmp!new!%s!key'%(key_entry), key)
        submit.bind ('submit_success', refresh.JS_to_refresh())

        self += submit


class Header_List (CTK.Container):
    class Content (CTK.Container):
        def __init__ (self, refresh, key):
            CTK.Container.__init__ (self)

            keys = CTK.cfg.keys(key)
            if keys:
                table = CTK.Table()
                table.set_header(1)
                table += [CTK.RawHTML(x) for x in (_('Regular Expression'), _('Substitution'))]

                for k in CTK.cfg.keys(key):
                    value = CTK.TextCfg ('%s!%s'%(key,k), False)
                    remove = CTK.ImageStock('del')
                    remove.bind('click', CTK.JS.Ajax (URL_APPLY, data={'%s!%s'%(key,k): ''},
                                                      complete = refresh.JS_to_refresh()))
                    table += [CTK.RawHTML(k), value, remove]

                submit = CTK.Submitter (URL_APPLY)
                submit += table

                self += CTK.Indenter (submit)

    def __init__ (self, key, key_entry):
        CTK.Container.__init__ (self)

        # List
        refresh = CTK.Refreshable ({'id': 'proxy_%s'%(key_entry)})
        refresh.register (lambda: self.Content(refresh, '%s!%s'%(key, key_entry)).Render())
        self += refresh

        # New
        new_regex  = CTK.TextCfg('tmp!new!%s!header'%(key_entry), False, {'class': 'noauto'})
        new_subst  = CTK.TextCfg('tmp!new!%s!value'%(key_entry), False, {'class': 'noauto'})
        add_button = CTK.SubmitterButton(_('Add'))

        table = CTK.Table()
        table.set_header(1)
        table += [CTK.RawHTML(x) for x in (_('Add Header Entry'), _('Value'))]
        table += [new_regex, new_subst, add_button]

        submit = CTK.Submitter (URL_APPLY)
        submit += CTK.Indenter (table)
        submit += CTK.Hidden ('tmp!new!%s!key'%(key_entry), key)
        submit.bind ('submit_success', refresh.JS_to_refresh())

        self += submit


class Header_Hide (CTK.Container):
    class Content (CTK.Container):
        def __init__ (self, refresh, key):
            CTK.Container.__init__ (self)

            keys = CTK.cfg.keys(key)
            if keys:
                table = CTK.Table()
                table.set_header(1)
                table += [CTK.RawHTML(_('Header'))]

                for k in CTK.cfg.keys(key):
                    remove = CTK.ImageStock('del')
                    remove.bind('click', CTK.JS.Ajax (URL_APPLY, data={'%s!%s'%(key,k): ''},
                                                          complete = refresh.JS_to_refresh()))
                    table += [CTK.RawHTML(CTK.cfg.get_val('%s!%s'%(key,k))), remove]

                submit = CTK.Submitter (URL_APPLY)
                submit += table

                self += CTK.Indenter (submit)

    def __init__ (self, key, key_entry):
        CTK.Container.__init__ (self)

        # List
        refresh = CTK.Refreshable ({'id': 'proxy_%s'%(key_entry)})
        refresh.register (lambda: self.Content(refresh, '%s!%s'%(key, key_entry)).Render())
        self += refresh

        # New
        new_hide  = CTK.TextCfg('tmp!new!%s!hide'%(key_entry), False, {'class': 'noauto'})
        add_button = CTK.SubmitterButton(_('Add'))

        table = CTK.Table()
        table.set_header(1)
        table += [CTK.RawHTML (_('Hide Header'))]
        table += [new_hide, add_button]

        submit = CTK.Submitter (URL_APPLY)
        submit += CTK.Indenter (table)
        submit += CTK.Hidden ('tmp!new!%s!key'%(key_entry), key)
        submit.bind ('submit_success', refresh.JS_to_refresh())

        self += submit


class Plugin_proxy (Handler.PluginHandler):
    def __init__ (self, key, **kwargs):
        kwargs['show_document_root'] = False
        Handler.PluginHandler.__init__ (self, key, **kwargs)
        Handler.PluginHandler.AddCommon (self)

        # Properties
        table = CTK.PropsTable()
        table.Add (_('Reuse connections'),         CTK.TextCfg ('%s!reuse_max'%(key), True), _(NOTE_REUSE_MAX))
        table.Add (_('Allow Keepalive'),           CTK.CheckCfgText('%s!in_allow_keepalive'%(key),  True,  _('Allow')),    _(NOTE_ALLOW_KEEPALIVE))
        table.Add (_('Preserve Host Header'),      CTK.CheckCfgText('%s!in_preserve_host'%(key),    False, _('Preserve')), _(NOTE_PRESERVE_HOST))
        table.Add (_('Preserve Server Header'),    CTK.CheckCfgText('%s!out_preserve_server'%(key), False, _('Preserve')), _(NOTE_PRESERVE_SERVER))
        table.Add (_('Use VServer error handler'), CTK.CheckCfgText('%s!vserver_errors'%(key),      False, _('Use it')),   _(NOTE_ERROR_HANDLER))

        submit = CTK.Submitter (URL_APPLY)
        submit += table

        self += CTK.RawHTML ('<h2>%s</h2>' %(_('Reverse Proxy Settings')))
        self += CTK.Indenter (submit)

        # Request
        self += CTK.RawHTML ('<h2>%s</h2>' %(_('Request')))

        self += CTK.Indenter (CTK.RawHTML ('<h3>%s</h3>' %(_('URL Rewriting'))))
        self += URL_Rewrite (key, 'in_rewrite_request')

        self += CTK.Indenter (CTK.RawHTML ('<h3>%s</h3>' %(_('Header Addition'))))
        self += Header_List (key, 'in_header_add')

        self += CTK.Indenter (CTK.RawHTML ('<h3>%s</h3>' %(_('Hide Headers'))))
        self += Header_Hide (key, 'in_header_hide')

        # Reply
        self += CTK.RawHTML ('<h2>%s</h2>' %(_('Reply')))

        self += CTK.Indenter (CTK.RawHTML ('<h3>%s</h3>' %(_('URL Rewriting'))))
        self += URL_Rewrite (key, 'out_rewrite_request')

        self += CTK.Indenter (CTK.RawHTML ('<h3>%s</h3>' %(_('Header Addition'))))
        self += Header_List (key, 'out_header_add')

        self += CTK.Indenter (CTK.RawHTML ('<h3>%s</h3>' %(_('Hide Headers'))))
        self += Header_Hide (key, 'out_header_hide')

        # Balancer
        modul = CTK.PluginSelector('%s!balancer'%(key), trans_options(Cherokee.support.filter_available (BALANCERS)))
        table = CTK.PropsTable()
        table.Add (_("Balancer"), modul.selector_widget, _(Balancer.NOTE_BALANCER))

        self += CTK.RawHTML ('<h2>%s</h2>' %(_('Back-end Servers')))
        self += CTK.Indenter (table)
        self += modul

CTK.publish ('^%s'%(URL_APPLY), commit, method="POST", validation=VALS)