121 lines
2.4 KiB
C++
121 lines
2.4 KiB
C++
|
#include "ba8.h"
|
||
|
#include "ba8700a.h"
|
||
|
|
||
|
#include <applicat.h>
|
||
|
#include <automask.h>
|
||
|
#include <config.h>
|
||
|
#include <dongle.h>
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TSignature_mask
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
class TSignature_mask : public TAutomask
|
||
|
{
|
||
|
TString _host, _user;
|
||
|
bool _admin;
|
||
|
|
||
|
protected:
|
||
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
|
||
|
public:
|
||
|
void load();
|
||
|
void save();
|
||
|
|
||
|
TSignature_mask();
|
||
|
};
|
||
|
|
||
|
bool TSignature_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
|
{
|
||
|
switch (o.dlg())
|
||
|
{
|
||
|
case F_LIST:
|
||
|
if (e == se_query_add || e == se_query_del)
|
||
|
return _admin;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void TSignature_mask::load()
|
||
|
{
|
||
|
TConfig ini(CONFIG_WST, "fd");
|
||
|
TAssoc_array& ass = ini.list_variables();
|
||
|
|
||
|
TSheet_field& sheet = sfield(F_LIST);
|
||
|
FOR_EACH_ASSOC_STRING(ass, h, key, val)
|
||
|
{
|
||
|
if (_admin || _user.compare(key, -1, true) == 0)
|
||
|
{
|
||
|
TToken_string& row = sheet.row(-1);
|
||
|
row = key; // "Cert_USER"
|
||
|
row.ltrim(5); // remove "Cert_"
|
||
|
row.add(val); // add "pkxxx.dll,certificate"
|
||
|
row.replace(',', row.separator());
|
||
|
}
|
||
|
}
|
||
|
sheet.sort();
|
||
|
}
|
||
|
|
||
|
void TSignature_mask::save()
|
||
|
{
|
||
|
TConfig ini(CONFIG_WST, "fd");
|
||
|
|
||
|
if (_admin)
|
||
|
ini.remove_all();
|
||
|
|
||
|
TSheet_field& sheet = sfield(F_LIST);
|
||
|
TString u, f, c;
|
||
|
FOR_EACH_SHEET_ROW(sheet, i, row)
|
||
|
{
|
||
|
row->get(0, u);
|
||
|
if (u.full())
|
||
|
{
|
||
|
u.insert("Cert_");
|
||
|
row->get(1, f);
|
||
|
row->get(2, c);
|
||
|
if (c.full())
|
||
|
f << ',' << c;
|
||
|
ini.set(u, f);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TSignature_mask::TSignature_mask() : TAutomask("ba8700a")
|
||
|
{
|
||
|
_admin = user() == dongle().administrator();
|
||
|
xvt_sys_get_host_name(_host.get_buffer(), _host.size());
|
||
|
xvt_sys_get_user_name(_user.get_buffer(), _user.size());
|
||
|
set(F_HOST, _host);
|
||
|
set(F_NAME, _user);
|
||
|
load();
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TSignature_app
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
class TSignature_app : public TSkeleton_application
|
||
|
{
|
||
|
protected:
|
||
|
virtual const char* extra_modules() const { return "fd"; }
|
||
|
|
||
|
public:
|
||
|
virtual void main_loop();
|
||
|
};
|
||
|
|
||
|
void TSignature_app::main_loop()
|
||
|
{
|
||
|
TSignature_mask m;
|
||
|
while (m.run() == K_ENTER)
|
||
|
m.save();
|
||
|
}
|
||
|
|
||
|
int ba8700(int argc, char* argv[])
|
||
|
{
|
||
|
TSignature_app app;
|
||
|
app.run(argc, argv, TR("Firma digitale"));
|
||
|
return 0;
|
||
|
}
|