You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

193 lines
7.1 KiB

// Copyright 2013 wetalk authors
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
// An open source project for Gopher community.
package main
import (
"fmt"
"github.com/astaxie/beego"
"github.com/beego/social-auth"
"hssc/smsp/modules/utils"
"hssc/smsp/routers/admin"
"hssc/smsp/routers/api"
"hssc/smsp/routers/attachment"
"hssc/smsp/routers/auth"
"hssc/smsp/routers/base"
"hssc/smsp/setting"
_ "github.com/go-sql-driver/mysql"
)
// We have to call a initialize function manully
// because we use `bee bale` to pack static resources
// and we cannot make sure that which init() execute first.
func initialize() {
setting.LoadConfig()
if err := utils.InitSphinxPools(); err != nil {
beego.Error(fmt.Sprint("sphinx init pool", err))
}
setting.SocialAuth = social.NewSocial("/login/", auth.SocialAuther)
setting.SocialAuth.ConnectSuccessURL = "/settings/profile"
setting.SocialAuth.ConnectFailedURL = "/settings/profile"
setting.SocialAuth.ConnectRegisterURL = "/register/connect"
setting.SocialAuth.LoginURL = "/admin/login"
}
func main() {
beego.SetLogFuncCall(true)
initialize()
beego.Info("AppPath:", beego.AppPath)
if setting.IsProMode {
beego.Info("Product mode enabled")
} else {
beego.Info("Develment mode enabled")
}
beego.Info(beego.BConfig.AppName, setting.APP_VER, setting.AppUrl)
if !setting.IsProMode {
beego.SetStaticPath("/static_source", "static_source")
beego.BConfig.WebConfig.DirectoryIndex = true
}
// Add Filters
beego.InsertFilter("/img/*", beego.BeforeRouter, attachment.ImageFilter)
beego.InsertFilter("/captcha/*", beego.BeforeRouter, setting.Captcha.Handler)
// Register routers.
//posts := new(post.PostListRouter)
//beego.Router("/", posts, "get:Home")
//beego.Router("/:slug(recent|best|cold|favs|follow)", posts, "get:Navs")
//beego.Router("/category/:slug", posts, "get:Category")
//beego.Router("/topic/:slug", posts, "get:Topic;post:TopicSubmit")
//postR := new(post.PostRouter)
//beego.Router("/new", postR, "get:New;post:NewSubmit")
//beego.Router("/post/:post([0-9]+)", postR, "get:Single;post:SingleSubmit")
//beego.Router("/post/:post([0-9]+)/edit", postR, "get:Edit;post:EditSubmit")
// if setting.NativeSearch || setting.SphinxEnabled {
// searchR := new(post.SearchRouter)
// beego.Router("/search", searchR, "get:Get")
// }
beego.InsertFilter("/login/*/access", beego.BeforeRouter, auth.OAuthAccess)
beego.InsertFilter("/login/*", beego.BeforeRouter, auth.OAuthRedirect)
login := new(auth.LoginRouter)
beego.Router("/admin/login", login, "get:Get;post:Login")
beego.Router("/logout", login, "get:Logout")
socialR := new(auth.SocialAuthRouter)
beego.Router("/register/connect", socialR, "get:Connect;post:ConnectPost")
register := new(auth.RegisterRouter)
beego.Router("/register", register, "get:Get;post:Register")
beego.Router("/active/success", register, "get:ActiveSuccess")
beego.Router("/active/:code([0-9a-zA-Z]+)", register, "get:Active")
settings := new(auth.SettingsRouter)
beego.Router("/settings/profile", settings, "get:Profile;post:ProfileSave")
beego.Router("/settings/home", settings, "get:HomeAbout;post:HomeAboutSave")
beego.Router("/settings/homeSliders", settings, "get:HomeSliders;post:HomeSlidersSave")
forgot := new(auth.ForgotRouter)
beego.Router("/forgot", forgot)
beego.Router("/reset/:code([0-9a-zA-Z]+)", forgot, "get:Reset;post:ResetPost")
upload := new(attachment.UploadRouter)
beego.Router("/upload", upload, "post:Post")
alarmR := new(api.AlarmApiRouter)
beego.Router("/api/alarm/list/:aid([0-9]+)", alarmR, "get:AlarmList")
smsR := new(api.SmsApiRouter)
beego.Router("/api/sms/ip/:ip", smsR, "post:SendSmsByIp")
beego.Router("/api/sms/mac/:mac", smsR, "post:SendSmsByMac")
beego.Router("/api/sms/warn/:sid([0-9]+)", smsR, "post:WarnBySubSystem")
beego.Router("/api/sms/list/:aid([0-9]+)", smsR, "get:SmsList")
apiR := new(api.ApiRouter)
beego.Router("/api/xsrf/refresh", apiR, "get:XSRF")
areaR := new(api.AreaApiRouter)
beego.Router("/api/area/list/:aid([0-9]+)", areaR, "get:Areas")
subsystemR := new(api.SubSystemApiRouter)
beego.Router("/api/subsystem/list/:aid([0-9]+)", subsystemR, "get:SubSystems")
beego.Router("/api/syncAreas/:sid([0-9]+)", subsystemR, "get:SyncAreas")
beego.Router("/api/subsystem/areas/:sid([0-9]+)", subsystemR, "get:Areas")
beego.Router("/api/subsystem/updaterelatedarea", subsystemR, "post:UpdateRelatedArea")
// beego.Router("/api/subsystem/newsbsarea", subsystemR, "post:NewSbsArea")
beego.Router("/api/subsystem/updatesbsarea", subsystemR, "post:UpdateSbsArea")
beego.Router("/api/subsystem/equiplist/:aid([0-9]+)", subsystemR, "get:EquipList")
personR := new(api.PersonApiRouter)
beego.Router("/api/person/list/:aid([0-9]+)", personR, "get:People")
equipR := new(api.EquipApiRouter)
beego.Router("/api/equip/list/:aid([0-9]+)", equipR, "get:Equips")
beego.Router("/api/equip/updatebatch", equipR, "post:UpdateBatchEquipsToArea")
beego.Router("/api/equip/sync/:sid([0-9]+)", equipR, "post:SyncEquips")
beego.Router("/api/equip/max/:sid([0-9]+)", equipR, "post:MaxEquipId")
reportR := new(api.ReportApiRouter)
beego.Router("/api/report/piechart", reportR, "get:PieChart")
beego.Router("/api/report/barchart", reportR, "get:BarChart")
adminReport := new(admin.AdminReportRouter)
beego.Router("/admin/report/piechart", adminReport, "get:PieChart")
beego.Router("/admin/report/barchart", adminReport, "get:BarChart")
adminDashboard := new(admin.AdminDashboardRouter)
beego.Router("/admin/", adminDashboard)
beego.Router("/admin/alarmlist", adminDashboard, "get:AlarmList")
beego.Router("/admin/smslist", adminDashboard, "get:SmsList")
adminR := new(admin.AdminRouter)
beego.Router("/admin/model/get", adminR, "post:ModelGet")
beego.Router("/admin/model/select", adminR, "post:ModelSelect")
routes := map[string]beego.ControllerInterface{
"user": new(admin.UserAdminRouter),
"area": new(admin.AreaAdminRouter),
"equip": new(admin.EquipAdminRouter),
"person": new(admin.PersonAdminRouter),
"subsystem": new(admin.SubSystemAdminRouter),
}
for name, router := range routes {
beego.Router(fmt.Sprintf("/admin/:model(%s)", name), router, "get:List")
beego.Router(fmt.Sprintf("/admin/:model(%s)/:id(new)", name), router, "get:Create;post:Save")
beego.Router(fmt.Sprintf("/admin/:model(%s)/:id([0-9]+)", name), router, "get:Edit;post:Update")
beego.Router(fmt.Sprintf("/admin/:model(%s)/:id([0-9]+)/:action(delete)", name), router, "get:Confirm;post:Delete")
}
// "robot.txt"
beego.Router("/robot.txt", &base.RobotRouter{})
if beego.BConfig.RunMode == "dev" {
beego.Router("/test/:tmpl(mail/.*)", new(base.TestRouter))
}
// For all unknown pages.
beego.Run()
}