Showing 3 changed files with 0 additions and 330 deletions
-192
action/action
... ...
@@ -1,192 +0,0 @@
1
-#!/usr/bin/perl -w
2
-use strict;
3
-use warnings;
4
-use DBI;
5
-use POSIX qw(strftime);
6
-#use Data::Dumper;
7
-use Email::Send::SMTP::Gmail;
8
-
9
-my $scriptconf = $ENV{PWD} . "/$0";
10
-$scriptconf =~ s/\.pl$//;
11
-$scriptconf =~ s/$/.conf/;
12
-if (-r $scriptconf) {
13
-    package cfg;
14
-    unless (my $return = do $scriptconf) {
15
-        warn "couldn't parse $scriptconf: $@" if $@;
16
-        warn "couldn't do $scriptconf: $!"    unless defined $return;
17
-        warn "couldn't run $scriptconf"       unless $return;
18
-    }
19
-}
20
-else {
21
-    print "pas de config\n";
22
-    exit;
23
-}
24
-
25
-if (-r $cfg::config{notification}->{flag}) {
26
-    open FLAG, $cfg::config{notification}->{flag};
27
-    while (<FLAG>) {
28
-        if (/^to:(.+)$/) {
29
-            $cfg::config{test}->{address} = $1;
30
-        }
31
-        elsif (/^intro:([[:alnum:]]+)/) {
32
-            $cfg::config{test}->{intro} = $1;
33
-        }
34
-    }
35
-    close FLAG;
36
-    if (exists $cfg::config{test}->{address} and exists $cfg::config{test}->{intro}) {
37
-        delete $cfg::config{notification}->{to};
38
-        $cfg::config{notification}->{to}->{test}->{address} = $cfg::config{test}->{address};
39
-        $cfg::config{notification}->{to}->{test}->{intro} = '@' . $cfg::config{test}->{intro};
40
-        $cfg::config{notification}->{to}->{test}->{outro} = "pour test";
41
-        $cfg::config{notification}->{to}->{test}->{subject} = "test de l'envoi des actions de la section";
42
-    }
43
-}
44
-
45
-my $dbh = DBI->connect($cfg::config{db}->{driver}, $cfg::config{db}->{user}, $cfg::config{db}->{password}, {'RaiseError' => 1, 'AutoCommit' => 1});
46
-
47
-my $request;
48
-my $sth;
49
-my $polls;
50
-my $slots;
51
-my $votes;
52
-my %tables = ();
53
-$tables{polls} = $cfg::config{prefix} . "poll";
54
-$tables{votes} = $cfg::config{prefix} . "vote";
55
-$tables{slots} = $cfg::config{prefix} . "slot";
56
-
57
-$request = "select id as poll_id, admin_name as category, admin_id, title, recurrent, description from $tables{polls}";
58
-$sth = $dbh->prepare($request);
59
-$polls = $dbh->selectall_hashref($sth, [ qw(category poll_id) ]);
60
-
61
-# admin_name = catégorie
62
-my $dt = strftime "%s", localtime;
63
-foreach my $category (keys(%{$polls})) {
64
-    foreach my $poll_id (keys(%{$polls->{$category}})) {
65
-        $request = "select id as slot_id, title, poll_id from $tables{slots} where poll_id = '$poll_id'";
66
-        $sth = $dbh->prepare($request);
67
-        $slots =  $dbh->selectall_hashref($sth, [ qw(poll_id slot_id) ]);
68
-
69
-        $request = "select id as vote_id, uniqId, poll_id, choices from $tables{votes} where poll_id = '$poll_id'";
70
-        $sth = $dbh->prepare($request);
71
-        $votes =  $dbh->selectall_hashref($sth, [ qw(poll_id uniqId) ]);
72
-
73
-        my $last_date = 0;
74
-        my @deleted = ();
75
-        foreach my $slot_id (keys(%{$slots->{$poll_id}})) {
76
-            if ($slots->{$poll_id}->{$slot_id}->{title} < $dt) {
77
-                $slots->{$poll_id}->{$slot_id}->{to_delete} = 1;
78
-            }
79
-            my $title = $slots->{$poll_id}->{$slot_id}->{title};
80
-            $last_date = strftime "%s", localtime($title) if ($title > $last_date);
81
-        }
82
-
83
-# PURGE DES ACTIONS DÉJÀ PASSÉES ET NON RÉCURRENTES
84
-        if ($last_date < $dt and ( ! defined $polls->{$category}->{$poll_id}->{recurrent} or $polls->{$category}->{$poll_id}->{recurrent} < 1)) {
85
-            print "purge de $category/$polls->{$category}->{$poll_id}->{title}\n";
86
-            $request = "delete from $tables{polls} where id = '$poll_id'";
87
-            delete $polls->{$category}->{$poll_id};
88
-            $dbh->do($request);
89
-#            print $request . "\n";
90
-            $request = "delete from $tables{slots} where poll_id = '$poll_id'";
91
-            delete $slots->{$poll_id};
92
-            $dbh->do($request);
93
-#            print $request . "\n";
94
-            $request = "delete from $tables{votes} where poll_id = '$poll_id'";
95
-            delete $votes->{$poll_id};
96
-            $dbh->do($request);
97
-#            print $request . "\n";
98
-            next;
99
-        }
100
-
101
-# SUPPRESSION DES VOTES PASSÉS ET AJOUT DES VOTES SUIVANTS
102
-        foreach my $slot_id (keys(%{$slots->{$poll_id}})) {
103
-            next if (! exists $slots->{$poll_id}->{$slot_id}->{to_delete});
104
-            $request = "delete from $tables{slots} where poll_id = '$poll_id' and title = '$slots->{$poll_id}->{$slot_id}->{title}'"; 
105
-            $dbh->do($request);
106
-#            print $request . "\n";            
107
-            if ($polls->{$category}->{$poll_id}->{recurrent} > 0) {
108
-                $last_date += $polls->{$category}->{$poll_id}->{recurrent} * 86400;
109
-                my $new_date = strftime "%s", localtime($last_date);
110
-                $request = "insert into $tables{slots} (poll_id, title, moments) values('$slots->{$poll_id}->{$slot_id}->{poll_id}', '$new_date', NULL)";
111
-                $dbh->do($request);
112
-#                print $request . "\n";
113
-                foreach my $uniqId (keys(%{$votes->{$poll_id}})) {
114
-                    my $vote = substr $votes->{$poll_id}->{$uniqId}->{choices}, 1;
115
-                    if ($vote eq "") {
116
-                        $request = "delete from $tables{votes} where uniqId = '$uniqId'";
117
-                        delete $votes->{$poll_id}->{$uniqId};
118
-                        $dbh->do($request);
119
-#                        print $request . "\n";
120
-                    }
121
-                    else {
122
-                        $request = "update $tables{votes} set choices='$vote' where uniqId = '$uniqId'";
123
-                        $dbh->do($request);
124
-#                        print $request . "\n";
125
-                    }
126
-                }
127
-            }
128
-        }
129
-    }
130
-}
131
-# commit ineffective with AutoCommit enabled
132
-# $dbh->commit();
133
-$dbh->disconnect();
134
-
135
-exit if (! -r $cfg::config{notification}->{flag});
136
-
137
-my ($mail,$error)=Email::Send::SMTP::Gmail->new(%{$cfg::config{notification}{from}});
138
-die "session error: $error" unless ($mail!=-1);
139
-
140
-foreach my $dest (keys(%{$cfg::config{notification}->{to}})) {
141
-
142
-    if (defined($cfg::config{notification}->{to}->{test}->{address}) and $dest ne 'test') {
143
-        continue;
144
-    }
145
-    my $data = '';
146
-
147
-    if (substr($cfg::config{notification}->{to}->{$dest}->{intro}, 0, 1) eq "@") {
148
-        if (-r $cfg::config{notification}->{intro_default_path} . substr($cfg::config{notification}->{to}->{$dest}->{intro},1) . $cfg::config{notification}->{intro_suffix}) {
149
-            open INTRO, $cfg::config{notification}->{intro_default_path} . substr($cfg::config{notification}->{to}->{$dest}->{intro},1) . $cfg::config{notification}->{intro_suffix};
150
-            while (<INTRO>) {
151
-                $data .= $_ . '<br>';
152
-            }
153
-            close INTRO;
154
-        }
155
-        else {
156
-            $data .= 'Salut,<br><br>voici les actions de la section pour les prochaines semaines:<br><br>';
157
-        }
158
-    }
159
-    else {
160
-        $data .= $cfg::config{notification}->{to}->{$dest}->{intro};
161
-    }
162
-
163
-    foreach my $category (keys(%{$polls})) {
164
-        next unless (keys%{$polls->{$category}});
165
-        $data .= "<h1>$category</h1>";
166
-        foreach my $poll_id (keys(%{$polls->{$category}})) {
167
-            my $title    = $polls->{$category}->{$poll_id}->{title};
168
-            if (exists $cfg::config{notification}->{to}->{$dest}->{admin}) {
169
-                my $admin_id = $polls->{$category}->{$poll_id}->{admin_id};
170
-                $data .= "<a href=$cfg::config{url}/adminstuds.php?poll=$admin_id>$title</a><br>";
171
-            }
172
-            else {
173
-                $data .= "<a href=$cfg::config{url}/studs.php?poll=$poll_id>$title</a><br>";
174
-                $data .= $polls->{$category}->{$poll_id}->{description} . "<br><br>";
175
-            }
176
-        }
177
-    }
178
-
179
-    $data .= $cfg::config{notification}->{to}->{$dest}->{outro};
180
-
181
-    $data =~ s/\n/<br>/g;
182
-
183
-    $mail->send(
184
-            -from=>$cfg::config{notification}{from_infos}{from},
185
-            -replyto=>$cfg::config{notification}{from_infos}{replyto},
186
-            -to=>$cfg::config{notification}->{to}->{$dest}->{address},
187
-            -subject=>$cfg::config{notification}->{to}->{$dest}->{subject},
188
-            -contenttype=>'text/html',
189
-            -body=>$data
190
-        );
191
-}
192
-$mail->bye();
-47
action/action.conf.example
... ...
@@ -1,47 +0,0 @@
1
-# vim: ft=perl
2
-%config = (
3
-        url    => 'https://xxxxxxxxxx.xx', # l'url de base vers les sondages
4
-        prefix => 'xxxxx', # préfixe des tables dans la base de donnée
5
-        db     => {
6
-            driver   => "DBI:mysql:database=xxxxxx;host=xxxxxx", # connecteur de la base de données mysql
7
-            user     => "xxxxxxxxxxxx",
8
-            password => "xxxxxxxxxxxx",
9
-        },
10
-        notification => {
11
-            from => { # config SMTP
12
-                -smtp=>'xxxxx.xxxx.xxx', # serveur SMTP
13
-                -port=> xxxx,  # port SMTP
14
-                -layer=>'ssl',
15
-                -login=>'xxxxxxxxxxx@xxxxxxx', # login
16
-                -pass=>'xxxxxxxxx' # mot de passe
17
-            },
18
-            from_infos => { # l'en-tête FROM et REPLY
19
-                from =>'"Joli nom" <adresse@mail.fr>',
20
-                replyto =>'xxxxxxxx@xxxxxxx',
21
-            },
22
-            flag => '/xxxxxx/xxxxxxx/xxxxx', # fichier de signal d'envoi, cf conf unit systemd, et appli sms
23
-            intro_default_path => '/var/www/owncloud/data/xxxxxxxxxxx/files/xxxxxxxxxxx/xxxxx', # cf appli sms
24
-            intro_suffix => '.html', # cf appli sms
25
-            to => { # chacune des entrées correspond à un mail envoyé, tous les mails sont envoyés en même temps
26
-                xxxxxxx => {
27
-                    address => 'xxxxxx@xxxxxxx', # adresse mail à laquelle envoyer
28
-                    subject => 'le sujet du mail',
29
-                    intro  => "du texte qui sera affiché AVANT les liens, avec balises html possible"
30
-                    outro  => "du texte qui sera affiché APRÈS les liens, avec balises html possible",
31
-                    admin => 1, # si cette valeur existe et est égale à 1, alors les liens vers les pages d'administration des sondage sont envoyés
32
-                },
33
-                yyyyyyyy => {
34
-                    address => 'yyyyyyy@yyyyyyyy', # adresse mail à laquelle envoyer
35
-                    subject => 'un sujet du mail',
36
-                    intro  => '@foo', # si cette valeur commence par @ alors prend le fichier html correspondant pour l'intro
37
-                    outro  => "du texte affiché après les liens avec possibilité de balise html",
38
-                },
39
-                zzzzzzzzz => {
40
-                    address => 'zzzzzzzz@zzzzzzz', # adresse mail à laquelle envoyer
41
-                    subject => 'un sujet du mail',
42
-                    intro  => '@bar', # si cette valeur commence par @ alors prend le fichier html correspondant pour l'intro
43
-                    outro  => "du texte affiché APRÈS les liens avec possibilité de balise html",
44
-                },
45
-            },
46
-        },
47
-    );
-91
action/synthesis
... ...
@@ -1,91 +0,0 @@
1
-#!/usr/bin/perl -w
2
-use strict;
3
-use warnings;
4
-use DBI;
5
-use POSIX qw(strftime);
6
-use Data::Dumper;
7
-
8
-my $scriptconf = $ENV{PWD} . "/action.conf";
9
-if (-r $scriptconf) {
10
-    package cfg;
11
-    unless (my $return = do $scriptconf) {
12
-        warn "couldn't parse $scriptconf: $@" if $@;
13
-        warn "couldn't do $scriptconf: $!"    unless defined $return;
14
-        warn "couldn't run $scriptconf"       unless $return;
15
-    }
16
-}
17
-else {
18
-    print "pas de config\n";
19
-    exit;
20
-}
21
-
22
-my $dbh = DBI->connect($cfg::config{db}->{driver}, $cfg::config{db}->{user}, $cfg::config{db}->{password}, {'RaiseError' => 1, 'AutoCommit' => 1});
23
-
24
-my $request;
25
-my $sth;
26
-my $polls;
27
-my $slots;
28
-my $votes;
29
-my %tables = ();
30
-$tables{polls} = $cfg::config{prefix} . "poll";
31
-$tables{votes} = $cfg::config{prefix} . "vote";
32
-$tables{slots} = $cfg::config{prefix} . "slot";
33
-
34
-$request = "select id as poll_id, admin_name as category, admin_id, title, recurrent, description from $tables{polls}";
35
-$sth = $dbh->prepare($request);
36
-$polls = $dbh->selectall_hashref($sth, [ qw(category poll_id) ]);
37
-
38
-# admin_name = catégorie
39
-my $dt = strftime "%s", localtime;
40
-foreach my $category (keys(%{$polls})) {
41
-    foreach my $poll_id (keys(%{$polls->{$category}})) {
42
-        $request = "select id as slot_id, title, poll_id from $tables{slots} where poll_id = '$poll_id'";
43
-        $sth = $dbh->prepare($request);
44
-        $slots =  $dbh->selectall_hashref($sth, [ qw(poll_id slot_id) ]);
45
-
46
-        $request = "select id as vote_id, uniqId, poll_id, choices, name from $tables{votes} where poll_id = '$poll_id'";
47
-        $sth = $dbh->prepare($request);
48
-        $votes =  $dbh->selectall_hashref($sth, [ qw(poll_id uniqId) ]);
49
-
50
-        my $last_date = 0;
51
-        my @deleted = ();
52
-        $polls->{$category}->{$poll_id}->{next} = strftime "%s", 0, 0, 0, 1, 12, 2099;
53
-        $polls->{$category}->{$poll_id}->{compteur} = 0;
54
-        foreach my $slot_id (keys(%{$slots->{$poll_id}})) {
55
-            my $title = $slots->{$poll_id}->{$slot_id}->{title};
56
-            if ($title lt $polls->{$category}->{$poll_id}->{next}) {
57
-                $polls->{$category}->{$poll_id}->{next} = $title;
58
-            }
59
-        }
60
-        foreach my $uniqId (keys(%{$votes->{$poll_id}})) {
61
-            $polls->{$category}->{$poll_id}->{compteur}++;
62
-            $polls->{$category}->{$poll_id}->{liste} .= $votes->{$poll_id}->{$uniqId}->{name} . ", " if (substr($votes->{$poll_id}->{$uniqId}->{choices},0, 1) eq '2');
63
-        }
64
-        $polls->{$category}->{$poll_id}->{liste} =~ s/,\s*$//;
65
-    }
66
-}
67
-$dbh->disconnect();
68
-
69
-my $data = '<!DOCTYPE html><html lang="fr"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body>';
70
-
71
-foreach my $category (keys(%{$polls})) {
72
-    next unless (keys%{$polls->{$category}});
73
-    $data .= "<center><h1>$category</h1></center>";
74
-    foreach my $poll_id (keys(%{$polls->{$category}})) {
75
-        my $title    = $polls->{$category}->{$poll_id}->{title};
76
-        $data .= "<b>" . strftime("[%a %e %b] ", localtime($polls->{$category}->{$poll_id}->{next})). $title . "</b><br>";
77
-        if ($polls->{$category}->{$poll_id}->{compteur} gt 0) {
78
-            $data .= "<i>$polls->{$category}->{$poll_id}->{compteur} inscrit-e";
79
-            $data .= "-s" if $polls->{$category}->{$poll_id}->{compteur} gt 1;
80
-            $data .= " dont présent-e: $polls->{$category}->{$poll_id}->{liste}" if length($polls->{$category}->{$poll_id}->{liste}) gt 0;
81
-            $data .= "</i><br>";
82
-        }
83
-        $data .= $polls->{$category}->{$poll_id}->{description} . "<br><br>";
84
-    }
85
-}
86
-
87
-$data .= "<HR><center>" . strftime("%c", localtime()) . '</center></body></html>';
88
-
89
-$data =~ s/\n/<br>/g;
90
-
91
-print $data;