Skip to content
Snippets Groups Projects
Commit 51d7b894 authored by Theo's avatar Theo :troll:
Browse files

Improve some stuff

parent 0ca6af4e
No related branches found
No related tags found
No related merge requests found
......@@ -10,8 +10,7 @@ To install, just clone the repo:
and build the binary:
cd useradm
go build -o useradm
cd useradm && go build -o useradm
if you want add it the go path use:
......@@ -42,7 +41,6 @@ in flags the command needs identifiers to make the search, such as:
here we are searching for a user with name with pedro, grr with 2024, is part
of the group 'bcc' and -i is to make the search case insensitive.
### Create
To create a user we can use:
......@@ -77,7 +75,6 @@ be removed from LDAP and Kerberos, their directories will end up at:
webdir: /home/contas_removidas/html/<Year of removal>/
webdir: /nobackup/contas_removidas/<Year of removal>/
### Modify
To modify a user we can do:
......@@ -141,7 +138,9 @@ Then we generate the request that will give us all the users, get the response,
and store the result in structs.
Many other requests are made in the code and you can learn the syntax by reading
it or via the docs of the module.
it or via the docs of the module. One thing I want to add it that in LDAP, group
assingments need to be done by setting the user object to be member of the group
and set the group object to have the user as a member. Interesting...
### Kerberos
......@@ -163,10 +162,48 @@ that minimizes those misfortunes.
`useradm.py` had 3 function to generate names that used a very wierd algorithm.
At first I just copied them, then I thought it was too long and repetitive so
I merged them into one (See commit e303dcc1). It was VERY ugly, so Fernando K.
I merged them into one (See commit e49eca75). It was VERY ugly, so Fernando K.
helped and rewrote/improved the algorithm to a more mantainable state, thanks :)
(See commit e9762f8b)
TODO: explain it
There are 3 types of login generation: ini, first, last. Instead of explaining
how the algorithm works, I believe it is best to just show examples. So for the
user with name Fabiano Antunes Pereira de Souza, with GRR 20241982:
'ini' would create the following (based on `variance` variable):
faps24
faaps24
faanps24
faanpes24
faanpeso24
fabanpeso24
and so on. 'first' would create something like this:
fabiano
fabianoa
fabianoap
fabianoaps
fabianoanps
fabianoanpes
fabianoanpeso
and so on. 'last' would generate:
fapsouza
faapsouza
faanpsouza
faanpesouza
fabanpesouza
fabantpesouza
and so on...
Essentially we add one letter to each name part for each variance added. We also
remove any connectives (do, da, de, dos, von...) from the name. If there comes a
time a person appears with a new connective, update the formatName() function
currently at `/cmd/user/create.go` to account for that :)
TODO: finish...
......@@ -15,7 +15,7 @@ new users, please do so with the bulk subcommand.`,
func init() {
userCmd.AddCommand(user.CreateUserCmd)
userCmd.AddCommand(user.DeleteUserCmd)
userCmd.AddCommand(user.RemoveUserCmd)
userCmd.AddCommand(user.ModCmd)
userCmd.AddCommand(user.ShowCmd)
userCmd.AddCommand(user.ResetCmd)
......
......@@ -99,8 +99,8 @@ func modifyUserFunc(cmd *cobra.Command, args []string) error {
}
if err := clearCache(); err != nil {
fmt.Printf(`Failed to reload cache
all is ok but may take a while to apply
fmt.Printf(`Failed to reload cache!
all is ok but may take a while to apply the changes
Output: %v`, err)
} else {
fmt.Printf("Changes applied!\n")
......@@ -174,6 +174,7 @@ func applyChangesToUser(c model.User, n cfg) model.User {
return c
}
// generates a yaml file of a config state for the user to edit
func promptUserYaml(state cfg) (cfg, error) {
var newState cfg
tmpFile, err := os.CreateTemp("", "config-*.yaml")
......
......@@ -21,20 +21,18 @@ var (
WEB_TRASH = "/home/contas_removidas/html/" + ANO
)
var DeleteUserCmd = &cobra.Command{
Use: "delete",
var RemoveUserCmd = &cobra.Command{
Use: "remove [username]",
Short: "Delete a user",
RunE: deleteUserFunc,
Args: cobra.ExactArgs(1),
RunE: removeUserFunc,
}
func init() {
DeleteUserCmd.Flags().StringP("login", "l", "", "User login for removal")
DeleteUserCmd.Flags().BoolP("confirm", "y", false, "Skip confirmation prompt")
DeleteUserCmd.MarkFlagRequired("login")
RemoveUserCmd.Flags().BoolP("confirm", "y", false, "Skip confirmation prompt")
}
func deleteUserFunc(cmd *cobra.Command, args []string) error {
func removeUserFunc(cmd *cobra.Command, args []string) error {
var opts model.Opts
success := false
......@@ -43,7 +41,8 @@ func deleteUserFunc(cmd *cobra.Command, args []string) error {
return err
}
u, err := locateUser(opts.UID)
login := args[0]
u, err := locateUser(login)
if err != nil {
return err
}
......
......@@ -54,6 +54,11 @@ func searchUserFunc(cmd *cobra.Command, args []string) error {
filtered := searchUser(users, o.Ignore, o.UID, o.GID,
o.Name, o.GRR, o.Status, o.Homedir)
if len(filtered) == 0 {
fmt.Printf("No user matched the search!")
return nil
}
for i := range filtered {
fmt.Printf("%v\n\n", filtered[i].ToString())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment