/usr/share/pyshared/Pyblosxom/plugins/trackback.py is in pyblosxom 1.5.3-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 | #######################################################################
# This file is part of Pyblosxom.
#
# Copyright (c) 2003-2005 Ted Leung
#
# Pyblosxom is distributed under the MIT license. See the file
# LICENSE for distribution details.
#######################################################################
"""
Summary
=======
This plugin allows pyblosxom to process trackback
http://www.sixapart.com/pronet/docs/trackback_spec pings.
Install
=======
Requires the ``comments`` plugin. Though you don't need to have
comments enabled on your blog in order for trackbacks to work.
This plugin comes with Pyblosxom. To install, do the following:
1. Add ``Pyblosxom.plugins.trackback`` to the ``load_plugins`` list
in your ``config.py`` file.
2. Add this to your ``config.py`` file::
py['trackback_urltrigger'] = "/trackback"
These web forms are useful for testing. You can use them to send
trackback pings with arbitrary content to the URL of your choice:
* http://kalsey.com/tools/trackback/
* http://www.reedmaniac.com/scripts/trackback_form.php
3. Now you need to advertise the trackback ping link. Add this to your
``story`` template::
<a href="$(base_url)/trackback/$(file_path)" title="Trackback">TB</a>
4. You can supply an embedded RDF description of the trackback ping, too.
Add this to your ``story`` or ``comment-story`` template::
<!--
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
about="$(base_url)/$(file_path)"
dc:title="$(title)"
dc:identifier="$(base_url)/$(file_path)"
trackback:ping="$(base_url)/trackback/$(file_path)"
/>
</rdf:RDF>
-->
"""
__author__ = "Ted Leung"
__email__ = ""
__version__ = ""
__url__ = "http://pyblosxom.github.com/"
__description__ = "Trackback support."
__category__ = "comments"
__license__ = "MIT"
__registrytags__ = "1.4, core"
from Pyblosxom import tools
from Pyblosxom.tools import pwrap
tb_good_response = """<?xml version="1.0" encoding="iso-8859-1"?>
<response>
<error>0</error>
</response>"""
tb_bad_response = """<?xml version="1.0" encoding="iso-8859-1"?>
<response>
<error>1</error>
<message>%s</message>
</response>"""
def verify_installation(request):
config = request.get_configuration()
# all config properties are optional
if not 'trackback_urltrigger' in config:
pwrap("missing optional property: 'trackback_urltrigger'")
return True
def cb_handle(args):
request = args['request']
pyhttp = request.get_http()
config = request.get_configuration()
urltrigger = config.get('trackback_urltrigger', '/trackback')
logger = tools.get_logger()
path_info = pyhttp['PATH_INFO']
if path_info.startswith(urltrigger):
response = request.get_response()
response.add_header("Content-type", "text/xml")
form = request.get_form()
message = ("A trackback must have at least a URL field (see "
"http://www.sixapart.com/pronet/docs/trackback_spec)")
if "url" in form:
from comments import decode_form
encoding = config.get('blog_encoding', 'iso-8859-1')
decode_form(form, encoding)
import time
cdict = {'title': form.getvalue('title', ''),
'author': form.getvalue('blog_name', ''),
'pubDate': str(time.time()),
'link': form['url'].value,
'source': form.getvalue('blog_name', ''),
'description': form.getvalue('excerpt', ''),
'ipaddress': pyhttp.get('REMOTE_ADDR', ''),
'type': 'trackback'
}
argdict = {"request": request, "comment": cdict}
reject = tools.run_callback("trackback_reject",
argdict,
donefunc=lambda x: x != 0)
if isinstance(reject, (tuple, list)) and len(reject) == 2:
reject_code, reject_message = reject
else:
reject_code, reject_message = reject, "Trackback rejected."
if reject_code == 1:
print >> response, tb_bad_response % reject_message
return 1
from Pyblosxom.entries.fileentry import FileEntry
datadir = config['datadir']
from comments import writeComment
try:
import os
pi = path_info.replace(urltrigger, '')
path = os.path.join(datadir, pi[1:])
data = request.get_data()
ext = tools.what_ext(data['extensions'].keys(), path)
entry = FileEntry(request, '%s.%s' % (path, ext), datadir)
data = {}
data['entry_list'] = [entry]
# Format Author
cdict['author'] = (
'Trackback from %s' % form.getvalue('blog_name', ''))
writeComment(request, config, data, cdict, encoding)
print >> response, tb_good_response
except OSError:
message = 'URI ' + path_info + " doesn't exist"
logger.error(message)
print >> response, tb_bad_response % message
else:
logger.error(message)
print >> response, tb_bad_response % message
# no further handling is needed
return 1
return 0
|