Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webconsole refactoring with react 18 #47

Merged
merged 24 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
661a8be
Apply changes for react-18.
kishiguro Jun 26, 2023
98fee90
Apply patches for react-18.
kishiguro Jun 26, 2023
287622b
Update favicon.
kishiguro Jun 27, 2023
402484b
Fix SubscriberCreate error when no S-NSSAI is defined.
kishiguro Jun 29, 2023
c4d6dc9
Show proper error message.
kishiguro Jul 1, 2023
0ca5b46
Add webconsole to .gitignore.
kishiguro Jul 1, 2023
5b7149e
Add MSISDN field in Subscription.
kishiguro Jul 2, 2023
4ffecad
Make label to be consistent.
kishiguro Jul 2, 2023
0b50d0e
Update diff to 3.3.0.
kishiguro Jul 30, 2023
a677871
Merge branch 'main' into react-18
kishiguro Jul 30, 2023
4b3fc5b
add apiConfig as default value
ianchen0119 Aug 1, 2023
c191a14
Fix bug of identify admin tenant.
kishiguro Aug 1, 2023
dc88acd
Fix FlowRule handling.
kishiguro Aug 1, 2023
37070a5
Fix golangci-lint error.
kishiguro Aug 2, 2023
99828d8
Merge branch 'react-18' of github.com:kishiguro/webconsole into react-18
kishiguro Aug 2, 2023
389ed71
Remove diff to avoid confusion.
kishiguro Aug 2, 2023
bcaf2fa
Handle non first DNN's FlowRules.
kishiguro Aug 2, 2023
1ff7846
Add number of subscribers for bulk creation of the user.
kishiguro Aug 3, 2023
d9ce446
Start from 1.
kishiguro Aug 3, 2023
8bac6d9
Set default S-NSSAI with 2 S-NSSAI configuration.
kishiguro Aug 4, 2023
61075c9
Fix Tenant Id -> Tenant Name.
kishiguro Aug 7, 2023
909d016
Refactor again -> confirm.
kishiguro Aug 7, 2023
25b3c96
Support Password Confirm feature when creating new user.
kishiguro Aug 7, 2023
290a7e1
Support password confirmation in editing the user.
kishiguro Aug 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ cscope.*
# Debug
*.log
*.pcap

# Binary
webconsole
92 changes: 85 additions & 7 deletions backend/WebUI/api_webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func setCorsHeader(c *gin.Context) {
c.Writer.Header().Set(
"Access-Control-Allow-Headers",
"Content-Type, Content-Length, Accept-Encoding, "+
"X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With",
"X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, Token",
)
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, PATCH, DELETE")
}
Expand Down Expand Up @@ -490,6 +490,8 @@ func generateHash(password string) error {
func Login(c *gin.Context) {
setCorsHeader(c)

EnsureAdminTenant()

login := LoginRequest{}
err := json.NewDecoder(c.Request.Body).Decode(&login)
if err != nil {
Expand Down Expand Up @@ -579,8 +581,10 @@ func ParseJWT(tokenStr string) (jwt.MapClaims, error) {
func CheckAuth(c *gin.Context) bool {
tokenStr := c.GetHeader("Token")
claims, err := ParseJWT(tokenStr)

if err == nil && claims["email"] == "admin" {
if err != nil {
return false
}
if claims["tenantId"].(string) == DEFAULT_ADMIN_TENANT {
return true
} else {
return false
Expand Down Expand Up @@ -1008,8 +1012,7 @@ func GetSubscribers(c *gin.Context) {

logger.ProcLog.Infoln("Get All Subscribers List")

tokenStr := c.GetHeader("Token")
claims, err := ParseJWT(tokenStr)
userTenantId, err := GetTenantId(c)
if err != nil {
logger.ProcLog.Errorln(err.Error())
c.JSON(http.StatusBadRequest, gin.H{
Expand Down Expand Up @@ -1047,7 +1050,7 @@ func GetSubscribers(c *gin.Context) {
return
}

if claims["email"] == "admin" || tenantId == claims["tenantId"].(string) {
if userTenantId == DEFAULT_ADMIN_TENANT || userTenantId == tenantId {
tmp := SubsListIE{
PlmnID: servingPlmnId.(string),
UeId: ueId.(string),
Expand Down Expand Up @@ -1709,7 +1712,7 @@ func GetRegisteredUEContext(c *gin.Context) {
return
}

if tenantId == "" {
if tenantId == DEFAULT_ADMIN_TENANT {
sendResponseToClient(c, resp)
} else {
sendResponseToClientFilterTenant(c, resp, tenantId)
Expand Down Expand Up @@ -1763,3 +1766,78 @@ func GetUEPDUSessionInfo(c *gin.Context) {
})
}
}

func ChangePasswordInfo(c *gin.Context) {
setCorsHeader(c)

// Need to get tenantId.
tenantId, err := GetTenantId(c)
if err != nil {
logger.ProcLog.Errorln(err.Error())
c.JSON(http.StatusBadRequest, gin.H{})
return
}

var newUserData User
if err := c.ShouldBindJSON(&newUserData); err != nil {
logger.ProcLog.Errorln(err.Error())
c.JSON(http.StatusBadRequest, gin.H{})
return
}

filterEmailOnly := bson.M{"tenantId": tenantId, "email": newUserData.Email}
userDataInterface, err := mongoapi.RestfulAPIGetOne(userDataColl, filterEmailOnly)
if err != nil {
logger.ProcLog.Errorf("ChangePassword err: %+v", err)
}
if len(userDataInterface) == 0 {
c.JSON(http.StatusNotFound, bson.M{})
return
}

var userData User
json.Unmarshal(mapToByte(userDataInterface), &userData)

if newUserData.EncryptedPassword != "" {
hash, _ := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12)
userData.EncryptedPassword = string(hash)
}

userBsonM := toBsonM(userData)
if _, err := mongoapi.RestfulAPIPost(userDataColl, filterEmailOnly, userBsonM); err != nil {
logger.ProcLog.Errorf("PutUserByID err: %+v", err)
}

c.JSON(http.StatusOK, userData)
}

const DEFAULT_ADMIN_EMAIL = "admin"
const DEFAULT_ADMIN_TENANT = "AdminTenant"
const DEFAULT_ADMIN_USER_PASSWORD = "free5gc"

// EnsureAdminTenant creates default admin user tenant when it does not exist.
func EnsureAdminTenant() {
adminTenantOnly := bson.M{"tenantId": DEFAULT_ADMIN_TENANT}
userDataInterface, err := mongoapi.RestfulAPIGetOne(userDataColl, adminTenantOnly)
if err == nil && len(userDataInterface) != 0 {
// Admin user already created.
return
}

var userData User
userData.Email = DEFAULT_ADMIN_EMAIL
userData.TenantId = DEFAULT_ADMIN_TENANT
hash, _ := bcrypt.GenerateFromPassword([]byte(DEFAULT_ADMIN_USER_PASSWORD), 12)
userData.EncryptedPassword = string(hash)

userBsonM := toBsonM(userData)
if _, err := mongoapi.RestfulAPIPost(userDataColl, adminTenantOnly, userBsonM); err != nil {
logger.ProcLog.Errorf("PutUserByID err: %+v", err)
}
}

func OptionsSubscribers(c *gin.Context) {
setCorsHeader(c)

c.JSON(http.StatusNoContent, gin.H{})
}
16 changes: 16 additions & 0 deletions backend/WebUI/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func AddService(engine *gin.Engine) *gin.RouterGroup {
group.DELETE(route.Pattern, route.HandlerFunc)
case http.MethodPatch:
group.PATCH(route.Pattern, route.HandlerFunc)
case http.MethodOptions:
group.OPTIONS(route.Pattern, route.HandlerFunc)
}
}

Expand Down Expand Up @@ -151,6 +153,13 @@ var routes = Routes{
GetSubscribers,
},

{
"OptionsSubscribers",
http.MethodOptions,
"/subscriber",
OptionsSubscribers,
},

{
"GetSubscriberByID",
http.MethodGet,
Expand Down Expand Up @@ -213,4 +222,11 @@ var routes = Routes{
"/ue-pdu-session-info/:smContextRef",
GetUEPDUSessionInfo,
},

{
"Change Password",
http.MethodPost,
"/change-password",
ChangePasswordInfo,
},
}
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GENERATE_SOURCEMAP=false
32 changes: 32 additions & 0 deletions frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"root": true,
"extends": [
"airbnb-typescript/base",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"overrides": [
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"react",
"@typescript-eslint",
"import"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-explicit-any": 0,
"import/extensions": "off"
}
}
42 changes: 40 additions & 2 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
node_modules
## openapi-generate
**/.DS_Store
/node_modules
/.pnp
.pnp.js
/build
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.openapi-generator-ignore
.openapi-generator/
mdm
README.md

build
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
9 changes: 9 additions & 0 deletions frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"tabWidth": 2,
"printWidth": 100,
"singleQuote": false,
"trailingComma": "all",
"jsxSingleQuote": false,
"bracketSpacing": true
}
Loading