2 Copyright (C) 2014-2015 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 "doremi_certificate_panel.h"
21 #include "download_certificate_dialog.h"
23 #include "lib/compose.hpp"
25 #include "lib/signal_manager.h"
26 #include "lib/internet.h"
27 #include <curl/curl.h>
29 #include <boost/foreach.hpp>
35 using boost::function;
36 using boost::optional;
38 DoremiCertificatePanel::DoremiCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog)
39 : DownloadCertificatePanel (parent, dialog)
41 add_label_to_sizer (_table, this, _("Server serial number"), true);
42 _serial = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (300, -1));
43 _table->Add (_serial, 1, wxEXPAND);
45 _serial->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DownloadCertificateDialog::setup_sensitivity, _dialog));
51 DoremiCertificatePanel::download (wxStaticText* message)
53 message->SetLabel (_("Downloading certificate"));
55 /* Hack: without this the SetLabel() above has no visible effect */
58 signal_manager->when_idle (boost::bind (&DoremiCertificatePanel::finish_download, this, wx_to_std (_serial->GetValue ()), message));
62 DoremiCertificatePanel::finish_download (string serial, wxStaticText* message)
64 /* Try dcp2000, imb and ims prefixes (see mantis #375) */
68 optional<string> error = get_from_zip_url (
70 "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/dcp2000-%2.dcicerts.zip",
71 serial.substr(0, 3), serial
73 String::compose ("dcp2000-%1.cert.sha256.pem", serial),
75 boost::bind (&DownloadCertificatePanel::load, this, _1)
79 errors.push_back (error.get ());
80 error = get_from_zip_url (
82 "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/dcp2000-%2.certs.zip",
83 serial.substr(0, 3), serial
85 String::compose ("dcp2000-%1.cert.sha256.pem", serial),
87 boost::bind (&DownloadCertificatePanel::load, this, _1)
92 errors.push_back (error.get ());
93 error = get_from_zip_url (
95 "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/imb-%2.dcicerts.zip",
96 serial.substr(0, 3), serial
98 String::compose ("imb-%1.cert.sha256.pem", serial),
100 boost::bind (&DownloadCertificatePanel::load, this, _1)
105 errors.push_back (error.get ());
106 error = get_from_zip_url (
108 "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/ims-%2.dcicerts.zip",
109 serial.substr(0, 3), serial
111 String::compose ("ims-%1.cert.sha256.pem", serial),
113 boost::bind (&DownloadCertificatePanel::load, this, _1)
118 errors.push_back (error.get ());
119 message->SetLabel (wxT (""));
122 BOOST_FOREACH (string e, errors) {
126 error_dialog (this, std_to_wx (s.str ()));
128 message->SetLabel (_("Certificate downloaded"));
129 _dialog->setup_sensitivity ();
134 DoremiCertificatePanel::ready_to_download () const
136 return !_serial->IsEmpty ();