Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ffdyndns
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Freifunk Luebeck
ffdyndns
Commits
9338c968
Commit
9338c968
authored
3 years ago
by
Paul
Browse files
Options
Downloads
Patches
Plain Diff
add config
parent
04d77a50
No related branches found
No related tags found
No related merge requests found
Pipeline
#3420
failed
3 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ffddns-web/src/config.rs
+24
-0
24 additions, 0 deletions
ffddns-web/src/config.rs
ffddns-web/src/main.rs
+66
-4
66 additions, 4 deletions
ffddns-web/src/main.rs
with
90 additions
and
4 deletions
ffddns-web/src/config.rs
0 → 100644
+
24
−
0
View file @
9338c968
use
serde
::{
Serialize
,
Deserialize
};
use
serde
;
#[derive(Clone,
Debug,
Serialize,
Deserialize)]
pub
struct
Config
{
pub
domain
:
Vec
<
Domain
>
,
pub
master
:
String
,
pub
rname
:
String
,
}
#[derive(Clone,
Debug,
Serialize,
Deserialize)]
pub
struct
Domain
{
/// the domain suffix. eg. for a dynamic domain
/// mydomain.ddns.org the name here is ddns.org
pub
name
:
String
,
/// a short description for a domain
pub
description
:
String
,
/// a list of networks, which a subdomain from this
/// domain is allowed to updated to
pub
nets
:
Vec
<
String
>
,
/// duration in days before a subdomain gets 'released' wgen not updated
pub
registration_time
:
usize
,
}
This diff is collapsed.
Click to expand it.
ffddns-web/src/main.rs
+
66
−
4
View file @
9338c968
...
...
@@ -2,6 +2,7 @@
mod
db
;
mod
web
;
mod
config
;
use
chrono
::
DateTime
;
use
chrono
::
Utc
;
...
...
@@ -18,17 +19,78 @@ use rocket::request::Outcome;
use
std
::
fmt
::{
self
,
Display
};
use
std
::
net
::
IpAddr
;
use
rand
;
use
toml
;
use
lazy_static
::
lazy_static
;
use
config
::
Config
;
use
std
::
fs
;
use
std
::
path
;
use
std
::
io
::
Read
;
use
log
::{
debug
,
info
,
error
};
use
std
::
process
::
exit
;
const
CONFIG_DIRS
:
&
[
&
str
]
=
&
[
"./ffdyndns.toml"
,
"/etc/ffdyndns.toml"
,
"/var/lib/ffdyndns/ffdyndns.toml"
,
];
lazy_static!
{
pub
static
ref
CONFIG
:
Config
=
{
let
file
=
CONFIG_DIRS
.iter
()
.map
(|
x
|
path
::
Path
::
new
(
x
))
.find
(|
p
|
p
.exists
()
&&
p
.is_file
());
match
file
{
Some
(
f
)
=>
{
debug!
(
"loading config: {}"
,
f
.to_str
()
.unwrap
());
let
mut
f
=
fs
::
File
::
open
(
f
)
.unwrap
();
let
mut
toml_str
=
String
::
new
();
f
.read_to_string
(
&
mut
toml_str
)
.expect
(
"can't read config file"
);
match
toml
::
from_str
::
<
Config
>
(
&
toml_str
)
{
Err
(
e
)
=>
{
eprintln!
(
"configuration error: {}"
,
e
);
exit
(
1
);
}
Ok
(
r
)
=>
r
}
}
None
=>
{
eprintln!
(
"could not find config file"
);
exit
(
1
);
},
}
};
}
// for p in CONFIG_DIRS.iter().map(|x| path::Path::new(x)) {
// if !p.exists() || !p.is_file() {
// continue;
// }
// debug!("loading config: {}", p.to_str().unwrap());
// let mut f = fs::File::open(p).unwrap();
// let mut toml_str = String::new();
// f.read_to_string(&mut toml_str).expect("can't read config file");
// config = toml::from_str::<Config>(&toml_str).unwrap()
// };
// return config;
#[derive(Debug,
Clone)]
pub
struct
DomainUpdate
{
domain
:
String
,
ip
:
IpAddr
domain
:
String
,
ip
:
IpAddr
}
fn
main
()
{
let
db
=
db
::
Database
::
new
(
"./ffddns.sqlite"
.into
());
web
::
start_web
(
db
);
println!
(
"{:?}"
,
CONFIG
.domain
);
let
db
=
db
::
Database
::
new
(
"./ffddns.sqlite"
.into
());
web
::
start_web
(
db
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment