eb127dd845
git-svn-id: svn://10.65.10.50/branches/R_10_00@22819 c028cbd2-c16b-5b4b-a496-9718f37d4682
1069 lines
28 KiB
C++
Executable File
1069 lines
28 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <dongle.h>
|
||
#include <form.h>
|
||
#include <modaut.h>
|
||
#include <msksheet.h>
|
||
#include <printer.h>
|
||
#include <toolfld.h>
|
||
#include <utility.h>
|
||
#include <urldefid.h>
|
||
|
||
#include "ba1.h"
|
||
#include "ba1500.h"
|
||
#include "ba1500a.h"
|
||
#include "ba1500b.h"
|
||
#include "ba1600.h"
|
||
|
||
///////////////////////////////////////////////////////////
|
||
|
||
TInformazione_moduli::TInformazione_moduli()
|
||
: _unassigned_modules(0)
|
||
{
|
||
const TDongle& d = dongle();
|
||
for (word mod = BAAUT+1; mod < ENDAUT; mod++)
|
||
{
|
||
TToken_string t = d.module_code2desc(mod);
|
||
if (t.len() > 2 && !t.starts_with("Modulo vario", true)) // Scarta moduli ignoti
|
||
{
|
||
if (d.shown(mod)) //controlla che sia veramente un modulo da mostrare!
|
||
{
|
||
t.add(d.module_code2name(mod));
|
||
t.add(mod);
|
||
_infos.add(t);
|
||
}
|
||
}
|
||
}
|
||
|
||
_infos.sort();
|
||
for (int i = 0; i < _infos.items(); i++)
|
||
{
|
||
TToken_string& riga = _infos.row(i);
|
||
const int mod = riga.get_int(2);
|
||
_index[mod] = i;
|
||
}
|
||
}
|
||
|
||
const char* TInformazione_moduli::get_description_by_order(int index)
|
||
{
|
||
if (index >= 0 && index < _infos.items())
|
||
return _infos.row(index).get(0);
|
||
else
|
||
return "";
|
||
}
|
||
|
||
const char* TInformazione_moduli::get_description_by_name(const char* code) const
|
||
{
|
||
FOR_EACH_ARRAY_ROW_BACK(_infos, i, info)
|
||
{
|
||
if (xvt_str_compare_ignoring_case(info->get(1), code) == 0)
|
||
return info->get(0);
|
||
}
|
||
return TR("{MODULO SCONOSCIUTO}");
|
||
}
|
||
|
||
const char* TInformazione_moduli::get_name_by_order(int index)
|
||
{
|
||
if (index >= 0 && index < _infos.items())
|
||
return _infos.row(index).get(1);
|
||
else
|
||
return "";
|
||
}
|
||
|
||
int TInformazione_moduli::get_module_by_order(int index)
|
||
{
|
||
if (index >= 0 && index < _infos.items())
|
||
return _infos.row(index).get_int(2);
|
||
else
|
||
return -1;
|
||
}
|
||
|
||
const char* TInformazione_moduli::get_description(int module)
|
||
{ return get_description_by_order(_index[module]); }
|
||
|
||
const char* TInformazione_moduli::get_name(int module)
|
||
{ return get_name_by_order(_index[module]); }
|
||
|
||
int TInformazione_moduli::get_index(int module) const
|
||
{ return _index[module]; }
|
||
|
||
int TInformazione_moduli::get_index_by_name(const char* code) const
|
||
{
|
||
FOR_EACH_ARRAY_ROW_BACK(_infos, i, info)
|
||
{
|
||
if (xvt_str_compare_ignoring_case(info->get(1), code) == 0)
|
||
break;
|
||
}
|
||
return i >= 0 ? get_index(i) : i;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TForm richiesta attivazione
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TRequest_form : public TForm
|
||
{
|
||
public:
|
||
void update_serno(const TString& serno);
|
||
void update_dongle();
|
||
void update_os();
|
||
void print_footer();
|
||
|
||
TRequest_form(const char* name);
|
||
virtual ~TRequest_form() { }
|
||
};
|
||
|
||
TRequest_form::TRequest_form(const char* name)
|
||
: TForm(name)
|
||
{
|
||
const TPrint_section& header = section('H', odd_page);
|
||
const TPrint_section& footer = section('F', odd_page);
|
||
|
||
int riga[66];
|
||
int y1 = header.height()-2;
|
||
int y2 = printer().formlen() - footer.height();
|
||
if ((y2-y1) & 0x1) y2--; // Forza un numero pari di righe
|
||
|
||
for (int i = 0; ; i++)
|
||
{
|
||
riga[i] = y1 + 2*(i+1);
|
||
if (riga[i] >= y2-1)
|
||
{
|
||
riga[i] = 0;
|
||
break;
|
||
}
|
||
}
|
||
genera_intestazioni(odd_page, y1+1);
|
||
genera_fincatura(odd_page, y1, y2, riga);
|
||
}
|
||
|
||
void TRequest_form::update_serno(const TString& num)
|
||
{
|
||
const TDate today(TODAY);
|
||
TForm_item& data = find_field('H', odd_page, FF_DATARICH);
|
||
data.set(today.string());
|
||
const char* hw = "";
|
||
switch (::dongle().hardware())
|
||
{
|
||
case _dongle_ssa : hw = "SSA"; break;
|
||
case _dongle_hardlock: hw = "HARDLOCK"; break;
|
||
default: hw = "EUTRON"; break;
|
||
}
|
||
find_field('H',odd_page,FF_DONGLE_HW).set(hw);
|
||
TForm_item& serno = find_field('H', odd_page, FF_DONGLE_SN);
|
||
serno.set(num);
|
||
}
|
||
|
||
void TRequest_form::update_dongle()
|
||
{
|
||
const TDongle& d = dongle();
|
||
|
||
TForm_item& year = find_field('H', odd_page, FF_YEAR);
|
||
TString16 str; str << d.year_assist();
|
||
year.set(str);
|
||
|
||
TForm_item& user = find_field('H', odd_page, FF_NUTENTI);
|
||
str.format("%d", d.max_users());
|
||
user.set(str);
|
||
}
|
||
|
||
void TRequest_form::update_os()
|
||
{
|
||
char stros[256];
|
||
xvt_sys_get_version(stros, NULL, sizeof(stros));
|
||
|
||
TForm_item& os = find_field('H', odd_page, FF_OS);
|
||
os.set(stros);
|
||
}
|
||
|
||
void TRequest_form::print_footer()
|
||
{
|
||
set_footer(odd_page, true);
|
||
printer().formfeed();
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TAttivazione_moduli
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TAttivazione_moduli : public TSkeleton_application
|
||
{
|
||
TMask* _msk;
|
||
TInformazione_moduli* _im;
|
||
|
||
word _serno;
|
||
word _wanted_users, _wanted_assist;
|
||
|
||
private:
|
||
void garble_dongle(word k[4]) const;
|
||
const TString& garble_md5(const char* strin) const;
|
||
const TString& garble_md5(long numin) const;
|
||
|
||
protected:
|
||
virtual bool create() ;
|
||
virtual bool destroy() ;
|
||
virtual void main_loop();
|
||
virtual bool use_files() const { return false; }
|
||
virtual bool test_assistance_year() const;
|
||
|
||
void garble_module(word n, TString& str1, TString& str2) const;
|
||
void garble_users(word u, TString& str1, TString& str2) const;
|
||
void garble_year(word year, TString& str1, TString& str2) const;
|
||
|
||
word& serno() { return _serno; }
|
||
|
||
void init_mask();
|
||
void update_listino();
|
||
void load_masklistino(TMask & m);
|
||
void save_masklistino(TMask & m);
|
||
int build_sheet(bool on = true);
|
||
void build_key_column();
|
||
|
||
bool burn_dongle();
|
||
|
||
static void keyext(const TString & s, word * v);
|
||
static void encode_second_key();
|
||
|
||
static bool date_hnd(TMask_field& f, KEY k);
|
||
static bool serno_hnd(TMask_field& f, KEY k);
|
||
|
||
static bool k_notify(TSheet_field& f, int r, KEY k);
|
||
static bool change_users_handler(TMask_field&, KEY key);
|
||
static bool maxuser_handler(TMask_field& fld, KEY key);
|
||
static bool change_assist_handler(TMask_field&, KEY key);
|
||
static bool assist_handler(TMask_field& fld, KEY key);
|
||
static bool print_handler(TMask_field& fld, KEY key);
|
||
static bool printlist_handler(TMask_field& fld, KEY key);
|
||
static bool aggiorna_listino_handler(TMask_field& fld, KEY key);
|
||
static bool modifica_listino_handler(TMask_field& fld, KEY key);
|
||
static bool aga_handler(TMask_field& fld, KEY key);
|
||
static bool sh_nposti_handler(TMask_field& fld, KEY key);
|
||
static bool sh_acquisto_handler(TMask_field& fld, KEY key);
|
||
static bool sh_aggiornamento_handler(TMask_field& fld, KEY key);
|
||
|
||
protected:
|
||
bool new_module_requested();
|
||
bool dongle_update_needed() const;
|
||
|
||
void print_request();
|
||
void print_answer();
|
||
void print_status();
|
||
|
||
public:
|
||
virtual void print();
|
||
|
||
TAttivazione_moduli() : _msk(NULL), _wanted_users(0), _wanted_assist(0) { }
|
||
virtual ~TAttivazione_moduli() { }
|
||
};
|
||
|
||
HIDDEN TAttivazione_moduli& app() { return (TAttivazione_moduli&)main_app(); }
|
||
|
||
int TAttivazione_moduli::build_sheet(bool on)
|
||
{
|
||
int nmod = 0;
|
||
TSheet_field& sf = _msk->sfield(F_MODULI);
|
||
for (int i = 0; i < _im->items(); i++)
|
||
{
|
||
TToken_string& riga = sf.row(i);
|
||
riga = _im->get_description_by_order(i);
|
||
riga.trim();
|
||
const int module = _im->get_module_by_order(i);
|
||
|
||
const bool ics = module == 0 || (on && ::dongle().active(module));
|
||
if (ics)
|
||
{
|
||
riga.add("X");
|
||
if (module != 0)
|
||
nmod++;
|
||
else
|
||
sf.disable_cell(i, -1); // Disabilita la riga della base
|
||
}
|
||
else
|
||
riga.add(" ");
|
||
riga.add(module);
|
||
}
|
||
return nmod;
|
||
}
|
||
|
||
void TAttivazione_moduli::garble_dongle(word k[4]) const
|
||
{
|
||
::dongle().garble(k);
|
||
}
|
||
|
||
void TAttivazione_moduli::garble_module(word n, TString& str1, TString& str2) const
|
||
{
|
||
const TDate today(_msk->get(F_DT));
|
||
const long val = today.date2julian();
|
||
|
||
word data[4];
|
||
data[0] = word(_msk->get_int(F_SN));
|
||
data[1] = word(val >> 16);
|
||
data[2] = n;
|
||
data[3] = word(val & 0xFFFF);
|
||
garble_dongle(data);
|
||
str1.format("%04X%04X", data[0], data[1]);
|
||
|
||
str2 = ::dongle().module_code2name(n);
|
||
str2.upper();
|
||
str2 = garble_md5(str2);
|
||
}
|
||
|
||
const TString& TAttivazione_moduli::garble_md5(const char* strin) const
|
||
{
|
||
const TDate today(_msk->get(F_DT));
|
||
TString80 chiaro, cifrato;
|
||
chiaro.format("%8ld%d%s", today.date2ansi(), _msk->get_int(F_SN), strin);
|
||
xvt_str_md5(chiaro, cifrato.get_buffer(32));
|
||
cifrato.upper();
|
||
return cifrato.right(8);
|
||
}
|
||
|
||
const TString& TAttivazione_moduli::garble_md5(long numin) const
|
||
{
|
||
TString16 strin; strin.format("%ld", numin);
|
||
return garble_md5(strin);
|
||
}
|
||
|
||
void TAttivazione_moduli::garble_users(word u, TString& str1, TString& str2) const
|
||
{
|
||
const TDate today(_msk->get(F_DT));
|
||
const long val = today.date2julian();
|
||
|
||
word data[4];
|
||
data[0] = u;
|
||
data[1] = word(val >> 16);
|
||
data[2] = word(_msk->get_int(F_SN));
|
||
data[3] = word(val & 0xFFFF);
|
||
garble_dongle(data);
|
||
str1.format("%04X%04X", data[0], data[1]);
|
||
|
||
str2 = garble_md5(u);
|
||
}
|
||
|
||
void TAttivazione_moduli::garble_year(word y, TString& str1, TString& str2) const
|
||
{
|
||
const TDate today(_msk->get(F_DT));
|
||
const long val = today.date2julian();
|
||
|
||
word data[4];
|
||
data[0] = word(_msk->get_int(F_SN));
|
||
data[1] = word(val >> 16);
|
||
data[2] = y;
|
||
data[3] = word(val & 0xFFFF);
|
||
garble_dongle(data);
|
||
str1.format("%04X%04X", data[0], data[1]);
|
||
|
||
str2 = garble_md5(y);
|
||
}
|
||
|
||
void TAttivazione_moduli::build_key_column()
|
||
{
|
||
TWait_cursor hourglass;
|
||
TSheet_field& sf = _msk->sfield(F_MODULI);
|
||
sf.enable_column(F_KEY, false);
|
||
|
||
const TDongle& d = dongle();
|
||
TString8 tmp1, tmp2;
|
||
FOR_EACH_SHEET_ROW_BACK(sf, i, riga)
|
||
{
|
||
if (!sf.cell_disabled(i, 1))
|
||
{
|
||
const int module = riga->get_int(2);
|
||
garble_module(module, tmp1, tmp2);
|
||
#ifdef DBG
|
||
if (d.type() == _developer_dongle)
|
||
riga->add(tmp2, 3); else // Backdoor di debug: mostra chiave web
|
||
#endif
|
||
riga->add(tmp1, 3); // Normalmente mostra chiave hardware
|
||
}
|
||
}
|
||
sf.force_update();
|
||
|
||
_msk->set(F_USERS, d.max_users());
|
||
_msk->set(F_ASSIST, d.year_assist());
|
||
}
|
||
|
||
bool TAttivazione_moduli::burn_dongle()
|
||
{
|
||
TDongle& din = ::dongle();
|
||
bool ok = din.type() == _user_dongle;
|
||
if (ok)
|
||
{
|
||
TString16 key;
|
||
|
||
TSheet_field& sf = _msk->sfield(F_MODULI);
|
||
FOR_EACH_SHEET_ROW(sf, i, riga)
|
||
{
|
||
key = riga->get(3); key.trim();
|
||
if (key.not_empty())
|
||
{
|
||
const int module = riga->get_int(2);
|
||
TString8 str1, str2;
|
||
garble_module(module, str1, str2);
|
||
const bool good = (key == str1) || (key == str2);
|
||
if (good)
|
||
{
|
||
if (!din.active(module) &&
|
||
yesno_box(FR("Confermare l'attivazione del modulo %d:\n%s"),
|
||
module, riga->get(0)))
|
||
din.activate(module);
|
||
}
|
||
else
|
||
{
|
||
if (din.active(module) &&
|
||
yesno_box(FR("Confermare la disattivazione del modulo %d:\n%s"),
|
||
module, riga->get(0)))
|
||
din.deactivate(module);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (din.dirty())
|
||
{
|
||
ok = din.burn();
|
||
if (!ok)
|
||
error_box(TR("Impossibile riprogrammare la chiave"));
|
||
}
|
||
}
|
||
|
||
return ok;
|
||
}
|
||
|
||
bool TAttivazione_moduli::maxuser_handler(TMask_field& fld, KEY key)
|
||
{
|
||
bool ok = true;
|
||
if (key == K_TAB && !fld.empty())
|
||
{
|
||
const int utenti = atoi(fld.get());
|
||
if (utenti > 0 && utenti < 1000)
|
||
{
|
||
TString8 str1, str2;
|
||
app().garble_users(utenti, str1, str2);
|
||
fld.mask().set(102, str1);
|
||
fld.mask().set(103, str2);
|
||
}
|
||
}
|
||
if (key == K_ENTER)
|
||
{
|
||
const int utenti = atoi(fld.get());
|
||
if (utenti <= 0 || utenti >= 1000)
|
||
ok = fld.error_box(TR("Numero di utenti errato"));
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TAttivazione_moduli::change_users_handler(TMask_field& fld, KEY key)
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
TDongle& d = ::dongle();
|
||
if (d.hardware() == _dongle_ssa)
|
||
return message_box(TR("E' necessario contattare attivazione_moduli@sirio-is.it"));
|
||
|
||
TMask m(TR("Utenti"), 1, 26, 7);
|
||
m.add_number(101, 0, PR("Utenti "), 1, 1, 4, "U");
|
||
m.add_string(102, 0, PR("Codice "), 1, 2, 8, "DU");
|
||
|
||
if (d.type() == _user_dongle)
|
||
{
|
||
m.set(101, d.max_users());
|
||
m.enable(102);
|
||
}
|
||
else
|
||
{
|
||
m.set_handler(101, maxuser_handler);
|
||
m.add_string(103, 0, PR("WebCod "), 1, 3, 8, "DU");
|
||
}
|
||
m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
|
||
m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
|
||
|
||
if (m.run() == K_ENTER)
|
||
{
|
||
const int utenti = m.get_int(101);
|
||
if (d.type() == _user_dongle)
|
||
{
|
||
if (utenti > 0 && utenti < 1000)
|
||
{
|
||
if (m.field(102).empty())
|
||
{
|
||
app()._wanted_users = utenti;
|
||
if (utenti > 0)
|
||
fld.message_box(TR("Premere 'Stampa'\nper richiedere l'attivazione di %d utenti."),
|
||
utenti);
|
||
}
|
||
else
|
||
{
|
||
TString8 str1, str2;
|
||
app().garble_users(utenti, str1, str2);
|
||
if ((m.get(102) == str1) || (m.get(102) == str2))
|
||
{
|
||
d.set_max_users(utenti);
|
||
fld.mask().set(F_USERS, utenti);
|
||
}
|
||
else
|
||
fld.error_box(TR("Codice errato"));
|
||
}
|
||
}
|
||
else
|
||
fld.error_box(TR("Numero di utenti errato"));
|
||
}
|
||
else
|
||
app()._wanted_users = utenti;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
#define YEAR_MIN 2081
|
||
#define YEAR_MAX 2777
|
||
|
||
bool TAttivazione_moduli::assist_handler(TMask_field& fld, KEY key)
|
||
{
|
||
bool ok = true;
|
||
if (key == K_TAB && !fld.empty())
|
||
{
|
||
const int year = atoi(fld.get());
|
||
if (year >= YEAR_MIN && year <= YEAR_MAX)
|
||
{
|
||
TString16 str1, str2;
|
||
app().garble_year(year, str1, str2);
|
||
fld.mask().set(102, str1);
|
||
fld.mask().set(103, str2);
|
||
}
|
||
}
|
||
if (key == K_ENTER)
|
||
{
|
||
const int year = atoi(fld.get());
|
||
if (year < YEAR_MIN || year > YEAR_MAX)
|
||
ok = fld.error_box(TR("Anno di assitenza errato"));
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TAttivazione_moduli::change_assist_handler(TMask_field& fld, KEY key)
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
TDongle& d = ::dongle();
|
||
|
||
if (d.hardware() == _dongle_ssa)
|
||
return message_box(TR("E' necessario contattare attivazione_moduli@sirio-is.it"));
|
||
|
||
TMask m(TR("Assistenza"), 1, 26, 9);
|
||
m.add_number(101, 0, PR("Anno "), 1, 1, 4, "U");
|
||
m.add_string(102, 0, PR("Codice "), 1, 2, 8, "DU");
|
||
|
||
if (d.type() == _user_dongle)
|
||
{
|
||
m.set(101, d.year_assist());
|
||
m.enable(102);
|
||
}
|
||
else
|
||
{
|
||
m.add_string(103, 0, PR("WebCod "), 1, 3, 8, "DU");
|
||
m.set_handler(101, assist_handler);
|
||
}
|
||
m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
|
||
m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
|
||
|
||
if (m.run() == K_ENTER)
|
||
{
|
||
word year = m.get_int(101);
|
||
if (d.type() == _user_dongle)
|
||
{
|
||
if (year >= YEAR_MIN && year <= YEAR_MAX)
|
||
{
|
||
if (m.field(102).empty())
|
||
{
|
||
app()._wanted_assist = year;
|
||
fld.message_box(FR("Premere 'Stampa'\nper richiedere il contratto di assistenza per l'anno %u."),
|
||
year);
|
||
}
|
||
else
|
||
{
|
||
TString16 str1, str2;
|
||
app().garble_year(year, str1, str2);
|
||
bool ok = (m.get(102) == str1) || (m.get(102) == str2);
|
||
if (ok)
|
||
{
|
||
d.set_year_assist(year);
|
||
fld.mask().set(F_ASSIST, year);
|
||
}
|
||
else
|
||
fld.error_box(TR("Codice errato"));
|
||
}
|
||
}
|
||
else
|
||
fld.error_box(TR("Anno errato"));
|
||
}
|
||
else
|
||
app()._wanted_assist = year;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool TAttivazione_moduli::print_handler(TMask_field& fld, KEY key)
|
||
{
|
||
if (key == K_SPACE)
|
||
app().print();
|
||
return true;
|
||
}
|
||
|
||
bool TAttivazione_moduli::aga_handler(TMask_field& fld, KEY key)
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
TMask mask(TR("Dati Release"), 1, 80, 13);
|
||
mask.add_string(101, 0, PR("Nome Breve "), 1, 1, 32);
|
||
mask.add_string(102, 0, PR("Prodotto "), 1, 2, 32);
|
||
mask.add_string(103, 0, PR("Distributore "), 1, 3, 60);
|
||
mask.add_string(104, 0, PR("Amministratore "), 1, 4, 16, "U");
|
||
mask.add_string(105, 0, PR("Password "), 1, 5, 16, "*");
|
||
mask.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
|
||
mask.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
|
||
|
||
//nuovo modo di gettare il producer da oem.ini
|
||
TConfig oemini(CONFIG_OEM, "MAIN");
|
||
const int oem = oemini.get_int("OEM", NULL, -1, -1);
|
||
if (oem >= 0)
|
||
{
|
||
TString8 para; para << "OEM_" << oem;
|
||
oemini.set_paragraph(para);
|
||
mask.set(101, ::decode(oemini.get("Name")));
|
||
mask.set(102, ::decode(oemini.get("Product")));
|
||
mask.set(103, ::decode(oemini.get("Reseller")));
|
||
mask.set(104, ::decode(oemini.get("Administrator")));
|
||
mask.set(105, ::decode(oemini.get("Password")));
|
||
}
|
||
else //vecchio modo; gi<67> che c'<27> elimina i vecchi valori dall'install.ini
|
||
{
|
||
TConfig ini("install.ini", "Main");
|
||
mask.set(103, ::decode(ini.get("Producer")));
|
||
mask.set(104, ::decode(ini.get("Administrator")));
|
||
mask.set(105, ::decode(ini.get("Password")));
|
||
ini.remove("Producer");
|
||
ini.remove("Administrator");
|
||
ini.remove("Password");
|
||
}
|
||
|
||
//setta comunque nel nuovo modo con producer = 0 se eventualmente ignoto
|
||
if (mask.run() == K_ENTER)
|
||
{
|
||
oemini.set("Name", ::encode(mask.get(101)));
|
||
oemini.set("Product", ::encode(mask.get(102)));
|
||
oemini.set("Reseller", ::encode(mask.get(103)));
|
||
oemini.set("Administrator", ::encode(mask.get(104)));
|
||
oemini.set("Password", ::encode(mask.get(105)));
|
||
if (oem < 0)
|
||
oemini.set("OEM", "0", "MAIN", true);
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void TAttivazione_moduli::init_mask()
|
||
{
|
||
const TDate oggi(TODAY);
|
||
const int nmod = build_sheet();
|
||
const TDongle& d = ::dongle();
|
||
switch (d.hardware())
|
||
{
|
||
case _dongle_hardlock: _msk->set_caption(TR("Attivazione HARDLOCK")); break;
|
||
case _dongle_eutron : _msk->set_caption(TR("Attivazione EUTRON")); break;
|
||
default : _msk->set_caption(TR("Attivazione SSA")); break;
|
||
}
|
||
|
||
_msk->set(F_SN, d.number());
|
||
_msk->set(F_DT, oggi);
|
||
_msk->set(F_USERS, d.max_users());
|
||
_msk->set(F_ASSIST, d.year_assist());
|
||
}
|
||
|
||
bool TAttivazione_moduli::serno_hnd(TMask_field& f, KEY k)
|
||
{
|
||
if (k == K_TAB && f.focusdirty())
|
||
app().build_key_column();
|
||
return true;
|
||
}
|
||
|
||
bool TAttivazione_moduli::date_hnd(TMask_field& f, KEY k)
|
||
{
|
||
if (k == K_TAB && f.focusdirty())
|
||
{
|
||
const TDate data(f.get());
|
||
const TDate oggi(TODAY);
|
||
if (data > oggi)
|
||
return f.error_box(FR("La data deve essere antecedente a quella di sistema"));
|
||
/*
|
||
const TDate& last_update = ::dongle().last_update();
|
||
if (data < last_update)
|
||
return f.error_box(FR("La data deve essere successiva al %s"), last_update.string());
|
||
|
||
const int year_assist = ::dongle().year_assist()+1;
|
||
if (data.year() > year_assist)
|
||
return f.error_box(FR("La data deve essere antecedente al 31-12-%d"), year_assist);
|
||
*/
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool TAttivazione_moduli::k_notify(TSheet_field& f, int r, KEY k)
|
||
{
|
||
if (k == K_INS || k == K_DEL)
|
||
return false;
|
||
return true;
|
||
}
|
||
|
||
void TAttivazione_moduli::print_request()
|
||
{
|
||
TRequest_form form("ba1500a");
|
||
TForm_item& num = form.find_field('B', odd_page, 101);
|
||
TForm_item& descr = form.find_field('B', odd_page, 102);
|
||
TForm_item& codice = form.find_field('B', odd_page, 103);
|
||
TForm_item& price = form.find_field('B', odd_page, 104);
|
||
TForm_item& manut = form.find_field('B', odd_page, 105);
|
||
|
||
TInstall_ini ini;
|
||
ini.write_protect();
|
||
|
||
const bool special = _wanted_assist > ::dongle().year_assist() || _wanted_users != 0;
|
||
const word users = max(_wanted_users, ::dongle().max_users());
|
||
|
||
TWait_cursor hourglass;
|
||
TSheet_field& sheet = _msk->sfield(F_MODULI);
|
||
int found = 0;
|
||
TString str;
|
||
|
||
FOR_EACH_SHEET_ROW(sheet, r, row)
|
||
{
|
||
const int module = row->get_int(2) ;
|
||
const bool active = ::dongle().active(module);
|
||
const bool wanted = *row->get(1) > ' ';
|
||
|
||
if (!special && active)
|
||
continue;
|
||
if (!wanted && !active)
|
||
continue;
|
||
|
||
if (found == 0)
|
||
{
|
||
printer().open();
|
||
form.find_field('H',odd_page,1).set(dongle().reseller());
|
||
form.update_serno(_msk->get(F_SN));
|
||
form.update_dongle();
|
||
form.update_os();
|
||
}
|
||
|
||
str.format("%3d", ++found);
|
||
num.set(str);
|
||
|
||
str = row->get(0);
|
||
descr.set(str);
|
||
|
||
str = active ? TR("*ATTIVO*") : "";
|
||
codice.set(str);
|
||
|
||
form.print(-1);
|
||
}
|
||
|
||
if (special && found > 0)
|
||
{
|
||
codice.set("");
|
||
price.set("");
|
||
manut.set("");
|
||
if (_wanted_users != 0)
|
||
{
|
||
str.format("%3d", ++found);
|
||
num.set(str);
|
||
|
||
str.format(FR("Variazione del numero utenti da %u a %u"),
|
||
::dongle().max_users(), _wanted_users);
|
||
descr.set(str);
|
||
form.print(-1);
|
||
}
|
||
if (_wanted_assist > ::dongle().year_assist())
|
||
{
|
||
str.format("%3d", ++found);
|
||
num.set(str);
|
||
str.format(FR("Contratto di assistenza per l'anno %u"), _wanted_assist);
|
||
descr.set(str);
|
||
form.print(-1);
|
||
}
|
||
}
|
||
|
||
if (found)
|
||
{
|
||
form.print_footer();
|
||
printer().close();
|
||
}
|
||
}
|
||
|
||
void TAttivazione_moduli::print_status()
|
||
{
|
||
TRequest_form form("ba1500a");
|
||
TForm_item& descr = form.find_field('B', odd_page, 102);
|
||
TForm_item& codice = form.find_field('B', odd_page, 103);
|
||
|
||
form.find_field('H',odd_page,1).set(dongle().reseller());
|
||
form.update_serno(_msk->get(F_SN));
|
||
form.update_dongle();
|
||
form.update_os();
|
||
|
||
TWait_cursor hourglass;
|
||
printer().open();
|
||
|
||
TSheet_field& sheet = _msk->sfield(F_MODULI);
|
||
FOR_EACH_SHEET_ROW(sheet, r, row)
|
||
{
|
||
const int module = row->get_int(2) ;
|
||
const bool active = ::dongle().active(module);
|
||
|
||
if (!active)
|
||
continue;
|
||
|
||
descr.set(row->get(0));
|
||
codice.set(TR("*ATTIVO*"));
|
||
form.print(-1);
|
||
}
|
||
|
||
printer().close();
|
||
}
|
||
|
||
void TAttivazione_moduli::print_answer()
|
||
{
|
||
TString str;
|
||
int found = 0;
|
||
|
||
TRequest_form form("ba1500a");
|
||
TForm_item& num = form.find_field('B', odd_page, 101);
|
||
TForm_item& descr = form.find_field('B', odd_page, 102);
|
||
TForm_item& codice = form.find_field('B', odd_page, 103);
|
||
|
||
TSheet_field& sheet = _msk->sfield(F_MODULI);
|
||
FOR_EACH_SHEET_ROW(sheet, r, row) if (*row->get(1) > ' ')
|
||
{
|
||
const int module = _im->get_module_by_order(r);
|
||
if (module != BAAUT)
|
||
{
|
||
if (found == 0)
|
||
{
|
||
printer().open();
|
||
form.update_serno(_msk->get(F_SN));
|
||
form.update_dongle();
|
||
form.update_os();
|
||
}
|
||
|
||
str.format("%3d", ++found);
|
||
num.set(str);
|
||
|
||
str = row->get(0);
|
||
descr.set(str);
|
||
|
||
str = row->get(3);
|
||
codice.set(str);
|
||
|
||
form.print(-1);
|
||
}
|
||
}
|
||
|
||
if (_wanted_users != 0 || _wanted_assist != 0)
|
||
{
|
||
if (found == 0)
|
||
{
|
||
printer().open();
|
||
form.update_serno(_msk->get(F_SN));
|
||
form.update_dongle();
|
||
}
|
||
if (_wanted_users != 0)
|
||
{
|
||
str.format("%3d", ++found);
|
||
num.set(str);
|
||
str.format(FR("Variazione del numero utenti da %u a %u"),
|
||
::dongle().max_users(), _wanted_users);
|
||
descr.set(str);
|
||
TString8 str1, str2;
|
||
garble_users(_wanted_users, str1, str2);
|
||
codice.set(str1);
|
||
form.print(-1);
|
||
}
|
||
if (_wanted_assist != 0)
|
||
{
|
||
str.format("%3d", ++found);
|
||
num.set(str);
|
||
str.format(FR("Contratto di assistenza per l'anno %u"), _wanted_assist);
|
||
descr.set(str);
|
||
TString8 str1, str2;
|
||
garble_year(_wanted_assist, str1, str2);
|
||
codice.set(str1);
|
||
form.print(-1);
|
||
}
|
||
}
|
||
|
||
if (found)
|
||
{
|
||
form.print_footer();
|
||
printer().close();
|
||
}
|
||
}
|
||
|
||
bool TAttivazione_moduli::new_module_requested()
|
||
{
|
||
TSheet_field& sheet = _msk->sfield(F_MODULI);
|
||
bool found = false;
|
||
FOR_EACH_SHEET_ROW(sheet, r, row)
|
||
{
|
||
if (*row->get(1) > ' ') // Wanted!
|
||
{
|
||
const int module = row->get_int(2);
|
||
if (!::dongle().active(module)) // Not active yet?
|
||
{
|
||
found = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return found;
|
||
}
|
||
|
||
void TAttivazione_moduli::print()
|
||
{
|
||
if (::dongle().type() == _user_dongle)
|
||
{
|
||
if (new_module_requested())
|
||
print_request();
|
||
else
|
||
print_status();
|
||
}
|
||
else
|
||
print_answer();
|
||
}
|
||
|
||
// Questo programma non deve bloccarsi per l'anno di assistenza!
|
||
bool TAttivazione_moduli::test_assistance_year() const
|
||
{ return true; }
|
||
|
||
bool TAttivazione_moduli::dongle_update_needed() const
|
||
{
|
||
bool ok = TApplication::test_assistance_year();
|
||
if (ok)
|
||
{
|
||
Tdninst dninst;
|
||
const int dninst_year = dninst.assist_year();
|
||
const int dongle_year = dongle().year_assist();
|
||
ok = dninst_year <= dongle_year;
|
||
}
|
||
|
||
return !ok;
|
||
}
|
||
|
||
bool TAttivazione_moduli::create()
|
||
{
|
||
TDongle& d = dongle();
|
||
bool ok = d.login(true);
|
||
if (!ok)
|
||
return false;
|
||
|
||
ok = !dongle_update_needed();
|
||
if (!ok)
|
||
{
|
||
ok = update_assistance_year();
|
||
if (ok && TApplication::test_assistance_year())
|
||
return false; // Aggiornamento automatico riuscito!
|
||
}
|
||
|
||
if (d.hardware() == _dongle_network)
|
||
{
|
||
if (yesno_box(TR("Questo programma non puo' essere utilizzato in quanto e' in funzione il server di autorizzazioni.\n"
|
||
"Si desidera connettersi al server per effettuare le operazioni di attivazione?")))
|
||
{
|
||
TString server = ini_get_string(CONFIG_INSTALL, "Server", "Dongle");
|
||
if (server.find(':') < 0)
|
||
server << ":1883";
|
||
server.insert("http://");
|
||
xvt_sys_goto_url(server, "open");
|
||
}
|
||
return false;
|
||
}
|
||
|
||
_im = new TInformazione_moduli;
|
||
|
||
disable_menu_item(M_FILE_NEW);
|
||
disable_menu_item(M_FILE_PG_SETUP);
|
||
|
||
_msk = new TMask("ba1500a") ;
|
||
|
||
_msk->set_handler(F_CHANGEUSERS, change_users_handler);
|
||
_msk->set_handler(F_CHANGEASSIST, change_assist_handler);
|
||
_msk->set_handler(DLG_PRINT, print_handler);
|
||
TDongleType mydongle = ::dongle().type();
|
||
#ifdef DBG
|
||
if (mydongle == _developer_dongle && is_power_reseller(true))
|
||
mydongle = _aga_dongle;
|
||
#endif
|
||
|
||
if (mydongle == _aga_dongle)
|
||
{
|
||
_msk->show(F_AGA);
|
||
_msk->set_handler(F_AGA, aga_handler);
|
||
}
|
||
|
||
TSheet_field& sf = _msk->sfield(F_MODULI);
|
||
sf.set_notify(k_notify);
|
||
|
||
const bool can_edit = serno() != 0 && d.hardware() != _dongle_ssa;
|
||
|
||
switch (mydongle)
|
||
{
|
||
case _user_dongle:
|
||
_msk->set_handler(F_DT, date_hnd);
|
||
case _developer_dongle:
|
||
init_mask();
|
||
_serno=_msk->get_int(F_SN);
|
||
sf.enable_column(F_ENABLE, can_edit);
|
||
sf.enable_column(F_KEY, can_edit);
|
||
break;
|
||
case _aga_dongle:
|
||
_msk->set_handler(F_SN, serno_hnd);
|
||
_msk->enable(F_SN);
|
||
init_mask();
|
||
_serno=_msk->get_int(F_SN);
|
||
|
||
build_sheet(false);
|
||
sf.enable_column(1, can_edit);
|
||
build_key_column();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
enable_menu_item(M_FILE_PG_SETUP);
|
||
enable_menu_item(M_FILE_PRINT);
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
bool TAttivazione_moduli::destroy()
|
||
{
|
||
if (_msk != NULL) delete _msk;
|
||
if (_im != NULL) delete _im;
|
||
return true;
|
||
}
|
||
|
||
void TAttivazione_moduli::main_loop()
|
||
{
|
||
if (_msk->run() == K_ENTER)
|
||
burn_dongle();
|
||
}
|
||
|
||
int ba1500(int argc, char** argv)
|
||
{
|
||
// dipende dalla check_parameters fatta in main()
|
||
if (user() == ::dongle().administrator())
|
||
{
|
||
TAttivazione_moduli a ;
|
||
a.run(argc, argv, TR("Attivazione moduli"));
|
||
}
|
||
else
|
||
error_box(FR("L'utente %s non e' abilitato all'esecuzione di questo programma"), (const char*)user());
|
||
return 0;
|
||
}
|