2001-06-25 10:41:20 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <scanner.h>
|
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
|
|
#include "ba1500.h"
|
|
|
|
|
|
|
|
|
|
HIDDEN void build_key(char* dninst_key)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
|
dninst_key[i] = 'A'+ rand() % 26;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIDDEN void decode_string(char* dninst_key, char* data)
|
|
|
|
|
{
|
|
|
|
|
build_key(dninst_key);
|
2003-04-24 13:34:54 +00:00
|
|
|
|
char tmp[1024];
|
2006-12-29 14:16:28 +00:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; data[i]; i++)
|
2003-04-24 13:34:54 +00:00
|
|
|
|
tmp[i] = data[i] - (i < 8 ? dninst_key[i] : tmp[i - 8]);
|
|
|
|
|
tmp[i] = '\0';
|
|
|
|
|
strcpy(data, tmp);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DBG
|
|
|
|
|
|
|
|
|
|
HIDDEN void encode_string(char* dninst_key, char* data)
|
|
|
|
|
{
|
|
|
|
|
build_key(dninst_key);
|
|
|
|
|
|
2003-04-24 13:34:54 +00:00
|
|
|
|
char tmp[1024];
|
2006-12-29 14:16:28 +00:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; data[i]; i++)
|
2003-04-24 13:34:54 +00:00
|
|
|
|
tmp[i] = data[i] + (i < 8 ? dninst_key[i] : data[i - 8]);
|
|
|
|
|
tmp[i] = '\0';
|
|
|
|
|
strcpy(data, tmp);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-13 17:56:02 +00:00
|
|
|
|
HIDDEN bool build_dninst()
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
2006-12-29 14:16:28 +00:00
|
|
|
|
ifstream inf("dninst.txt", ios::in);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
if (inf.good())
|
|
|
|
|
{
|
|
|
|
|
char dninst_key[8] = "";
|
|
|
|
|
|
2006-04-13 17:56:02 +00:00
|
|
|
|
ofstream ouf("dninst.zip", ios::out | ios::binary);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
char line[256];
|
2006-12-13 16:22:33 +00:00
|
|
|
|
inf.getline(line, sizeof(line));
|
|
|
|
|
const int year = atoi(line);
|
2008-10-22 14:20:20 +00:00
|
|
|
|
CHECKD(year >= 2091 && year <= 3000, "Anno errato:", year);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
srand(883); // Inizializza generatore numeri casuali per l'anno
|
|
|
|
|
encode_string(dninst_key, line);
|
|
|
|
|
ouf << line << '\n';
|
|
|
|
|
srand(year); // Inizializza generatore numeri casuali per i moduli
|
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
while (!inf.eof())
|
|
|
|
|
{
|
|
|
|
|
inf.getline(line, sizeof(line));
|
|
|
|
|
encode_string(dninst_key, line);
|
|
|
|
|
ouf << line << '\n';
|
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return true;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
|
const char* split_ass(const int ass_year)
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
2007-03-30 13:51:17 +00:00
|
|
|
|
int year = ass_year, number = 0;
|
2008-07-08 13:31:11 +00:00
|
|
|
|
if (ass_year > 2008)
|
2007-03-30 13:51:17 +00:00
|
|
|
|
{
|
|
|
|
|
year = (ass_year/1000)*1000 + (ass_year%1000)/10;
|
|
|
|
|
number = ass_year%10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TString& tmp = get_tmp_string();
|
|
|
|
|
tmp << year;
|
|
|
|
|
if (number > 0)
|
|
|
|
|
tmp << '/' << number;
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HIDDEN bool show_error(const char* str)
|
|
|
|
|
{
|
|
|
|
|
int app_year, dum1, dum2, dum3;
|
|
|
|
|
TApplication::get_version_info(app_year, dum1, dum2, dum3);
|
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
TString msg;
|
2007-03-30 13:51:17 +00:00
|
|
|
|
msg << TR("Impossibile aggiornare automaticamente l'assistenza ")
|
|
|
|
|
<< split_ass(app_year) << ":\n" << str << '.';
|
2001-06-25 10:41:20 +00:00
|
|
|
|
return error_box(msg);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
// Copia il file dninst.zip dal CD/server alla cartella corrente
|
2002-05-27 13:16:06 +00:00
|
|
|
|
bool update_dninst(bool force)
|
|
|
|
|
{
|
2006-04-13 17:56:02 +00:00
|
|
|
|
#ifdef DBG
|
|
|
|
|
if (force && main_app().argc() > 2 && strcmp(main_app().argv(2), "-dninst") == 0)
|
|
|
|
|
{
|
|
|
|
|
build_dninst();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
//legge dal diskpath di install.ini la directory da cui aggiornarsi;se il dninst.zip di tale..
|
|
|
|
|
//..directory e' piu' nuovo di quello in locale -> lo copia in locale
|
2007-12-19 11:41:00 +00:00
|
|
|
|
const TFilename local_name = "setup/dninst.zip";
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TConfig ini("install.ini", "Main");
|
|
|
|
|
TFilename remote_name = ini.get("DiskPath");
|
|
|
|
|
remote_name.add(local_name);
|
|
|
|
|
if (remote_name.exist())
|
|
|
|
|
{
|
|
|
|
|
if (!force)
|
|
|
|
|
{
|
|
|
|
|
force = !local_name.exist();
|
|
|
|
|
if (!force)
|
|
|
|
|
{
|
|
|
|
|
const long local_date = xvt_fsys_file_attr(local_name, XVT_FILE_ATTR_MTIME);
|
|
|
|
|
const long remote_date = xvt_fsys_file_attr(remote_name, XVT_FILE_ATTR_MTIME);
|
|
|
|
|
force = remote_date > local_date;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (force)
|
2007-12-19 11:41:00 +00:00
|
|
|
|
{
|
|
|
|
|
make_dir(local_name.path());
|
2006-12-13 16:22:33 +00:00
|
|
|
|
fcopy(remote_name, local_name);
|
2007-12-19 11:41:00 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
2006-04-13 17:56:02 +00:00
|
|
|
|
return true;
|
2002-05-27 13:16:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool update_assistance_year()
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (dongle().hardware() == _dongle_network)
|
|
|
|
|
{
|
2007-03-30 13:51:17 +00:00
|
|
|
|
show_error(TR("Il server di autorizzazioni deve essere disattivato"));
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-13 17:56:02 +00:00
|
|
|
|
update_dninst(true);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
2007-12-19 11:41:00 +00:00
|
|
|
|
const TFilename dninst = "setup/dninst.zip";
|
2003-06-03 08:28:28 +00:00
|
|
|
|
if (dninst.exist())
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
char dninst_key[8] = "";
|
2003-06-03 08:28:28 +00:00
|
|
|
|
|
|
|
|
|
TScanner keys(dninst);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
TString& anno = keys.line();
|
|
|
|
|
srand(883);
|
|
|
|
|
decode_string(dninst_key, anno.get_buffer());
|
|
|
|
|
const int ass_year = atoi(anno);
|
2008-07-08 13:31:11 +00:00
|
|
|
|
//se l'anno di assistenza della versione (dninst.zip) e' piu' grande di quello attualmente registrato sulla...
|
2008-07-07 14:27:32 +00:00
|
|
|
|
//...chiavetta controlla se il serialnumber della chiavetta e' presente nella lista dei codici...
|
|
|
|
|
//...validi dentro il dninst.zip
|
2003-06-03 08:28:28 +00:00
|
|
|
|
if (ass_year > dongle().year_assist())
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
2003-06-03 08:28:28 +00:00
|
|
|
|
const int serno = get_serial_number();
|
|
|
|
|
srand(ass_year);
|
|
|
|
|
while (!keys.eof())
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
2003-06-03 08:28:28 +00:00
|
|
|
|
TString& line = keys.line();
|
|
|
|
|
if (line.empty())
|
|
|
|
|
break;
|
|
|
|
|
decode_string(dninst_key, line.get_buffer());
|
|
|
|
|
const int sn = atoi(line);
|
2004-02-12 14:01:39 +00:00
|
|
|
|
if (sn == serno || line[0] == '*')
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
2003-06-03 08:28:28 +00:00
|
|
|
|
dongle().set_year_assist(ass_year);
|
|
|
|
|
if (dongle().burn())
|
|
|
|
|
{
|
2008-07-07 14:27:32 +00:00
|
|
|
|
return true; //Complimenti,la chiavetta e' presente nella lista e sara' aggiornato l'anno di assistenza
|
2003-06-03 08:28:28 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-03-30 13:51:17 +00:00
|
|
|
|
show_error(FR("Errore di scrittura sulla chiave di protezione"));
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
2007-12-19 11:41:00 +00:00
|
|
|
|
} //if(dongle().burn...
|
|
|
|
|
} //if(sn==serno...
|
|
|
|
|
} //while(!keys.eof()...
|
2008-07-07 14:27:32 +00:00
|
|
|
|
//Non e' riuscito a trovare la chiavetta nell'elenco, non puo' aggiornare automaticamente
|
2007-03-30 13:51:17 +00:00
|
|
|
|
show_error(TR("Il numero di serie di questa postazione non <20> presente sul database"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
2007-12-19 11:41:00 +00:00
|
|
|
|
else //if(ass_year>dongle...
|
2008-07-07 14:27:32 +00:00
|
|
|
|
{
|
|
|
|
|
//Se l'anno di assistenza sulla chiave e' maggiore di quello sul dninst segnala l'incongruenza e poi?
|
|
|
|
|
if (ass_year < dongle().year_assist())
|
|
|
|
|
show_error(TR("L'anno di assistenza sul database e' inferiore a quello registrato sulla chiave di protezione"));
|
|
|
|
|
//Se l'anno di assistenza coincide con quello sulla chiave -> la chiave ha gia' l'assistenza...
|
|
|
|
|
//...corretta abilitata e puo' proseguire l'aggiornamento
|
|
|
|
|
else
|
2008-07-08 13:31:11 +00:00
|
|
|
|
return true; //ok, sei abilitato a proseguire!
|
2008-07-07 14:27:32 +00:00
|
|
|
|
}
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-03-30 13:51:17 +00:00
|
|
|
|
show_error(TR("Il database dei numeri di serie non <20> accessibile"));
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|