2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <curl/curl.h>
22 #include "lib/compose.hpp"
24 #include "lib/internet.h"
25 #include "doremi_certificate_dialog.h"
30 using boost::function;
31 using boost::optional;
33 DoremiCertificateDialog::DoremiCertificateDialog (wxWindow* parent, function<void (boost::filesystem::path)> load)
34 : DownloadCertificateDialog (parent, load)
36 add (_("Server serial number"), true);
37 _serial = add (new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (300, -1)));
39 _serial->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DoremiCertificateDialog::set_sensitivity, this));
41 add_common_widgets ();
45 DoremiCertificateDialog::download ()
47 string const serial = wx_to_std (_serial->GetValue ());
48 if (serial.length() != 6) {
49 error_dialog (this, _("Doremi serial numbers must have 6 digits"));
53 _message->SetLabel (_("Downloading certificate"));
56 /* Try dcp2000, imb and ims prefixes (see mantis #375) */
58 optional<string> error = get_from_zip_url (
60 "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/dcp2000-%2.dcicerts.zip",
61 serial.substr(0, 3), serial
63 String::compose ("dcp2000-%1.cert.sha256.pem", serial),
68 error = get_from_zip_url (
70 "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/imb-%2.dcicerts.zip",
71 serial.substr(0, 3), serial
73 String::compose ("imb-%1.cert.sha256.pem", serial),
79 error = get_from_zip_url (
81 "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/ims-%2.dcicerts.zip",
82 serial.substr(0, 3), serial
84 String::compose ("ims-%1.cert.sha256.pem", serial),
90 error_dialog (this, std_to_wx (error.get ()));
92 _message->SetLabel (_("Certificate downloaded"));
97 DoremiCertificateDialog::set_sensitivity ()
99 _download->Enable (!_serial->IsEmpty ());