https://wiki.creativecommons.org/index.php?title=Cchost/developer/tutorial/Replacing_the_File_Verifier&feed=atom&action=history
Cchost/developer/tutorial/Replacing the File Verifier - Revision history
2024-03-29T09:48:10Z
Revision history for this page on the wiki
MediaWiki 1.30.0
https://wiki.creativecommons.org/index.php?title=Cchost/developer/tutorial/Replacing_the_File_Verifier&diff=19729&oldid=prev
Fourstones at 10:50, 12 November 2008
2008-11-12T10:50:28Z
<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr style="vertical-align: top;" lang="en">
<td colspan="2" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: white; color:black; text-align: center;">Revision as of 10:50, 12 November 2008</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l4" >Line 4:</td>
<td colspan="2" class="diff-lineno">Line 4:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Software]]</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Software]]</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Technology]]</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Technology]]</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>{{<del class="diffchange diffchange-inline">draft</del>}}</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{<ins class="diffchange diffchange-inline">cchost_head</ins>}}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>{{lowercase}}</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>{{lowercase}}</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">{{Infobox|NOTE: This code is untested. It is only theoretical until someone can verify it works as advertised.}}</del></div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>The ccHost philosophy for file verifying is a whitelist - a list of file types to be accepted, all others rejected. At least one installation has chosen to implement a blacklist instead. The portable way to do this is to use ccHost's verify hook - basically a global variable.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>The ccHost philosophy for file verifying is a whitelist - a list of file types to be accepted, all others rejected. At least one installation has chosen to implement a blacklist instead. The portable way to do this is to use ccHost's verify hook - basically a global variable.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
</table>
Fourstones
https://wiki.creativecommons.org/index.php?title=Cchost/developer/tutorial/Replacing_the_File_Verifier&diff=19620&oldid=prev
Fourstones: New page: Category:ccHost Category:ccMixter Category:Developer Category:Software Category:Technology {{draft}} {{lowercase}} {{Infobox|NOTE: This code is untested. It is only the...
2008-11-06T20:21:25Z
<p>New page: <a href="/wiki/Category:CcHost" title="Category:CcHost">Category:ccHost</a> <a href="/wiki/Category:CcMixter" title="Category:CcMixter">Category:ccMixter</a> <a href="/wiki/Category:Developer" title="Category:Developer">Category:Developer</a> <a href="/wiki/Category:Software" title="Category:Software">Category:Software</a> <a href="/wiki/Category:Technology" title="Category:Technology">Category:Technology</a> {{draft}} {{lowercase}} {{Infobox|NOTE: This code is untested. It is only the...</p>
<p><b>New page</b></p><div>[[Category:ccHost]]<br />
[[Category:ccMixter]]<br />
[[Category:Developer]]<br />
[[Category:Software]]<br />
[[Category:Technology]]<br />
{{draft}}<br />
{{lowercase}}<br />
{{Infobox|NOTE: This code is untested. It is only theoretical until someone can verify it works as advertised.}}<br />
The ccHost philosophy for file verifying is a whitelist - a list of file types to be accepted, all others rejected. At least one installation has chosen to implement a blacklist instead. The portable way to do this is to use ccHost's verify hook - basically a global variable.<br />
<br />
The following code is a skeleton of how to hook the system. The actual blacklisting algorithm is left as an exercise for the reader. Put this code into a file '''<local_files>/lib/blacklist_validator.php''':<br />
<br />
<nowiki><?</nowiki><br />
<br />
// the uploader looks for this variable:<br />
<br />
global $CC_UPLOAD_VALIDATOR;<br />
<br />
// set the global to our validator factory...<br />
<br />
$CC_UPLOAD_VALIDATOR = 'make_blacklist_validator';<br />
<br />
function make_blacklist_validator()<br />
{<br />
return new Blacklist_Validator(true); // set this to false if you don't want to <br />
// delegate to the system's validator<br />
}<br />
<br />
/**<br />
* Blacklist_Validator <br />
*<br />
* Replace (or override) the existing whitelist base verifier<br />
* with an alternate version<br />
*<br />
*/<br />
class Blacklist_Validator <br />
{<br />
var $old_validator; // store a pointer to the system validator<br />
var $do_delegation; // flag as to whether to delegate to the system.<br />
<br />
function Blacklist_Validator($do_delegation=true)<br />
{<br />
$this->do_delegation = $do_delegation;<br />
<br />
if( $this->do_delegation )<br />
{<br />
require_once('cchost_lib/ccextras/cc-pseudo-verify.inc');<br />
$this->old_validator = new CCPseudoVerifyAPI();<br />
}<br />
}<br />
<br />
function GetValidFileTypes(&$types)<br />
{<br />
if( $this->do_delegation )<br />
{<br />
$retval = $this->old_validator->GetValidFileTypes($types);<br />
}<br />
else<br />
{<br />
$retval = true;<br />
}<br />
<br />
$types[] = '*.*';<br />
return $retval;<br />
}<br />
<br />
function FileValidate(&$formatinfo)<br />
{<br />
if( $this->do_delegation )<br />
{<br />
$retval = $this->old_validator->FileValidate($formatinfo);<br />
if( $retval )<br />
return true;<br />
}<br />
else<br />
{<br />
if( !is_array( $types ) )<br />
$types = array();<br />
$retval = false;<br />
}<br />
<br />
$path = $formatinfo->GetFilePath();<br />
<br />
// things really break down if we don't have a<br />
// file extension so we just reject them out<br />
// of hand<br />
<br />
$got_ext = <nowiki>preg_match( '/\.([a-z0-9]+)$/', strtolower($path), $m )</nowiki>;<br />
<br />
if( !$got_ext )<br />
{<br />
$formatinfo->SetErrors( _('Cannot determine file type'));<br />
return false;<br />
}<br />
<br />
/*********************************** <br />
* Edit the code below here... *<br />
***********************************/<br />
<br />
$retval = 1 ? true : false; // <<<---- your verification code goes here<br />
<br />
if( $retval )<br />
{<br />
$FI['tags'] = 'archive,' . $m[0]; // tags here will be added to <br />
$FI['default-ext'] = $m[0]; // your default extension goes here<br />
$FI['media-type'] = 'archive'; // media type (e.g. video, audio, image, archive, etc.)<br />
$FI['mime_type'] = 'octect/stream'; // or whatever you think<br />
<br />
$formatinfo->SetData( $FI );<br />
$formatinfo->_errors = <nowiki>''</nowiki>;<br />
}<br />
<br />
return $retval;<br />
}<br />
<br />
}<br />
<nowiki>?></nowiki></div>
Fourstones