@@ -29,6 +29,7 @@ use rocket::response::NamedFile;
29
29
use rocket:: http:: RawStr ;
30
30
use rocket:: response:: content;
31
31
use rocket_contrib:: templates:: Template ;
32
+ use rocket_contrib:: serve:: StaticFiles ;
32
33
33
34
use getopts:: Options ;
34
35
use regex:: Regex ;
@@ -115,10 +116,10 @@ fn index_post(form: Result<Form<FormInput>, FormError>) -> content::Html<String>
115
116
content:: Html ( match form {
116
117
Ok ( form) => {
117
118
let config = & * CONFIG . lock ( ) . unwrap ( ) ;
118
- let destinations = if form. authkey == config. user_psk {
119
- & config. user_destinations
120
- } else if & form. authkey == & config. admin_psk {
119
+ let destinations = if form. authkey == config. admin_psk {
121
120
& config. admin_destinations
121
+ } else if & form. authkey == & config. user_psk {
122
+ & config. user_destinations
122
123
} else {
123
124
return content:: Html ( format ! ( "Wrong AUTHKEY: {:?}" , form) )
124
125
} ;
@@ -194,30 +195,6 @@ fn favicon() -> io::Result<NamedFile> {
194
195
NamedFile :: open ( "static/favicon.ico" )
195
196
}
196
197
197
- #[ get( "/static/<file..>" ) ]
198
- fn static_files ( file : PathBuf ) -> Option < NamedFile > {
199
- let allowed_files = vec ! (
200
- "css/bootstrap.min.css" ,
201
- "css/bootstrap.min.css.map" ,
202
- "css/style.css"
203
- ) ;
204
-
205
- if let Some ( file) = file. to_str ( ) {
206
- if allowed_files. contains ( & file) {
207
- return NamedFile :: open ( Path :: new ( "static/" ) . join ( file) ) . ok ( ) ;
208
- }
209
- }
210
- None
211
- }
212
-
213
- #[ get( "/keyfiles/<file..>" ) ]
214
- fn key_files ( file : PathBuf ) -> Option < NamedFile > {
215
- if let Some ( file) = file. to_str ( ) {
216
- return NamedFile :: open ( Path :: new ( "keyfiles/" ) . join ( file) ) . ok ( )
217
- }
218
- None
219
- }
220
-
221
198
fn main ( ) {
222
199
let args: Vec < String > = env:: args ( ) . collect ( ) ;
223
200
let program = args[ 0 ] . clone ( ) ;
@@ -292,7 +269,9 @@ fn main() {
292
269
}
293
270
294
271
rocket:: ignite ( )
295
- . mount ( "/" , routes ! [ static_files, index_post, index_get, deploy_get, deploy_post, favicon, key_files] )
272
+ . mount ( "/static" , StaticFiles :: from ( "static" ) )
273
+ . mount ( "/keyfiles" , StaticFiles :: from ( "keyfiles" ) )
274
+ . mount ( "/" , routes ! [ index_post, index_get, deploy_get, deploy_post, favicon] )
296
275
. attach ( Template :: fairing ( ) )
297
276
. launch ( ) ;
298
277
}
0 commit comments