Patch level : 10.0
Files correlati : ba1 Ricompilazione Demo : [ ] Commento : Migliorata gestione dninst.zip git-svn-id: svn://10.65.10.50/trunk@19860 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
effd5d5c0b
commit
6237b1ae22
@ -307,7 +307,7 @@ TInfo_mask::TInfo_mask() : TProperty_sheet(TR("Informazioni"))
|
|||||||
TString arg;
|
TString arg;
|
||||||
for (int a = 0; a < main_app().argc(); a++)
|
for (int a = 0; a < main_app().argc(); a++)
|
||||||
arg << main_app().argv(a) << ' ';
|
arg << main_app().argv(a) << ' ';
|
||||||
arg.trim(); arg.lower();
|
arg.trim();
|
||||||
|
|
||||||
TConfig campoini(CONFIG_INSTALL, "Main");
|
TConfig campoini(CONFIG_INSTALL, "Main");
|
||||||
TConfig userini(CONFIG_GUI, "Printer");
|
TConfig userini(CONFIG_GUI, "Printer");
|
||||||
|
@ -77,7 +77,7 @@ HIDDEN void paint_background(WINDOW win)
|
|||||||
xvt_dwin_draw_text(win, x, y, t, -1);
|
xvt_dwin_draw_text(win, x, y, t, -1);
|
||||||
|
|
||||||
xvtil_set_font(win, NULL, XVT_FS_NONE);
|
xvtil_set_font(win, NULL, XVT_FS_NONE);
|
||||||
xvt_dwin_set_fore_color(win, NORMAL_COLOR);
|
xvt_dwin_set_fore_color(win, PROMPT_COLOR);
|
||||||
|
|
||||||
TString spa; spa << dongle().product();
|
TString spa; spa << dongle().product();
|
||||||
if (!xvt_sys_is_pda())
|
if (!xvt_sys_is_pda())
|
||||||
@ -88,8 +88,8 @@ HIDDEN void paint_background(WINDOW win)
|
|||||||
|
|
||||||
if (ADVANCED_GRAPHICS)
|
if (ADVANCED_GRAPHICS)
|
||||||
{
|
{
|
||||||
const int ix = xvt_vobj_get_attr(NULL_WIN, ATTR_ICON_WIDTH);
|
const int ix = xvt_vobj_get_attr(win, ATTR_ICON_WIDTH);
|
||||||
const int iy = xvt_vobj_get_attr(NULL_WIN, ATTR_ICON_HEIGHT);
|
const int iy = xvt_vobj_get_attr(win, ATTR_ICON_HEIGHT);
|
||||||
xvt_dwin_draw_icon(win, r.right-ix-CHARY, r.bottom-iy-CHARY, ICON_RSRC);
|
xvt_dwin_draw_icon(win, r.right-ix-CHARY, r.bottom-iy-CHARY, ICON_RSRC);
|
||||||
xvt_dwin_draw_icon(win, CHARY, r.bottom-iy-CHARY, ICON_RSRC);
|
xvt_dwin_draw_icon(win, CHARY, r.bottom-iy-CHARY, ICON_RSRC);
|
||||||
}
|
}
|
||||||
@ -483,8 +483,8 @@ bool TApplication::test_assistance_year() const
|
|||||||
ok = app_year <= dongle_year;
|
ok = app_year <= dongle_year;
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
const int solar_year = (dongle_year/1000)*1000 + (dongle_year%1000)/10;
|
Tdninst dninst;
|
||||||
ok = TDate(TODAY).year() <= solar_year+2;
|
ok = dninst.can_I_run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
|
@ -1032,3 +1032,310 @@ bool TDongle::shown(word code) const
|
|||||||
|
|
||||||
bool TDongle::demo() const
|
bool TDongle::demo() const
|
||||||
{ return hardware() == _dongle_unknown && type() == _no_dongle; }
|
{ return hardware() == _dongle_unknown && type() == _no_dongle; }
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TEnigma_machine
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define DNINST_PATH "setup/dninst.zip"
|
||||||
|
|
||||||
|
class TEnigma_machine : public TObject
|
||||||
|
{
|
||||||
|
TScanner* _scan;
|
||||||
|
int _year_assist;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void init_key(char key[8]) const;
|
||||||
|
bool decode_string(const TString& datain, TString& dataout) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual bool ok() const { return _scan != NULL && !_scan->eof(); }
|
||||||
|
|
||||||
|
bool line(TString& data);
|
||||||
|
bool find_serno(long serno);
|
||||||
|
int year_assist() const { return _year_assist; }
|
||||||
|
|
||||||
|
TEnigma_machine();
|
||||||
|
~TEnigma_machine();
|
||||||
|
};
|
||||||
|
|
||||||
|
void TEnigma_machine::init_key(char key[8]) const
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
key[i] = 'A' + ::rand() % 26;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TEnigma_machine::decode_string(const TString& datain, TString& dataout) const
|
||||||
|
{
|
||||||
|
dataout.cut(0);
|
||||||
|
if (datain.not_empty())
|
||||||
|
{
|
||||||
|
char* tmp = dataout.get_buffer(datain.len());
|
||||||
|
char key[8]; init_key(key);
|
||||||
|
int i;
|
||||||
|
for (i = 0; datain[i]; i++)
|
||||||
|
tmp[i] = datain[i] - (i < 8 ? key[i] : tmp[i - 8]);
|
||||||
|
tmp[i] = '\0';
|
||||||
|
}
|
||||||
|
return dataout.full();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TEnigma_machine::line(TString& data)
|
||||||
|
{ return _scan != NULL ? decode_string(_scan->line(), data) : false; }
|
||||||
|
|
||||||
|
bool TEnigma_machine::find_serno(long serno)
|
||||||
|
{
|
||||||
|
if (serno == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
TToken_string row(80, ';');
|
||||||
|
if (_year_assist > 2100)
|
||||||
|
{
|
||||||
|
TString8 para; para << '[' << serno << ']';
|
||||||
|
while (line(row))
|
||||||
|
{
|
||||||
|
if (row == para)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (line(row))
|
||||||
|
{
|
||||||
|
if (row.get_long(0) == serno)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEnigma_machine::TEnigma_machine()
|
||||||
|
: _scan(NULL), _year_assist(0)
|
||||||
|
{
|
||||||
|
if (fexist(DNINST_PATH))
|
||||||
|
{
|
||||||
|
_scan = new TScanner(DNINST_PATH);
|
||||||
|
::srand(883);
|
||||||
|
TString4 l1; line(l1);
|
||||||
|
_year_assist = atoi(l1);
|
||||||
|
::srand(_year_assist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEnigma_machine::~TEnigma_machine()
|
||||||
|
{
|
||||||
|
if (_scan != NULL)
|
||||||
|
delete _scan;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tdninst::assistance_year2solar(int ay) const
|
||||||
|
{
|
||||||
|
return (ay/1000)*1000 + (ay%1000)/10;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tdninst::parse_date(const TString& line, TString& key, TDate& datascad) const
|
||||||
|
{
|
||||||
|
const int equal = line.find('=');
|
||||||
|
if (equal > 0 && equal <= 16)
|
||||||
|
{
|
||||||
|
key = line.left(equal); key.trim();
|
||||||
|
TString16 strdate = line.mid(equal+1, 16); strdate.trim();
|
||||||
|
int d, m, y;
|
||||||
|
if (sscanf(strdate, "%2d-%2d-%4d", &d, &m, &y) == 3)
|
||||||
|
{
|
||||||
|
datascad = TDate(d, m, y);
|
||||||
|
return datascad.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tdninst::test_cmdline(const TString& cmdline, bool key_must_exist, TString& msg) const
|
||||||
|
{
|
||||||
|
msg.cut(0);
|
||||||
|
|
||||||
|
const TDongle& don = dongle();
|
||||||
|
const long serno = don.number();
|
||||||
|
if (serno == 0)
|
||||||
|
{
|
||||||
|
if (is_power_reseller(true))
|
||||||
|
return 0; // Solo chiavi per uso interno aga
|
||||||
|
msg = TR("Chiave di sviluppo non autorizzata");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TString4 strmod = cmdline.left(2);
|
||||||
|
const word codmod = don.module_name2code(strmod);
|
||||||
|
if (codmod == BAAUT)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!don.active(codmod))
|
||||||
|
{
|
||||||
|
msg << TR("Modulo non attivo sulla chiave: ") << strmod;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TDate oggi(TODAY);
|
||||||
|
const int solar_year = oggi.year();
|
||||||
|
const int dongle_ass = don.year_assist();
|
||||||
|
const int dongle_year = assistance_year2solar(dongle_ass);
|
||||||
|
if (solar_year - dongle_year >= 2)
|
||||||
|
{
|
||||||
|
msg << TR("Anno di assitenza non valido sulla chiave: ") << dongle_year;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEnigma_machine em;
|
||||||
|
const int dninst_ass = em.year_assist();
|
||||||
|
if (dongle_ass > dninst_ass)
|
||||||
|
{
|
||||||
|
msg << TR("File dninst.zip obsoleto");
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bFound = false;
|
||||||
|
if (dninst_ass > 2100)
|
||||||
|
{
|
||||||
|
if (em.find_serno(serno))
|
||||||
|
{
|
||||||
|
TString80 dninst_line;
|
||||||
|
TString16 key;
|
||||||
|
TDate datascad;
|
||||||
|
while (em.line(dninst_line))
|
||||||
|
{
|
||||||
|
if (dninst_line.empty() || dninst_line.starts_with("["))
|
||||||
|
break; // Fine file o paragrafo
|
||||||
|
|
||||||
|
if (parse_date(dninst_line, key, datascad))
|
||||||
|
{
|
||||||
|
const bool scaduto = datascad < oggi;
|
||||||
|
if (key == "*")
|
||||||
|
{
|
||||||
|
if (scaduto)
|
||||||
|
{
|
||||||
|
msg << TR("Chiave scaduta il ") << datascad;
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (key == cmdline)
|
||||||
|
{
|
||||||
|
bFound = true;
|
||||||
|
if (scaduto)
|
||||||
|
{
|
||||||
|
msg << TR("Applicazione scaduta il ") << datascad;
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (key == strmod)
|
||||||
|
{
|
||||||
|
if (scaduto)
|
||||||
|
{
|
||||||
|
msg << TR("Modulo scaduto il ") << datascad;
|
||||||
|
return 9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TToken_string dninst_line(80, ';');
|
||||||
|
while (em.line(dninst_line))
|
||||||
|
{
|
||||||
|
bFound = dninst_line.get_long(0) == serno;
|
||||||
|
if (bFound)
|
||||||
|
{
|
||||||
|
if (dninst_line.get_pos(strmod) > 0)
|
||||||
|
{
|
||||||
|
msg << TR("Modulo non attivo in dninst.zip : ") << strmod;
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bFound && key_must_exist)
|
||||||
|
{
|
||||||
|
msg << TR("Impossibile trovare ") << cmdline;
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tdninst::can_I_run() const
|
||||||
|
{
|
||||||
|
TFilename cmdline = main_app().argv(0);
|
||||||
|
cmdline = cmdline.name_only();
|
||||||
|
if (cmdline.starts_with("ba", true))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const bool me = cmdline.len()>3;
|
||||||
|
const char* option = main_app().argc() > 1 ? main_app().argv(1) : "";
|
||||||
|
if (*option == '-' && isdigit(*(option+1)))
|
||||||
|
cmdline << ' ' << option;
|
||||||
|
cmdline.lower();
|
||||||
|
TString msg;
|
||||||
|
return test_cmdline(cmdline, me, msg) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tdninst::find_killed(TToken_string& kill_list) const
|
||||||
|
{
|
||||||
|
kill_list.cut(0);
|
||||||
|
|
||||||
|
const int serno = dongle().number();
|
||||||
|
if (serno == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
bool good = false;
|
||||||
|
TEnigma_machine em;
|
||||||
|
if (em.ok())
|
||||||
|
{
|
||||||
|
if (em.year_assist() > 2100)
|
||||||
|
{
|
||||||
|
TToken_string l(80, '=');
|
||||||
|
good = em.find_serno(serno);
|
||||||
|
if (good)
|
||||||
|
{
|
||||||
|
const TDate oggi(TODAY);
|
||||||
|
TString16 str;
|
||||||
|
TDate ds;
|
||||||
|
while (em.line(l))
|
||||||
|
{
|
||||||
|
if (l.empty() || l[0] == '[')
|
||||||
|
break;
|
||||||
|
if (parse_date(l, str, ds) && ds < oggi)
|
||||||
|
kill_list.add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TToken_string l(80, ';');
|
||||||
|
while (em.line(l))
|
||||||
|
{
|
||||||
|
if (l.get_long(0) == serno)
|
||||||
|
{
|
||||||
|
const int semicolon = l.find(l.separator());
|
||||||
|
if (semicolon > 0)
|
||||||
|
{
|
||||||
|
kill_list = l.mid(semicolon+1);
|
||||||
|
kill_list.lower();
|
||||||
|
kill_list.replace(l.separator(), kill_list.separator());
|
||||||
|
}
|
||||||
|
good = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return good;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tdninst::Tdninst() : _year_assist(0)
|
||||||
|
{
|
||||||
|
TEnigma_machine s;
|
||||||
|
_year_assist = s.year_assist(); // 2091 or 2101?
|
||||||
|
}
|
||||||
|
@ -106,6 +106,27 @@ public:
|
|||||||
virtual ~TDongle();
|
virtual ~TDongle();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Tdninst
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class Tdninst : public TObject
|
||||||
|
{
|
||||||
|
int _year_assist;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int assistance_year2solar(int ay) const;
|
||||||
|
bool parse_date(const TString& line, TString& key, TDate& d) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
int assist_year() const { return _year_assist; }
|
||||||
|
int solar_year() const { return assistance_year2solar(_year_assist); }
|
||||||
|
int test_cmdline(const TString& cmdline, bool key_must_exist, TString& msg) const;
|
||||||
|
bool can_I_run() const;
|
||||||
|
bool find_killed(TToken_string& kill_list) const;
|
||||||
|
Tdninst();
|
||||||
|
};
|
||||||
|
|
||||||
TDongle& dongle();
|
TDongle& dongle();
|
||||||
bool destroy_dongle();
|
bool destroy_dongle();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user