From fe4126c8c309f03f8e9279124fadf118a750b924 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Fri, 13 Mar 2009 02:59:45 +0000 Subject: [PATCH] "REPOSITORY, SMB/MDL-16907, remove smb plugin from core" --- lang/en_utf8/repository_smb.php | 3 - lib/smblib.php | 419 ---------------------------- repository/smb/icon.png | Bin 1150 -> 0 bytes repository/smb/repository.class.php | 90 ------ 4 files changed, 512 deletions(-) delete mode 100644 lang/en_utf8/repository_smb.php delete mode 100644 lib/smblib.php delete mode 100755 repository/smb/icon.png delete mode 100755 repository/smb/repository.class.php diff --git a/lang/en_utf8/repository_smb.php b/lang/en_utf8/repository_smb.php deleted file mode 100644 index f430b30970..0000000000 --- a/lang/en_utf8/repository_smb.php +++ /dev/null @@ -1,3 +0,0 @@ - -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -################################################################### - -define ('SMB4PHP_VERSION', '0.8'); - -################################################################### -# CONFIGURATION SECTION - Change for your needs -################################################################### - -define ('SMB4PHP_SMBCLIENT', 'smbclient'); -define ('SMB4PHP_SMBOPTIONS', 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192'); -define ('SMB4PHP_AUTHMODE', 'arg'); # set to 'env' to use USER enviroment variable - -################################################################### -# SMB - commands that does not need an instance -################################################################### - -$GLOBALS['__smb_cache'] = array ('stat' => array (), 'dir' => array ()); - -class smb { - - function parse_url ($url) { - $pu = parse_url (trim($url)); - foreach (array ('domain', 'user', 'pass', 'host', 'port', 'path') as $i) - if (! isset($pu[$i])) $pu[$i] = ''; - if (count ($userdomain = split (';', urldecode ($pu['user']))) > 1) - @list ($pu['domain'], $pu['user']) = $userdomain; - $path = preg_replace (array ('/^\//', '/\/$/'), '', urldecode ($pu['path'])); - list ($pu['share'], $pu['path']) = (preg_match ('/^([^\/]+)\/(.*)/', $path, $regs)) - ? array ($regs[1], preg_replace ('/\//', '\\', $regs[2])) - : array ($path, ''); - $pu['type'] = $pu['path'] ? 'path' : ($pu['share'] ? 'share' : ($pu['host'] ? 'host' : '**error**')); - if (! ($pu['port'] = intval(@$pu['port']))) $pu['port'] = 139; - return $pu; - } - - - function look ($purl) { - return smb::client ('-L ' . escapeshellarg ($purl['host']), $purl); - } - - - function execute ($command, $purl) { - return smb::client ('-d 0 ' - . escapeshellarg ('//' . $purl['host'] . '/' . $purl['share']) - . ' -c ' . escapeshellarg ($command), $purl - ); - } - - function client ($params, $purl) { - - static $regexp = array ( - '^added interface ip=(.*) bcast=(.*) nmask=(.*)$' => 'skip', - 'Anonymous login successful' => 'skip', - '^Domain=\[(.*)\] OS=\[(.*)\] Server=\[(.*)\]$' => 'skip', - '^\tSharename[ ]+Type[ ]+Comment$' => 'shares', - '^\t---------[ ]+----[ ]+-------$' => 'skip', - '^\tServer [ ]+Comment$' => 'servers', - '^\t---------[ ]+-------$' => 'skip', - '^\tWorkgroup[ ]+Master$' => 'workg', - '^\t(.*)[ ]+(Disk|IPC)[ ]+IPC.*$' => 'skip', - '^\tIPC\\\$(.*)[ ]+IPC' => 'skip', - '^\t(.*)[ ]+(Disk)[ ]+(.*)$' => 'share', - '^\t(.*)[ ]+(Printer)[ ]+(.*)$' => 'skip', - '([0-9]+) blocks of size ([0-9]+)\. ([0-9]+) blocks available' => 'skip', - 'Got a positive name query response from ' => 'skip', - '^(session setup failed): (.*)$' => 'error', - '^(.*): ERRSRV - ERRbadpw' => 'error', - '^Error returning browse list: (.*)$' => 'error', - '^tree connect failed: (.*)$' => 'error', - '^(Connection to .* failed)$' => 'error', - '^NT_STATUS_(.*) ' => 'error', - '^NT_STATUS_(.*)\$' => 'error', - 'ERRDOS - ERRbadpath \((.*).\)' => 'error', - 'cd (.*): (.*)$' => 'error', - '^cd (.*): NT_STATUS_(.*)' => 'error', - '^\t(.*)$' => 'srvorwg', - '^([0-9]+)[ ]+([0-9]+)[ ]+(.*)$' => 'skip', - '^Job ([0-9]+) cancelled' => 'skip', - '^[ ]+(.*)[ ]+([0-9]+)[ ]+(Mon|Tue|Wed|Thu|Fri|Sat|Sun)[ ](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]+([0-9]+)[ ]+([0-9]{2}:[0-9]{2}:[0-9]{2})[ ]([0-9]{4})$' => 'files', - '^message start: ERRSRV - (ERRmsgoff)' => 'error' - ); - - if (SMB4PHP_AUTHMODE == 'env') { - putenv("USER={$purl['user']}%{$purl['pass']}"); - $auth = ''; - } else { - $auth = ($purl['user'] <> '' ? (' -U ' . escapeshellarg ($purl['user'] . '%' . $purl['pass'])) : ''); - } - if ($purl['domain'] <> '') { - $auth .= ' -W ' . escapeshellarg ($purl['domain']); - } - $port = ($purl['port'] <> 139 ? ' -p ' . escapeshellarg ($purl['port']) : ''); - $options = '-O ' . escapeshellarg(SMB4PHP_SMBOPTIONS); - $output = popen (SMB4PHP_SMBCLIENT." -N {$auth} {$options} {$port} {$options} {$params} 2>/dev/null", 'r'); - $info = array (); - while ($line = fgets ($output, 4096)) { - list ($tag, $regs, $i) = array ('skip', array (), array ()); - reset ($regexp); - foreach ($regexp as $r => $t) if (preg_match ('/'.$r.'/', $line, $regs)) { - $tag = $t; - break; - } - switch ($tag) { - case 'skip': continue; - case 'shares': $mode = 'shares'; break; - case 'servers': $mode = 'servers'; break; - case 'workg': $mode = 'workgroups'; break; - case 'share': - list($name, $type) = array ( - trim(substr($line, 1, 15)), - trim(strtolower(substr($line, 17, 10))) - ); - $i = ($type <> 'disk' && preg_match('/^(.*) Disk/', $line, $regs)) - ? array(trim($regs[1]), 'disk') - : array($name, 'disk'); - break; - case 'srvorwg': - list ($name, $master) = array ( - strtolower(trim(substr($line,1,21))), - strtolower(trim(substr($line, 22))) - ); - $i = ($mode == 'servers') ? array ($name, "server") : array ($name, "workgroup", $master); - break; - case 'files': - list ($attr, $name) = preg_match ("/^(.*)[ ]+([D|A|H|S|R]+)$/", trim ($regs[1]), $regs2) - ? array (trim ($regs2[2]), trim ($regs2[1])) - : array ('', trim ($regs[1])); - list ($his, $im) = array ( - split(':', $regs[6]), 1 + strpos("JanFebMarAprMayJunJulAugSepOctNovDec", $regs[4]) / 3); - $i = ($name <> '.' && $name <> '..') - ? array ( - $name, - (strpos($attr,'D') === FALSE) ? 'file' : 'folder', - 'attr' => $attr, - 'size' => intval($regs[2]), - 'time' => mktime ($his[0], $his[1], $his[2], $im, $regs[5], $regs[7]) - ) - : array(); - break; - case 'error': trigger_error($regs[1], E_USER_ERROR); - } - if ($i) switch ($i[1]) { - case 'file': - case 'folder': $info['info'][$i[0]] = $i; - case 'disk': - case 'server': - case 'workgroup': $info[$i[1]][] = $i[0]; - } - } - pclose($output); - return $info; - } - - - # stats - - function url_stat ($url, $flags = STREAM_URL_STAT_LINK) { - if ($s = smb::getstatcache($url)) { return $s; } - list ($stat, $pu) = array (array (), smb::parse_url ($url)); - switch ($pu['type']) { - case 'host': - if ($o = smb::look ($pu)) - $stat = stat ("/tmp"); - else - trigger_error ("url_stat(): list failed for host '{$host}'", E_USER_WARNING); - break; - case 'share': - if ($o = smb::look ($pu)) { - $found = FALSE; - $lshare = strtolower ($pu['share']); # fix by Eric Leung - foreach ($o['disk'] as $s) if ($lshare == strtolower($s)) { - $found = TRUE; - $stat = stat ("/tmp"); - break; - } - if (! $found) - trigger_error ("url_stat(): disk resource '{$share}' not found in '{$host}'", E_USER_WARNING); - } - break; - case 'path': - if ($o = smb::execute ('dir "'.$pu['path'].'"', $pu)) { - $p = split ("[\\]", $pu['path']); - $name = $p[count($p)-1]; - if (isset ($o['info'][$name])) { - $stat = smb::addstatcache ($url, $o['info'][$name]); - } else { - trigger_error ("url_stat(): path '{$pu['path']}' not found", E_USER_WARNING); - } - } else { - trigger_error ("url_stat(): dir failed for path '{$pu['path']}'", E_USER_WARNING); - } - break; - default: trigger_error ('error in URL', E_USER_ERROR); - } - return $stat; - } - - function addstatcache ($url, $info) { - global $__smb_cache; - $is_file = (strpos ($info['attr'],'D') === FALSE); - $s = ($is_file) ? stat ('/etc/passwd') : stat ('/tmp'); - $s[7] = $s['size'] = $info['size']; - $s[8] = $s[9] = $s[10] = $s['atime'] = $s['mtime'] = $s['ctime'] = $info['time']; - return $__smb_cache['stat'][$url] = $s; - } - - function getstatcache ($url) { - global $__smb_cache; - return isset ($__smb_cache['stat'][$url]) ? $__smb_cache['stat'][$url] : FALSE; - } - - function clearstatcache ($url='') { - global $__smb_cache; - if ($url == '') $__smb_cache['stat'] = array (); else unset ($__smb_cache['stat'][$url]); - } - - - # commands - - function unlink ($url) { - $pu = smb::parse_url($url); - if ($pu['type'] <> 'path') trigger_error('unlink(): error in URL', E_USER_ERROR); - smb::clearstatcache ($url); - return smb::execute ('del "'.$pu['path'].'"', $pu); - } - - function rename ($url_from, $url_to) { - list ($from, $to) = array (smb::parse_url($url_from), smb::parse_url($url_to)); - if ($from['host'] <> $to['host'] || - $from['share'] <> $to['share'] || - $from['user'] <> $to['user'] || - $from['pass'] <> $to['pass'] || - $from['domain'] <> $to['domain']) { - trigger_error('rename(): FROM & TO must be in same server-share-user-pass-domain', E_USER_ERROR); - } - if ($from['type'] <> 'path' || $to['type'] <> 'path') { - trigger_error('rename(): error in URL', E_USER_ERROR); - } - smb::clearstatcache ($url_from); - return smb::execute ('rename "'.$from['path'].'" "'.$to['path'].'"', $to); - } - - function mkdir ($url, $mode, $options) { - $pu = smb::parse_url($url); - if ($pu['type'] <> 'path') trigger_error('mkdir(): error in URL', E_USER_ERROR); - return smb::execute ('mkdir "'.$pu['path'].'"', $pu); - } - - function rmdir ($url) { - $pu = smb::parse_url($url); - if ($pu['type'] <> 'path') trigger_error('rmdir(): error in URL', E_USER_ERROR); - smb::clearstatcache ($url); - return smb::execute ('rmdir "'.$pu['path'].'"', $pu); - } - -} - -################################################################### -# SMB_STREAM_WRAPPER - class to be registered for smb:// URLs -################################################################### - -class smb_stream_wrapper extends smb { - - # variables - - var $stream, $url, $parsed_url = array (), $mode, $tmpfile; - var $need_flush = FALSE; - var $dir = array (), $dir_index = -1; - - - # directories - - function dir_opendir ($url, $options) { - if ($d = $this->getdircache ($url)) { - $this->dir = $d; - $this->dir_index = 0; - return TRUE; - } - $pu = smb::parse_url ($url); - switch ($pu['type']) { - case 'host': - if ($o = smb::look ($pu)) { - $this->dir = $o['disk']; - $this->dir_index = 0; - } else { - trigger_error ("dir_opendir(): list failed for host '{$pu['host']}'", E_USER_WARNING); - } - break; - case 'share': - case 'path': - if ($o = smb::execute ('dir "'.$pu['path'].'\*"', $pu)) { - $this->dir = array_keys($o['info']); - $this->dir_index = 0; - $this->adddircache ($url, $this->dir); - foreach ($o['info'] as $name => $info) { - smb::addstatcache($url . '/' . urlencode($name), $info); - } - } else { - trigger_error ("dir_opendir(): dir failed for path '{$path}'", E_USER_WARNING); - } - break; - default: - trigger_error ('dir_opendir(): error in URL', E_USER_ERROR); - } - return TRUE; - } - - function dir_readdir () { return ($this->dir_index < count($this->dir)) ? $this->dir[$this->dir_index++] : FALSE; } - - function dir_rewinddir () { $this->dir_index = 0; } - - function dir_closedir () { $this->dir = array(); $this->dir_index = -1; return TRUE; } - - - # cache - - function adddircache ($url, $content) { - global $__smb_cache; - return $__smb_cache['dir'][$url] = $content; - } - - function getdircache ($url) { - global $__smb_cache; - return isset ($__smb_cache['dir'][$url]) ? $__smb_cache['dir'][$url] : FALSE; - } - - function cleardircache ($url='') { - global $__smb_cache; - if ($url == '') $__smb_cache['dir'] = array (); else unset ($__smb_cache['dir'][$url]); - } - - - # streams - - function stream_open ($url, $mode, $options, $opened_path) { - $this->url = $url; - $this->mode = $mode; - $this->parsed_url = $pu = smb::parse_url($url); - if ($pu['type'] <> 'path') trigger_error('stream_open(): error in URL', E_USER_ERROR); - switch ($mode) { - case 'r': - case 'r+': - case 'rb': - case 'a': - case 'a+': $this->tmpfile = tempnam('/tmp', 'smb.down.'); - smb::execute ('get "'.$pu['path'].'" "'.$this->tmpfile.'"', $pu); - break; - case 'w': - case 'w+': - case 'wb': - case 'x': - case 'x+': $this->cleardircache(); - $this->tmpfile = tempnam('/tmp', 'smb.up.'); - } - $this->stream = fopen ($this->tmpfile, $mode); - return TRUE; - } - - function stream_close () { return fclose($this->stream); } - - function stream_read ($count) { return fread($this->stream, $count); } - - function stream_write ($data) { $this->need_flush = TRUE; return fwrite($this->stream, $data); } - - function stream_eof () { return feof($this->stream); } - - function stream_tell () { return ftell($this->stream); } - - function stream_seek ($offset, $whence=null) { return fseek($this->stream, $offset, $whence); } - - function stream_flush () { - if ($this->mode <> 'r' && $this->need_flush) { - smb::clearstatcache ($this->url); - smb::execute ('put "'.$this->tmpfile.'" "'.$this->parsed_url['path'].'"', $this->parsed_url); - $this->need_flush = FALSE; - } - } - - function stream_stat () { return smb::url_stat ($this->url); } - - function __destruct () { - if ($this->tmpfile <> '') { - if ($this->need_flush) $this->stream_flush (); - unlink ($this->tmpfile); - - } - } - -} - -################################################################### -# Register 'smb' protocol ! -################################################################### - -stream_wrapper_register('smb', 'smb_stream_wrapper') - or die ('Failed to register protocol'); - -?> diff --git a/repository/smb/icon.png b/repository/smb/icon.png deleted file mode 100755 index 692680fc68eda603be449aa3fd436e39ca5f8b84..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1150 zcmV-^1cCdBP)DvRD-%zgSu6O zyIF?2T8X|~ioacq!D5iZW0AyWin(c#!D*JrYL2{Wk-%$^zH61mZI8Tek-lz{z;2bp zZkEMwlfQ73!Elwsag)DtpU-rd!*!a*cbUX@n#FmX#(AB{dY#65jiZ2ogMfmEfq{d8 zfrWyDh=PQPgM){Igo%TNiiCuRg@uTQh=YiTi-?Mai;jqmkBW|ui;j?tk&}*g(z5?(FaI?(gvL@bK{P^Y`)b z@bmNY_xJbt`uY0%`u+X<{{H^||No^LR{sD10626~PE!B@2M7rZ3=R(w5)&2}8XZ1Y zSXfwOY;t^kfRK@_t+lzu$IOQLlg+}jc*AZ`H%Ir&AUrLT$#9RNhLoG5|kugj~dYbswj0X47l%v1u;N-EwI zXQVtn0sinDp!VI{W~{0HLkk}Qv|Zq}%b-y)1ZbCZMVAbeLx6TmS9CKFFK#P`0PU5o z=w;xxAxb#}=)fXxfB~Yuq#OdYr?a0u;UfZfNSHy8`?BC^c4m623_3Qx2zI;uGXn4M zF#$nZmMJgKl=Vag-v)mPR;%?Z0^R)K0Rp4(5oR>X;OFx4lFerOfdC*Tra|0xCdM-` z_xmq9a|k@OT5XU)uWx;iwd(bTKn4~jSJ+vgP!@aV<`vaNji&7r)~3;@`MX#h;%Ak@ zV(<+YHY9P{^4&6JnMq6lcYNJzegD{56QL~buHP*jG9io#Bf|Lb>{ysL3E6b~Vg84> z;uF~rsr`ff!+9OK8VYiu*WB2ZIOI40a>47eBM%hlibdir.'/smblib.php'); - -class repository_smb extends repository { - public function __construct($repositoryid, $context = SITEID, $options = array()) { - parent::__construct($repositoryid, $context, $options); - } - public function check_login() { - global $SESSION; - return true; - } - public function get_file($url, $title) { - global $CFG; - if (!file_exists($CFG->dataroot.'/temp/download')) { - mkdir($CFG->dataroot.'/temp/download/', 0777, true); - } - if (is_dir($CFG->dataroot.'/temp/download')) { - $dir = $CFG->dataroot.'/temp/download/'; - } - if (empty($file)) { - $file = uniqid('repo').'_'.time().'.tmp'; - } - if (file_exists($dir.$file)) { - $file = uniqid('m').$file; - } - - $content = ''; - $fp = fopen($url, 'r'); - while (!feof($fp)) { - $content .= fread($fp, 1024*8); - } - $fp = fopen($dir.$file, 'wb'); - fwrite($fp, $content); - return $dir.$file; - } - public function global_search() { - return false; - } - public function get_listing($path='', $page = '') { - global $CFG; - $list = array(); - $ret = array(); - $ret['dynload'] = true; - $ret['nosearch'] = true; - $ret['nologin'] = true; - $ret['list'] = array(); - $ret['path'] = array(array('name'=>'Root', 'path'=>0)); - if (empty($path)) { - $path = $this->smb_server; - } - $fp = opendir($path); - while (($file = readdir($fp)) !== false) { - if (is_dir($path.$file)) { - $ret['list'][] = array( - 'title'=>$file, - 'path'=>$path.$file.'/', - 'thumbnail'=>$CFG->pixpath.'/f/folder.gif', - 'size'=>0, - 'date'=>'', - 'children'=>array()); - } else { - $ret['list'][] = array( - 'title'=>$file, - 'thumbnail' => $CFG->pixpath .'/f/'. mimeinfo('icon32', $file), - 'size'=>'', - 'date'=>'', - 'source'=>$path.$file); - } - } - return $ret; - } - public static function get_instance_option_names() { - return array('smb_server'); - } - - public function instance_config_form(&$mform) { - $mform->addElement('text', 'smb_server', get_string('smb_server', 'repository_smb'), array('size' => '40')); - $mform->addRule('smb_server', get_string('required'), 'required', null, 'client'); - } -} - - -- 2.39.5