summaryrefslogtreecommitdiffstats
path: root/lib/ASM/Config.pm
blob: ff6f7457b9ce33ff6001aadbe223a846cada91c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package ASM::Config;
no autovivification;
use warnings;
use strict;
use feature 'state';

use JSON;
use IO::All;

our $json = JSON->new->utf8->pretty->canonical;

sub serialize {
  return $json->encode(@_);
}
sub deserialize {
  return $json->decode(@_);
}

sub readConfig {
  $::settings     = deserialize(io->file("$::cset/settings.json")->all);
  $::channels     = deserialize(io->file("$::cset/channels.json")->all);
  $::users        = deserialize(io->file("$::cset/users.json")->all);
  $::mysql        = deserialize(io->file("$::cset/mysql.json")->all);
  $::dnsbl        = deserialize(io->file("$::cset/dnsbl.json")->all);
  $::rules        = deserialize(io->file("$::cset/rules.json")->all);
  $::restrictions = deserialize(io->file("$::cset/restrictions.json")->all);
  $::blacklist    = deserialize(io->file("$::cset/blacklist.json")->all);
}

sub writeConfig {
  writeMysql();
  writeChannels();
  writeUsers();
  writeSettings();
  writeRestrictions();
  writeBlacklist();
  writeDnsbl();
  writeRules();
}

sub writeMysql {
  $::settingschanged=1;
  serialize($::mysql) > io->file("$::cset/mysql.json");
}

sub writeRules {
  $::settingschanged=1;
  serialize($::rules) > io->file("$::cset/rules.json");
}

sub writeDnsbl {
  $::settingschanged=1;
  serialize($::dnsbl) > io->file("$::cset/dnsbl.json");
}

sub writeChannels {
  $::settingschanged=1;
  serialize($::channels) > io("$::cset/channels.json");
}

sub writeUsers {
  $::settingschanged=1;
  serialize($::users) > io("$::cset/users.json");
}

sub writeSettings {
  $::settingschanged=1;
  serialize($::settings) > io("$::cset/settings.json");
}

sub writeRestrictions {
  $::settingschanged=1;
  serialize($::restrictions) > io("$::cset/restrictions.json");
}

sub writeBlacklist {
  $::settingschanged=1;
  serialize($::blacklist) > io("$::cset/blacklist.json");
}

return 1;
# vim: ts=2:sts=2:sw=2:expandtab