mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-02-23 16:39:57 -05:00
Added page preprocessing
This commit is contained in:
parent
b8e67721b8
commit
a77f423362
@ -2,6 +2,7 @@ import os
|
|||||||
import RNS
|
import RNS
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
import subprocess
|
||||||
import RNS.vendor.umsgpack as msgpack
|
import RNS.vendor.umsgpack as msgpack
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
@ -87,10 +88,14 @@ class Node:
|
|||||||
file_path = path.replace("/page", self.app.pagespath, 1)
|
file_path = path.replace("/page", self.app.pagespath, 1)
|
||||||
try:
|
try:
|
||||||
RNS.log("Serving page: "+file_path, RNS.LOG_VERBOSE)
|
RNS.log("Serving page: "+file_path, RNS.LOG_VERBOSE)
|
||||||
fh = open(file_path, "rb")
|
if os.access(file_path, os.X_OK):
|
||||||
response_data = fh.read()
|
generated = subprocess.run([file_path], stdout=subprocess.PIPE)
|
||||||
fh.close()
|
return generated.stdout
|
||||||
return response_data
|
else:
|
||||||
|
fh = open(file_path, "rb")
|
||||||
|
response_data = fh.read()
|
||||||
|
fh.close()
|
||||||
|
return response_data
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error occurred while handling request "+RNS.prettyhexrep(request_id)+" for: "+str(path), RNS.LOG_ERROR)
|
RNS.log("Error occurred while handling request "+RNS.prettyhexrep(request_id)+" for: "+str(path), RNS.LOG_ERROR)
|
||||||
|
@ -3,6 +3,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
import urwid
|
import urwid
|
||||||
import nomadnet
|
import nomadnet
|
||||||
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
from .MicronParser import markup_to_attrmaps
|
from .MicronParser import markup_to_attrmaps
|
||||||
from nomadnet.vendor.Scrollable import *
|
from nomadnet.vendor.Scrollable import *
|
||||||
@ -488,9 +489,13 @@ class Browser:
|
|||||||
|
|
||||||
page_data = b"The requested local page did not exist in the file system"
|
page_data = b"The requested local page did not exist in the file system"
|
||||||
if os.path.isfile(page_path):
|
if os.path.isfile(page_path):
|
||||||
file = open(page_path, "rb")
|
if os.access(page_path, os.X_OK):
|
||||||
page_data = file.read()
|
generated = subprocess.run([page_path], stdout=subprocess.PIPE)
|
||||||
file.close()
|
page_data = generated.stdout
|
||||||
|
else:
|
||||||
|
file = open(page_path, "rb")
|
||||||
|
page_data = file.read()
|
||||||
|
file.close()
|
||||||
|
|
||||||
self.status = Browser.DONE
|
self.status = Browser.DONE
|
||||||
self.page_data = page_data
|
self.page_data = page_data
|
||||||
|
@ -234,7 +234,7 @@ To add pages to your node, place micron files in the `*pages`* directory of your
|
|||||||
|
|
||||||
You can control how long a peer will cache your pages by including the cache header in a page. To do so, the first line of your page must start with `!#!c=X`!, where `!X`! is the cache time in seconds. To tell the peer to always load the page from your node, and never cache it, set the cache time to zero. You should only do this if there is a real need, for example if your page displays dynamic content that `*must`* be updated at every page view. The default caching time is 12 hours. In most cases, you should not need to include the cache control header in your pages.
|
You can control how long a peer will cache your pages by including the cache header in a page. To do so, the first line of your page must start with `!#!c=X`!, where `!X`! is the cache time in seconds. To tell the peer to always load the page from your node, and never cache it, set the cache time to zero. You should only do this if there is a real need, for example if your page displays dynamic content that `*must`* be updated at every page view. The default caching time is 12 hours. In most cases, you should not need to include the cache control header in your pages.
|
||||||
|
|
||||||
Pages are static in this version, but the next release of Nomad Network will add the ability to use a preprocessor such as PHP, bash, Python (or whatever you prefer) to generate dynamic pages.
|
You can use a preprocessor such as PHP, bash, Python (or whatever you prefer) to generate dynamic pages. To do so, just set executable permissions on the relevant page file, and be sure to include the interpreter at the beginning of the file, for example `!#!/usr/bin/python3`!.
|
||||||
|
|
||||||
>>Files
|
>>Files
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user