c33af66c6e
* fix bug * updata UI * 0.3.2 ### Added - [Files] Files can now be selected multiple files and downloaded, deleted, moved, etc. - [Apps] Support to modify the application opening address.([#204](https://github.com/IceWhaleTech/CasaOS/issues/204)) ### Changed - [Apps] Hide the display of non-essential environment variables in the application. - [System] Network, disk, cpu, memory, etc. information is modified to be pushed via socket. - [System] Optimize opening speed.([#214](https://github.com/IceWhaleTech/CasaOS/issues/214)) ### Fixed - [System] Fixed the problem that sync data cannot submit the device ID ([#68](https://github.com/IceWhaleTech/CasaOS/issues/68)) - [Files] Fixed the code editor center alignment display problem.([#210](https://github.com/IceWhaleTech/CasaOS/issues/210)) - [Files] Fixed the problem of wrong name when downloading files.([#240](https://github.com/IceWhaleTech/CasaOS/issues/240)) - [System] Fixed the network display as a negative number problem.([#224](https://github.com/IceWhaleTech/CasaOS/issues/224)) * Modify log help class * Fix some bugs in 0.3.2 * Solve the operation file queue problem * Exclude web folders * update UI * add cancel file operate * Update UI * Merge sockets to transfer data * Conflict Resolution * Update send data interval
131 lines
3.2 KiB
Go
131 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/model/notify"
|
|
"github.com/IceWhaleTech/CasaOS/pkg/cache"
|
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
|
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
|
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
|
"github.com/IceWhaleTech/CasaOS/route"
|
|
"github.com/IceWhaleTech/CasaOS/service"
|
|
|
|
"github.com/robfig/cron"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var sqliteDB *gorm.DB
|
|
|
|
var configFlag = flag.String("c", "", "config address")
|
|
var dbFlag = flag.String("db", "", "db path")
|
|
var showUserInfo = flag.Bool("show-user-info", false, "show user info")
|
|
|
|
func init() {
|
|
flag.Parse()
|
|
config.InitSetup(*configFlag)
|
|
config.UpdateSetup()
|
|
loger.LogInit()
|
|
if len(*dbFlag) == 0 {
|
|
*dbFlag = config.AppInfo.ProjectPath + "/db"
|
|
}
|
|
sqliteDB = sqlite.GetDb(*dbFlag)
|
|
//gredis.GetRedisConn(config.RedisInfo),
|
|
service.MyService = service.NewService(sqliteDB)
|
|
service.Cache = cache.Init()
|
|
|
|
go service.UDPService()
|
|
|
|
fmt.Println("t", service.GetToken())
|
|
service.UDPAddressMap = make(map[string]string)
|
|
//go service.SocketConnect()
|
|
service.CancelList = make(map[string]string)
|
|
service.InternalInspection = make(map[string][]string)
|
|
service.NewVersionApp = make(map[string]string)
|
|
route.InitFunction()
|
|
|
|
go service.SendIPToServer()
|
|
// go service.LoopFriend()
|
|
// go service.MyService.App().CheckNewImage()
|
|
|
|
}
|
|
|
|
// @title casaOS API
|
|
// @version 1.0.0
|
|
// @contact.name lauren.pan
|
|
// @contact.url https://www.zimaboard.com
|
|
// @contact.email lauren.pan@icewhale.org
|
|
// @description casaOS v1版本api
|
|
// @host 192.168.2.217:8089
|
|
// @securityDefinitions.apikey ApiKeyAuth
|
|
// @in header
|
|
// @name Authorization
|
|
// @BasePath /v1
|
|
func main() {
|
|
service.NotifyMsg = make(chan notify.Message, 10)
|
|
if *showUserInfo {
|
|
fmt.Println("CasaOS User Info")
|
|
fmt.Println("UserName:" + config.UserInfo.UserName)
|
|
fmt.Println("Password:" + config.UserInfo.PWD)
|
|
return
|
|
}
|
|
|
|
go route.SocketInit(service.NotifyMsg)
|
|
go func() {
|
|
for i := 0; i < 1000; i++ {
|
|
time.Sleep(2 * time.Second)
|
|
//service.NotifyMsg <- strconv.Itoa(i)
|
|
}
|
|
}()
|
|
|
|
//model.Setup()
|
|
//gredis.Setup()
|
|
r := route.InitRouter()
|
|
//service.SyncTask(sqliteDB)
|
|
cron2 := cron.New()
|
|
//every day execution
|
|
err := cron2.AddFunc("0 0/5 * * * *", func() {
|
|
//service.PushIpInfo(*&config.ServerInfo.Token)
|
|
//service.UpdataDDNSList(mysqldb)
|
|
//service.SyncTask(sqliteDB)
|
|
|
|
service.SendIPToServer()
|
|
|
|
service.LoopFriend()
|
|
//service.MyService.App().CheckNewImage()
|
|
})
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
err = cron2.AddFunc("0/5 * * * * *", func() {
|
|
if service.ClientCount > 0 {
|
|
// route.SendNetINfoBySocket()
|
|
// route.SendCPUBySocket()
|
|
// route.SendMemBySocket()
|
|
// route.SendDiskBySocket()
|
|
// route.SendUSBBySocket()
|
|
route.SendAllHardwareStatusBySocket()
|
|
}
|
|
})
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
cron2.Start()
|
|
defer cron2.Stop()
|
|
s := &http.Server{
|
|
Addr: fmt.Sprintf(":%v", config.ServerInfo.HttpPort),
|
|
Handler: r,
|
|
ReadTimeout: 60 * time.Second,
|
|
WriteTimeout: 60 * time.Second,
|
|
MaxHeaderBytes: 1 << 20,
|
|
}
|
|
|
|
s.ListenAndServe()
|
|
|
|
// if err := r.Run(fmt.Sprintf(":%v", config.ServerInfo.HttpPort)); err != nil {
|
|
// fmt.Println("failed run app: ", err)
|
|
// }
|
|
}
|