ctf-server
old server for hosting capture-the-flag
git clone https://9o.is/git/ctf-server.git
Boot.scala
(3245B)
1 package bootstrap.liftweb
2
3 import com.jcabrra.model._
4 import net.liftweb._
5 import util._
6 import common._
7 import http._
8 import mapper._
9 import sitemap._, Loc._
10 import net.liftmodules.extras.LiftExtras
11
12
13 /**
14 * A class that's instantiated early and run. It allows the application
15 * to modify lift's environment
16 */
17 class Boot {
18 def boot {
19
20 // where to search snippet
21 LiftRules.addToPackages("com.jcabrra")
22
23 if (!DB.jndiJdbcConnAvailable_?) {
24 val vendor =
25 new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver",
26 Props.get("db.url") openOr
27 "jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE",
28 Props.get("db.user"), Props.get("db.password"))
29
30 LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)
31
32 DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)
33 }
34
35 Schemifier.schemify(true, Schemifier.infoF _, User)
36 Schemifier.schemify(true, Schemifier.infoF _, Flag)
37 Schemifier.schemify(true, Schemifier.infoF _, Challenge)
38 Schemifier.schemify(true, Schemifier.infoF _, CapturedFlags)
39 Schemifier.schemify(true, Schemifier.infoF _, RequiredFlags)
40 Schemifier.schemify(true, Schemifier.infoF _, ChatMessage)
41 Schemifier.schemify(true, Schemifier.infoF _, BroadcastMessage)
42
43 // Build SiteMap
44 val entries = List(
45 Menu.i("Index") / "index",
46 Menu.i("About") / "about" >> LocGroup("topbar"),
47 Menu.i("Intro") / "intro" >> LocGroup("topbar"),
48 Menu.i("Players") / "players" >> LocGroup("topbar"),
49 Menu.i("Settings") / "settings" >> If(() => User.loggedIn_?, () => RedirectResponse("/")) >> LocGroup("topbar"),
50 Menu.i("Challenges") / "challenges" >> If(() => User.loggedIn_?, () => RedirectResponse("/")) >> LocGroup("topbar"),
51 Menu.i("Join The Fun") / "login" >> If(() => User.notLoggedIn_?, () => RedirectResponse("/")) >> LocGroup("topbar"),
52 Menu.i("Logout") / "logout" >> If(() => User.loggedIn_?, () => RedirectResponse("/")) >> LocGroup("topbar") >> EarlyResponse(() => {
53 User.logUserOut()
54 Full(RedirectResponse("/"))
55 })
56 )
57
58 // set the sitemap. Note if you don't want access control for
59 // each page, just comment this line out.
60 LiftRules.setSiteMap(SiteMap(entries:_*))
61
62
63 //Show the spinny image when an Ajax call starts
64 LiftRules.ajaxStart =
65 Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)
66
67 // Make the spinny image go away when it ends
68 LiftRules.ajaxEnd =
69 Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)
70
71 // Force the request to be UTF-8
72 LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
73
74 // set DocType to HTML5
75 LiftRules.htmlProperties.default.set((r: Req) =>new Html5Properties(r.userAgent))
76
77 // Init Extras
78 LiftExtras.init()
79
80 // don't include the liftAjax.js code. It's served statically.
81 LiftRules.autoIncludeAjaxCalc.default.set(() => (session: LiftSession) => false)
82
83 // H2 Console
84 if (Props.devMode || Props.testMode) {
85 LiftRules.liftRequest.append({
86 case r if (r.path.partPath match {
87 case "console" :: _ => true
88 case _ => false
89 }) => false
90 })
91 }
92
93 } //boot
94
95 } //Boot
96