├── .gitignore ├── .index.html ├── JavaScript ├── Calendar.js ├── Contents.js ├── ContentsMain.js ├── CustomEditor.js ├── DatabaseView.js ├── FileView.js ├── Log.js ├── Main.js ├── PluginView.js ├── Session.js ├── SettingView.js ├── TextEditor.js ├── UserView.js └── include │ ├── AflLib.js │ ├── Gui.js │ └── md5.js ├── PHP ├── LocalDB.php ├── MainDB.php ├── Manager.php ├── Modules │ ├── Calendar.php │ ├── Contents.php │ ├── Files.php │ ├── GParams.php │ ├── Log.php │ ├── Params.php │ ├── Session.php │ └── Users.php └── include │ ├── Database.php │ ├── PostgreSQL.php │ └── SQLite.php ├── css ├── Gui.css ├── Main.css ├── TextEditor.css ├── images │ ├── close.svg │ ├── file.svg │ ├── folder.svg │ ├── max.svg │ ├── min.svg │ ├── normal.svg │ ├── talone.svg │ ├── tclose.svg │ └── topen.svg └── routeros.css ├── index.php └── save └── readme.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | .vscode 3 | save/.local.db 4 | robots.txt 5 | favicon.ico 6 | test.html 7 | -------------------------------------------------------------------------------- /.index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | [[SCRIPTS]] 9 |%s
\n", date("Y-m-d H:i:s", strtotime($contens["date"])), $contens["value"]); 633 | 634 | foreach($contens["childs"] as $child){ 635 | $body .= Self::outputContents($child); 636 | } 637 | return $body; 638 | } 639 | 640 | } -------------------------------------------------------------------------------- /PHP/Modules/Files.php: -------------------------------------------------------------------------------- 1 | "ファイルプラグイン", 6 | "VERSION"=>1.00, 7 | "DESCRIPTION"=>"ファイルデータの管理", 8 | "AUTHOR"=>"SoraKumo", 9 | "TABLES"=>[["t_log",0,1]] 10 | ]; 11 | public static function initModule(){ 12 | if(MG::DB()->isConnect() && !MG::DB()->isTable("files")){ 13 | MG::DB()->exec("create table files(files_id SERIAL PRIMARY KEY,files_parent INTEGER references files(files_id),files_kind INTEGER,users_id INTEGER references users(users_id),files_name TEXT,files_date TIMESTAMP with time zone,files_byte BYTEA);"); 14 | MG::DB()->exec("insert into files values(default,null,0,null,'[ROOT]',now(),null)"); 15 | } 16 | 17 | } 18 | public static function JS_createDir($parent,$name){ 19 | if(!MG::isAdmin()) 20 | return ["result"=>0,"message"=>"ディレクトリ作成 権限エラー"]; 21 | $id = Self::createDir($parent,$name); 22 | if($id === 0) 23 | return ["result" => 0, "message" => "フォルダの作成失敗"]; 24 | return ["result" => 1, "message" => "フォルダの作成", "value" => $id]; 25 | } 26 | public static function JS_setFileName($id,$name){ 27 | if(!MG::isAdmin()) 28 | return ["result"=>0,"message"=>"ファイル名変更 権限エラー"]; 29 | return Self::setFileName($id,$name); 30 | } 31 | public static function JS_deleteFiles($ids){ 32 | if(!MG::isAdmin()) 33 | return ["result"=>0,"message"=>"ファイル削除 権限エラー"]; 34 | return Self::deleteFiles($ids); 35 | } 36 | public static function JS_deleteFile($id){ 37 | if(!MG::isAdmin()) 38 | return ["result"=>0,"message"=>"ファイル削除 権限エラー"]; 39 | return Self::deleteFile($id); 40 | } 41 | public static function JS_getFileList($pid){ 42 | if(!MG::isAdmin()) 43 | return ["result"=>0,"message"=>"ファイルリスト取得 権限エラー"]; 44 | return Self::getFileList($pid); 45 | } 46 | public static function JS_getDirList(){ 47 | if(!MG::isAdmin()) 48 | return ["result"=>0,"message"=>"ディレクトリリスト取得 権限エラー"]; 49 | return Self::getDirList(); 50 | } 51 | public static function JS_getDirId($parent,$name){ 52 | if(!MG::isAdmin()) 53 | return ["result"=>0,"message"=>"ディレクトリリスト取得 権限エラー"]; 54 | $id = Self::getDirId(MG::getParam("parent"),MG::getParam("name")); 55 | if($id === null) 56 | return ["result"=>0,"message"=>"フォルダID取得 エラー"]; 57 | else 58 | return ["result"=>1,"message"=>"フォルダID取得","id"=>$id]; 59 | } 60 | public static function JS_uploadFile($parent,$name){ 61 | if(!MG::isAdmin()) 62 | return ["result"=>0,"message"=>"ファイルアップロード 権限エラー"]; 63 | if(MG::getUserCode() === null) 64 | $result = ["result"=>0,"message"=>"ファイルアップロード 権限エラー"]; 65 | else if(!isset($_SERVER['CONTENT_LENGTH'])) 66 | $result = ["result"=>0,"message"=>"ファイルアップロード パラメータエラー"]; 67 | else{ 68 | $file = fopen("php://input", "r"); 69 | $result = Self::saveFile($parent,$name,$file,$_SERVER['CONTENT_LENGTH']); 70 | fclose($file); 71 | } 72 | return $result; 73 | } 74 | public static function JS_download(){ 75 | if(MG::isParams(["id"])) 76 | Self::getFileStream(MG::getParam("id")); 77 | return null; 78 | } 79 | public static function getFileInfo($fileId){ 80 | return MG::DB()->gets("select files_name,files_kind,octet_length(files_byte),files_date from files where files_id=?",$fileId); 81 | } 82 | public static function getFile($fileId) 83 | { 84 | return MG::DB()->gets("select files_id as id,files_kind as kind,files_name as name,octet_length(files_byte) as size,files_date as date,encode(files_byte, 'base64') as value from files where files_id=? and files_kind=1", $fileId); 85 | } 86 | public static function setFile($pid,$name,$date,$value){ 87 | return MG::DB()->get( 88 | "insert into files values(default,?,1,?,?,?,decode(?,'base64')) returning files_id", 89 | $pid,MG::getUserCode(),$name,$date,$value); 90 | } 91 | public static function getFileStream($fileId){ 92 | $stmt = MG::DB()->query("select files_name,octet_length(files_byte),files_date,files_byte from files where files_id=? and files_kind=1",$fileId); 93 | $stmt->bindColumn(1, $name, PDO::PARAM_STR); 94 | $stmt->bindColumn(2, $size, PDO::PARAM_INT); 95 | $stmt->bindColumn(3, $date, PDO::PARAM_STR); 96 | $stmt->bindColumn(4, $fp, PDO::PARAM_LOB); 97 | 98 | if($stmt->fetch() === false) 99 | return; 100 | $httpDisposition= "inline;"; 101 | $contentType = "application/octet-stream"; 102 | $ext = substr($name, strrpos($name, '.') + 1); 103 | switch(strtolower($ext)){ 104 | case "png": 105 | $contentType = "image/png"; 106 | break; 107 | case "svg": 108 | $contentType = "image/svg+xml"; 109 | break; 110 | case "jpeg": 111 | case "jpg": 112 | $contentType = "image/jpeg"; 113 | break; 114 | case "gif": 115 | $contentType = "image/gif"; 116 | break; 117 | default: 118 | $httpDisposition= "attachment;"; 119 | break; 120 | } 121 | header("content-length: " . $size); 122 | header("Last-Modified: ". date("r", strtotime($date))); 123 | header("Content-type: $contentType"); 124 | header("Content-Disposition: $httpDisposition filename*=utf-8'jp'".urlencode($name)); 125 | fpassthru($fp); 126 | exit(0); 127 | 128 | } 129 | public static function getDirList(){ 130 | $values = MG::DB()->queryData("select files_id,files_parent,files_kind,files_name,files_date,octet_length(files_byte) as size 131 | from files where files_kind=0 order by files_name"); 132 | $hash = []; 133 | if($values!==null){ 134 | foreach($values as &$value){ 135 | $id = $value["files_id"]; 136 | $hash[$id] = [ 137 | "id"=>$value["files_id"], 138 | "parent"=>$value["files_parent"], 139 | "kind"=>$value["files_kind"], 140 | "name"=>$value["files_name"], 141 | "size"=>$value["size"], 142 | "files_date"=>null, 143 | "childs"=>[]]; 144 | } 145 | foreach($hash as $id=>&$file){ 146 | $parent = $file["parent"]; 147 | if($parent > 0) 148 | $hash[$parent]["childs"][] = &$file; 149 | } 150 | $result = ["result"=>1,"message"=>"フォルダリストの取得","value"=>$hash[1]]; 151 | } 152 | else 153 | $result = ["result"=>0,"message"=>"フォルダリストの取得 エラー"]; 154 | return $result; 155 | } 156 | public static function getFileList($parentId){ 157 | date_default_timezone_set("UTC"); 158 | $values = MG::DB()->queryData( 159 | "select files_id,files_parent,files_kind,files_name,files_date,octet_length(files_byte) as size 160 | from files where files_parent=? order by files_kind,files_name",$parentId); 161 | $files = []; 162 | if($values!==null){ 163 | foreach($values as &$value){ 164 | $files[] = [ 165 | "id"=>$value["files_id"], 166 | "parent"=>$value["files_parent"], 167 | "kind"=>$value["files_kind"], 168 | "name"=>$value["files_name"], 169 | "date"=>date("Y-m-d\TH:i:s\Z", strtotime($value["files_date"])), 170 | "size"=>$value["size"], 171 | "files_date"=>null, 172 | "childs"=>[]]; 173 | } 174 | $result = ["result"=>1,"message"=>"ファイルリストの取得","values"=>$files]; 175 | } 176 | else 177 | $result = ["result"=>0,"message"=>"ファイルリストの取得 エラー"]; 178 | return $result; 179 | } 180 | public static function getChildList($fileId){ 181 | $sql = sprintf("select files_id from files where files_parent=%d",$fileId); 182 | $values = MG::DB()->queryData2($sql); 183 | return $values; 184 | } 185 | public static function getFileId($parentId,$name){ 186 | //フォルダを分解 187 | $values = explode("/",$name); 188 | $p = $parentId; 189 | $count = count($values); 190 | for($i=0;$i<$count;$i++){ 191 | $name2 = $values[$i]; 192 | $id = MG::DB()->get("select files_id from files where files_parent=? and files_name=?", 193 | $p,$name2); 194 | if($id === null) 195 | return null; 196 | $p = $id; 197 | } 198 | return $id; 199 | } 200 | public static function setFileName($fileId,$name){ 201 | if(MG::DB()->exec("update files set files_name=? where files_id=?",$name,$fileId)>0){ 202 | return ["result"=>1,"message"=>"ファイル名の変更"]; 203 | } 204 | return ["result"=>0,"message"=>"ファイル名の変更 失敗"]; 205 | } 206 | 207 | public static function saveFile($parentId,$name,$file,$size){ 208 | $id = Self::getFileId(MG::getParam("parent"),MG::getParam("name")); 209 | if($id === null){ 210 | $row = MG::DB()->gets2("insert into files values(default,?,1,?,?,now(),?) returning files_id,octet_length(files_byte)", 211 | $parentId,MG::getUserCode(),$name,$file); 212 | }else{ 213 | $row = MG::DB()->gets2("update files set files_byte=?,user_data_id=?,files_date=now() where files_id=? returning files_id,octet_length(files_byte)", 214 | $file,MG::getUserCode(),$id); 215 | } 216 | 217 | if($row[0] < 1 || $row[1] != $size){ 218 | Self::deleteFile($row[0]); 219 | return ["result"=>0,"message"=>"ファイルアップロード エラー"]; 220 | } 221 | return ["result"=>1,"message"=>"ファイルアップロード","value"=>$row[0]]; 222 | } 223 | public static function deleteFiles($files){ 224 | foreach($files as $fileId){ 225 | $result = Self::deleteFile($fileId); 226 | if($result["result"] == 0) 227 | break; 228 | } 229 | return $result; 230 | } 231 | public static function deleteFile($fileId){ 232 | $fileId = (int)$fileId; 233 | if($fileId > 1){ 234 | //配下のオブジェクトを削除 235 | $childs = Self::getChildList($fileId); 236 | foreach($childs as $child){ 237 | Self::deleteFile($child[0]); 238 | } 239 | //ファイル削除 240 | $sql = sprintf("delete from files where files_id=%d", 241 | $fileId); 242 | if(MG::DB()->exec($sql) > 0){ 243 | return ["result"=>1,"message"=>"ファイル削除"]; 244 | } 245 | } 246 | return ["result"=>0,"message"=>"ファイル削除 失敗"]; 247 | } 248 | public static function createDir($parentId,$name){ 249 | //フォルダを分解 250 | $values = explode("/",ltrim($name, '/')); 251 | 252 | $p = $parentId; 253 | for($i=0;$i