first commit
This commit is contained in:
99
crontab/call.go
Normal file
99
crontab/call.go
Normal file
@ -0,0 +1,99 @@
|
||||
package crontab
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
|
||||
"arno/skeletor/service"
|
||||
"arno/skeletor/repository"
|
||||
"arno/skeletor/entity"
|
||||
"arno/skeletor/tool"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
type stubMapping map[string]interface{}
|
||||
var StubStorage = stubMapping{}
|
||||
|
||||
func init() {
|
||||
StubStorage = map[string]interface{}{
|
||||
"AppClear": AppClear,
|
||||
"AppSetPassword": AppSetPassword,
|
||||
}
|
||||
}
|
||||
|
||||
func Lauch(ctn *service.Container) {
|
||||
mydb := repository.Must(ctn)
|
||||
|
||||
tool.LogTitle("CRON")
|
||||
tool.LogInfo("Création des Jobs Cron")
|
||||
c := cron.New()
|
||||
|
||||
var crons []entity.Cron
|
||||
var command entity.Command
|
||||
mydb.Find(&crons)
|
||||
|
||||
for _, cron := range crons {
|
||||
mydb.First(&command, "id = ?", cron.CommandId)
|
||||
tool.Log("["+command.Name+"] "+cron.Every)
|
||||
c.AddFunc(cron.Every, func() {
|
||||
var prntA string
|
||||
|
||||
if(cron.Arg05!="") {
|
||||
resA,_ := Call(command.Name,ctn,cron.Arg01,cron.Arg02,cron.Arg03,cron.Arg04,cron.Arg05)
|
||||
prntA = resA.(string)
|
||||
tool.Log(prntA)
|
||||
}
|
||||
|
||||
if(cron.Arg04!="") {
|
||||
resA,_ := Call(command.Name,ctn,cron.Arg01,cron.Arg02,cron.Arg03,cron.Arg04)
|
||||
prntA = resA.(string)
|
||||
tool.Log(prntA)
|
||||
}
|
||||
|
||||
if(cron.Arg03!="") {
|
||||
resA,_ := Call(command.Name,ctn,cron.Arg01,cron.Arg02,cron.Arg03)
|
||||
prntA = resA.(string)
|
||||
tool.Log(prntA)
|
||||
}
|
||||
|
||||
if(cron.Arg02!="") {
|
||||
resA,_ := Call(command.Name,ctn,cron.Arg01,cron.Arg02)
|
||||
prntA = resA.(string)
|
||||
tool.Log(prntA)
|
||||
}
|
||||
|
||||
if(cron.Arg01!="") {
|
||||
resA,_ := Call(command.Name,ctn,cron.Arg01)
|
||||
prntA = resA.(string)
|
||||
tool.Log(prntA)
|
||||
}
|
||||
|
||||
if(cron.Arg01=="") {
|
||||
resA,_ := Call(command.Name,ctn)
|
||||
prntA = resA.(string)
|
||||
tool.Log(prntA)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Start cron with one scheduled job
|
||||
c.Start()
|
||||
|
||||
}
|
||||
|
||||
func Call(funcName string, params ... interface{}) (result interface{}, err error) {
|
||||
f := reflect.ValueOf(StubStorage[funcName])
|
||||
if len(params) != f.Type().NumIn() {
|
||||
err = errors.New("The number of params is out of index.")
|
||||
return
|
||||
}
|
||||
in := make([]reflect.Value, len(params))
|
||||
for k, param := range params {
|
||||
in[k] = reflect.ValueOf(param)
|
||||
}
|
||||
var res []reflect.Value
|
||||
res = f.Call(in)
|
||||
result = res[0].Interface()
|
||||
return
|
||||
}
|
25
crontab/clear.go
Normal file
25
crontab/clear.go
Normal file
@ -0,0 +1,25 @@
|
||||
package crontab
|
||||
|
||||
import (
|
||||
"arno/skeletor/config"
|
||||
"arno/skeletor/entity"
|
||||
"arno/skeletor/repository"
|
||||
"arno/skeletor/service"
|
||||
"arno/skeletor/tool"
|
||||
)
|
||||
|
||||
func AppClear(ctn *service.Container) string {
|
||||
tool.LogJobTitle("APPCLEAR")
|
||||
|
||||
myconfig := config.Must(ctn)
|
||||
mydb := repository.Must(ctn)
|
||||
|
||||
tool.Log(myconfig.AppWeburl)
|
||||
var users []entity.User
|
||||
mydb.Find(&users)
|
||||
for _, user := range users {
|
||||
tool.Log(user.Login)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
36
crontab/setpassword.go
Normal file
36
crontab/setpassword.go
Normal file
@ -0,0 +1,36 @@
|
||||
package crontab
|
||||
|
||||
import (
|
||||
"arno/skeletor/repository"
|
||||
"arno/skeletor/entity"
|
||||
"arno/skeletor/service"
|
||||
"arno/skeletor/tool"
|
||||
)
|
||||
|
||||
func AppSetPassword(ctn *service.Container,login string, password string) string {
|
||||
tool.LogJobTitle("APPSETPASSWORD")
|
||||
|
||||
mydb := repository.Must(ctn)
|
||||
|
||||
var user entity.User
|
||||
result := mydb.First(&user, "login = ?", login)
|
||||
if result.RowsAffected == 0 {
|
||||
tool.LogFatal("Utilisateur inexistant")
|
||||
return ""
|
||||
}
|
||||
|
||||
salt := []byte("example key 1234")
|
||||
encpassword := tool.Encrypt(salt, password)
|
||||
user.Password = encpassword
|
||||
user.Salt = salt
|
||||
err := mydb.Save(&user).Error
|
||||
if(err!=nil) {
|
||||
tool.LogFatal(err.Error())
|
||||
return ""
|
||||
}
|
||||
|
||||
tool.Log("Login = "+login)
|
||||
tool.Log("Nouveau Password = "+password)
|
||||
|
||||
return ""
|
||||
}
|
Reference in New Issue
Block a user