78197136aed8bcfa0603d66413cf182c76ed0ca8
[strongswan.git] / src / libcharon / plugins / vici / perl / Vici-Session / lib / Vici / Session.pm
1 package Vici::Session;
2
3 our $VERSION = '0.9';
4
5 use strict;
6 use Vici::Packet;
7 use Vici::Message;
8
9 sub new {
10 my $class = shift;
11 my $socket = shift;
12 my $self = {
13 Packet => Vici::Packet->new($socket),
14 };
15 bless($self, $class);
16 return $self;
17 }
18
19 sub version {
20 return request('version', @_);
21 }
22
23 sub stats {
24 return request('stats', @_);
25 }
26
27 sub reload_settings {
28 return request_res('reload-settings', @_);
29 }
30
31 sub initiate {
32 return request_vars_res('initiate', @_);
33 }
34
35 sub terminate {
36 return request_vars_res('terminate', @_);
37 }
38
39 sub redirect {
40 return request_vars_res('redirect', @_);
41 }
42
43 sub install {
44 return request_vars_res('install', @_);
45 }
46
47 sub uninstall {
48 return request_vars_res('uninstall', @_);
49 }
50
51 sub list_sas {
52 return request_list('list-sas', 'list-sa', @_);
53 }
54
55 sub list_policies {
56 return request_list('list-policies', 'list-policy', @_);
57 }
58
59 sub list_conns {
60 return request_list('list-conns', 'list-conn', @_);
61 }
62
63 sub get_conns {
64 return request('get-conns', @_);
65 }
66
67 sub list_certs {
68 return request_list('list-certs', 'list-cert', @_);
69 }
70
71 sub list_authorities {
72 return request_list('list-authorities', 'list-authority', @_);
73 }
74
75 sub get_authorities {
76 return request('get-authorities', @_);
77 }
78
79 sub load_conn {
80 return request_vars_res('load-conn', @_);
81 }
82
83 sub unload_conn {
84 return request_vars_res('unload-conn', @_);
85 }
86
87 sub load_cert {
88 return request_vars_res('load-cert', @_);
89 }
90
91 sub load_key {
92 return request_vars_res('load-key', @_);
93 }
94
95 sub load_shared {
96 return request_vars_res('load-shared', @_);
97 }
98
99 sub clear_creds {
100 return request_res('clear-creds', @_);
101 }
102
103 sub load_authority {
104 return request_vars_res('load-authority', @_);
105 }
106
107 sub unload_authority {
108 return request_vars_res('unload-authority', @_);
109 }
110
111 sub load_pool {
112 return request_vars_res('load-pool', @_);
113 }
114
115 sub unload_pool {
116 return request_vars_res('unload-pool', @_);
117 }
118
119 sub get_pools {
120 return request('get-pools', @_);
121 }
122
123 sub get_algorithms {
124 return request('get-algorithms', @_);
125 }
126
127 # Private functions
128
129 sub request {
130 my ($command, $self) = @_;
131 return $self->{'Packet'}->request($command);
132 }
133
134 sub request_res {
135 my ($command, $self) = @_;
136 my $msg = $self->{'Packet'}->request($command);
137 return $msg->result();
138 }
139
140 sub request_vars_res {
141 my ($command, $self, $vars) = @_;
142 my $msg = $self->{'Packet'}->request($command, $vars);
143 return $msg->result();
144 }
145
146 sub request_list {
147 my ($command, $event, $self, $vars) = @_;
148 return $self->{'Packet'}->streamed_request($command, $event, $vars);
149 }
150
151 1;
152 __END__
153 =head1 NAME
154
155 Vici::Session - Perl binding for the strongSwan VICI configuration interface
156
157 =head1 SYNOPSIS
158
159 use Vici::Session;
160
161 =head1 DESCRIPTION
162
163 The Vici::Session module allows a Perl script to communicate with the open
164 source strongSwan IPsec daemon (https://www.strongswan.com) via the documented
165 Versatile IKE Configuration Interface (VICI). VICI allows the configuration,
166 management and monitoring of multiple IPsec connections.
167
168 =head2 EXPORT
169
170 None by default.
171
172 =head1 SEE ALSO
173
174 strongSwan Wiki: https://wiki.strongswan.org/projects/strongswan/wiki/Vici
175
176 strongSwan Mailing list: users@lists.strongswan.org
177
178 =head1 AUTHOR
179
180 Andreas Steffen, E<lt>andreas.steffen@strongswan.orgE<gt>
181
182 =head1 COPYRIGHT AND LICENSE
183
184 Copyright (C) 2015 by Andreas Steffen
185
186 Permission is hereby granted, free of charge, to any person obtaining a copy
187 of this software and associated documentation files (the "Software"), to deal
188 in the Software without restriction, including without limitation the rights
189 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
190 copies of the Software, and to permit persons to whom the Software is
191 furnished to do so, subject to the following conditions:
192
193 The above copyright notice and this permission notice shall be included in
194 all copies or substantial portions of the Software.
195
196 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
197 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
198 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
199 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
200 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
201 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
202 THE SOFTWARE.
203
204 =cut