diff --git a/backend/app_sdk/app_base.py b/backend/app_sdk/app_base.py index 101569fa..4ed95b03 100644 --- a/backend/app_sdk/app_base.py +++ b/backend/app_sdk/app_base.py @@ -1215,6 +1215,8 @@ class AppBase: return " ".join(newlist) # Parses JSON loops and such down to the item you're looking for + # $nodename.#.id + # $nodename.data.#min-max.info.id def recurse_json(basejson, parsersplit): match = "#([0-9a-z]+):?-?([0-9a-z]+)?#?" #print("Split: %s\n%s" % (parsersplit, basejson)) @@ -1254,15 +1256,17 @@ class AppBase: newvalue = [] firstitem = actualitem[0][0] seconditem = actualitem[0][1] + print("ACTUAL PARSED: %s" % actualitem) # Means it's a single item -> continue if seconditem == "": print("[INFO] In first - handling %s. Len: %d" % (firstitem, len(basejson))) if firstitem.lower() == "max" or firstitem.lower() == "last": firstitem = len(basejson)-1 - if firstitem.lower() == "min" or firstitem.lower() == "first": + elif firstitem.lower() == "min" or firstitem.lower() == "first": firstitem = 0 + #print("Post lower checks") tmpitem = basejson[int(firstitem)] try: newvalue, is_loop = recurse_json(tmpitem, parsersplit[outercnt+1:]) @@ -1272,13 +1276,15 @@ class AppBase: print("[INFO] In ELSE - handling %s and %s" % (firstitem, seconditem)) if firstitem.lower() == "max" or firstitem.lower() == "last": firstitem = len(basejson)-1 - if firstitem.lower() == "min" or firstitem.lower() == "first": + elif firstitem.lower() == "min" or firstitem.lower() == "first": firstitem = 0 + if seconditem.lower() == "max" or seconditem.lower() == "last": seconditem = len(basejson)-1 - if seconditem.lower() == "min" or seconditem.lower() == "first": + elif seconditem.lower() == "min" or seconditem.lower() == "first": seconditem = 0 + print("Post lower checks") newvalue = [] if int(seconditem) > len(basejson): seconditem = len(basejson) diff --git a/backend/go-app/go.mod b/backend/go-app/go.mod index c99e10a9..ba3a0575 100644 --- a/backend/go-app/go.mod +++ b/backend/go-app/go.mod @@ -2,7 +2,7 @@ module shuffle go 1.13 -//replace github.com/frikky/shuffle-shared => ../../../../git/shuffle-shared +replace github.com/frikky/shuffle-shared => ../../../../git/shuffle-shared //replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 43852d29..b2921afd 100644 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -5870,6 +5870,7 @@ func initHandlers() { // PS: For cloud, this has to use cloud storage. // https://developer.box.com/reference/get-files-id-content/ // 1. Creating the "get file" option. Make it possible to run this in the frontend. + r.HandleFunc("/api/v1/files/namespaces/{namespace}", shuffle.HandleGetFileNamespace).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/files/{fileId}/content", shuffle.HandleGetFileContent).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/files/create", shuffle.HandleCreateFile).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/files/{fileId}/upload", shuffle.HandleUploadFile).Methods("POST", "OPTIONS") diff --git a/backend/tests/files.sh b/backend/tests/files.sh index d27a4755..64417941 100755 --- a/backend/tests/files.sh +++ b/backend/tests/files.sh @@ -1,16 +1,22 @@ -curl http://192.168.3.6:5001/api/v1/files/create -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" -d '{"filename": "file.txt", "org_id": "b199646b-16d2-456d-9fd6-b9972e929466", "workflow_id": "global"}' - -curl http://localhost:5001/api/v1/files/create -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" -d '{"filename": "file.txt", "org_id": "b199646b-16d2-456d-9fd6-b9972e929466", "workflow_id": "global"}' - -echo -curl http://localhost:5001/api/v1/files/e19cffe4-e2da-47e9-809e-904f5cb03687/upload -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" -F 'shuffle_file=@files.sh' - -curl http://localhost:5001/api/v1/files/1915981b-b897-4db1-8a2e-44bc34cead3b/content -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" -curl http://localhost:5001/api/v1/files/e19cffe4-e2da-47e9-809e-904f5cb03687 -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" -curl -XDELETE http://localhost:5001/api/v1/files/e19cffe4-e2da-47e9-809e-904f5cb03687 -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" +#curl http://192.168.3.6:5001/api/v1/files/create -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" -d '{"filename": "file.txt", "org_id": "b199646b-16d2-456d-9fd6-b9972e929466", "workflow_id": "global"}' +# +#curl http://localhost:5001/api/v1/files/create -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" -d '{"filename": "file.txt", "org_id": "b199646b-16d2-456d-9fd6-b9972e929466", "workflow_id": "global"}' +# +#echo +#curl http://localhost:5001/api/v1/files/e19cffe4-e2da-47e9-809e-904f5cb03687/upload -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" -F 'shuffle_file=@files.sh' +# +#curl http://localhost:5001/api/v1/files/1915981b-b897-4db1-8a2e-44bc34cead3b/content -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" +#curl http://localhost:5001/api/v1/files/e19cffe4-e2da-47e9-809e-904f5cb03687 -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" +#curl -XDELETE http://localhost:5001/api/v1/files/e19cffe4-e2da-47e9-809e-904f5cb03687 -H "Authorization: Bearer db0373c6-1083-4dec-a05d-3ba73f02ccd4" #r.HandleFunc("/api/v1/files/{fileId}/content", handleGetFileContent).Methods("GET", "OPTIONS") #r.HandleFunc("/api/v1/files/create", handleCreateFile).Methods("POST", "OPTIONS") #r.HandleFunc("/api/v1/files/{fileId}/upload", handleUploadFile).Methods("POST", "OPTIONS") #r.HandleFunc("/api/v1/files/{fileId}", handleGetFileMeta).Methods("GET", "OPTIONS") #r.HandleFunc("/api/v1/files/{fileId}", handleDeleteFile).Methods("DELETE", "OPTIONS") + + +#curl http://localhost:5001/api/v1/files/create -H "Authorization: Bearer c5b4c827-65ec-47f4-9e8a-234cdba38959" -d '{"filename": "rule2.yar", "org_id": "b4e88fe9-352b-47b4-b280-960181670acf", "workflow_id": "global", "namespace": "yara"}' +#curl http://localhost:5001/api/v1/files/5cb941ad-fa1c-4444-a685-92024b1fa31c/upload -H "Authorization: Bearer c5b4c827-65ec-47f4-9e8a-234cdba38959" -F 'shuffle_file=@upload.sh' + +curl http://localhost:5001/api/v1/files/namespaces/yara -H "Authorization: Bearer c5b4c827-65ec-47f4-9e8a-234cdba38959" --output rules.zip diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsx index 64237cb8..c5a42ed3 100644 --- a/frontend/src/views/Admin.jsx +++ b/frontend/src/views/Admin.jsx @@ -4,7 +4,7 @@ import { makeStyles } from '@material-ui/styles'; import { useTheme } from '@material-ui/core/styles'; import {Link} from 'react-router-dom'; -import {Paper, Card, Tooltip, FormControlLabel, Typography, Switch, Select, MenuItem, Divider, TextField, Button, Tabs, Tab, Grid, List, ListItem, ListItemText, ListItemAvatar, ListItemSecondaryAction, IconButton, Avatar, Zoom, Dialog, DialogTitle, DialogActions, DialogContent, CircularProgress } from '@material-ui/core'; +import {FormControl, InputLabel, Paper, Card, Tooltip, FormControlLabel, Typography, Switch, Select, MenuItem, Divider, TextField, Button, Tabs, Tab, Grid, List, ListItem, ListItemText, ListItemAvatar, ListItemSecondaryAction, IconButton, Avatar, Zoom, Dialog, DialogTitle, DialogActions, DialogContent, CircularProgress } from '@material-ui/core'; import {Edit as EditIcon, FileCopy as FileCopyIcon, Publish as PublishIcon, SelectAll as SelectAllIcon, OpenInNew as OpenInNewIcon, CloudDownload as CloudDownloadIcon, Description as DescriptionIcon, Polymer as PolymerIcon, CheckCircle as CheckCircleIcon, Close as CloseIcon, Apps as AppsIcon, Image as ImageIcon, Delete as DeleteIcon, Cached as CachedIcon, AccessibilityNew as AccessibilityNewIcon, Lock as LockIcon, Eco as EcoIcon, Schedule as ScheduleIcon, Cloud as CloudIcon, Business as BusinessIcon} from '@material-ui/icons'; @@ -49,6 +49,8 @@ const Admin = (props) => { const [authentication, setAuthentication] = React.useState([]); const [schedules, setSchedules] = React.useState([]) const [files, setFiles] = React.useState([]) + const [selectedNamespace, setSelectedNamespace] = React.useState("default") + const [fileNamespaces, setFileNamespaces] = React.useState([]); const [selectedUser, setSelectedUser] = React.useState({}) const [newPassword, setNewPassword] = React.useState(""); const [selectedUserModalOpen, setSelectedUserModalOpen] = React.useState(false) @@ -868,8 +870,16 @@ const Admin = (props) => { return response.json() }) .then((responseJson) => { - //console.log(responseJson) - setFiles(responseJson) + if (responseJson.files === undefined || responseJson.files === null) { + setFiles(responseJson) + } else { + setFiles(responseJson.files) + } + + console.log("NAMESPACES: ", responseJson.namespaces) + if (responseJson.namespaces !== undefined && responseJson.namespaces !== null) { + setFileNamespaces(responseJson.namespaces) + } }) .catch(error => { alert.error(error.toString()) @@ -2169,6 +2179,30 @@ const Admin = (props) => { > + + {fileNamespaces !== undefined && fileNamespaces !== null && fileNamespaces.length > 1 ? + + Namespace + + + : null} + @@ -2204,6 +2238,14 @@ const Admin = (props) => { /> {files === undefined || files === null ? null : files.map((file, index) => { + if (file.namespace === "") { + file.namespace = "default" + } + + if (file.namespace !== selectedNamespace) { + return null + } + var bgColor = "#27292d" if (index % 2 === 0) { bgColor = "#1f2023"