1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014-2015 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Configuration of the Web server of xymus.net
23 # Use actions defined by contribs
25 import benitlux
::benitlux_controller
26 import opportunity
::opportunity_controller
27 import nitiwiki
::wiki_edit
29 # Header for the whole site
33 # Current page id, is used to set the `active` class on the header tab
34 var page
: nullable String
36 # Make room for a login or logout placeholder (used by tnitter)
37 var login_placeholder
: Bool
41 var actives
= new HashMap[String, String]
43 if page
!= null then actives
[page
] = " class=\"active\
""
46 <nav class="navbar navbar-default" role="navigation">
47 <div class="container-fluid">
48 <div class="navbar-header">
49 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
50 <span class="sr-only">Toggle navigation</span>
51 <span class="icon-bar"></span>
52 <span class="icon-bar"></span>
53 <span class="icon-bar"></span>
55 <a class="navbar-brand" href="http://xymus.net/">Xymus.net</a>
58 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
59 <ul class="nav navbar-nav">
60 <li{{{actives.get_or_default("ens", "")}}}><a href="http://xymus.net/ens/">Enseignement</a></li>
61 <li{{{actives.get_or_default("opportunity", "")}}}><a href="http://xymus.net/opportunity/">Opportunité</a></li>
62 <li{{{actives.get_or_default("tnitter", "")}}}><a href="http://tnitter.xymus.net/">Tnitter</a></li>
63 <li><a href="http://pep8.xymus.net/">Pep/8 Analysis</a></li>
64 <li{{{actives.get_or_default("benitlux", "")}}}><a href="http://benitlux.xymus.net/">Benitlux</a></li>
67 <ul class="nav navbar-nav pull-right">
69 if login_placeholder
then add
"%header_right%"
78 redef fun to_s
do return write_to_string
81 class OpportunityMasterHeader
82 super OpportunityHeader
84 var master_header
: MasterHeader
92 <title>Opportunity - The meetup planner</title>
93 <meta charset="utf-8">
94 <meta name="viewport" content="width=device-width, initial-scale=1">
95 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
96 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
97 <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
105 .opportunity-action:hover {
115 redef class TnitterWeb
116 redef var header
: String = (new MasterHeader("tnitter", true)).to_s
119 redef class BenitluxDocument
120 redef var header
= new MasterHeader("benitlux", false)
123 redef class ErrorTemplate
124 redef var header
= new MasterHeader(null, false)
127 redef class OpportunityPage
128 redef var header
= new OpportunityMasterHeader(new MasterHeader("opportunity", false))
131 redef class MeetupCreationPage
132 redef var templates
do
134 map
["Pizzas spécial LATECE"] = ["Végétarienne", "Pepperoni", "Viandes", "Poulet BBQ"]
135 map
["Heures de réunion à l'UQAM"] = ["7h 30", "9h", "10h 30", "12h",
136 "13h 30", "15h", "16h 30", "18h"]
141 # Avoid executing when running tests
142 if "NIT_TESTING".environ
== "true" then exit
0
144 # Setup server interfaces
146 # Change these to use this config on your own server!
147 var default_vh
= new VirtualHost("xymus.net:80")
148 var vps_vh
= new VirtualHost("vps.xymus.net:80")
149 var tnitter_vh
= new VirtualHost("tnitter.xymus.net:80")
150 var pep8_vh
= new VirtualHost("pep8.xymus.net:80")
151 var benitlux_vh
= new VirtualHost("benitlux.xymus.net:80")
153 var factory
= new HttpFactory.and_libevent
154 factory
.config
.virtual_hosts
.add default_vh
155 factory
.config
.virtual_hosts
.add vps_vh
156 factory
.config
.virtual_hosts
.add tnitter_vh
157 factory
.config
.virtual_hosts
.add pep8_vh
158 factory
.config
.virtual_hosts
.add benitlux_vh
160 # Ports are open, drop to a low-privileged user if we are root
161 var user_group
= new UserGroup("nitcorn", "nitcorn")
162 if sys
.uid
== 0 then user_group
.drop_privileges
164 # Tnitter is available at `tnitter.xymus.net` and `xymus.net/tnitter/`
165 var tnitter
= new TnitterWeb
166 default_vh
.routes
.add
new Route("/tnitter/", tnitter
)
168 tnitter_vh
.routes
.add
new Route("/rest/", new TnitterREST)
169 tnitter_vh
.routes
.add
new Route("/push/", new TnitterPush)
170 tnitter_vh
.routes
.add
new Route(null, tnitter
)
172 # Pep/8 Analysis is only a file server. It is available at `pep8.xymus.net`
173 # and through the global/default file server at `xymus.net/pep8/`
175 # TODO Implement pep8analysis server-side with a nitcorn action
176 pep8_vh
.routes
.add
new Route(null, new FileServer("/var/www/pep8/"))
178 # Benitlux is available at `benitlux.xymus.net` and `xymus.net/benitlux/`
180 # It has 2 actions/Web interfaces. The Web user UI to subscribe and unsubscribe
181 # to the mailing list. And the RESTful interface used by the Android app.
182 var benitlux_sub
= new BenitluxSubscriptionAction
183 var benitlux_rest
= new BenitluxRESTAction
184 default_vh
.routes
.add
new Route("/benitlux/rest/", benitlux_rest
)
185 default_vh
.routes
.add
new Route("/benitlux/", benitlux_sub
)
186 benitlux_vh
.routes
.add
new Route("/rest/", benitlux_rest
)
187 benitlux_vh
.routes
.add
new Route(null, benitlux_sub
)
189 # Opportunity service
190 var opportunity
= new OpportunityWelcome
191 var opportunity_rest
= new OpportunityRESTAction
192 default_vh
.routes
.add
new Route("/opportunity/rest/", opportunity_rest
)
193 default_vh
.routes
.add
new Route("/opportunity/", opportunity
)
195 # Nitiwiki modification form
196 var passwords
= "nitiwiki_passwords".to_path
.read_lines
197 assert passwords
.not_empty
198 default_vh
.routes
.add
new Route("/edit", new EditAction("http://xymus.net/", "/home/xymus/projects/wiki/config.ini", passwords
))
200 # We use a special file server for the path `xymus.net/ens` only to display
201 # a different header.
202 var file_server_ens
= new FileServer("/var/www/ens/")
203 file_server_ens
.header
= (new MasterHeader("ens", false))
204 default_vh
.routes
.add
new Route("/ens/", file_server_ens
)
206 # Default file server is used for the main page at `xymus.net` and it is
207 # the default action for any path not caught by other actions.
208 var file_server
= new FileServer("/var/www/")
209 file_server
.header
= (new MasterHeader(null, false))
210 default_vh
.routes
.add
new Route(null, file_server
)
211 vps_vh
.routes
.add
new Route(null, file_server
)
213 # Launch server main loop