chiark / gitweb /
Merge remote branch 'origin/master'
[modbot-mtm.git] / ModerationCommon.pm
1
2 package ModerationCommon;
3
4 BEGIN {
5     use Exporter   ();
6     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
7
8     $VERSION     = 1.00;
9
10     @ISA         = qw(Exporter);
11     @EXPORT      = qw(hash $hashlen
12                       readsettings %setting
13                       sendmail_start sendmail_finish);
14     %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
15
16     @EXPORT_OK   = qw();
17 }
18
19 our $hashlen=32;
20
21 sub hash ($) {
22     my $r= `echo $_[0] | sha256sum`; $? and die $?;
23     $r =~ s/ *\-$//;
24     chomp $r;
25     return $r;
26 }
27
28 sub sendmail_start () {
29     open ::P, "|/usr/sbin/sendmail -odb -oee -oi -t" or die $!;
30 }
31 sub sendmail_finish () {
32     $?=0; $!=0; close ::P or warn "$! $?";
33 }
34
35 our %setting;
36
37 sub readsettingsfile ($) {
38     my ($file) = @_;
39     open SET, "<$file" or die "$file $!";
40     while (<SET>) {
41         next unless m/\S/;
42         next if m/^\#/;
43         m/^([A-Z_]+)\=(.*?)\s*$/ or die;
44         $setting{$1}= $2;
45     }
46 }
47
48 sub readsettings () {
49     readsettingsfile("../../global-settings");
50     readsettingsfile("../settings");
51 }
52
53 1;