diff --git a/cmd/config_init.go b/cmd/config_init.go index 12b11688..1dc0fd52 100644 --- a/cmd/config_init.go +++ b/cmd/config_init.go @@ -39,6 +39,7 @@ override the options.`, DisableExternal: mustGetBool(flags, "branding.disableExternal"), Files: mustGetString(flags, "branding.files"), }, + OnlyOffice: "", } ser := &settings.Server{ diff --git a/cmd/config_set.go b/cmd/config_set.go index 058f0d6b..d5485017 100644 --- a/cmd/config_set.go +++ b/cmd/config_set.go @@ -57,6 +57,8 @@ you want to change. Other options will remain unchanged.`, set.Branding.DisableExternal = mustGetBool(flags, flag.Name) case "branding.files": set.Branding.Files = mustGetString(flags, flag.Name) + case "onlyoffice": + set.OnlyOffice = mustGetString(flags, flag.Name) } }) diff --git a/files/file.go b/files/file.go index 675f7df1..f90c28e4 100644 --- a/files/file.go +++ b/files/file.go @@ -236,6 +236,9 @@ func (i *FileInfo) detectType(modify, saveContent, readHeader bool) error { i.Content = string(content) } return nil + case strings.HasPrefix(mimetype, "application/vnd.openxmlformats-officedocument"): + i.Type = "officedocument" + return nil default: i.Type = "blob" } diff --git a/frontend/src/i18n/ar.json b/frontend/src/i18n/ar.json index 92552b00..1ddd4098 100644 --- a/frontend/src/i18n/ar.json +++ b/frontend/src/i18n/ar.json @@ -190,6 +190,8 @@ "newPassword": "كلمة المرور الجديدة", "newPasswordConfirm": "تأكيد كلمة المرور", "newUser": "مستخدم جديد", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "كلمة المرور", "passwordUpdated": "تم تغيير كلمة المرور", "path": "", @@ -253,4 +255,4 @@ "seconds": "ثواني", "unit": "وحدة الوقت" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/de.json b/frontend/src/i18n/de.json index 1c3cf49e..b77c195c 100644 --- a/frontend/src/i18n/de.json +++ b/frontend/src/i18n/de.json @@ -190,6 +190,8 @@ "newPassword": "Ihr neues Passwort.", "newPasswordConfirm": "Bestätigen Sie Ihr neues Passwort", "newUser": "Neuer Benutzer", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Passwort", "passwordUpdated": "Passwort aktualisiert!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Sekunden", "unit": "Zeiteinheit" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index 2f11b7e5..91d3ac43 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -198,6 +198,8 @@ "newPassword": "Your new password", "newPasswordConfirm": "Confirm your new password", "newUser": "New User", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Password", "passwordUpdated": "Password updated!", "path": "Path", @@ -263,4 +265,4 @@ "seconds": "Seconds", "unit": "Time Unit" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/es.json b/frontend/src/i18n/es.json index 0fe23c79..b58da12a 100644 --- a/frontend/src/i18n/es.json +++ b/frontend/src/i18n/es.json @@ -190,6 +190,8 @@ "newPassword": "Tu nueva contraseña", "newPasswordConfirm": "Confirma tu contraseña", "newUser": "Nuevo usuario", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Contraseña", "passwordUpdated": "¡Contraseña actualizada!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Segundos", "unit": "Unidad" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/fr.json b/frontend/src/i18n/fr.json index d0bf31d4..d5a7dbdd 100644 --- a/frontend/src/i18n/fr.json +++ b/frontend/src/i18n/fr.json @@ -190,6 +190,8 @@ "newPassword": "Votre nouveau mot de passe", "newPasswordConfirm": "Confirmation du nouveau mot de passe", "newUser": "Nouvel Utilisateur", + "onlyOffice": "Intégration Only Office", + "onlyOfficeUrl": "URL vers OnlyOffice (laisser vide pour désactiver)", "password": "Mot de passe", "passwordUpdated": "Mot de passe mis à jour !", "path": "", @@ -253,4 +255,4 @@ "seconds": "Secondes", "unit": "Unité de temps" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/is.json b/frontend/src/i18n/is.json index a39ddc9f..fdabf2a6 100644 --- a/frontend/src/i18n/is.json +++ b/frontend/src/i18n/is.json @@ -190,6 +190,8 @@ "newPassword": "Nýja lykilorðið þitt", "newPasswordConfirm": "Staðfestu nýja lykilorðið", "newUser": "Nýr notandi", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Lykilorð", "passwordUpdated": "Lykilorð vistað!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Sekúndur", "unit": "Tímastilling" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/it.json b/frontend/src/i18n/it.json index e0b97ef0..c5e770d4 100644 --- a/frontend/src/i18n/it.json +++ b/frontend/src/i18n/it.json @@ -190,6 +190,8 @@ "newPassword": "La tua nuova password", "newPasswordConfirm": "Conferma la password", "newUser": "Nuovo utente", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Password", "passwordUpdated": "Password aggiornata!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Secondi", "unit": "Unità di tempo" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/ja.json b/frontend/src/i18n/ja.json index 21764b95..5c01723e 100644 --- a/frontend/src/i18n/ja.json +++ b/frontend/src/i18n/ja.json @@ -190,6 +190,8 @@ "newPassword": "新しいパスワード", "newPasswordConfirm": "新しいパスワードを確認します", "newUser": "新しいユーザー", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "パスワード", "passwordUpdated": "パスワードは更新されました!", "path": "", @@ -253,4 +255,4 @@ "seconds": "秒", "unit": "時間単位" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/ko.json b/frontend/src/i18n/ko.json index e898d750..dfbec985 100644 --- a/frontend/src/i18n/ko.json +++ b/frontend/src/i18n/ko.json @@ -190,6 +190,8 @@ "newPassword": "새로운 비밀번호", "newPasswordConfirm": "새로운 비밀번호 확인", "newUser": "새로운 사용자", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "비밀번호", "passwordUpdated": "비밀번호 수정 완료!", "path": "", @@ -253,4 +255,4 @@ "seconds": "초", "unit": "Time Unit" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/nl-be.json b/frontend/src/i18n/nl-be.json index f760ef44..83356e2e 100644 --- a/frontend/src/i18n/nl-be.json +++ b/frontend/src/i18n/nl-be.json @@ -190,6 +190,8 @@ "newPassword": "Uw nieuw wachtwoord", "newPasswordConfirm": "Bevestig uw nieuw wachtwoord", "newUser": "Nieuwe gebruiker", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Wachtwoord", "passwordUpdated": "Wachtwoord bijgewerkt!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Seconden", "unit": "Tijdseenheid" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/pl.json b/frontend/src/i18n/pl.json index 9712d64a..71bf5397 100644 --- a/frontend/src/i18n/pl.json +++ b/frontend/src/i18n/pl.json @@ -190,6 +190,8 @@ "newPassword": "Twoje nowe hasło", "newPasswordConfirm": "Potwierdź swoje hasło", "newUser": "Nowy Użytkownik", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Hasło", "passwordUpdated": "Hasło zostało zapisane!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Sekundy", "unit": "Jednostka czasu" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/pt-br.json b/frontend/src/i18n/pt-br.json index 045b803e..01b91cd4 100644 --- a/frontend/src/i18n/pt-br.json +++ b/frontend/src/i18n/pt-br.json @@ -190,6 +190,8 @@ "newPassword": "Nova senha", "newPasswordConfirm": "Confirme a nova senha", "newUser": "Novo usuário", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Senha", "passwordUpdated": "Senha atualizada!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Segundos", "unit": "Unidades de Tempo" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/pt.json b/frontend/src/i18n/pt.json index 59f26e95..20df73fe 100644 --- a/frontend/src/i18n/pt.json +++ b/frontend/src/i18n/pt.json @@ -190,6 +190,8 @@ "newPassword": "Nova palavra-passe", "newPasswordConfirm": "Confirme a nova palavra-passe", "newUser": "Novo utilizador", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Palavra-passe", "passwordUpdated": "Palavra-passe atualizada!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Segundos", "unit": "Unidades de tempo" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/ro.json b/frontend/src/i18n/ro.json index 28d18356..4cfbe734 100644 --- a/frontend/src/i18n/ro.json +++ b/frontend/src/i18n/ro.json @@ -190,6 +190,8 @@ "newPassword": "Noua ta parolă", "newPasswordConfirm": "Confirmă noua parolă", "newUser": "Utilizator nou", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Parola", "passwordUpdated": "Parola actualizată!", "path": "", @@ -253,4 +255,4 @@ "seconds": "Secunde", "unit": "Unitate de timp" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/ru.json b/frontend/src/i18n/ru.json index 1cdebf82..bd5d076e 100644 --- a/frontend/src/i18n/ru.json +++ b/frontend/src/i18n/ru.json @@ -189,6 +189,8 @@ "newPassword": "Новый пароль", "newPasswordConfirm": "Повтор нового пароля", "newUser": "Новый пользователь", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Пароль", "passwordUpdated": "Пароль обновлен!", "path": "Путь", @@ -252,4 +254,4 @@ "seconds": "Секунды", "unit": "Единица времени" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/sv-se.json b/frontend/src/i18n/sv-se.json index 046a342d..c0da4092 100644 --- a/frontend/src/i18n/sv-se.json +++ b/frontend/src/i18n/sv-se.json @@ -190,6 +190,8 @@ "newPassword": "Ditt nya lösenord", "newPasswordConfirm": "Bekräfta ditt nya lösenord", "newUser": "Ny användare", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "Lösenord", "passwordUpdated": "Lösenord uppdaterat", "path": "", @@ -253,4 +255,4 @@ "seconds": "Sekunder", "unit": "Tidsenhet" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/zh-cn.json b/frontend/src/i18n/zh-cn.json index 55367f12..c11c055d 100644 --- a/frontend/src/i18n/zh-cn.json +++ b/frontend/src/i18n/zh-cn.json @@ -193,6 +193,8 @@ "newPassword": "您的新密码", "newPasswordConfirm": "重输一遍新密码", "newUser": "新建用户", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "密码", "passwordUpdated": "密码已更新!", "path": "路径", @@ -256,4 +258,4 @@ "seconds": "秒", "unit": "时间单位" } -} +} \ No newline at end of file diff --git a/frontend/src/i18n/zh-tw.json b/frontend/src/i18n/zh-tw.json index 9a056138..c8d8b985 100644 --- a/frontend/src/i18n/zh-tw.json +++ b/frontend/src/i18n/zh-tw.json @@ -190,6 +190,8 @@ "newPassword": "您的新密碼", "newPasswordConfirm": "重輸一遍新密碼", "newUser": "建立使用者", + "onlyOffice": "Only Office Integration", + "onlyOfficeUrl": "Only Office URL (leave blank to disable)", "password": "密碼", "passwordUpdated": "密碼已更新!", "path": "", @@ -253,4 +255,4 @@ "seconds": "秒", "unit": "時間單位" } -} +} \ No newline at end of file diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js index 9761339b..a0d4dbd0 100644 --- a/frontend/src/utils/constants.js +++ b/frontend/src/utils/constants.js @@ -14,6 +14,7 @@ const theme = window.FileBrowser.Theme; const enableThumbs = window.FileBrowser.EnableThumbs; const resizePreview = window.FileBrowser.ResizePreview; const enableExec = window.FileBrowser.EnableExec; +const onlyOffice = window.FileBrowser.OnlyOffice; export { name, @@ -31,4 +32,5 @@ export { enableThumbs, resizePreview, enableExec, + onlyOffice, }; diff --git a/frontend/src/views/Files.vue b/frontend/src/views/Files.vue index 8f50426d..69ce635f 100644 --- a/frontend/src/views/Files.vue +++ b/frontend/src/views/Files.vue @@ -22,6 +22,7 @@ diff --git a/frontend/src/views/settings/Global.vue b/frontend/src/views/settings/Global.vue index 5adf21eb..060fcea4 100644 --- a/frontend/src/views/settings/Global.vue +++ b/frontend/src/views/settings/Global.vue @@ -83,6 +83,20 @@ id="branding-files" />

+ +

{{ $t("settings.onlyOffice") }}

+ +

+ + +

diff --git a/http/http.go b/http/http.go index 88acea75..f4ecd194 100644 --- a/http/http.go +++ b/http/http.go @@ -59,6 +59,8 @@ func NewHandler( users.Handle("/{id:[0-9]+}", monkey(userGetHandler, "")).Methods("GET") users.Handle("/{id:[0-9]+}", monkey(userDeleteHandler, "")).Methods("DELETE") + api.PathPrefix("/onlyoffice").Handler(monkey(onlyofficeCallbackHandler, "/api/onlyoffice/callback")).Methods("POST") + api.PathPrefix("/resources").Handler(monkey(resourceGetHandler, "/api/resources")).Methods("GET") api.PathPrefix("/resources").Handler(monkey(resourceDeleteHandler(fileCache), "/api/resources")).Methods("DELETE") api.PathPrefix("/resources").Handler(monkey(resourcePostHandler(fileCache), "/api/resources")).Methods("POST") diff --git a/http/onlyoffice.go b/http/onlyoffice.go new file mode 100644 index 00000000..054ed0f5 --- /dev/null +++ b/http/onlyoffice.go @@ -0,0 +1,65 @@ +package http + +import ( + "encoding/json" + "errors" + "io/ioutil" + "net/http" +) + +type OnlyOfficeCallback struct { + ChangesURL string `json:"changesurl,omitempty"` + Key string `json:"key"` + Status int `json:"status"` + URL string `json:"url,omitempty"` + Users []string `json:"users,omitempty"` + UserData string `json:"userdata,omitempty"` +} + +var onlyofficeCallbackHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { + body, e1 := ioutil.ReadAll(r.Body) + if e1 != nil { + return http.StatusInternalServerError, e1 + } + + var data OnlyOfficeCallback + err1 := json.Unmarshal(body, &data) + if err1 != nil { + return http.StatusInternalServerError, err1 + } + + if data.Status == 2 || data.Status == 6 { + docPath := r.URL.Query().Get("save") + if docPath == "" { + return http.StatusInternalServerError, errors.New("unable to get file save path") + } + + if !d.user.Perm.Modify || !d.Check(docPath) { + return http.StatusForbidden, nil + } + + doc, err2 := http.Get(data.URL) + if err2 != nil { + return http.StatusInternalServerError, err2 + } + defer doc.Body.Close() + + err := d.RunHook(func() error { + _, writeErr := writeFile(d.user.Fs, docPath, doc.Body) + if writeErr != nil { + return writeErr + } + return nil + }, "save", docPath, "", d.user) + + if err != nil { + _ = d.user.Fs.RemoveAll(docPath) + return http.StatusInternalServerError, err + } + } + + resp := map[string]int{ + "error": 0, + } + return renderJSON(w, r, resp) +}) diff --git a/http/settings.go b/http/settings.go index 0148b383..5e551e91 100644 --- a/http/settings.go +++ b/http/settings.go @@ -16,6 +16,7 @@ type settingsData struct { Branding settings.Branding `json:"branding"` Shell []string `json:"shell"` Commands map[string][]string `json:"commands"` + OnlyOffice string `json:"onlyoffice"` } var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { @@ -27,6 +28,7 @@ var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, Branding: d.settings.Branding, Shell: d.settings.Shell, Commands: d.settings.Commands, + OnlyOffice: d.settings.OnlyOffice, } return renderJSON(w, r, data) @@ -46,6 +48,7 @@ var settingsPutHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d.settings.Branding = req.Branding d.settings.Shell = req.Shell d.settings.Commands = req.Commands + d.settings.OnlyOffice = req.OnlyOffice err = d.store.Settings.Save(d.settings) return errToStatus(err), err diff --git a/http/static.go b/http/static.go index 3529513b..4e2bb036 100644 --- a/http/static.go +++ b/http/static.go @@ -43,6 +43,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys "EnableThumbs": d.server.EnableThumbnails, "ResizePreview": d.server.ResizePreview, "EnableExec": d.server.EnableExec, + "OnlyOffice": d.settings.OnlyOffice, } if d.settings.Branding.Files != "" { diff --git a/settings/settings.go b/settings/settings.go index 9cd45af6..65c8d7bd 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -21,6 +21,7 @@ type Settings struct { Commands map[string][]string `json:"commands"` Shell []string `json:"shell"` Rules []rules.Rule `json:"rules"` + OnlyOffice string `json:"onlyoffice"` } // GetRules implements rules.Provider.