Ejemplo n.º 1
0
 /**
  * 获取当前文件版本列表
  * @param $path
  * @return mixed
  */
 public function getList($path)
 {
     $item = explode("/", $path);
     $permissionArr = UserPermissionBiz::getInstance()->getPermission($path, $this->user['id']);
     if ($item[1] !== $this->user['id'] && count($permissionArr) == 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR), MConst::HTTP_CODE_400);
     }
     $file = MiniFile::getInstance()->getByPath($path);
     $version_id = $file['version_id'];
     $fileMeta = MiniFileMeta::getInstance()->getFileMeta($path, "version");
     $fileVersion = MiniVersion::getInstance()->getVersion($version_id);
     $currentSignature = $fileVersion['file_signature'];
     $historyArr = array_reverse(unserialize($fileMeta['meta_value']));
     // 去掉delete事件版本
     $histories = array();
     foreach ($historyArr as $item) {
         $history = array();
         if ($item['type'] == CConst::DELETE) {
             continue;
         }
         $history['type'] = $item['type'];
         $history['file_size'] = $item['file_size'];
         $history['user_nick'] = $item['user_nick'];
         $history['device_name'] = $item['device_name'];
         $history['datetime'] = MiniUtil::formatTime(strtotime($item['datetime']));
         $fileVersion = MiniVersion::getInstance()->getVersion($item['version_id']);
         $history['signature'] = $fileVersion['file_signature'];
         array_push($histories, $history);
     }
     $data['histories'] = $histories;
     $data['current_signature'] = $currentSignature;
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * 根據文件Id获取文件数据
  */
 public function getLink($fileId, $linkType, $shareKey)
 {
     $data = array();
     $file = MiniFile::getInstance()->getById($fileId);
     $data["name"] = $file["file_name"];
     $data["bytes"] = intval($file["file_size"] + "");
     $fileType = $file["file_type"];
     if ($fileType == 0) {
         $data["icon"] = MiniHttp::getIcon4File($file["file_name"]);
         if (!MiniUtil::isMixCloudVersion()) {
             $data["icon"] = MiniHttp::getMiniHost() . "statics/static/mini-box/images/link/" . $data["icon"];
         } else {
             $data["icon"] = "http://static.miniyun.cn/static/mini-box/images/link/" . $data["icon"];
         }
     }
     $ext = MiniUtil::getFileExtension($file["file_name"]);
     $path = MiniUtil::getRelativePath($file["file_path"]);
     if ($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif") {
         $data["thumbnail_link"] = MiniHttp::createAnonymousUrl("linkAccess/thumbnail?key=" . $shareKey . "&size=256x256&path=" . urlencode($path));
     } else {
         $data["thumbnail_link"] = "";
     }
     if ($linkType == MiniLink::$PREVIEW_LINK) {
         $data["link"] = MiniHttp::createUrl("link/access/key/" . $shareKey);
     } else {
         $data["link"] = MiniHttp::createAnonymousUrl("linkAccess/download?key=" . $shareKey . "&path=" . urlencode($path));
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  *   获取events数据
  */
 public function getList($path, $time, $deviceUuid, $pageSize, $currentPage)
 {
     $user = $this->user;
     $userId = $user['id'];
     $time = $this->getTime($time);
     if ($path != "") {
         $path = MiniUtil::joinPath($path);
     }
     $total = MiniEvent::getInstance()->getTotal($path, $time, $userId, $deviceUuid);
     $totalPage = ceil($total / $pageSize);
     $events = MiniEvent::getInstance()->getByCondition($path, $userId, $time, $deviceUuid, $pageSize, ($currentPage - 1) * $pageSize);
     $itemList = array();
     $data = array();
     foreach ($events as $event) {
         $item = array();
         $device = MiniUserDevice::getInstance()->getUserDevice($event['user_device_id']);
         $item['create_user_id'] = $device['user_id'];
         $item['file_path'] = MiniUtil::getRelativePath($event['file_path']);
         $item['action'] = $event['action'];
         $item['user_name'] = $user['user_name'];
         $item['user_device_type'] = $device['user_device_type'];
         if ($device['user_id'] == $userId) {
             $item['user_self'] = true;
         } else {
             $item['user_self'] = false;
             $user = MiniUser::getInstance()->getById($device['user_id']);
             $userMetas = MiniUserMeta::getInstance()->getUserMetas($device['user_id']);
             if (isset($userMetas['nick'])) {
                 $item['user_name'] = $userMetas['nick'];
             } else {
                 $item['user_name'] = $user['user_name'];
             }
         }
         $item['created_at'] = MiniUtil::formatTime(strtotime($event['created_at']));
         $item['user_device_name'] = $device['user_device_name'];
         $item['context'] = MiniUtil::getRelativePath($event['context']);
         $item['device_uuid'] = $device['user_device_uuid'];
         if ($event['action'] == 2) {
             //判断是否是重命名还是创建
             $fromParent = CUtils::pathinfo_utf($event['file_path']);
             $toParent = CUtils::pathinfo_utf($event['context']);
             if ($fromParent['dirname'] == $toParent['dirname']) {
                 $item['action'] = MConst::RENAME;
             }
         }
         $itemList[] = $item;
     }
     $data['events'] = $itemList;
     $data['totalPage'] = $totalPage;
     return $data;
 }
Ejemplo n.º 4
0
 /**
  * 获取系统已用空间
  */
 public function getUsedSpace()
 {
     $storeData = MiniUtil::getPluginMiniStoreData();
     if (empty($storeData)) {
         //非迷你存储模式
         $remain = $this->getDiskFreeSpace();
         //空闲空间 字节
         $total = $this->getDiskTotalSpace();
         //总空间 字节
         $usedSpace = $this->_byteFormat(MiniVersion::getInstance()->getTotalSize());
         $totalSpace = $this->_byteFormat($total);
         $usedPercentage = $this->getUsedPercent();
         //已用空间占的百分比
     } else {
         //迷你存储模式下,获得迷你存储所有节点的空间使用情况
         $usedSpace = 0;
         $totalSpace = 0;
         $usedPercentage = 100;
         $nodes = PluginMiniStoreNode::getInstance()->getNodeList();
         foreach ($nodes as $node) {
             if ($node["status"] == 1) {
                 $url = $node["host"] . "/api.php?route=store/info";
                 $content = file_get_contents($url);
                 if ($content != "") {
                     $disks = json_decode($content);
                     foreach ($disks as $disk) {
                         $usedSpace += $disk->{"used"};
                         $totalSpace += $disk->{"total"};
                     }
                 }
             }
         }
         if ($totalSpace > 0) {
             $usedPercentage = round($usedSpace / $totalSpace, 3) * 100;
         }
         $usedSpace = round($usedSpace / 1024 / 1024, 2);
         $totalSpace = round($totalSpace / 1024 / 1024, 2);
     }
     //获得缓存空间大小
     $tempDirectory = $this->getDirectorySize(BASE . 'temp');
     $tempSize = $tempDirectory['size'];
     $cacheSize = $this->countCache();
     $cacheSpace = MiniUtil::formatSize($tempSize + $cacheSize);
     $data = array();
     $data['usedSpace'] = $usedSpace;
     $data['totalSpace'] = $totalSpace;
     $data['usedPercentage'] = $usedPercentage;
     $data['cacheSpace'] = $cacheSpace;
     return $data;
 }
Ejemplo n.º 5
0
 /** 按照文件名查找假删除文件
  * @param $fileName
  * @return mixed
  */
 public function search($fileName)
 {
     $sessionUser = $this->user;
     $user_id = $sessionUser["id"];
     $deleteList = MiniFile::getInstance()->getFileByNameRecycle($user_id, $fileName);
     $list = array();
     $data = array();
     foreach ($deleteList as $value) {
         $data["file_name"] = $value["file_name"];
         $data["file_size"] = $value["file_size"];
         $data["file_path"] = MiniUtil::getRelativePath($value["file_path"]);
         $data["create_time"] = $value["file_create_time"];
         $data["is_deleted"] = $value["is_deleted"];
         $data["type"] = $value["file_type"];
         $list[] = $data;
     }
     $dataList['list'] = $list;
     return $dataList;
 }
Ejemplo n.º 6
0
 /**
  * 迷你存储报俊
  * @param string $path 用户文件的存储路径
  * @param string $signature 文件sha1
  * @param int $size 文件大小,单位字节
  * @param int $nodeId 迷你存储节点值 
  */
 public function report($path, $signature, $size, $nodeId)
 {
     //防止重复文件通过网页上传,生成多条记录
     $version = MiniVersion::getInstance()->getBySignature($signature);
     if (empty($version)) {
         //创建version/versionMeta数据
         $pathParts = pathinfo($path);
         $type = MiniUtil::getMimeType($pathParts["basename"]);
         $version = MiniVersion::getInstance()->create($signature, $size, $type);
         MiniVersionMeta::getInstance()->create($version["id"], "store_id", $nodeId);
         //更新迷你存储节点状态,把新上传的文件数+1
         PluginMiniStoreNode::getInstance()->newUploadFile($nodeId);
         //清理垃圾数据
         PluginMiniBreakFile::getInstance()->deleteBySignature($signature);
     }
     //执行文件秒传逻辑
     $filesController = new MFileSecondsController();
     $filesController->invoke();
 }
Ejemplo n.º 7
0
 /**
  * 创建外链
  */
 public function create($userId, $fileId)
 {
     $mode = Link::model()->find("user_id=:user_id and file_id=:file_id", array("user_id" => $userId, "file_id" => $fileId));
     if (!isset($mode)) {
         $mode = new Link();
         //寻找唯一的Key,如果发现系统已经存在,则重新生成一个,直到寻找到
         $shareKey = MiniUtil::randomString(6);
         $link = $this->getByKey($shareKey);
         while (!empty($link)) {
             $shareKey = MiniUtil::randomString(8);
             $link = $this->getByKey($shareKey);
         }
         $mode->expiry = -1;
         $mode->password = "******";
         $mode->share_key = $shareKey;
     }
     $mode->file_id = $fileId;
     $mode->user_id = $userId;
     $mode->save();
     return $this->db2Item($mode);
 }
Ejemplo n.º 8
0
 /**
  * 创建元数据对象
  */
 public static function CreateFileDetail($file_detail, $user_id)
 {
     $sql = "insert into " . DB_PREFIX . "_files(user_id,file_type,parent_file_id,";
     $sql .= "file_create_time,file_update_time,file_name,version_id,";
     $sql .= "file_size,file_path,event_uuid,mime_type,created_at,updated_at,file_name_pinyin) values ";
     //
     // 新建对象,需要生成对应的长度信息
     //
     $file_detail->event_uuid = MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID);
     if (isset($file_detail->version_id) === false) {
         $file_detail->version_id = 0;
     }
     $sql .= "({$user_id},{$file_detail->file_type},";
     $sql .= "{$file_detail->parent_file_id},";
     $sql .= "{$file_detail->file_create_time},";
     $sql .= "{$file_detail->file_update_time},";
     $sql .= "\"{$file_detail->file_name}\",";
     $sql .= "{$file_detail->version_id},";
     $sql .= "{$file_detail->file_size},";
     $sql .= "\"{$file_detail->file_path}\",";
     $sql .= "\"{$file_detail->event_uuid}\",";
     if ($file_detail->mime_type === NULL) {
         $sql .= "NULL,";
     } else {
         $sql .= "\"{$file_detail->mime_type}\",";
     }
     $sql .= "now(),now(),'" . MiniUtil::getPinYinByName($file_detail->file_name) . "')";
     $db_manager = MDbManager::getInstance();
     $result = $db_manager->insertDb($sql);
     if ($result === false) {
         return false;
     }
     //
     // 修复sort值为id值,确保唯一
     //
     $sql = "update  " . DB_PREFIX . "_files set sort=id where sort=0";
     $db_manager->insertDb($sql);
     return $file_detail;
 }
Ejemplo n.º 9
0
 /**
  * (non-PHPdoc)
  * @see MFilesecController::invoke()
  */
 public function invoke($uri = NULL)
 {
     $size = isset($_REQUEST['size']) ? $_REQUEST['size'] : NULL;
     if ($size === NULL || $size < 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . 'Missing parameter'), MConst::HTTP_CODE_400);
     }
     $hash = $_REQUEST["hash"];
     $this->size = $size;
     $url_manager = new MUrlManager();
     $path = $url_manager->parsePathFromUrl($uri);
     $path_info = MUtils::pathinfo_utf($path);
     $file_name = $path_info["basename"];
     $this->type = MiniUtil::getMimeType($file_name);
     //如果文件的block存在则直接创建meta,表示创建成功否则返回上传文件的参数
     if ($this->handleCheckFileVersionSearch($hash)) {
         parent::invoke($uri);
     } else {
         //空间检查
         $this->spaceFilter($size);
         echo json_encode(array("hash" => $hash, "filename" => $file_name));
     }
 }
Ejemplo n.º 10
0
 /**
  *
  * 在用户验证失败后是否需要进行自身用户系统的验证
  */
 public static function getDevice($userId, $deviceType, $deviceName, $deviceInfo)
 {
     //生成设备的uuid
     if ($deviceType == MConst::DEVICE_WEB) {
         $deviceUuid = MiniUtil::getDeviceUUID("web", $deviceType, "web", $userId);
     } else {
         $deviceUuid = MiniUtil::getDeviceUUID($deviceInfo, $deviceType, $deviceName, $userId);
     }
     //存在用户指定设备则通过
     $device = NULL;
     if ($deviceType == MConst::DEVICE_WEB) {
         $device = MiniUserDevice::getInstance()->getWebDevice($userId);
     } else {
         $device = MiniUserDevice::getInstance()->getByUuid($deviceUuid);
     }
     if (isset($device)) {
         return $device;
     }
     //生成设备
     $device = MiniUserDevice::getInstance()->create($userId, $deviceUuid, $deviceType, $deviceInfo, $deviceName);
     return $device;
 }
Ejemplo n.º 11
0
 /**
  *
  * 文件上传成功后,向迷你文档服务器发送文档转换请求
  * @param $data 文件sha1编码
  * @return bool
  */
 function fileUploadAfter($data)
 {
     $signature = $data["signature"];
     $fileName = $data["file_name"];
     $newMimeType = MiniUtil::getMimeType($fileName);
     $mimeTypeList = array("text/plain", "text/html", "application/javascript", "text/css", "application/xml");
     foreach ($mimeTypeList as $mimeType) {
         if ($mimeType === $newMimeType) {
             //文本类文件直接把内容存储到数据库中,便于全文检索
             do_action("pull_text_search", $signature);
             return;
         }
     }
     $mimeTypeList = array("application/mspowerpoint", "application/msword", "application/msexcel", "application/pdf");
     foreach ($mimeTypeList as $mimeType) {
         if ($mimeType === $newMimeType) {
             //文档类增量转换
             PluginMiniDocVersion::getInstance()->pushConvertSignature($signature, $newMimeType);
             break;
         }
     }
     return true;
 }
Ejemplo n.º 12
0
 /**
  * 初始化DB配置文件
  */
 private function initDbConfigFile()
 {
     $filePath = dirname(__FILE__) . '/../../config/miniyun-config-simple.php';
     $content = "";
     $fileHandle = fopen($filePath, "rb");
     while (!feof($fileHandle)) {
         $content = $content . fgets($fileHandle);
     }
     $this->base = str_replace("\\", "/", $this->base);
     fclose($fileHandle);
     $content = str_replace("#dBType#", "mysql", $content);
     $content = str_replace("#dBName#", $this->dbName, $content);
     $content = str_replace("#dBUser#", $this->userName, $content);
     $content = str_replace("#dBPasswd#", $this->password, $content);
     $content = str_replace("#tablePrefix#", $this->tablePrefix, $content);
     $content = str_replace("#key#", MiniUtil::genRandomString(), $content);
     $content = str_replace("#base#", $this->base, $content);
     $content = str_replace("#dBHost#", $this->dbHost, $content);
     $content = str_replace("#dBPort#", $this->dbPort, $content);
     $filePath = dirname(__FILE__) . '/../../config/miniyun-config.php';
     $fh = fopen($filePath, 'w');
     fwrite($fh, $content);
     fclose($fh);
 }
Ejemplo n.º 13
0
 /**
  *
  * 取消共享文件夹
  *
  * @since 1.0.7
  */
 private function handlerCancelSharedFolder()
 {
     $this->_file = UserFile::model()->findByPk($this->_id);
     if (empty($this->_file)) {
         throw new ApiException("NOT FOUND");
     }
     if ($this->_file['file_type'] != 2 && $this->_file['file_type'] != 3 && $this->_file['file_type'] != 4) {
         throw new ApiException("NOT FOUND");
     }
     $file_meta = FileMeta::model()->findByAttributes(array('file_path' => $this->_file['file_path'], 'meta_key' => self::SHARED_META_FLAG));
     if (empty($file_meta)) {
         $this->_file['file_type'] = 1;
         $this->_file->save();
         return;
     }
     $meta_value = unserialize($file_meta['meta_value']);
     $this->_master = $meta_value['master'];
     $this->_slaves = $meta_value['slaves'];
     $path = $meta_value['path'];
     //
     // 表示共享者删除共享,所有全部都删除,否则只删除自己的
     //
     if ($this->_master == $this->_userId) {
         $this->_file['file_type'] = 1;
         //
         // 删除共享信息
         //
         foreach ($this->_slaves as $k => $v) {
             //添加需要删除的共享用户到列表中
             $this->deleteShareUsers[] = $k;
             $event_uuid = MiniUtil::getEventRandomString(46);
             UserFile::model()->deleteAllByAttributes(array('file_path' => $v, 'file_type' => 3));
             FileMeta::model()->deleteAllByAttributes(array('file_path' => $v, 'meta_key' => self::SHARED_META_FLAG));
             MiniEvent::getInstance()->createEvent($k, $this->_deviceId, 1, $v, $v, $event_uuid);
             $this->handlerDeleteMyFavorate($k, $path);
         }
         FileMeta::model()->deleteAllByAttributes(array('file_path' => $meta_value['path'], 'meta_key' => self::SHARED_META_FLAG));
         $event_uuid = MiniUtil::getEventRandomString(46);
         MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, 6, $this->_file['file_path'], $this->_file['file_path'], $event_uuid);
         $this->_file['event_uuid'] = $event_uuid;
         $this->_file->save();
     } else {
         if (isset($this->_slaves[$this->_userId])) {
             UserFile::model()->deleteAllByAttributes(array('file_path' => $this->_slaves[$this->_userId], 'file_type' => 3));
             //
             // 只读共享
             // 如果 type发生改变
             // by kindac
             //
             UserFile::model()->deleteAllByAttributes(array('file_path' => $this->_slaves[$this->_userId], 'file_type' => 4));
             FileMeta::model()->deleteAllByAttributes(array('file_path' => $this->_slaves[$this->_userId], 'meta_key' => self::SHARED_META_FLAG));
         }
         $event_uuid = MiniUtil::getEventRandomString(46);
         MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, 1, $this->_slaves[$this->_userId], $this->_slaves[$this->_userId], $event_uuid);
         //
         // 删除
         //
         unset($this->_slaves[$this->_userId]);
         $meta_value['slaves'] = $this->_slaves;
         $meta_value['send_msg'] = $this->_send_msg;
         $this->_slaves[$meta_value['master']] = $meta_value['path'];
         $meta_value = serialize($meta_value);
         foreach ($this->_slaves as $k => $v) {
             FileMeta::model()->updateAll(array('meta_value' => $meta_value), 'meta_key=:meta_key and file_path=:file_path', array(':meta_key' => self::SHARED_META_FLAG, ':file_path' => $v));
         }
         $this->handlerDeleteMyFavorate($this->_userId, $path);
         //
         // 取消没有被共享者的共享
         //
         if (count($this->_slaves) <= 1) {
             FileMeta::model()->deleteAllByAttributes(array('file_path' => $path, 'meta_key' => self::SHARED_META_FLAG));
             $event_uuid = MiniUtil::getEventRandomString(46);
             MiniEvent::getInstance()->createEvent($this->_master, $this->_deviceId, 6, $path, $path, $event_uuid);
             UserFile::model()->updateAll(array('file_type' => 1, 'event_uuid' => $event_uuid), 'file_path=:file_path', array(':file_path' => $path));
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * 获取文本内容
  * @param $key
  * @param $path
  * @return mixed
  */
 public function txtContent($key, $path)
 {
     $link = MiniLink::getInstance()->getByKey($key);
     if ($link !== NULL) {
         $file = MiniFile::getInstance()->getById($link["file_id"]);
         $parentPath = $file["file_path"];
         if ($file !== NULL) {
             $userId = $file["user_id"];
             $absolutePath = MiniUtil::getAbsolutePath($userId, $path);
             //必须限定子目录在外链目录下
             if (strpos($absolutePath, $parentPath) == 0) {
                 return MiniFile::getInstance()->getTxtContent($absolutePath);
             }
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * 获得最好的的迷你搜索节点
  * 先找出build_file_count最大的节点
  * 如果build_file_count相同,找出search_count最小的节点
  * @return array
  */
 public function getBestNode()
 {
     $nodes = $this->getValidNodeList();
     if (count($nodes) > 0) {
         $sortNodes = MiniUtil::arraySort($nodes, "build_file_count", SORT_DESC);
         $sortNodes = MiniUtil::getFistArray($sortNodes, 1);
         $bestNode = $sortNodes[0];
         $buildFileCount = $bestNode["build_file_count"];
         $searchCount = $bestNode["search_count"];
         foreach ($nodes as $node) {
             if ($node["build_file_count"] == $buildFileCount) {
                 if ($node["search_count"] < $searchCount) {
                     $bestNode = $node;
                 }
             }
         }
         return $bestNode;
     }
     return null;
 }
Ejemplo n.º 16
0
 /**
  * 获取已分享的文件
  * @param $path
  * @return bool
  */
 public function shared($path)
 {
     $userId = $this->user['id'];
     $absolutePath = MiniUtil::getAbsolutePath($userId, $path);
     $file = MiniFile::getInstance()->getByPath($absolutePath);
     $link = MiniLink::getInstance()->getByFileId($file['id']);
     if (empty($link['share_key'])) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 17
0
 /**
  * 控制器执行主逻辑函数
  */
 public function invoke($uri = null)
 {
     $this->setAction(MConst::CREATE_FILE);
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $urlManager = new MUrlManager();
     $root = $urlManager->parseRootFromUrl($uri);
     if ($root == false) {
         //支持参数模式传递上传路径
         $path = MiniHttp::getParam("path", "");
         if (empty($path)) {
             throw new MFilesException(Yii::t('api', MConst::PATH_ERROR), MConst::HTTP_CODE_411);
         }
     }
     // 初始化创建文件公共类句柄
     $createFileHandler = MFilesCommon::initMFilesCommon();
     if (count($_FILES) == 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "5"), MConst::HTTP_CODE_400);
     }
     $keys = array_keys($_FILES);
     if (count($keys) != 1) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "6"), MConst::HTTP_CODE_400);
     }
     $key = $keys[0];
     // 检查请求参数$_FILES
     if (isset($_FILES[$key]) === false) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "7"), MConst::HTTP_CODE_400);
     }
     // 检查文件上传过程是否有错
     if ($_FILES[$key]["error"] != 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "8"), MConst::HTTP_CODE_400);
     }
     $fileName = $_FILES[$key]["name"];
     $type = MiniUtil::getMimeType($fileName);
     $size = $_FILES[$key]["size"];
     $tmpName = $_FILES[$key]["tmp_name"];
     // 验证文件是否已经上传成功
     if (file_exists($tmpName) === false) {
         throw new MFilesException(Yii::t('api', MConst::INTERNAL_SERVER_ERROR), MConst::HTTP_CODE_500);
     }
     // 检查文件上传错误
     if (filesize($tmpName) != $size) {
         throw new MFilesException(Yii::t('api', "The file upload error!"), MConst::HTTP_CODE_400);
     }
     //断点文件上传
     if ($this->isBreakpointUpload()) {
         $filesController = new MFilePutController();
         $filesController->invoke($uri);
     } else {
         //完整文件上传
         $signature = MiniUtil::getFileHash($tmpName);
         // 解析路径
         $path = MiniHttp::getParam("path", "");
         $path = MiniUtil::specialWordReplace($path);
         $parentPath = dirname($path);
         $user = MUserManager::getInstance()->getCurrentUser();
         $parentFile = MiniFile::getInstance()->getByPath($parentPath);
         //如果目录存在,且该目录is_delete=1,则把目录状态删除状态修改为0
         if (!empty($parentFile) && $parentFile['is_deleted'] == 1) {
             $values = array();
             $values['is_deleted'] = false;
             MiniFile::getInstance()->updateByPath($parentPath, $values);
         } else {
             //如果是根目录,则不用新建目录
             //否则会创建文件名名称的文件夹出来,而且目标文件位于该文件夹的下面
             if (!MiniUtil::isRootPath($parentPath, $user["id"])) {
                 MiniFile::getInstance()->createFolder($parentPath, $user['id']);
             }
         }
         $createFileHandler->size = $size;
         $createFileHandler->parent_path = MUtils::convertStandardPath($parentPath);
         $createFileHandler->file_name = MiniUtil::specialWordReplace($fileName);
         $createFileHandler->root = $root;
         $createFileHandler->path = MUtils::convertStandardPath($path);
         $createFileHandler->type = $type;
         // 文件不存在,保存文件
         $createFileHandler->saveFile($tmpName, $signature, $size);
         // 保存文件meta
         $createFileHandler->saveFileMeta();
         // 处理不同端,不同返回值
         if (MUserManager::getInstance()->isWeb() === true) {
             $createFileHandler->buildWebResponse();
             return;
         }
         $createFileHandler->buildResult();
     }
 }
Ejemplo n.º 18
0
 /**
  * 设置站点信息
  * @param $site
  * @return array
  */
 public function settingSiteInfo($site)
 {
     //迷你存储没有启用,将判断用户存储路径的完整性
     $storeData = MiniUtil::getPluginMiniStoreData();
     if (empty($storeData)) {
         $fileStorePath = $site['fileStorePath'];
         //文件存储路径的合法性检测
         if (is_dir($fileStorePath) == false) {
             return array('success' => false, 'msg' => 'dir_is_not_exist');
         }
         //
         // 判断父目录是否存在
         //
         if (file_exists(dirname($fileStorePath)) == false) {
             return array('success' => false, 'msg' => 'parent_dir_is_not_exist');
         }
         //
         // 文件不存在
         //
         if (file_exists($fileStorePath) == false) {
             mkdir($fileStorePath);
             chmod($fileStorePath, 0755);
         }
         //
         // 文件夹不可写
         //
         if (is_writable($fileStorePath) == false) {
             return array('success' => false, 'msg' => 'dir_is_not_writable');
         }
         //修改文件存储配置
         $this->setStorePath($site['fileStorePath']);
     }
     MiniOption::getInstance()->setOptionValue("miniyun_host", $site['miniyun_host']);
     MiniOption::getInstance()->setOptionValue("site_title", $site['siteTitle']);
     MiniOption::getInstance()->setOptionValue("site_name", $site['siteName']);
     MiniOption::getInstance()->setOptionValue("site_default_space", $site['siteDefaultSpace']);
     MiniOption::getInstance()->setOptionValue("site_company", $site['siteCompany']);
     MiniOption::getInstance()->setOptionValue("user_register_enabled", $site['userRegisterEnabled']);
     //如果是混合云版,则调整迷你存储的访问地址
     if (MiniUtil::isMixCloudVersion()) {
         $plugins = MiniUtil::getActivedPluginsInfo();
         if (!empty($plugins)) {
             foreach ($plugins as $plugin) {
                 if ($plugin["name"] === "miniStore") {
                     //创建默认迷你存储站点
                     PluginMiniStoreNode::getInstance()->createDefault();
                 }
             }
         }
     }
     return array('success' => true);
 }
Ejemplo n.º 19
0
 /**
  * 把系统中的中文文件名转化为拼音
  */
 public function updateAllFileNamePinyin()
 {
     $criteria = new CDbCriteria();
     $criteria->order = "-id";
     $items = UserFile::model()->findAll($criteria);
     foreach ($items as $item) {
         if ($item->file_name_pinyin == null) {
             //把文件名转化为拼音
             $name = $item->file_name;
             $item->file_name_pinyin = MiniUtil::getPinYinByName($name);
             $item->save();
         }
     }
 }
Ejemplo n.º 20
0
 /**
  * 获得有效文件下载服务器节点
  * 找到min(downloaded_file_count) and status=1的记录分配
  * @param string $signature 文件内容hash
  * @return array
  */
 private function getDownloadNode($signature)
 {
     $version = MiniVersion::getInstance()->getBySignature($signature);
     if (!empty($version)) {
         $metaKey = "store_id";
         $meta = MiniVersionMeta::getInstance()->getMeta($version["id"], $metaKey);
         if (!empty($meta)) {
             $value = $meta["meta_value"];
             $ids = explode(",", $value);
             $nodes = $this->getNodeList();
             $validNodes = array();
             foreach ($nodes as $node) {
                 //先找到当前文件存储的节点
                 $isValidNode = false;
                 foreach ($ids as $validNodeId) {
                     if ($validNodeId == $node["id"]) {
                         $isValidNode = true;
                     }
                 }
                 if (!$isValidNode) {
                     continue;
                 }
                 //然后判断节点是否有效,并在有效的节点找到下载次数最小的节点
                 if ($node["status"] == 1) {
                     array_push($validNodes, $node);
                 }
             }
             //选出downloaded_file_count最小的个节点
             $validNodes = MiniUtil::arraySort($validNodes, "downloaded_file_count", SORT_ASC);
             $nodes = MiniUtil::getFistArray($validNodes, 1);
             if (count($nodes) > 0) {
                 $node = $nodes[0];
                 $urlInfo = parse_url($node["host"]);
                 if ($urlInfo["host"] == "127.0.0.1") {
                     //说明迷你存储在本机,直接把127.0.0.1替换为迷你存储端口
                     $defaultHost = MiniHttp::getMiniHost();
                     $miniHostInfo = parse_url($defaultHost);
                     $node['host'] = $miniHostInfo["scheme"] . "://" . $miniHostInfo["host"] . ":" . $urlInfo["port"] . $miniHostInfo["path"];
                 }
                 return $node;
             }
             return null;
         }
     }
     return null;
 }
Ejemplo n.º 21
0
 /**
  * 创建事件
  */
 public function createEvent($userId, $userDeviceId, $action, $path, $context)
 {
     $eventUuid = MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID);
     MiniEvent::getInstance()->createEvent($userId, $userDeviceId, $action, $path, $context, $eventUuid, $extends = NULL);
 }
Ejemplo n.º 22
0
 /**
  * 根据文件名获得适配该文件名的icon地址
  * @param $fileName
  * @return string
  */
 public static function getIcon4File($fileName)
 {
     $iconName = "page_white.png";
     $ext = MiniUtil::getFileExtension($fileName);
     if (!empty($ext)) {
         $type = "page_white";
         if ($ext === "pdf") {
             $type = "page-white-acrobat";
         }
         if ($ext === "psd") {
             $type = "page-white-paint";
         }
         $mimeTypes = array("c", "c++", "m", "php", "java", "h", "py", "js", "css", "xml", "sql");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-code";
             }
         }
         $mimeTypes = array("zip", "rar", "7z", "gz");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-compressed";
             }
         }
         $mimeTypes = array("iso");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-dvd";
             }
         }
         $mimeTypes = array("xls", "xlsx");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-excel";
             }
         }
         $mimeTypes = array("mp4", "rm", "avi", "rmvb", "mov", "asf", "wmv", "3gp", "flv");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-film";
             }
         }
         $mimeTypes = array("exe", "dll");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-gear";
             }
         }
         $mimeTypes = array("jpg", "jpeg", "png", "bmp", "gif");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-picture";
             }
         }
         $mimeTypes = array("ppt", "pptx");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-powerpoint";
             }
         }
         $mimeTypes = array("mp3", "mid", "wav", "ape", "flac");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-sound";
             }
         }
         $mimeTypes = array("doc", "docx");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-word";
             }
         }
         $iconName = $type . ".png";
     }
     return $iconName;
 }
Ejemplo n.º 23
0
 /**
  * 计算文件附加属性
  * @param string $deviceName
  * @param int $fileSize
  * @param int $versionId
  * @param string $action
  * @param int $userId
  * @param string $userNick
  * @param string $versions
  * @return string
  */
 public static function getFileVersions($deviceName, $fileSize, $versionId, $action, $userId, $userNick, $versions = "a:0:{}")
 {
     $versions = is_null($versions) || empty($versions) ? "a:0:{}" : $versions;
     $version = array();
     $version["type"] = $action;
     $version["version_id"] = $versionId;
     $version["user_id"] = $userId;
     $version["user_nick"] = $userNick;
     $version["device_name"] = $deviceName;
     $version["file_size"] = $fileSize;
     $version["datetime"] = MiniUtil::getCurrentTime();
     $versions = @unserialize($versions);
     if (!$versions) {
         $versions = array();
     }
     // 当文件历史版本超过一定数量后,扎断处理
     $count = count($versions);
     $fileMaxVersion = MiniConst::MAX_VERSION_COUNT;
     if ($count >= $fileMaxVersion) {
         $limit = $count - $fileMaxVersion + 1;
         $versions = CUtils::mergeFileMetaVersion($versions, $limit);
     }
     array_push($versions, $version);
     return serialize($versions);
 }
Ejemplo n.º 24
0
 /**
  * 
  * 执行文件夹删除
  * @param UserFile $file
  */
 public function delete($parenFile)
 {
     $share_filter = MSharesFilter::init();
     $share_filter->handlerCheckByFile($this->_userId, $parenFile);
     //
     // 取消共享
     //
     if ($parenFile['file_type'] == 2 && $parenFile['user_id'] != $this->_userId || $parenFile['file_type'] == 3) {
         $parenFile = UserFile::model()->findByAttributes(array('file_path' => $share_filter->slaves[$this->_userId], 'is_deleted' => 0));
         if (!$parenFile) {
             throw new ApiException("Not found");
         }
         $handler = new ShareManager();
         $handler->_userId = $share_filter->operator;
         $handler->_id = $parenFile["id"];
         try {
             $handler->invoke(ShareManager::CANCEL_SHARED);
         } catch (Exception $e) {
             throw new ApiException("Not found");
         }
         return;
     }
     // 更新每个元素以及子元素
     $parentPath = $parenFile["file_path"];
     $handler = new UserFile();
     $files = $handler->getFilesByPath($parentPath);
     // 轮询删除
     foreach ($files as $file) {
         if ($file["is_deleted"]) {
             continue;
         }
         // 已经删除的文件不做操作
         $file["event_uuid"] = MiniUtil::getEventRandomString(46);
         if ($file["file_type"] == 0) {
             if ($file["is_deleted"]) {
                 continue;
             }
             // 已经删除的文件不做操作
             $file["is_deleted"] = 1;
             $file->save();
             // 创建版本信息
             $this->handleFileMeta($file["file_path"], $file["version_id"], $file['user_id'], $this->_userNick, $this->_deviceName, $file['file_size']);
             // 创建事件
             MiniEvent::getInstance()->createEvent($file['user_id'], $this->_deviceId, $this->_action, $file["file_path"], $file["file_path"], $file["event_uuid"]);
             $share_filter->handlerAction($this->_action, $this->_deviceId, $file["file_path"], $file["file_path"]);
             continue;
         }
         $this->delete($file);
         $file["is_deleted"] = 1;
         $file->save();
         // 创建事件
         MiniEvent::getInstance()->createEvent($file['user_id'], $this->_deviceId, $this->_action, $file["file_path"], $file["file_path"], $file["event_uuid"]);
         $share_filter->handlerAction($this->_action, $this->_deviceId, $file["file_path"], $file["file_path"]);
     }
     $parenFile["event_uuid"] = MiniUtil::getEventRandomString(46);
     $parenFile["is_deleted"] = 1;
     $parenFile->save();
     // 创建事件
     MiniEvent::getInstance()->createEvent($parenFile['user_id'], $this->_deviceId, $this->_action, $parenFile["file_path"], $parenFile["file_path"], $parenFile["event_uuid"]);
     $share_filter->handlerAction($this->_action, $this->_deviceId, $parenFile["file_path"], $parenFile["file_path"]);
     //
     // 删除共享目录
     //
     if ($share_filter->_is_shared_path && $share_filter->operator == $share_filter->master) {
         $id = $parenFile["id"];
         $handler = new ShareManager();
         $handler->_userId = $share_filter->operator;
         $handler->_id = $id;
         try {
             $handler->invoke(ShareManager::CANCEL_SHARED);
         } catch (Exception $e) {
             throw new ApiException('Internal Server Error');
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * 全部还原
  */
 public function revertFileAll()
 {
     $models = $this->findAllByAttributes(array('is_deleted' => 1));
     $device_id = Yii::app()->session["deviceId"];
     foreach ($models as $model) {
         $shareFilter = MSharesFilter::init();
         $shareFilter->handlerCheckByFile($model['user_id'], $model);
         $user_id = $model['user_id'];
         $path = $model['file_path'];
         $context = $path;
         $event_uuid = MiniUtil::getEventRandomString(46);
         $action = 0;
         // 修改文件
         if ($model['file_type'] == 0) {
             //
             // 如果是文件,需要创建版本
             //
             $user = Yii::app()->session['user'];
             $device = UserDevice::model()->findByUserIdAndType($user['id'], CConst::DEVICE_WEB);
             $deviceName = $device["user_device_name"];
             $this->_saveFileMeta($path, $model['version_id'], $user['id'], $user['name'], CConst::WEB_RESTORE, $deviceName, $model['file_size']);
             $action = CConst::CREATE_FILE;
             $version = FileVersion::model()->findByPk($model["version_id"]);
             $context = array("hash" => $version['file_signature'], "rev" => (int) $model["version_id"], "bytes" => (int) $model["file_size"]);
             $context = serialize($context);
         }
         $model['event_uuid'] = $event_uuid;
         $model["is_deleted"] = 0;
         $model->save();
         MiniEvent::getInstance()->createEvent($user_id, $device_id, $action, $path, $context, $event_uuid, $shareFilter->type);
     }
     return true;
 }
Ejemplo n.º 26
0
 /**
  *
  * 执行插入数据等操作
  *
  * @since 1.0.4
  */
 public function executeMigrate()
 {
     $data = date("Y-m-d H:i:s", time());
     $dbType = "mysql";
     $extend = "";
     if ($dbType == "mysql") {
         $extend = "ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
     }
     // 新数据库版本的代码,可以是创建新表、修改表结构、增删数据 等等
     $this->createTable(DB_PREFIX . '_access_logs', array('id' => 'pk', 'namespace' => 'varchar(45) NOT NULL', 'start_time' => 'bigint(14) NOT NULL', 'end_time' => 'bigint(20) NOT NULL', 'appliction_id' => 'int(11) NOT NULL', 'use_time' => 'bigint(20) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createTable(DB_PREFIX . '_online_devices', array('id' => 'pk', 'user_id' => 'int(11) NOT NULL', 'device_id' => 'int(11) NOT NULL', 'application_id' => 'int(11) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createTable(DB_PREFIX . '_pv', array('id' => 'pk', 'current_date' => 'varchar(32) NOT NULL', 'application_id' => 'int(11) NOT NULL', 'hour_period' => 'int(11) NOT NULL', 'namespace' => 'varchar(255) NOT NULL', 'use_count' => 'int(11) NOT NULL', 'use_time' => 'int(11) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("current_date", DB_PREFIX . '_pv', "current_date,application_id,hour_period,namespace");
     $this->createTable(DB_PREFIX . '_error_logs', array('id' => 'pk', 'namespace' => 'varchar(45) NOT NULL', 'memo' => 'text NOT NULL', 'appliction_id' => 'int(11) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createTable(DB_PREFIX . '_events', array('id' => 'pk', 'user_id' => 'int(11) NOT NULL', 'user_device_id' => 'int(11) NOT NULL', 'action' => 'int(11) NOT NULL', 'file_path' => 'varchar(300) NOT NULL', 'context' => 'text NOT NULL', 'event_uuid' => 'char(64) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("user_id", DB_PREFIX . '_events', "user_id, user_device_id, created_at");
     $this->createIndex("id", DB_PREFIX . '_events', "id, user_id, user_device_id, created_at");
     $this->createIndex("event_uuid", DB_PREFIX . '_events', "event_uuid");
     $this->createTable(DB_PREFIX . '_files', array('id' => 'pk', 'user_id' => 'int(11) NOT NULL', 'file_type' => 'int(11) NOT NULL', 'parent_file_id' => 'int(11) NOT NULL', 'file_create_time' => 'bigint(20) NOT NULL', 'file_update_time' => 'bigint(20) NOT NULL', 'file_name' => 'varchar(255) NOT NULL', 'version_id' => 'int(11) NOT NULL', 'file_size' => 'bigint(64) NOT NULL', 'file_path' => 'varchar(300) NOT NULL', 'event_uuid' => 'char(64) NOT NULL', 'is_deleted' => 'tinyint(4) NOT NULL DEFAULT \'0\'', 'mime_type' => 'varchar(64)', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("file_user_id", DB_PREFIX . '_files', "user_id");
     $this->createIndex("file_file_type", DB_PREFIX . '_files', "file_type");
     $this->createIndex("file_parent_file_id", DB_PREFIX . '_files', "parent_file_id");
     $this->createIndex("file_user_id_p", DB_PREFIX . '_files', "user_id, parent_file_id");
     $this->createIndex("file_file_path", DB_PREFIX . '_files', "file_path");
     $this->createIndex("file_user_id_file_type", DB_PREFIX . '_files', "user_id, file_type");
     $this->createIndex("file_file_path_is_deleted", DB_PREFIX . '_files', "file_path, is_deleted");
     $this->createIndex("file_user_id_parent_is_deleted", DB_PREFIX . '_files', "user_id, parent_file_id, is_deleted");
     $this->createTable(DB_PREFIX . '_file_metas', array('id' => 'pk', 'file_path' => 'varchar(255) NOT NULL', 'meta_key' => 'varchar(255) NOT NULL', 'meta_value' => 'text NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("file_path", DB_PREFIX . '_file_metas', "file_path");
     $this->createTable(DB_PREFIX . '_file_versions', array('id' => 'pk', 'file_signature' => 'varchar(64) NOT NULL', 'file_size' => 'bigint(64) NOT NULL', 'ref_count' => 'int(11) NOT NULL', 'mime_type' => 'varchar(255)', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("file_signature", DB_PREFIX . '_file_versions', "file_signature");
     $this->createTable(DB_PREFIX . '_file_version_metas', array('id' => 'pk', 'version_id' => 'int(11) NOT NULL', 'meta_key' => 'varchar(255) NOT NULL', 'meta_value' => 'text NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createTable(DB_PREFIX . '_options', array('option_id' => 'pk', 'option_name' => 'varchar(64) NOT NULL DEFAULT \'\'', 'option_value' => 'longtext NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("option_name", DB_PREFIX . '_options', "option_name", true);
     $this->createTable(DB_PREFIX . '_share_files', array('id' => 'pk', 'share_key' => 'varchar(45) NOT NULL', 'file_id' => 'int(11) NOT NULL', 'password' => 'varchar(45) NOT NULL DEFAULT \'-1\'', 'down_count' => 'int(11) NOT NULL DEFAULT \'0\'', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("share_file_share_key", DB_PREFIX . '_share_files', "share_key");
     $this->createIndex("share_file_file_id", DB_PREFIX . '_share_files', "file_id");
     $this->createTable(DB_PREFIX . '_users', array('id' => 'pk', 'user_uuid' => 'varchar(32) NOT NULL', 'user_name' => 'varchar(255) NOT NULL', 'user_pass' => 'varchar(255) NOT NULL', 'user_status' => 'tinyint(1) NOT NULL DEFAULT \'1\'', 'salt' => 'char(6) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("user_name", DB_PREFIX . '_users', "user_name", true);
     $this->createIndex("user_uuid", DB_PREFIX . '_users', "user_uuid");
     $salt = MiniUtil::genRandomString(6);
     $user_pass = MiniUtil::signPassword("admin", $salt);
     $this->insert(DB_PREFIX . '_users', array("id" => 1, "user_uuid" => uniqid(), "user_name" => "admin", "user_pass" => $user_pass, "user_status" => 1, "salt" => $salt, "created_at" => $data, "updated_at" => $data));
     $this->createTable(DB_PREFIX . '_user_metas', array('id' => 'pk', 'user_id' => 'int(11) NOT NULL', 'meta_key' => 'varchar(255) NOT NULL', 'meta_value' => 'text NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->insert(DB_PREFIX . '_user_metas', array("id" => 1, "user_id" => 1, "meta_key" => "is_admin", "meta_value" => "1", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_user_metas', array("id" => 2, "user_id" => 1, "meta_key" => "space", "meta_value" => "1048576", "created_at" => $data, "updated_at" => $data));
     $this->createTable(DB_PREFIX . '_user_devices', array('id' => 'pk', 'user_device_uuid' => 'varchar(32) NOT NULL', 'user_id' => 'int(11) NOT NULL', 'user_device_type' => 'int(11) NOT NULL', 'user_device_name' => 'varchar(255) NOT NULL', 'user_device_info' => 'varchar(255) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("user_device_device_uuid", DB_PREFIX . '_user_devices', "user_device_uuid");
     $this->createIndex("user_device_user_id", DB_PREFIX . '_user_devices', "user_id");
     $this->createIndex("user_device_user_id_and_type", DB_PREFIX . '_user_devices', "user_id, user_device_type");
     $this->createIndex("user_device_user_id_and_type_uuid", DB_PREFIX . '_user_devices', "user_id, user_device_type, user_device_uuid");
     $this->execute("INSERT INTO `" . DB_PREFIX . "_user_devices` (`id`, `user_device_uuid`, `user_id`, `user_device_type`, `user_device_name`, `user_device_info`, `created_at`, `updated_at`) VALUES (1, '4e1e434de8808a289f064da60cf9a48d', 1, 1, 'web', 'admin_Mozilla/5.0', '{$data}', '{$data}');;");
     $this->createTable(DB_PREFIX . '_user_devices_metas', array('id' => 'pk', 'user_id' => 'int(11) NOT NULL', 'device_id' => 'int(11) NOT NULL', 'meta_name' => 'varchar(255) NOT NULL', 'meta_value' => 'text NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createTable(DB_PREFIX . '_file_star', array('id' => 'pk', 'user_id' => 'int(11) NOT NULL', 'file_id' => 'int(11) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("file_star_user_id", DB_PREFIX . '_file_star', "user_id, file_id");
     $this->createTable(DB_PREFIX . '_file_exifs', array('id' => 'pk', 'version_id' => 'int(11) NOT NULL', 'latitude' => 'varchar(11)', 'longtitude' => 'varchar(11)', 'exif' => 'text', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createTable(DB_PREFIX . '_auth_codes', array('code' => 'varchar(40) NOT NULL', 'client_id' => 'varchar(32) NOT NULL', 'redirect_uri' => 'varchar(200) NOT NULL', 'expires' => 'int(11) NOT NULL', 'scope' => 'varchar(250)', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL', 'PRIMARY KEY (`code`)'), $extend);
     $this->createTable(DB_PREFIX . '_clients', array('id' => 'pk', 'user_id' => 'int(11)', 'client_name' => 'varchar(255) NOT NULL', 'client_id' => 'varchar(32) NOT NULL', 'client_secret' => 'varchar(32) NOT NULL', 'redirect_uri' => 'varchar(200)', 'enabled' => 'tinyint(1) NOT NULL DEFAULT \'1\'', 'description' => 'text', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), $extend);
     $this->createIndex("client_id", DB_PREFIX . '_clients', "client_id");
     $this->insert(DB_PREFIX . '_clients', array("id" => 1, "user_id" => -1, "client_name" => "MiniyunWeb", "client_id" => "JsQCsjF3yr7KACyT", "client_secret" => "bqGeM4Yrjs3tncJZ", "redirect_uri" => "", "enabled" => 1, "description" => "MiniyunWeb", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_clients', array("id" => 2, "user_id" => -1, "client_name" => "MiniyunDesktopWindows", "client_id" => "d6n6Hy8CtSFEVqNh", "client_secret" => "e6yvZuKEBZQe9TdA", "redirect_uri" => "", "enabled" => 1, "description" => "MiniyunDesktopWindows", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_clients', array("id" => 3, "user_id" => -1, "client_name" => "MiniyunDesktopMac", "client_id" => "c9Sxzc47pnmavzfy", "client_secret" => "9ZQ4bsxEjBntFyXN", "redirect_uri" => "", "enabled" => 1, "description" => "MiniyunDesktopMac", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_clients', array("id" => 4, "user_id" => -1, "client_name" => "MiniyunAndroidPhone", "client_id" => "MsUEu69sHtcDDeCp", "client_secret" => "5ABU5XPzsR6tTxeK", "redirect_uri" => "", "enabled" => 1, "description" => "MiniyunAndroidPhone", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_clients', array("id" => 5, "user_id" => -1, "client_name" => "MiniyunDesktopLinux", "client_id" => "V8G9svK8VDzezLum", "client_secret" => "waACXBybj9QXhE3a", "redirect_uri" => "", "enabled" => 1, "description" => "MiniyunDesktopLinux", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_clients', array("id" => 6, "user_id" => -1, "client_name" => "MiniyuniPhone", "client_id" => "UmxT6CuwQYrtJGFp", "client_secret" => "GxsxayamApUSwTq9", "redirect_uri" => "", "enabled" => 1, "description" => "MiniyuniPhone", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_clients', array("id" => 7, "user_id" => -1, "client_name" => "MiniyuniPad", "client_id" => "Lt7hPcA6nuX38FY4", "client_secret" => "vV2RpBsZBE4pNGG2", "redirect_uri" => "", "enabled" => 1, "description" => "MiniyuniPad", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_clients', array("id" => 8, "user_id" => -1, "client_name" => "MiniyunTest", "client_id" => "c1d8132456e5d2eef452", "client_secret" => "c988b0cc440c5dcde2d39e4d47d0baf4", "redirect_uri" => "", "enabled" => 1, "description" => "MiniyunTest", "created_at" => $data, "updated_at" => $data));
     $this->createTable(DB_PREFIX . '_refresh_token', array('client_id' => 'varchar(32) NOT NULL', 'oauth_token' => 'varchar(32) NOT NULL', 'refresh_token' => 'varchar(32) NOT NULL', 'expires' => 'int(11) NOT NULL', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL', 'PRIMARY KEY (`oauth_token`)'), $extend);
     $this->createTable(DB_PREFIX . '_tokens', array('oauth_token' => 'varchar(40) NOT NULL', 'client_id' => 'varchar(32) NOT NULL', 'device_id' => 'int(11) NOT NULL', 'expires' => 'int(11) NOT NULL', 'scope' => 'varchar(200)', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL', 'PRIMARY KEY (`oauth_token`)'), $extend);
     $this->createIndex("tokens_client_id", DB_PREFIX . '_tokens', "client_id");
     $this->createIndex("tokens_oauth_token", DB_PREFIX . '_tokens', "oauth_token");
     $this->createIndex("tokens_oauth_token_client_id", DB_PREFIX . '_tokens', "oauth_token, client_id");
     //模版文件中 初始化option数据
     $this->insert(DB_PREFIX . '_options', array("option_id" => 1, "option_name" => "site_url", "option_value" => "NETLOC", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_options', array("option_id" => 2, "option_name" => "site_title", "option_value" => "新型文件管理平台", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_options', array("option_id" => 3, "option_name" => "site_name", "option_value" => "迷你云", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_options', array("option_id" => 4, "option_name" => "site_logo_small_url", "option_value" => "/static/images/logo.png", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_options', array("option_id" => 5, "option_name" => "site_company", "option_value" => "成都迷你云科技有限公司", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_options', array("option_id" => 6, "option_name" => "user_register_enabled", "option_value" => "1", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_options', array("option_id" => 7, "option_name" => "mid", "option_value" => "ORIGINAL_MID", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_options', array("option_id" => 8, "option_name" => "site_logo_url", "option_value" => "/static/images/logo.png", "created_at" => $data, "updated_at" => $data));
     $this->insert(DB_PREFIX . '_options', array("option_id" => 9, "option_name" => "site_default_space", "option_value" => "1048576", "created_at" => $data, "updated_at" => $data));
 }
Ejemplo n.º 27
0
 /**
  * 取消共享,删除权限
  */
 public function delete($filePath)
 {
     $arr = explode('/', $filePath);
     $isRoot = false;
     $isMine = false;
     if (count($arr) == 3) {
         $isRoot = true;
     }
     $fileOwnerId = $arr[1];
     $currentUser = $this->user;
     $currentUserId = $currentUser['user_id'];
     if ($fileOwnerId == $currentUserId) {
         $isMine = true;
     }
     if ($isRoot && !$isMine) {
         //如果是在根目录下且不是自己的目录 则后台控制不准取消共享
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_409);
     }
     $this->share_filter = MSharesFilter::init();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $userDeviceId = $device["device_id"];
     $this->share_filter->slaves = $this->getSlaveIdsByPath($filePath);
     MiniUserPrivilege::getInstance()->deleteByFilePath($filePath);
     MiniGroupPrivilege::getInstance()->deleteByFilePath($filePath);
     MiniFile::getInstance()->cancelPublic($filePath);
     $eventAction = MConst::CANCEL_SHARED;
     MiniEvent::getInstance()->createEvent($this->user['id'], $userDeviceId, $eventAction, $filePath, $filePath, MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID), $this->share_filter->type);
     $this->share_filter->is_shared = true;
     //把共享目录下的共享目录设置记录删除
     MiniFileMeta::getInstance()->deleteFileMetaByPath($filePath, "share_model");
     // 为每个共享用户创建事件
     $this->share_filter->handlerAction($eventAction, $userDeviceId, $filePath, $filePath);
     return true;
 }
Ejemplo n.º 28
0
 /**
  *
  * 获得微信信息加密的Token
  * @since 1.0.7
  */
 public static function getWxToken()
 {
     $wxToken = MiniOption::getInstance()->getOptionValue("wx_token");
     if ($wxToken === NULL) {
         $wxToken = md5(MiniUtil::random(32));
         MiniOption::getInstance()->setOptionValue("wx_token", $wxToken);
     }
     return $wxToken;
 }
Ejemplo n.º 29
0
 /**
  * 
  * 根据路径创建目录
  */
 public function handleCreateByPath($path)
 {
     if ($path == "/{$this->_userId}" || $path == "\\" || $path == "/{$this->_userId}/") {
         return 0;
     }
     $event_uuid = MiniUtil::getEventRandomString(46);
     $file = UserFile::model()->find(array('condition' => 'file_path=:file_path', 'params' => array(':file_path' => $path)));
     if (empty($file) || is_null($file)) {
         $pathInfo = CUtils::pathinfo_utf($path);
         $parenPath = $pathInfo["dirname"];
         $fileName = $pathInfo["basename"];
         $parentId = $this->handleCreateByPath($parenPath);
         $file = new UserFile();
         $file['user_id'] = $this->_userId;
         $file['file_type'] = 1;
         $file['parent_file_id'] = $parentId;
         $file['file_create_time'] = time();
         $file['file_update_time'] = time();
         $file['file_name'] = $fileName;
         $file['file_path'] = $path;
         $file['is_deleted'] = 0;
         $file['version_id'] = 0;
         $file['file_size'] = 0;
         $file["event_uuid"] = $event_uuid;
         $file->save();
         $file['sort'] = $file['id'];
         $file->save();
         // 创建事件
         MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, $this->_action, $path, $path, $event_uuid, $this->share_filter->type);
         $this->share_filter->handlerAction($this->_action, $this->_deviceId, $path, $path);
     } else {
         //
         // 回收站插件: -1保留值 0正常 1删除
         // 这里由is_deleted==1 特别修改为 is_deleted!=0
         // By Kindac 2012/11/5
         //
         if ($file["is_deleted"] != 0) {
             $file["is_deleted"] = 0;
             $file["file_update_time"] = time();
             $file["event_uuid"] = $event_uuid;
             //
             // 递归创建父目录
             //
             $pathInfo = CUtils::pathinfo_utf($path);
             $parenPath = $pathInfo["dirname"];
             $this->handleCreateByPath($parenPath);
             $file->save();
             MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, $this->_action, $path, $path, $event_uuid, $this->share_filter->type);
             $this->share_filter->handlerAction($this->_action, $this->_deviceId, $path, $path);
         }
     }
     return $file["id"];
 }
Ejemplo n.º 30
0
 /**
  * 处理返回值
  */
 public function buildResult($query_db_file, $to_path = null)
 {
     // 处理不同端,不同返回值
     if (MUserManager::getInstance()->isWeb() === true) {
         $this->buildWebResponse();
         return;
     }
     if ($this->isEcho === false) {
         return;
     }
     $is_dir = true;
     $size = $query_db_file["file_size"];
     $response = array();
     if ($query_db_file["file_type"] == MConst::OBJECT_TYPE_FILE) {
         // 根据文件名后缀判断mime type
         $mime_type = MiniUtil::getMimeType($query_db_file["file_name"]);
         $is_dir = false;
         $response["mime_type"] = $mime_type;
         $response["thumb_exists"] = MUtils::isExistThumbnail($mime_type, (int) $query_db_file["file_size"]);
     }
     // 去除/{user_id}
     $path = CUtils::removeUserFromPath($query_db_file["file_path"]);
     $response["size"] = MUtils::getSizeByLocale($this->_locale, $size);
     $response["is_deleted"] = false;
     $response["bytes"] = intval($size);
     $response["modified"] = MUtils::formatIntTime($query_db_file["file_update_time"]);
     if ($to_path) {
         $path = $to_path;
     } else {
         $path = $query_db_file["file_path"];
     }
     $path_info = MUtils::pathinfo_utf($path);
     $path_info_out = MUtils::pathinfo_utf($this->to_share_filter->src_path);
     $path = MUtils::convertStandardPath($path_info_out['dirname'] . "/" . $path_info['basename']);
     $response["path"] = $path;
     $response["root"] = $this->_root;
     $response["is_dir"] = $is_dir;
     $response["rev"] = strval($query_db_file["version_id"]);
     $response["revision"] = intval($query_db_file["version_id"]);
     // 增加操作返回事件编码
     $response["event_uuid"] = $query_db_file["event_uuid"];
     echo json_encode($response);
 }