1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
//***************************************************************************
/*
* TOra - An Oracle Toolkit for DBA's and developers
* Copyright (C) 2000-2001,2001 Underscore AB
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; only version 2 of
* the License is valid for this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* As a special exception, you have permission to link this program
* with the Oracle Client libraries and distribute executables, as long
* as you follow the requirements of the GNU GPL in regard to all of the
* software in the executable aside from Oracle client libraries.
*
* Specifically you are not permitted to link this program with the
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
* And you are not permitted to distribute binaries compiled against
* these libraries without written consent from Underscore AB. Observe
* that this does not disallow linking to the Qt Free Edition.
*
* All trademarks belong to their respective owners.
*
****************************************************************************/
#include "md5.c"
#include "tolicense.h"
#include <time.h>
#include <stdlib.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qregexp.h>
#include <qtextview.h>
#include "tolicense.moc"
#include "tolicenseui.moc"
toLicense::toLicense(QWidget *parent)
: toLicenseUI(parent,"license",WStyle_Customize|WStyle_DialogBorder|WType_Modal)
{
QWidget *d=QApplication::desktop();
move((d->width()-width())/2,(d->height()-height())/2);
TextView->setText(QString(toAbout::aboutText()).arg(TOVERSION));
TextView->setPaper(QColor(227,183,54));
srand(time(NULL));
switch(rand()%6) {
case 0:
Button1->setText("Register");
connect(Button1,SIGNAL(clicked()),this,SLOT(licenseButton()));
Button1->setDefault(true);
Button2->setText("Quit");
connect(Button2,SIGNAL(clicked()),this,SLOT(quitButton()));
Button3->setText("Continue");
connect(Button3,SIGNAL(clicked()),this,SLOT(dontRegisterButton()));
break;
case 1:
Button2->setText("Register");
connect(Button2,SIGNAL(clicked()),this,SLOT(licenseButton()));
Button2->setDefault(true);
Button1->setText("Quit");
connect(Button1,SIGNAL(clicked()),this,SLOT(quitButton()));
Button3->setText("Continue");
connect(Button3,SIGNAL(clicked()),this,SLOT(dontRegisterButton()));
break;
case 2:
Button3->setText("Register");
connect(Button3,SIGNAL(clicked()),this,SLOT(licenseButton()));
Button3->setDefault(true);
Button2->setText("Quit");
connect(Button2,SIGNAL(clicked()),this,SLOT(quitButton()));
Button1->setText("Continue");
connect(Button1,SIGNAL(clicked()),this,SLOT(dontRegisterButton()));
break;
case 3:
Button2->setText("Register");
connect(Button2,SIGNAL(clicked()),this,SLOT(licenseButton()));
Button2->setDefault(true);
Button3->setText("Quit");
connect(Button3,SIGNAL(clicked()),this,SLOT(quitButton()));
Button1->setText("Continue");
connect(Button1,SIGNAL(clicked()),this,SLOT(dontRegisterButton()));
break;
case 4:
Button1->setText("Register");
connect(Button1,SIGNAL(clicked()),this,SLOT(licenseButton()));
Button1->setDefault(true);
Button3->setText("Quit");
connect(Button3,SIGNAL(clicked()),this,SLOT(quitButton()));
Button2->setText("Continue");
connect(Button2,SIGNAL(clicked()),this,SLOT(dontRegisterButton()));
break;
default:
Button3->setText("Register");
connect(Button3,SIGNAL(clicked()),this,SLOT(licenseButton()));
Button3->setDefault(true);
Button1->setText("Quit");
connect(Button1,SIGNAL(clicked()),this,SLOT(quitButton()));
Button2->setText("Continue");
connect(Button2,SIGNAL(clicked()),this,SLOT(dontRegisterButton()));
break;
}
Name->setFocus();
connect(Name,SIGNAL(returnPressed()),this,SLOT(licenseButton()));
connect(License,SIGNAL(returnPressed()),this,SLOT(licenseButton()));
Status=running;
}
void toLicense::dontRegisterButton(void)
{
Status=dontRegister;
hide();
}
#include "license.c"
static int DecodeChar(char c)
{
for (int i=0;i<32;i++)
if (Base[i]==c)
return i;
return -1;
}
static QString CheckLicense(const QString &user,const QString &license)
{
QString ret;
MD5_CTX MD5;
unsigned char output[16];
int i;
QString userstr=user.upper();
userstr.replace(QRegExp("[^A-Z0-9]"),"");
const char *userp=userstr;
QString licstr=license.upper();
licstr.replace(QRegExp("[^0123456789ABCDEFGHJKMNPQRSTUVWXYZ]"),"");
QString prep=licstr.mid(0,6);
const char *prepstr=prep;
/** Calculate hash sum value of secret value and username in argv[1] concatenated.
*/
MD5Init(&MD5);
MD5Update(&MD5,(unsigned char *)SECRET_HASH,strlen(SECRET_HASH));
if (prepstr)
MD5Update(&MD5,(unsigned char *)prepstr,strlen(prepstr));
MD5Update(&MD5,(unsigned char *)userp,strlen(userp)>255?255:strlen(userp));
MD5Final(output,&MD5);
ret=prep;
ret+=QChar(Base[output[15]&31]);
ret+=QChar(Base[(output[15]>>3)&31]);
/* Output MD5 checksum in base 32 with a few characters left out.
*/
for(i=0;i<3;i++) {
ret+=QChar(Base[output[i*5]&31]);
ret+=QChar(Base[((output[i*5+0]>>5)+(output[i*5+1]<<3))&31]);
ret+=QChar(Base[(output[i*5+1]>>2)&31]);
ret+=QChar(Base[((output[i*5+1]>>7)+(output[i*5+2]<<1))&31]);
ret+=QChar(Base[((output[i*5+2]>>4)+(output[i*5+3]<<4))&31]);
ret+=QChar(Base[(output[i*5+3]>>1)&31]);
ret+=QChar(Base[((output[i*5+3]>>6)+(output[i*5+4]<<2))&31]);
ret+=QChar(Base[(output[i*5+4]>>3)&31]);
}
if (licstr==ret) {
int license=DecodeChar(prepstr[4])*32+DecodeChar(prepstr[5]);
QString ret="Welcome to TOra";
if (license==0)
ret+=" (Personal license, not for commerical use)";
else if (license==1)
ret+=" (Commercial license one user)";
else if (license==1000)
ret+=" (Commerical site license)";
else
ret+=" (Commercial license "+QString::number(license)+" users)";
return ret;
}
return QString::null;
}
void toLicense::licenseButton(void)
{
if (!CheckLicense(Name->text(),License->text()).isNull()) {
Status=license;
hide();
} else {
TOMessageBox::information(this,
"Not a valid license key",
"Please check your name and registration key?",
"Ok");
}
}
void toLicense::quitButton(void)
{
if (TOMessageBox::warning(this,
"Really quit?",
"Are you sure you want to quit?",
"Yes",
"No")==0) {
Status=quit;
hide();
}
}
toLicense::status toLicense::exec(void)
{
Status=running;
show();
do {
qApp->processOneEvent();
} while(Status==running);
return Status;
}
QString toCheckLicense(bool force)
{
QString user=toTool::globalConfig("UserName","");
QString regkey=toTool::globalConfig("RegKey","");
QString ret=CheckLicense(user,regkey);
if (ret.isNull()||force) {
toLicense license(NULL);
license.Name->setText(user);
license.License->setText(regkey);
if (license.exec()==toLicense::quit)
exit(0);
user=license.Name->text();
regkey=license.License->text();
toTool::globalSetConfig("UserName",user);
toTool::globalSetConfig("RegKey",regkey);
ret=CheckLicense(user,regkey);
if (ret.isNull())
ret="Welcome to TOra (Unregistered version, not for commercial use)";
else
toTool::saveConfig();
}
return ret;
}
bool toFreeware(void)
{
return false;
}
|