<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>帮助-系统设置/附件</title></articleinfo><para>通过<ulink url="http://research.math.uvt.ro/wiki/%E5%B8%AE%E5%8A%A9-%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE/%E9%99%84%E4%BB%B6/wiki/%E5%B8%AE%E5%8A%A9-%E6%93%8D%E4%BD%9C/%E9%99%84%E4%BB%B6#">附件操作功能</ulink>，一个网页可以添加多个附件。 由于文件上传功能有可能被滥用于DoS (Denial of Service) 攻击，因此维基管理员可以通过<code>AttachFile</code>操作控制附件功能，只需在配置文件中添加&quot;<code>allowed_actions = ['AttachFile']</code>&quot;。 </para><informaltable><tgroup cols="1"><colspec colname="col_0"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para> <inlinemediaobject><imageobject><imagedata depth="16" fileref="http://research.math.uvt.ro/wiki//static/moniker/img/alert.png" width="16"/></imageobject><textobject><phrase>/!\</phrase></textobject></inlinemediaobject> <emphasis role="strong">警告: 如果通过网络服务器可以直接访问维基附件，您必须确保网络服务器不会运行恶意用户上传的附件(比如 .php 或 .asp 或其他脚本)。如果你不太理解，切勿按照下面的说明操作，否则您的服务器可能会被远程攻击。</emphasis> </para></entry></row></tbody></tgroup></informaltable><section><title>附件的处理方式</title><para>附件有两种存储/获取模型: </para><orderedlist numeration="arabic"><listitem><para>附件存储地址是隐藏的，只能通过 CGI GET 操作获得(通过URLs，比如 <code>http://myorg.org/mywiki/&lt;SomePage&gt;?action=AttachFile&amp;do=get&amp;target=filename.ext</code>)。 </para></listitem><listitem><para>附件存储在可以被网络服务器直接访问的目录下，因而可以通过服务器直接使用，而无须通过<ulink url="http://research.math.uvt.ro/wiki/%E5%B8%AE%E5%8A%A9-%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE/%E9%99%84%E4%BB%B6/wiki/MoinMoin#">MoinMoin</ulink> (URLs类似于<code>http://myorg.org/mywikiattach/&lt;Somepage&gt;/attachments/filename.ext</code>)。 </para></listitem></orderedlist><para>默认配置是第一种模型。附件存储在&quot;...mywiki/data/pages/&quot; 目录，路径为&quot;<code>...mywiki/data/pages/&lt;pagename&gt;/attachments/&lt;filename&gt;</code>&quot;. </para><para><ulink url="http://research.math.uvt.ro/wiki/%E5%B8%AE%E5%8A%A9-%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE/%E9%99%84%E4%BB%B6/wiki/MoinMoin#">MoinMoin</ulink>的<emphasis>attachments</emphasis> 配置选项允许您将存储附件的目录转移到其他位置。不过一般来说不需要如此操作，除非你有明确的原因。使用其他位置存储附件需要将现有的附件拷贝到新的位置，所以会比较麻烦，而且会带来更多风险。下面的建议是针对Apache服务器的，假设您想把附件放在他们现在的位置，而原来的安装使用的名称为&quot;mywiki&quot;。 </para></section><section><title>通过网络服务器直接访问附件</title><itemizedlist><listitem><para><inlinemediaobject><imageobject><imagedata depth="16" fileref="http://research.math.uvt.ro/wiki//static/moniker/img/alert.png" width="16"/></imageobject><textobject><phrase>/!\</phrase></textobject></inlinemediaobject> 注意，这个配置对于文件名含有非Ascii字符的附件不适用。 </para></listitem><listitem><para><inlinemediaobject><imageobject><imagedata depth="16" fileref="http://research.math.uvt.ro/wiki//static/moniker/img/alert.png" width="16"/></imageobject><textobject><phrase>/!\</phrase></textobject></inlinemediaobject> <emphasis role="strong">注意，在2.0中这个选项将被移除。因为其潜在的安全问题，我们建议不使用这个选项。</emphasis> </para></listitem></itemizedlist><para>第一步是让Apache知道有一个Alias目录，可以访问其中的文件。查看安装<ulink url="http://research.math.uvt.ro/wiki/%E5%B8%AE%E5%8A%A9-%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE/%E9%99%84%E4%BB%B6/wiki/MoinMoin#">MoinMoin</ulink>过程中修改的httpd.conf(或者commonhttpd.conf)文件，找到与下面类似的Alias语句: </para><screen><![CDATA[    ScriptAlias /mywiki           ".../mywiki/moin.cgi" ]]></screen><para>新建一个与上面类似的Alias语句, 将 <emphasis>/mywiki</emphasis> 替换为 <emphasis>/mywikiattach/</emphasis> ，将 <emphasis>moin.cgi</emphasis> 替换为 <emphasis>data/pages/</emphasis>。 </para><screen><![CDATA[    Alias       /mywikiattach/    ".../mywiki/data/pages/"]]></screen><para>请注意这两个语句尾部的 '/' 符号，配置语句必须如上所示。修改配置之后，必须重新启动Apache，改动才能生效。 </para><para>第二步是让<ulink url="http://research.math.uvt.ro/wiki/%E5%B8%AE%E5%8A%A9-%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE/%E9%99%84%E4%BB%B6/wiki/MoinMoin#">MoinMoin</ulink>知道获取附件的操作由Apache完成。你需要在 .../mywiki/wikiconfig.py 文件中增加<code>attachments</code>选项. 该选项是带有两个值的字典: </para><screen><![CDATA[attachments = {
    'dir': '.../mywiki/data/pages',
    'url': '/mywikiattach',
}]]></screen><para>上传文件的操作仍然由MoinMoin完成。<emphasis>dir</emphasis>告诉MoinMoin附件的存储位置，注意它的路径与Apache中新增加的Alias语句中的路径是一样的，但是尾部没有&quot;/&quot;。<emphasis>url</emphasis>告诉MoinMoin如何获取附件，其和Alias语句的中路径一致，但是尾部也没有&quot;/&quot;。 </para><para><inlinemediaobject><imageobject><imagedata depth="16" fileref="http://research.math.uvt.ro/wiki//static/moniker/img/alert.png" width="16"/></imageobject><textobject><phrase>/!\</phrase></textobject></inlinemediaobject> 您的附件现在通过Apache Your attached files are now directly servable by Apache. However if you also have PHP (or ASP or any other server parsed language) installed then an attacker can upload a PHP script an then run it to exploit other local weaknesses. </para><para>For example, you can disable PHP for the appropriate directory (note that it's difficult to include instructions for disabling all server parsed languages). </para><screen><![CDATA[<Directory .../mywiki/data/pages/>
    RemoveType .php .php3 .php4 .phtml
</Directory>]]></screen><para><inlinemediaobject><imageobject><imagedata depth="16" fileref="http://research.math.uvt.ro/wiki//static/moniker/img/alert.png" width="16"/></imageobject><textobject><phrase>/!\</phrase></textobject></inlinemediaobject> This only disables php stuff - you have to add everything else on your own! </para><para>After you have completed the configuration changes, test by uploading an attachment for <ulink url="http://research.math.uvt.ro/wiki/%E5%B8%AE%E5%8A%A9-%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE/%E9%99%84%E4%BB%B6/wiki/WikiSandBox#">WikiSandBox</ulink>. Then modify the <ulink url="http://research.math.uvt.ro/wiki/%E5%B8%AE%E5%8A%A9-%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE/%E9%99%84%E4%BB%B6/wiki/WikiSandBox#">WikiSandBox</ulink> page to display the uploaded image or download the file. If there were existing attachments before this change, verify the old attachments are still available.  Finally, review the Apache <emphasis>access.log</emphasis> file to verify you have a log entry showing the expected file access: </para><itemizedlist><listitem><para><emphasis>&quot;...GET /mywikiattach/WikiSandBox/attachments/mypix.jpg HTTP/1.1...&quot;</emphasis>. </para></listitem></itemizedlist></section></article>