2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2013-03-05 15:07:55 -04:00
|
|
|
|
2011-02-01 12:49:40 +00:00
|
|
|
/**
|
|
|
|
|
* class.webdav.php
|
2012-10-09 13:26:29 -04:00
|
|
|
*
|
2011-02-01 12:49:40 +00:00
|
|
|
* @package workflow.engine.classes
|
|
|
|
|
*/
|
2017-08-14 16:13:46 -04:00
|
|
|
|
|
|
|
|
use ProcessMaker\Core\System;
|
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
require_once "HTTP/WebDAV/Server.php";
|
2012-10-09 13:26:29 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/**
|
|
|
|
|
* ProcessMaker Filesystem access using WebDAV
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2011-02-01 12:49:40 +00:00
|
|
|
* @package workflow.engine.classes
|
2012-10-09 13:26:29 -04:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class ProcessMakerWebDav extends HTTP_WebDAV_Server
|
2010-12-02 23:34:41 +00:00
|
|
|
{
|
2013-03-05 15:07:55 -04:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
/**
|
|
|
|
|
* Root directory for WebDAV access
|
|
|
|
|
*
|
|
|
|
|
* Defaults to webserver document root (set by ServeRequest)
|
|
|
|
|
*
|
|
|
|
|
* @access private
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public $base = "";
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Serve a webdav request
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
* @param string
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function ServeRequest($base = false)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
//$this->base = '/';
|
|
|
|
|
$this->uriBase = '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/webdav/';
|
|
|
|
|
|
|
|
|
|
// let the base class do all the work
|
|
|
|
|
parent::ServeRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* No authentication is needed here
|
|
|
|
|
*
|
|
|
|
|
* @access private
|
|
|
|
|
* @param string HTTP Authentication type (Basic, Digest, ...)
|
|
|
|
|
* @param string Username
|
|
|
|
|
* @param string Password
|
|
|
|
|
* @return bool true on successful authentication
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function check_auth($type, $user, $pass)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
return true;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
/**
|
|
|
|
|
* PROPFIND method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array general parameter passing array
|
|
|
|
|
* @param array return array for file properties
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function PROPFIND(&$options, &$files)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
$paths = $this->paths;
|
|
|
|
|
// prepare property array
|
2013-03-05 15:07:55 -04:00
|
|
|
$files["files"] = array();
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
$pathClasses = PATH_DB . PATH_SEP . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 0 && is_dir($pathClasses)) {
|
|
|
|
|
$props = array();
|
|
|
|
|
$props[] = $this->mkprop("displayname", 'Classes');
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathClasses));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathClasses));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathClasses));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", 'collection');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'httpd/unix-directory');
|
|
|
|
|
$files["files"][] = array('path' => 'classes', 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) > 0 && $paths[0] == 'classes' && is_dir($pathClasses)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// try to open directory
|
2013-03-05 15:07:55 -04:00
|
|
|
$handle = @opendir($pathClasses);
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($handle) {
|
2013-03-05 15:07:55 -04:00
|
|
|
while ($filename = readdir($handle)) {
|
|
|
|
|
$ext = array_pop(explode('.', $filename));
|
|
|
|
|
if ($filename != "." && $filename != ".." && !is_dir($pathClasses . $filename) && $ext == 'php') {
|
|
|
|
|
$props = array();
|
|
|
|
|
$props[] = $this->mkprop("displayname", $filename);
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathClasses . $filename));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathClasses . $filename));
|
|
|
|
|
$props[] = $this->mkprop("getetag", fileatime($pathClasses . $filename));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathClasses . $filename));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", '');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'text/plain');
|
|
|
|
|
$props[] = $this->mkprop("getcontentlength", filesize($pathClasses . $filename));
|
|
|
|
|
if (count($paths) == 1 || (count($paths) == 2 && $paths[1] == $filename)) {
|
|
|
|
|
$files["files"][] = array('path' => "classes/$filename", 'props' => $props);
|
|
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //path classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pathProcesses = PATH_DB . SYS_SYS . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 0 && is_dir($pathProcesses)) {
|
|
|
|
|
$props = array();
|
|
|
|
|
$props[] = $this->mkprop("displayname", 'Processes');
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", 'collection');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'httpd/unix-directory');
|
|
|
|
|
$files["files"][] = array('path' => 'processes', 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//list all active processes
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 1 && $paths[0] == 'processes' && is_dir($pathProcesses)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// try to get the process directory list
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2017-08-04 16:21:06 -04:00
|
|
|
$oProcessMap = new ProcessMap();
|
2012-10-09 13:26:29 -04:00
|
|
|
$oProcess = new Process();
|
|
|
|
|
$c = $oProcessMap->getConditionProcessList();
|
2013-03-05 15:07:55 -04:00
|
|
|
$oDataset = ProcessPeer::doSelectRS($c);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2012-10-09 13:26:29 -04:00
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
if ($aRow['PRO_STATUS'] == 'ACTIVE') {
|
2013-03-05 15:07:55 -04:00
|
|
|
$aProcess = $oProcess->load($aRow['PRO_UID']);
|
|
|
|
|
$props = array();
|
|
|
|
|
$props[] = $this->mkprop("displayname", $aProcess['PRO_TITLE']);
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", 'collection');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'httpd/unix-directory');
|
|
|
|
|
$files["files"][] = array('path' => "processes/" . $aRow['PRO_UID'], 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
} //dir of processes
|
|
|
|
|
//content of any process ( the three major folders of Processes )
|
|
|
|
|
$pathXmlform = $pathProcesses . 'xmlForms' . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 2 && $paths[0] == 'processes' && is_dir($pathProcesses)) {
|
|
|
|
|
$props = array();
|
|
|
|
|
$props[] = $this->mkprop("displayname", 'xmlforms');
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathXmlform));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathXmlform));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathXmlform));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", 'collection');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'httpd/unix-directory');
|
|
|
|
|
$files["files"][] = array('path' => 'processes/' . $paths[1] . '/xmlforms', 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$props[] = $this->mkprop("displayname", 'mailTemplates');
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", 'collection');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'httpd/unix-directory');
|
|
|
|
|
$files["files"][] = array('path' => 'processes/' . $paths[1] . '/mailTemplates', 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$props[] = $this->mkprop("displayname", 'public_html');
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathProcesses));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", 'collection');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'httpd/unix-directory');
|
|
|
|
|
$files["files"][] = array('path' => 'processes/' . $paths[1] . '/public_html', 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
} //content of any processes
|
|
|
|
|
//list available xmlforms
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 3 && $paths[0] == 'processes' && $paths[2] == 'xmlforms' && is_dir($pathXmlform)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
$pathXmlform = $pathProcesses . 'xmlForms' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$handle = @opendir($pathXmlform);
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($handle) {
|
2013-03-05 15:07:55 -04:00
|
|
|
while ($filename = readdir($handle)) {
|
|
|
|
|
$ext = array_pop(explode('.', $filename));
|
|
|
|
|
if ($filename != "." && $filename != ".." && !is_dir($pathXmlform . $filename) && ($ext == 'xml' || $ext == 'html')) {
|
|
|
|
|
$props = array();
|
|
|
|
|
$props[] = $this->mkprop("displayname", $filename);
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathXmlform . $filename));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathXmlform . $filename));
|
|
|
|
|
$props[] = $this->mkprop("getetag", fileatime($pathXmlform . $filename));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathXmlform . $filename));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", '');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'text/plain');
|
|
|
|
|
$props[] = $this->mkprop("getcontentlength", filesize($pathXmlform . $filename));
|
2012-10-09 13:26:29 -04:00
|
|
|
//if ( count( $paths ) == 1 || ( count( $paths ) == 2 && $paths[1] == $filename ) )
|
2013-03-05 15:07:55 -04:00
|
|
|
$files["files"][] = array('path' => 'processes/' . $paths[1] . '/xmlforms/' . $filename, 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //content of xmlforms
|
|
|
|
|
//list available mailTemplates
|
|
|
|
|
$pathTemplates = $pathProcesses . 'mailTemplates' . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 3 && $paths[0] == 'processes' && $paths[2] == 'mailTemplates' && is_dir($pathTemplates)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
$pathTemplates = $pathProcesses . 'mailTemplates' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$handle = @opendir($pathTemplates);
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($handle) {
|
2013-03-05 15:07:55 -04:00
|
|
|
while ($filename = readdir($handle)) {
|
|
|
|
|
$ext = array_pop(explode('.', $filename));
|
|
|
|
|
if ($filename != "." && $filename != ".." && !is_dir($pathTemplates . $filename) /* && ( $ext == 'xml' || $ext == 'html' ) */) {
|
|
|
|
|
$props = array();
|
|
|
|
|
$props[] = $this->mkprop("displayname", $filename);
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathTemplates . $filename));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathTemplates . $filename));
|
|
|
|
|
$props[] = $this->mkprop("getetag", fileatime($pathTemplates . $filename));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathTemplates . $filename));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", '');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'text/plain');
|
|
|
|
|
$props[] = $this->mkprop("getcontentlength", filesize($pathTemplates . $filename));
|
2012-10-09 13:26:29 -04:00
|
|
|
//if ( count( $paths ) == 1 || ( count( $paths ) == 2 && $paths[1] == $filename ) )
|
2013-03-05 15:07:55 -04:00
|
|
|
$files["files"][] = array('path' => 'processes/' . $paths[1] . '/mailTemplates/' . $filename, 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //content of mailTemplates
|
|
|
|
|
//list available public_html files
|
|
|
|
|
$pathPublic = $pathProcesses . 'public' . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 3 && $paths[0] == 'processes' && $paths[2] == 'public_html' && is_dir($pathTemplates)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
$pathPublic = $pathProcesses . 'public' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$handle = @opendir($pathPublic);
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($handle) {
|
2013-03-05 15:07:55 -04:00
|
|
|
while ($filename = readdir($handle)) {
|
|
|
|
|
$ext = array_pop(explode('.', $filename));
|
|
|
|
|
if ($filename != "." && $filename != ".." && !is_dir($pathPublic . $filename) /* && ( $ext == 'xml' || $ext == 'html' ) */) {
|
|
|
|
|
$props = array();
|
|
|
|
|
$props[] = $this->mkprop("displayname", $filename);
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime($pathPublic . $filename));
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime($pathPublic . $filename));
|
|
|
|
|
$props[] = $this->mkprop("getetag", fileatime($pathPublic . $filename));
|
|
|
|
|
$props[] = $this->mkprop("lastaccessed", filemtime($pathPublic . $filename));
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", '');
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'text/plain');
|
|
|
|
|
$props[] = $this->mkprop("getcontentlength", filesize($pathPublic . $filename));
|
2012-10-09 13:26:29 -04:00
|
|
|
//if ( count( $paths ) == 1 || ( count( $paths ) == 2 && $paths[1] == $filename ) )
|
2013-03-05 15:07:55 -04:00
|
|
|
$files["files"][] = array('path' => 'processes/' . $paths[1] . '/public_html/' . $filename, 'props' => $props
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //content of public_html files
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2013-03-05 15:07:55 -04:00
|
|
|
if ( 1 ) {
|
|
|
|
|
$props = array ();
|
|
|
|
|
$props[] = $this->mkprop("displayname", print_r ($pathPublic, 1) );
|
|
|
|
|
$props[] = $this->mkprop("creationdate", filectime( PATH_DB ) );
|
|
|
|
|
$props[] = $this->mkprop("getlastmodified", filemtime( PATH_DB ) );
|
|
|
|
|
$props[] = $this->mkprop("resourcetype", 'collection' );
|
|
|
|
|
$props[] = $this->mkprop("getcontenttype", 'httpd/unix-directory' );
|
|
|
|
|
$files["files"][] = array ( 'path' => '/' , 'props' => $props);
|
|
|
|
|
} */
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
// ok, all done
|
|
|
|
|
return true;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
/**
|
|
|
|
|
* detect if a given program is found in the search PATH
|
|
|
|
|
*
|
|
|
|
|
* helper function used by _mimetype() to detect if the
|
|
|
|
|
* external 'file' utility is available
|
|
|
|
|
*
|
|
|
|
|
* @param string program name
|
|
|
|
|
* @param string optional search path, defaults to $PATH
|
|
|
|
|
* @return bool true if executable program found in path
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function _can_execute($name, $path = false)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
// path defaults to PATH from environment if not set
|
|
|
|
|
if ($path === false) {
|
2013-03-05 15:07:55 -04:00
|
|
|
$path = getenv("PATH");
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check method depends on operating system
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!strncmp(PHP_OS, "WIN", 3)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// on Windows an appropriate COM or EXE file needs to exist
|
2013-03-05 15:07:55 -04:00
|
|
|
$exts = array(".exe", ".com"
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
$check_fn = "file_exists";
|
|
|
|
|
} else {
|
|
|
|
|
// anywhere else we look for an executable file of that name
|
2013-03-05 15:07:55 -04:00
|
|
|
$exts = array(""
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
$check_fn = "is_executable";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now check the directories in the path for the program
|
2013-03-05 15:07:55 -04:00
|
|
|
foreach (explode(PATH_SEPARATOR, $path) as $dir) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// skip invalid path entries
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!file_exists($dir)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
continue;
|
2013-03-05 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
if (!is_dir($dir)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
continue;
|
2013-03-05 15:07:55 -04:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
// and now look for the file
|
2012-10-09 13:26:29 -04:00
|
|
|
foreach ($exts as $ext) {
|
2013-03-05 15:07:55 -04:00
|
|
|
if ($check_fn("$dir/$name" . $ext)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return true;
|
2013-03-05 15:07:55 -04:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* try to detect the mime type of a file
|
|
|
|
|
*
|
|
|
|
|
* @param string file path
|
|
|
|
|
* @return string guessed mime type
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function _mimetype($fspath)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
2013-03-05 15:07:55 -04:00
|
|
|
if (@is_dir($fspath)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// directories are easy
|
|
|
|
|
return "httpd/unix-directory";
|
2013-03-05 15:07:55 -04:00
|
|
|
} elseif (function_exists("mime_content_type")) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// use mime magic extension if available
|
2013-03-05 15:07:55 -04:00
|
|
|
$mime_type = mime_content_type($fspath);
|
|
|
|
|
} elseif ($this->_can_execute("file")) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// it looks like we have a 'file' command,
|
|
|
|
|
// lets see it it does have mime support
|
2013-03-05 15:07:55 -04:00
|
|
|
$fp = popen("file -i '$fspath' 2>/dev/null", "r");
|
|
|
|
|
$reply = fgets($fp);
|
|
|
|
|
pclose($fp);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
// popen will not return an error if the binary was not found
|
|
|
|
|
// and find may not have mime support using "-i"
|
|
|
|
|
// so we test the format of the returned string
|
|
|
|
|
// the reply begins with the requested filename
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!strncmp($reply, "$fspath: ", strlen($fspath) + 2)) {
|
|
|
|
|
$reply = substr($reply, strlen($fspath) + 2);
|
2012-10-09 13:26:29 -04:00
|
|
|
// followed by the mime type (maybe including options)
|
2013-03-05 15:07:55 -04:00
|
|
|
if (preg_match('/^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*/', $reply, $matches)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
$mime_type = $matches[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (empty($mime_type)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// Fallback solution: try to guess the type by the file extension
|
|
|
|
|
// TODO: add more ...
|
|
|
|
|
// TODO: it has been suggested to delegate mimetype detection
|
|
|
|
|
// to apache but this has at least three issues:
|
|
|
|
|
// - works only with apache
|
|
|
|
|
// - needs file to be within the document tree
|
|
|
|
|
// - requires apache mod_magic
|
|
|
|
|
// TODO: can we use the registry for this on Windows?
|
|
|
|
|
// OTOH if the server is Windos the clients are likely to
|
|
|
|
|
// be Windows, too, and tend do ignore the Content-Type
|
|
|
|
|
// anyway (overriding it with information taken from
|
|
|
|
|
// the registry)
|
|
|
|
|
// TODO: have a seperate PEAR class for mimetype detection?
|
2013-03-05 15:07:55 -04:00
|
|
|
switch (strtolower(strrchr(basename($fspath), "."))) {
|
2012-10-09 13:26:29 -04:00
|
|
|
case ".html":
|
|
|
|
|
$mime_type = "text/html";
|
|
|
|
|
break;
|
|
|
|
|
case ".gif":
|
|
|
|
|
$mime_type = "image/gif";
|
|
|
|
|
break;
|
|
|
|
|
case ".jpg":
|
|
|
|
|
$mime_type = "image/jpeg";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$mime_type = "application/octet-stream";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $mime_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GET method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array parameter passing array
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function GET(&$options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2015-03-17 15:25:49 -04:00
|
|
|
$filter = new InputFilter();
|
|
|
|
|
$options = $filter->xssFilterHard($options);
|
|
|
|
|
$paths = $filter->xssFilterHard($this->paths);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
$pathClasses = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) > 0 && $paths[0] == 'classes' && is_dir($pathClasses)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
$fsFile = $pathClasses . $paths[1];
|
2015-03-17 15:25:49 -04:00
|
|
|
$fsFile = $filter->xssFilterHard($fsFile);
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 2 && file_exists($fsFile)) {
|
|
|
|
|
$content = file_get_contents($fsFile);
|
2015-03-17 15:25:49 -04:00
|
|
|
$content = $filter->xssFilterHard($content);
|
2012-10-09 13:26:29 -04:00
|
|
|
print $content;
|
2013-03-05 15:07:55 -04:00
|
|
|
header("Content-Type: " . mime_content_type($fsFile));
|
|
|
|
|
header("Last-Modified: " . date("D, j M Y H:m:s ", file_mtime($fsFile)) . "GMT");
|
|
|
|
|
header("Content-Length: " . filesize($fsFile));
|
2012-10-09 13:26:29 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pathProcesses = PATH_DB . SYS_SYS . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) > 0 && $paths[0] == 'processes' && is_dir($pathProcesses)) {
|
|
|
|
|
if (count($paths) == 4 && $paths[2] == 'xmlforms') {
|
2012-10-09 13:26:29 -04:00
|
|
|
$pathXmlform = $pathProcesses . 'xmlForms' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
$fsFile = $pathXmlform . $paths[3];
|
2015-03-17 15:25:49 -04:00
|
|
|
$fsFile = $filter->xssFilterHard($fsFile);
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 4 && file_exists($fsFile)) {
|
|
|
|
|
$content = file_get_contents($fsFile);
|
2015-03-17 15:25:49 -04:00
|
|
|
$content = $filter->xssFilterHard($content);
|
2012-10-09 13:26:29 -04:00
|
|
|
print $content;
|
2013-03-05 15:07:55 -04:00
|
|
|
header("Content-Type: " . mime_content_type($fsFile));
|
|
|
|
|
header("Last-Modified: " . date("D, j M Y H:m:s ", file_mtime($fsFile)) . "GMT");
|
|
|
|
|
header("Content-Length: " . filesize($fsFile));
|
2012-10-09 13:26:29 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 4 && $paths[2] == 'mailTemplates') {
|
2012-10-09 13:26:29 -04:00
|
|
|
$pathTemplates = $pathProcesses . 'mailTemplates' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
$fsFile = $pathTemplates . $paths[3];
|
2015-03-17 15:25:49 -04:00
|
|
|
$fsFile = $filter->xssFilterHard($fsFile);
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 4 && file_exists($fsFile)) {
|
|
|
|
|
$content = file_get_contents($fsFile);
|
2015-03-17 15:25:49 -04:00
|
|
|
$content = $filter->xssFilterHard($content);
|
2012-10-09 13:26:29 -04:00
|
|
|
print $content;
|
2013-03-05 15:07:55 -04:00
|
|
|
header("Content-Type: " . mime_content_type($fsFile));
|
|
|
|
|
header("Last-Modified: " . date("D, j M Y H:m:s ", file_mtime($fsFile)) . "GMT");
|
|
|
|
|
header("Content-Length: " . filesize($fsFile));
|
2012-10-09 13:26:29 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 4 && $paths[2] == 'public_html') {
|
2012-10-09 13:26:29 -04:00
|
|
|
$pathPublic = $pathProcesses . 'public' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
$fsFile = $pathPublic . $paths[3];
|
2015-03-17 15:25:49 -04:00
|
|
|
$fsFile = $filter->xssFilterHard($fsFile);
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 4 && file_exists($fsFile)) {
|
|
|
|
|
$content = file_get_contents($fsFile);
|
2015-03-17 15:25:49 -04:00
|
|
|
$content = $filter->xssFilterHard($content);
|
2012-10-09 13:26:29 -04:00
|
|
|
print $content;
|
2013-03-05 15:07:55 -04:00
|
|
|
header("Content-Type: " . mime_content_type($fsFile));
|
|
|
|
|
header("Last-Modified: " . date("D, j M Y H:m:s ", file_mtime($fsFile)) . "GMT");
|
|
|
|
|
header("Content-Length: " . filesize($fsFile));
|
2012-10-09 13:26:29 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
print_r($paths);
|
2010-12-02 23:34:41 +00:00
|
|
|
return true;
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($options["path"] == '/') {
|
2013-03-05 15:07:55 -04:00
|
|
|
return $this->getRoot($options);
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
//print_r ($options);
|
|
|
|
|
// get absolute fs path to requested resource
|
|
|
|
|
$fspath = $this->base . $options["path"];
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
// sanity check
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!file_exists($fspath)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return false;
|
2013-03-05 15:07:55 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
// is this a collection?
|
|
|
|
|
if (is_dir($fspath)) {
|
|
|
|
|
return $this->GetDir($fspath, $options);
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
// detect resource type
|
2013-03-05 15:07:55 -04:00
|
|
|
$options['mimetype'] = $this->_mimetype($fspath);
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
// detect modification time
|
|
|
|
|
// see rfc2518, section 13.7
|
|
|
|
|
// some clients seem to treat this as a reverse rule
|
|
|
|
|
// requiering a Last-Modified header if the getlastmodified header was set
|
2013-03-05 15:07:55 -04:00
|
|
|
$options['mtime'] = filemtime($fspath);
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
// detect resource size
|
2013-03-05 15:07:55 -04:00
|
|
|
$options['size'] = filesize($fspath);
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
// no need to check result here, it is handled by the base class
|
2013-03-05 15:07:55 -04:00
|
|
|
$options['stream'] = fopen($fspath, "r");
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
return true;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
/**
|
|
|
|
|
* getRoot
|
|
|
|
|
*
|
|
|
|
|
* @param string &$options
|
|
|
|
|
* @return boolean false
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function getRoot(&$options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
2013-03-05 15:07:55 -04:00
|
|
|
$path = $this->_slashify($options["path"]);
|
2012-10-09 13:26:29 -04:00
|
|
|
// fixed width directory column format
|
|
|
|
|
$format = "%15s %-19s %-s\n";
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
echo "<html><head><title>Index of " . htmlspecialchars($options['path']) . "</title></head>\n";
|
|
|
|
|
echo "<h1>Index of " . htmlspecialchars($options['path']) . "</h1>\n";
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
echo "<pre>";
|
2013-03-05 15:07:55 -04:00
|
|
|
printf($format, "Size", "Last modified", "Filename");
|
2012-10-09 13:26:29 -04:00
|
|
|
echo "<hr>";
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$pathRoot = array('xmlforms', 'public_html', 'dir1', 'dir2'
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($pathRoot as $key => $val) {
|
|
|
|
|
$fullpath = $fspath . "/" . $filename;
|
2013-03-05 15:07:55 -04:00
|
|
|
$name = htmlspecialchars($val);
|
|
|
|
|
printf($format, number_format(filesize($fullpath)), strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), "<a href='$this->base_uri$path$name'>$name</a>");
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "</pre>";
|
|
|
|
|
echo "</html>\n";
|
|
|
|
|
|
|
|
|
|
die();
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$handle = @opendir($fspath);
|
|
|
|
|
if (!$handle) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
while ($filename = readdir($handle)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($filename != "." && $filename != "..") {
|
|
|
|
|
$fullpath = $fspath . "/" . $filename;
|
2013-03-05 15:07:55 -04:00
|
|
|
$name = htmlspecialchars($filename);
|
|
|
|
|
printf($format, number_format(filesize($fullpath)), strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), "<a href='$this->base_uri$path$name'>$name</a>");
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "</pre>";
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
closedir($handle);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
echo "</html>\n";
|
|
|
|
|
|
|
|
|
|
exit();
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
/**
|
|
|
|
|
* GET method handler for directories
|
|
|
|
|
*
|
|
|
|
|
* This is a very simple mod_index lookalike.
|
|
|
|
|
* See RFC 2518, Section 8.4 on GET/HEAD for collections
|
|
|
|
|
*
|
|
|
|
|
* @param string directory path
|
|
|
|
|
* @return void function has to handle HTTP response itself
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function GetDir($fspath, &$options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
2013-03-05 15:07:55 -04:00
|
|
|
$path = $this->_slashify($options["path"]);
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($path != $options["path"]) {
|
2013-03-05 15:07:55 -04:00
|
|
|
header("Location: " . $this->base_uri . $path);
|
2012-10-09 13:26:29 -04:00
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fixed width directory column format
|
|
|
|
|
$format = "%15s %-19s %-s\n";
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$handle = @opendir($fspath);
|
|
|
|
|
if (!$handle) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
echo "<html><head><title>Index of " . htmlspecialchars($options['path']) . "</title></head>\n";
|
2012-10-09 13:26:29 -04:00
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
echo "<h1>Index of " . htmlspecialchars($options['path']) . "</h1>\n";
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
echo "<pre>";
|
2013-03-05 15:07:55 -04:00
|
|
|
printf($format, "Size", "Last modified", "Filename");
|
2012-10-09 13:26:29 -04:00
|
|
|
echo "<hr>";
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
while ($filename = readdir($handle)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($filename != "." && $filename != "..") {
|
|
|
|
|
$fullpath = $fspath . "/" . $filename;
|
2013-03-05 15:07:55 -04:00
|
|
|
$name = htmlspecialchars($filename);
|
|
|
|
|
printf($format, number_format(filesize($fullpath)), strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), "<a href='$this->base_uri$path$name'>$name</a>");
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "</pre>";
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
closedir($handle);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
echo "</html>\n";
|
|
|
|
|
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PUT method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array parameter passing array
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function PUT(&$options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
$paths = $this->paths;
|
|
|
|
|
|
|
|
|
|
$pathClasses = PATH_DB . PATH_SEP . 'classes' . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) > 0 && $paths[0] == 'classes' && is_dir($pathClasses)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
$fsFile = $pathClasses . $paths[1];
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 2 && file_exists($fsFile)) {
|
|
|
|
|
$fp = fopen($fsFile, "w");
|
|
|
|
|
if (is_resource($fp) && is_resource($options["stream"])) {
|
|
|
|
|
while (!feof($options["stream"])) {
|
|
|
|
|
fwrite($fp, fread($options["stream"], 4096));
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
2013-03-05 15:07:55 -04:00
|
|
|
fclose($fp);
|
|
|
|
|
fclose($options["stream"]);
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
return "201 Created " . $fsFile;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pathProcesses = PATH_DB . SYS_SYS . PATH_SEP;
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) > 0 && $paths[0] == 'processes' && is_dir($pathProcesses)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($paths[2] == 'xmlforms') {
|
|
|
|
|
$pathTemplates = $pathProcesses . 'xmlForms' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
$fsFile = $pathTemplates . $paths[3];
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 4 && file_exists($fsFile)) {
|
|
|
|
|
$fp = fopen($fsFile, "w");
|
|
|
|
|
if (is_resource($fp) && is_resource($options["stream"])) {
|
|
|
|
|
while (!feof($options["stream"])) {
|
|
|
|
|
fwrite($fp, fread($options["stream"], 4096));
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
2013-03-05 15:07:55 -04:00
|
|
|
fclose($fp);
|
|
|
|
|
fclose($options["stream"]);
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
return "201 Created " . $fsFile;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($paths[2] == 'mailTemplates') {
|
|
|
|
|
$pathTemplates = $pathProcesses . 'mailTemplates' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
$fsFile = $pathTemplates . $paths[3];
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 4 && file_exists($fsFile)) {
|
|
|
|
|
$fp = fopen($fsFile, "w");
|
|
|
|
|
if (is_resource($fp) && is_resource($options["stream"])) {
|
|
|
|
|
while (!feof($options["stream"])) {
|
|
|
|
|
fwrite($fp, fread($options["stream"], 4096));
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
2013-03-05 15:07:55 -04:00
|
|
|
fclose($fp);
|
|
|
|
|
fclose($options["stream"]);
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
return "201 Created " . $fsFile;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($paths[2] == 'public_html') {
|
|
|
|
|
$pathPublic = $pathProcesses . 'public' . PATH_SEP . $paths[1] . PATH_SEP;
|
|
|
|
|
$fsFile = $pathPublic . $paths[3];
|
2013-03-05 15:07:55 -04:00
|
|
|
if (count($paths) == 4 && file_exists($fsFile)) {
|
|
|
|
|
$fp = fopen($fsFile, "w");
|
|
|
|
|
if (is_resource($fp) && is_resource($options["stream"])) {
|
|
|
|
|
while (!feof($options["stream"])) {
|
|
|
|
|
fwrite($fp, fread($options["stream"], 4096));
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
2013-03-05 15:07:55 -04:00
|
|
|
fclose($fp);
|
|
|
|
|
fclose($options["stream"]);
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
return "201 Created " . $fsFile;
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
return "409 Conflict";
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
/**
|
|
|
|
|
* MKCOL method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array general parameter passing array
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function MKCOL($options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
$path = $this->base . $options["path"];
|
2013-03-05 15:07:55 -04:00
|
|
|
$parent = dirname($path);
|
|
|
|
|
$name = basename($path);
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!file_exists($parent)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "409 Conflict";
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!is_dir($parent)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "403 Forbidden";
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (file_exists($parent . "/" . $name)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "405 Method not allowed";
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!empty($_SERVER["CONTENT_LENGTH"])) {
|
|
|
|
|
// no body parsing yet
|
2012-10-09 13:26:29 -04:00
|
|
|
return "415 Unsupported media type";
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$stat = mkdir($parent . "/" . $name, 0777);
|
|
|
|
|
if (!$stat) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "403 Forbidden";
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
return ("201 Created");
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DELETE method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array general parameter passing array
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function DELETE($options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
$path = $this->base . "/" . $options["path"];
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!file_exists($path)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "404 Not found";
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (is_dir($path)) {
|
|
|
|
|
$query = "DELETE FROM properties WHERE path LIKE '" . $this->_slashify($options["path"]) . "%'";
|
|
|
|
|
mysql_query($query);
|
2017-08-23 13:38:43 -04:00
|
|
|
PearSystem::rm("-rf $path");
|
2012-10-09 13:26:29 -04:00
|
|
|
} else {
|
2013-03-05 15:07:55 -04:00
|
|
|
unlink($path);
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
$query = "DELETE FROM properties WHERE path = '$options[path]'";
|
2013-03-05 15:07:55 -04:00
|
|
|
mysql_query($query);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
return "204 No Content";
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
/**
|
|
|
|
|
* MOVE method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array general parameter passing array
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function MOVE($options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
return "423 Locked";
|
|
|
|
|
//return $this->COPY($options, true);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
/**
|
|
|
|
|
* COPY method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array general parameter passing array
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function COPY($options, $del = false)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
// TODO Property updates still broken (Litmus should detect this?)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!empty($_SERVER["CONTENT_LENGTH"])) {
|
|
|
|
|
// no body parsing yet
|
2012-10-09 13:26:29 -04:00
|
|
|
return "415 Unsupported media type";
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
// no copying to different WebDAV Servers yet
|
2013-03-05 15:07:55 -04:00
|
|
|
if (isset($options["dest_url"])) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "502 bad gateway";
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
$source = $this->base . $options["path"];
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!file_exists($source)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "404 Not found";
|
2013-03-05 15:07:55 -04:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
$dest = $this->base . $options["dest"];
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$new = !file_exists($dest);
|
2012-10-09 13:26:29 -04:00
|
|
|
$existing_col = false;
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!$new) {
|
|
|
|
|
if ($del && is_dir($dest)) {
|
|
|
|
|
if (!$options["overwrite"]) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "412 precondition failed";
|
|
|
|
|
}
|
2013-03-05 15:07:55 -04:00
|
|
|
$dest .= basename($source);
|
|
|
|
|
if (file_exists($dest)) {
|
|
|
|
|
$options["dest"] .= basename($source);
|
2012-10-09 13:26:29 -04:00
|
|
|
} else {
|
|
|
|
|
$new = true;
|
|
|
|
|
$existing_col = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!$new) {
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($options["overwrite"]) {
|
2013-03-05 15:07:55 -04:00
|
|
|
$stat = $this->DELETE(array("path" => $options["dest"]
|
|
|
|
|
));
|
|
|
|
|
if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return $stat;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return "412 precondition failed";
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (is_dir($source) && ($options["depth"] != "infinity")) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// RFC 2518 Section 9.2, last paragraph
|
|
|
|
|
return "400 Bad request";
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
if ($del) {
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!rename($source, $dest)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "500 Internal server error";
|
|
|
|
|
}
|
2013-03-05 15:07:55 -04:00
|
|
|
$destpath = $this->_unslashify($options["dest"]);
|
|
|
|
|
if (is_dir($source)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
$query = "UPDATE properties
|
|
|
|
|
SET path = REPLACE(path, '" . $options["path"] . "', '" . $destpath . "')
|
2013-03-05 15:07:55 -04:00
|
|
|
WHERE path LIKE '" . $this->_slashify($options["path"]) . "%'";
|
|
|
|
|
mysql_query($query);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
$query = "UPDATE properties
|
|
|
|
|
SET path = '" . $destpath . "'
|
|
|
|
|
WHERE path = '" . $options["path"] . "'";
|
2013-03-05 15:07:55 -04:00
|
|
|
mysql_query($query);
|
2010-12-02 23:34:41 +00:00
|
|
|
} else {
|
2013-03-05 15:07:55 -04:00
|
|
|
if (is_dir($source)) {
|
2017-08-23 13:38:43 -04:00
|
|
|
$files = PearSystem::find($source);
|
2013-03-05 15:07:55 -04:00
|
|
|
$files = array_reverse($files);
|
2012-10-09 13:26:29 -04:00
|
|
|
} else {
|
2013-03-05 15:07:55 -04:00
|
|
|
$files = array($source
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!is_array($files) || empty($files)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "500 Internal server error";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
2013-03-05 15:07:55 -04:00
|
|
|
if (is_dir($file)) {
|
|
|
|
|
$file = $this->_slashify($file);
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
$destfile = str_replace($source, $dest, $file);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
if (is_dir($file)) {
|
|
|
|
|
if (!is_dir($destfile)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
// TODO "mkdir -p" here? (only natively supported by PHP 5)
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!mkdir($destfile)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "409 Conflict";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-03-05 15:07:55 -04:00
|
|
|
error_log("existing dir '$destfile'");
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2013-03-05 15:07:55 -04:00
|
|
|
if (!copy($file, $destfile)) {
|
2012-10-09 13:26:29 -04:00
|
|
|
return "409 Conflict";
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
$query = "INSERT INTO properties SELECT ... FROM properties WHERE path = '" . $options['path'] . "'";
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-05 15:07:55 -04:00
|
|
|
return ($new && !$existing_col) ? "201 Created" : "204 No Content";
|
2012-10-09 13:26:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* LOCK method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array general parameter passing array
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function LOCK(&$options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
2013-03-05 15:07:55 -04:00
|
|
|
if (isset($options["update"])) {
|
|
|
|
|
// Lock Update
|
2012-10-09 13:26:29 -04:00
|
|
|
$query = "UPDATE locks SET expires = " . (time() + 300);
|
2013-03-05 15:07:55 -04:00
|
|
|
mysql_query($query);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
if (mysql_affected_rows()) {
|
|
|
|
|
$options["timeout"] = 300; // 5min hardcoded
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$options["timeout"] = time() + 300; // 5min. hardcoded
|
2010-12-02 23:34:41 +00:00
|
|
|
|
|
|
|
|
|
2012-10-09 13:26:29 -04:00
|
|
|
$query = "INSERT INTO locks
|
2010-12-02 23:34:41 +00:00
|
|
|
SET token = '$options[locktoken]'
|
|
|
|
|
, path = '$options[path]'
|
|
|
|
|
, owner = '$options[owner]'
|
|
|
|
|
, expires = '$options[timeout]'
|
2012-10-09 13:26:29 -04:00
|
|
|
, exclusivelock = " . ($options['scope'] === "exclusive" ? "1" : "0");
|
2013-03-05 15:07:55 -04:00
|
|
|
mysql_query($query);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
return mysql_affected_rows() ? "200 OK" : "409 Conflict";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* UNLOCK method handler
|
|
|
|
|
*
|
|
|
|
|
* @param array general parameter passing array
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function UNLOCK(&$options)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
$query = "DELETE FROM locks
|
2010-12-02 23:34:41 +00:00
|
|
|
WHERE path = '$options[path]'
|
|
|
|
|
AND token = '$options[token]'";
|
2013-03-05 15:07:55 -04:00
|
|
|
mysql_query($query);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* checkLock() helper
|
|
|
|
|
*
|
|
|
|
|
* @param string resource path to check for locks
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function checkLock($path)
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2015-03-16 12:03:45 -04:00
|
|
|
$filter = new InputFilter();
|
|
|
|
|
$path = $filter->validateInput($path, 'nosql');
|
2012-10-09 13:26:29 -04:00
|
|
|
$result = false;
|
|
|
|
|
|
|
|
|
|
$query = "SELECT owner, token, expires, exclusivelock
|
2010-12-02 23:34:41 +00:00
|
|
|
FROM locks
|
2015-03-16 12:03:45 -04:00
|
|
|
WHERE path = '%s' ";
|
|
|
|
|
$query = $filter->preventSqlInjection($query, array($path));
|
2013-03-05 15:07:55 -04:00
|
|
|
$res = mysql_query($query);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
if ($res) {
|
2013-03-05 15:07:55 -04:00
|
|
|
$row = mysql_fetch_array($res);
|
|
|
|
|
mysql_free_result($res);
|
2012-10-09 13:26:29 -04:00
|
|
|
|
|
|
|
|
if ($row) {
|
2013-03-05 15:07:55 -04:00
|
|
|
$result = array("type" => "write", "scope" => $row["exclusivelock"] ? "exclusive" : "shared", "depth" => 0, "owner" => $row['owner'], "token" => $row['token'], "expires" => $row['expires']
|
2012-10-09 13:26:29 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* create database tables for property and lock storage
|
|
|
|
|
*
|
|
|
|
|
* @param void
|
|
|
|
|
* @return bool true on success
|
|
|
|
|
*/
|
2013-03-05 15:07:55 -04:00
|
|
|
public function create_database()
|
2012-10-09 13:26:29 -04:00
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
return false;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-03-05 15:07:55 -04:00
|
|
|
|