Skip to content

Commit 6f4c199

Browse files
committed
improce DSM compatability
1 parent 3af83fe commit 6f4c199

4 files changed

Lines changed: 28 additions & 35 deletions

File tree

package/src/synoedit/auth.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,24 @@ func auth() {
9393
}
9494

9595
// check permissions
96-
cmd = exec.Command("/usr/syno/synoman/webman/initdata.cgi") // performance hit
97-
cmdOut, err := cmd.Output()
98-
if err != nil {
99-
logUnauthorised(err.Error())
100-
}
101-
cmdOut = bytes.TrimLeftFunc(cmdOut, findJSON)
102-
103-
var jsonData AuthJSON
104-
if err := json.Unmarshal(cmdOut, &jsonData); err != nil { // performance hit
105-
logUnauthorised(err.Error())
106-
}
107-
108-
isAdmin := jsonData.Session.IsAdmin // Session.IsAdmin:true
109-
isPermitted := jsonData.AppPrivilege.IsPermitted // AppPrivilege.SYNO.SDS.DNSCryptProxy.Application:true
110-
if !(isAdmin || isPermitted) {
111-
notFound()
96+
if FileExists("/usr/syno/synoman/webman/initdata.cgi") {
97+
cmd = exec.Command("/usr/syno/synoman/webman/initdata.cgi") // performance hit
98+
cmdOut, err := cmd.Output()
99+
if err != nil {
100+
logUnauthorised(err.Error())
101+
}
102+
cmdOut = bytes.TrimLeftFunc(cmdOut, findJSON)
103+
104+
var jsonData AuthJSON
105+
if err := json.Unmarshal(cmdOut, &jsonData); err != nil { // performance hit
106+
logUnauthorised(err.Error())
107+
}
108+
109+
isAdmin := jsonData.Session.IsAdmin // Session.IsAdmin:true
110+
isPermitted := jsonData.AppPrivilege.IsPermitted // AppPrivilege.SYNO.SDS.DNSCryptProxy.Application:true
111+
if !(isAdmin || isPermitted) {
112+
notFound()
113+
}
112114
}
113115

114116
os.Setenv("QUERY_STRING", tempQueryEnv)

package/src/synoedit/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@ func main() {
144144
action := postData.Get("action")
145145
if action != "" && appName != "" {
146146
output := ExecuteAction(appName)
147-
fmt.Println("Status: 200 OK\nContent-Type: text/plain;\n")
148-
fmt.Println(output)
149147

150-
if ajax != "" {
151-
renderHTML(fileData, "Not implemented", "")
148+
if ajax == "true" {
149+
fmt.Println("Status: 200 OK\nContent-Type: text/plain;\n")
150+
fmt.Println(output)
152151
return
153152
}
153+
renderHTML(fileData, "Not implemented", "")
154154
return
155155
}
156156

157157
if fileData != "" && appName != "" && fileName != "" {
158158
filePath := GetFilePath(appName, fileName)
159159
SaveFile(filePath, fileData)
160160

161-
if ajax != "" {
161+
if ajax == "true" {
162162
fmt.Println("Status: 200 OK\nContent-Type: text/plain;\n")
163163
fmt.Println("File saved successfully!")
164164
return
@@ -178,7 +178,7 @@ func main() {
178178
fileData = ReadFile(GetFilePath(appName, fileName))
179179
}
180180

181-
if ajax := readGet().Get("ajax"); ajax != "" {
181+
if ajax := readGet().Get("ajax"); ajax == "true" {
182182
// expect an ajax response
183183
fmt.Println("Status: 200 OK\nContent-Type: text/plain;\n")
184184
fmt.Println(fileData)

package/src/synoedit/utils.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ import (
2222
"os/exec"
2323
)
2424

25-
// CheckCmdExists looks for command in $PATH
26-
func CheckCmdExists(cmd string) bool {
27-
_, err := exec.LookPath(cmd)
28-
if err != nil {
29-
return false
30-
}
31-
return true
32-
}
33-
3425
// GetFilePath returns the complete file path given the App and file name
3526
func GetFilePath(appName string, fileName string) string {
3627
if app, exists := config.Applications[appName]; exists {
@@ -47,7 +38,7 @@ func GetFilePath(appName string, fileName string) string {
4738
}
4839

4940
// Look for command in $PATH or Check that file exits
50-
func checkCmdExists(cmd string) bool {
41+
func CheckCmdExists(cmd string) bool {
5142
_, err := exec.LookPath(cmd)
5243
if err != nil {
5344
return FileExists(cmd)
@@ -59,7 +50,7 @@ func checkCmdExists(cmd string) bool {
5950
func ExecuteAction(appName string) string {
6051
if app, exists := config.Applications[appName]; exists {
6152

62-
if !checkCmdExists(*app.Action.Exec) {
53+
if !CheckCmdExists(*app.Action.Exec) {
6354
logError("Command could not be found or is not installed!")
6455
}
6556

package/ui/js/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (typeof CodeMirror === "undefined") {
3333
CodeMirror.commands.save = function(insance) { // overload save function
3434
debug("CodeMirror save event", insance)
3535
insance.save()
36-
var param = addParameter('app', appSelector.value) + addParameter('file', fileSelector.value)
36+
var param = addParameter('app', appSelector.value) + addParameter('file', fileSelector.value) + addParameter('ajax', 'true')
3737
ajax('POST', 'fileContent='+encodeURIComponent(textArea.value) + param, function() { // insance.getTextArea().value
3838
// restart fade animation
3939
successMessage.style.animation = 'none';
@@ -170,7 +170,7 @@ actionForm.addEventListener('submit', function(e) {
170170
fileForm.addEventListener('submit', function saveForm (e) {
171171
if (e && typeof e.preventDefault === 'function') e.preventDefault();
172172
debug('file content submit event', e)
173-
var param = addParameter('app', appSelector.value) + addParameter('file', fileSelector.value)
173+
var param = addParameter('app', appSelector.value) + addParameter('file', fileSelector.value) + addParameter('ajax', 'true')
174174
debug('params', param)
175175
ajax('POST', 'fileContent='+encodeURIComponent(textArea.value) + param, function() {
176176
// restart fade animation

0 commit comments

Comments
 (0)