0xGA: Check-in [0b81284ae3]

Yet another PHP framework, but made for org-mode and geeks.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add default error page template and better regex for routes
Timelines: family | ancestors | descendants | both | narv
Files: files | file ages | folders
SHA1:0b81284ae34512d5a8182df035a07bc8e95191b8
User & Date: milouse 2014-05-03 00:14:22
Context
2014-05-03
14:32
Add narv installer check-in: f67e1fe4ed user: milouse tags: narv
00:14
Add default error page template and better regex for routes check-in: 0b81284ae3 user: milouse tags: narv
2014-05-01
00:28
First bit of code check-in: e93a96317e user: milouse tags: narv
Changes

Changes to narv.

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
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

    exec 6>&1 # bind fd #6 to stdout (save stdout)
    exec > $WORKINGREP/etc/passwd # redirect stdout to etc/passwd
    cat <<EOF
root:x:0:0:root:/root:/bin/bash
nobody:x:1:1:nobody:/:/bin/false
EOF
    
    exec > $WORKINGREP/etc/group # redirect stdout to etc/group
    cat <<EOF
root:x:0:root
nobody:x:1:
EOF

    exec 1>&6 6>&- # Restore stdout and close fd #6
    chmod 644 $WORKINGREP/etc/passwd
    chmod 644 $WORKINGREP/etc/group    


    # Creating /bin for compatibility. Link MUST be local
    if [ ! -e "$WORKINGREP/bin" ] ; then
        cd $WORKINGREP
        ln -s usr/bin
    fi
................................................................................

;;; Project configuration
(setq org-publish-project-alist
      '(
        ("${APPNAME}-org"
         :base-directory "${WORKINGREP}/home/$APPNAME"
         :recursive t
         :publishing-function org-html-publish-to-html
         :publishing-directory "${WORKINGREP}/srv/$APPNAME"
         :base-extension "org"
;;       :language "fr"                     ;; Your language?
;;       :headline-levels 3                 ;; You can customize
;;       :section-numbers nil               ;; the following lines too
;;       :table-of-contents nil
;;       :html-preamble "<h1>My Blog</h1>"
;;       :html-postamble "<p>Still reading?</p>"
;;       :html-head "<link rel=\"stylesheet\" href=\"/.themes/style.css\" type=\"text/css\"/>"
         )
        ("${APPNAME}-data"
         :base-directory "${WORKINGREP}/home/$APPNAME"
         :recursive t
         :base-extension "png\\|jpg\\|pdf\\|ogg"
         :publishing-function org-publish-attachment
         :publishing-directory "${WORKINGREP}/srv/$APPNAME")
        ("${APPNAME}-style"
         :base-directory "${WORKINGREP}/home/${APPNAME}/.themes"
         :recursive t
         :base-extension "css\\|js\\|png\\|jpg\\|otf"
         :publishing-function org-publish-attachment
         :publishing-directory "${WORKINGREP}/srv/${APPNAME}/.themes")
        ("$APPNAME" :components ("${APPNAME}-org" "${APPNAME}-data" "${APPNAME}-style"))))
EOF

        exec 1>&6 6>&- # Restore stdout and close fd #6








|








|







 







|













|





|







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
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

    exec 6>&1 # bind fd #6 to stdout (save stdout)
    exec > $WORKINGREP/etc/passwd # redirect stdout to etc/passwd
    cat <<EOF
root:x:0:0:root:/root:/bin/bash
nobody:x:1:1:nobody:/:/bin/false
EOF

    exec > $WORKINGREP/etc/group # redirect stdout to etc/group
    cat <<EOF
root:x:0:root
nobody:x:1:
EOF

    exec 1>&6 6>&- # Restore stdout and close fd #6
    chmod 644 $WORKINGREP/etc/passwd
    chmod 644 $WORKINGREP/etc/group


    # Creating /bin for compatibility. Link MUST be local
    if [ ! -e "$WORKINGREP/bin" ] ; then
        cd $WORKINGREP
        ln -s usr/bin
    fi
................................................................................

;;; Project configuration
(setq org-publish-project-alist
      '(
        ("${APPNAME}-org"
         :base-directory "${WORKINGREP}/home/$APPNAME"
         :recursive t
         :publishing-function (org-html-publish-to-html org-org-publish-to-org)
         :publishing-directory "${WORKINGREP}/srv/$APPNAME"
         :base-extension "org"
;;       :language "fr"                     ;; Your language?
;;       :headline-levels 3                 ;; You can customize
;;       :section-numbers nil               ;; the following lines too
;;       :table-of-contents nil
;;       :html-preamble "<h1>My Blog</h1>"
;;       :html-postamble "<p>Still reading?</p>"
;;       :html-head "<link rel=\"stylesheet\" href=\"/.themes/style.css\" type=\"text/css\"/>"
         )
        ("${APPNAME}-data"
         :base-directory "${WORKINGREP}/home/$APPNAME"
         :recursive t
         :base-extension "png\\\|jpg\\\|pdf\\\|ogg"
         :publishing-function org-publish-attachment
         :publishing-directory "${WORKINGREP}/srv/$APPNAME")
        ("${APPNAME}-style"
         :base-directory "${WORKINGREP}/home/${APPNAME}/.themes"
         :recursive t
         :base-extension "css\\\|js\\\|png\\\|jpg\\\|otf"
         :publishing-function org-publish-attachment
         :publishing-directory "${WORKINGREP}/srv/${APPNAME}/.themes")
        ("$APPNAME" :components ("${APPNAME}-org" "${APPNAME}-data" "${APPNAME}-style"))))
EOF

        exec 1>&6 6>&- # Restore stdout and close fd #6

Changes to narv.py.

39
40
41
42
43
44
45

46
47
48
49
50
51
52
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
...
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
        'otf': 'application/font-sfnt',
        'woff': 'application/font-woff',
        'atom': 'application/atom+xml; charset=utf-8',
        'json': 'application/json; charset=utf-8',
        'js': 'text/javascript; charset=utf-8',
        'py': 'text/plain',
        'el': 'text/plain',

    }

    def __init__(self, request, App):

        self.routes = []
        self.App = App
        self.appname = App.appname
................................................................................

        for potential_path in self.routes:
            if fnmatch.fnmatch(self.request_path, potential_path):
                log("[{0}] Found potential match with {1}".format(
                    self.request_path, potential_path
                ))

                expand_wildcards = re.sub(r'\*', '([^/]+)', potential_path)
                tokens = re.search(
                    expand_wildcards,
                    self.request_path
                )

                if tokens:
                    interesting_routes.append(
................................................................................
            if 'appname' in self.config:
                self.appname = self.config['appname']
                log('Request is for App {0}'.format(self.appname))

            else:
                self.error = 'No claimed application in config file'







































    def do_404(self, reason='File not found'):
        log('[Error 404] {0}'.format(reason), True)
        self.build_headers(404)
        self.wfile.write(bytes(reason, 'utf-8'))



    def do_501(self, reason='Lack of configuration'):
        log('[Error 501] {0}'.format(reason), True)
        self.build_headers(501)
        self.wfile.write(bytes(reason, 'utf-8'))


    def build_headers(self, resno, content_type = 'text/plain'):
        self.send_response(resno)
        if content_type != None:
            self.send_header('Content-Type', content_type)
        self.end_headers()







>







 







|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<
<
>




|
<







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
...
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
        'otf': 'application/font-sfnt',
        'woff': 'application/font-woff',
        'atom': 'application/atom+xml; charset=utf-8',
        'json': 'application/json; charset=utf-8',
        'js': 'text/javascript; charset=utf-8',
        'py': 'text/plain',
        'el': 'text/plain',
        'org': 'text/plain; charset=utf-8'
    }

    def __init__(self, request, App):

        self.routes = []
        self.App = App
        self.appname = App.appname
................................................................................

        for potential_path in self.routes:
            if fnmatch.fnmatch(self.request_path, potential_path):
                log("[{0}] Found potential match with {1}".format(
                    self.request_path, potential_path
                ))

                expand_wildcards = re.sub(r'\*', '(.+)', potential_path)
                tokens = re.search(
                    expand_wildcards,
                    self.request_path
                )

                if tokens:
                    interesting_routes.append(
................................................................................
            if 'appname' in self.config:
                self.appname = self.config['appname']
                log('Request is for App {0}'.format(self.appname))

            else:
                self.error = 'No claimed application in config file'


    def do_error_page(self, errno, reason):
        self.build_headers(int(errno), 'text/html; charset=utf-8')

        if errno in self.config:
            with open(self.config[errno], 'rb') as f:
                shutil.copyfileobj(f, self.wfile)

        else:
            error_html = """<!DOCTYPE html>
<html>
<head>
  <title>{0}</title>
  <style type="text/css">
    body {{
      background-color: #d8d8d8;
      font-family: sans-serif;
    }}
    #content {{
      background-color: #ffffff;
      border: 1px solid #adadad;
      border-radius: 10px;
      width: 600px;
      margin: 20px auto;
      padding: 10px 20px;
    }}
  </style>
</head>
<body>
<div id="content">
<h1>Error {0}</h1>
<p>{1}</p>
</div>
</body>
</html>""".format(errno, reason)
            self.wfile.write(bytes(error_html, 'utf-8'))


    def do_404(self, reason='File not found'):
        log('[Error 404] {0}'.format(reason), True)


        self.do_error_page('404', reason)


    def do_501(self, reason='Lack of configuration'):
        log('[Error 501] {0}'.format(reason), True)
        self.do_error_page('501', reason)



    def build_headers(self, resno, content_type = 'text/plain'):
        self.send_response(resno)
        if content_type != None:
            self.send_header('Content-Type', content_type)
        self.end_headers()