deleted unused code
This commit is contained in:
parent
654bd6fbf9
commit
18e6994b3d
|
@ -195,41 +195,9 @@ namespace FileConverterUtils2
|
|||
|
||||
public static LicenseInfo CreateLicenseInfo(DateTime buildTime)
|
||||
{
|
||||
#if OPEN_SOURCE
|
||||
|
||||
return new OpenSourceLicenseInfo();
|
||||
#else
|
||||
|
||||
LicenseType licType = (LicenseType)int.Parse(ConfigurationManager.AppSettings["license.type"] ?? "3");
|
||||
|
||||
LicenseInfo lic = null;
|
||||
switch (licType)
|
||||
{
|
||||
case LicenseType.ByVKey:
|
||||
lic = new VKeyLicenseInfo();
|
||||
break;
|
||||
|
||||
case LicenseType.ByUserCount:
|
||||
lic = new UserCountLicenseInfo();
|
||||
break;
|
||||
|
||||
case LicenseType.ByDocumentSessions:
|
||||
lic = new DocumentSessionLicenseInfo();
|
||||
break;
|
||||
|
||||
case LicenseType.ByUserCount2:
|
||||
lic = new UserCount2LicenseInfo();
|
||||
break;
|
||||
|
||||
case LicenseType.ByActiveConnections:
|
||||
default:
|
||||
lic = new ActiveConnectionLicenseInfo();
|
||||
break;
|
||||
}
|
||||
if (null != lic)
|
||||
lic.m_dtBuildTime = buildTime;
|
||||
|
||||
return lic;
|
||||
#endif
|
||||
}
|
||||
|
||||
public abstract LicenseCustomerInfo getCustomerInfo();
|
||||
|
@ -248,7 +216,6 @@ namespace FileConverterUtils2
|
|||
}
|
||||
|
||||
}
|
||||
#if OPEN_SOURCE
|
||||
|
||||
public class OpenSourceLicenseInfo : LicenseInfo
|
||||
{
|
||||
|
@ -271,408 +238,5 @@ namespace FileConverterUtils2
|
|||
return info;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
public class MockLicenseInfo : LicenseInfo
|
||||
{
|
||||
public override LicenseRights getRights(LicenseMetaData metaData, out ErrorTypes errorCode)
|
||||
{
|
||||
LicenseRights oRights = new LicenseRights(true);
|
||||
errorCode = ErrorTypes.NoError;
|
||||
return oRights;
|
||||
}
|
||||
public override LicenseCustomerInfo getCustomerInfo()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class VKeyLicenseInfo : LicenseInfo
|
||||
{
|
||||
public VKeyLicenseInfo()
|
||||
{
|
||||
}
|
||||
public override LicenseRights getRights(LicenseMetaData metaData, out ErrorTypes errorCode)
|
||||
{
|
||||
errorCode = ErrorTypes.NoError;
|
||||
LicenseRights oRights = new LicenseRights();
|
||||
if (metaData is LicenseMetaData)
|
||||
{
|
||||
LicenseMetaData metaVKey = (LicenseMetaData)metaData;
|
||||
errorCode = Signature.isAccept(metaVKey.VKey, metaVKey.DocId, false, null);
|
||||
|
||||
if (ErrorTypes.NoError == errorCode ||
|
||||
ErrorTypes.VKeyTimeExpire == errorCode)
|
||||
{
|
||||
|
||||
oRights.CanOpen = (ErrorTypes.VKeyTimeExpire != errorCode);
|
||||
|
||||
string sAffilieteId = null;
|
||||
Signature.getVKeyStringParam(metaVKey.VKey, ConfigurationSettings.AppSettings["keyKeyID"], out sAffilieteId);
|
||||
ASC.Core.Billing.PaymentOffice oPaymentOffice = Signature.getPaymentOffice(sAffilieteId);
|
||||
if (32 <= sAffilieteId.Length)
|
||||
{
|
||||
oRights.CanSave = oPaymentOffice.Editing;
|
||||
oRights.CanCoAuthoring = oPaymentOffice.CoEditing;
|
||||
oRights.CanExport = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
oRights.CanSave = true;
|
||||
oRights.CanCoAuthoring = true;
|
||||
oRights.CanExport = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorCode = ErrorTypes.LicenseErrorArgument;
|
||||
}
|
||||
return oRights;
|
||||
}
|
||||
public override LicenseCustomerInfo getCustomerInfo()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ActiveConnectionLicenseInfo : LicenseInfo
|
||||
{
|
||||
protected ITrackingInfo trackInfo;
|
||||
|
||||
protected virtual ActiveConnectionsLicenseReader createLicenseReader(string licensePath)
|
||||
{
|
||||
return new ActiveConnectionsLicenseReader(licensePath);
|
||||
}
|
||||
protected virtual ITrackingInfo createTrackingInfo ()
|
||||
{
|
||||
return new TrackingInfo ();
|
||||
}
|
||||
public ActiveConnectionLicenseInfo ()
|
||||
{
|
||||
trackInfo = createTrackingInfo ();
|
||||
|
||||
int interval = int.Parse(ConfigurationSettings.AppSettings["license.activeconnections.tracking.interval"] ?? "300");
|
||||
string licensePath = ConfigurationSettings.AppSettings["license.file.path"];
|
||||
|
||||
trackInfo.setLicense(createLicenseReader(licensePath));
|
||||
}
|
||||
|
||||
public virtual void track(string clientId, string docId, int isAlive)
|
||||
{
|
||||
trackInfo.track (clientId, docId, isAlive);
|
||||
}
|
||||
|
||||
public void getUserCount (out int active, out int inactive)
|
||||
{
|
||||
trackInfo.getUserCount(out active, out inactive);
|
||||
}
|
||||
|
||||
public override LicenseCustomerInfo getCustomerInfo()
|
||||
{
|
||||
ActiveConnectionsLicenseReader lic = (ActiveConnectionsLicenseReader) trackInfo.getLicense();
|
||||
if (null == lic)
|
||||
return null;
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
bool found = lic.isLicenseFound();
|
||||
bool correct = lic.isLicenseCorrect();
|
||||
bool notStarted = (lic.getStartDate() > now);
|
||||
bool expired = (lic.getEndDate() < now) && (lic.getEndDateThreshold() > now);
|
||||
bool fully_expired = notStarted || (lic.getEndDateThreshold() < now);
|
||||
|
||||
if (notStarted && found && correct)
|
||||
{
|
||||
LicenseCustomerInfo infoUnreg = new LicenseCustomerInfo();
|
||||
infoUnreg.customer = lic.getCustomer();
|
||||
infoUnreg.customer_addr = lic.getCustomerAddr();
|
||||
infoUnreg.customer_www = lic.getCustomerWww();
|
||||
infoUnreg.customer_mail = lic.getCustomerMail();
|
||||
infoUnreg.customer_logo = lic.getCustomerLogo();
|
||||
infoUnreg.customer_info = "License starts on " + lic.getStartDate().ToUniversalTime().ToString("MM/dd/yyyy H:mm:ss zzz")+ "(UTC)";
|
||||
return infoUnreg;
|
||||
}
|
||||
if (fully_expired || !found || !correct)
|
||||
{
|
||||
LicenseCustomerInfo infoUnreg = new LicenseCustomerInfo();
|
||||
infoUnreg.customer = "Unregistered";
|
||||
return infoUnreg;
|
||||
}
|
||||
|
||||
LicenseCustomerInfo info = new LicenseCustomerInfo();
|
||||
info.customer = lic.getCustomer();
|
||||
info.customer_addr = lic.getCustomerAddr();
|
||||
info.customer_www = lic.getCustomerWww();
|
||||
info.customer_mail = lic.getCustomerMail();
|
||||
info.customer_info = expired ? "License has expired" : lic.getCustomerInfo();
|
||||
info.customer_logo = lic.getCustomerLogo();
|
||||
|
||||
return info;
|
||||
}
|
||||
protected virtual string getUserId(LicenseMetaData metaData)
|
||||
{
|
||||
return metaData.UserId;
|
||||
}
|
||||
protected virtual string getDocumentId(LicenseMetaData metaData)
|
||||
{
|
||||
return metaData.DocId;
|
||||
}
|
||||
protected bool checkQuotaExceeded(LicenseMetaData metaData)
|
||||
{
|
||||
string userId = getUserId(metaData);
|
||||
string documentId = getDocumentId(metaData);
|
||||
bool bQuotaExceed = trackInfo.isQuotaExceed(userId, documentId);
|
||||
|
||||
if (bQuotaExceed)
|
||||
{
|
||||
|
||||
trackInfo.Cleanup();
|
||||
bQuotaExceed = trackInfo.isQuotaExceed(userId, documentId);
|
||||
}
|
||||
|
||||
return bQuotaExceed;
|
||||
}
|
||||
public ILicenseReader getLicense()
|
||||
{
|
||||
return trackInfo.getLicense();
|
||||
}
|
||||
public override LicenseRights getRights(LicenseMetaData metaData, out ErrorTypes errorCode)
|
||||
{
|
||||
errorCode = ErrorTypes.NoError;
|
||||
|
||||
LicenseRights oRights = new LicenseRights();
|
||||
|
||||
bool bValidLicenseFile = trackInfo.isLicenseFileValid();
|
||||
if (!bValidLicenseFile)
|
||||
{
|
||||
errorCode = ErrorTypes.LicenseErrorFile;
|
||||
|
||||
bool bUnlicensedQuotaExceed = checkQuotaExceeded (metaData);
|
||||
|
||||
if (bUnlicensedQuotaExceed)
|
||||
{
|
||||
errorCode = ErrorTypes.LicenseErrorActiveConnectionQuotaExceed;
|
||||
}
|
||||
else
|
||||
{
|
||||
oRights.CanSave = true;
|
||||
oRights.CanCoAuthoring = true;
|
||||
oRights.CanExport = true;
|
||||
}
|
||||
|
||||
return oRights;
|
||||
}
|
||||
|
||||
bool bValidDate = false;
|
||||
|
||||
if (trackInfo.isLicenseDateValid())
|
||||
{
|
||||
|
||||
bValidDate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
errorCode = ErrorTypes.LicenseErrorInvalidDate;
|
||||
|
||||
if (!trackInfo.isLicenseDateTresholdExpired())
|
||||
bValidDate = true;
|
||||
}
|
||||
|
||||
bool bBuildTimeValid = trackInfo.isLicenseEndDateGreater(m_dtBuildTime);
|
||||
bool bQuotaExceed = true;
|
||||
bool bEditorAllowed = false;
|
||||
|
||||
uint permissions = trackInfo.getLicense().getPermissions();
|
||||
|
||||
if ((metaData.EditorId == (int)EditorType.Convertation)
|
||||
&& (permissions != EditorPermissions.PERMISSION_NONE))
|
||||
{
|
||||
|
||||
bQuotaExceed = false;
|
||||
bEditorAllowed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
bQuotaExceed = checkQuotaExceeded(metaData);
|
||||
|
||||
if (bQuotaExceed)
|
||||
{
|
||||
errorCode = ErrorTypes.LicenseErrorActiveConnectionQuotaExceed;
|
||||
}
|
||||
|
||||
if (((metaData.EditorId == (int)EditorType.Word) && (0 != (permissions & EditorPermissions.PERMISSION_WRITER)))
|
||||
|| ((metaData.EditorId == (int)EditorType.Spreadsheet) && (0 != (permissions & EditorPermissions.PERMISSION_SPREADSHEET)))
|
||||
|| ((metaData.EditorId == (int)EditorType.Presentation) && (0 != (permissions & EditorPermissions.PERMISSION_PRESENTATION)))
|
||||
)
|
||||
{
|
||||
|
||||
bEditorAllowed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (bValidDate && bEditorAllowed && !bQuotaExceed && bBuildTimeValid)
|
||||
{
|
||||
oRights.CanSave = true;
|
||||
oRights.CanCoAuthoring = true;
|
||||
oRights.CanExport = true;
|
||||
}
|
||||
|
||||
return oRights;
|
||||
}
|
||||
}
|
||||
|
||||
public class UserCountLicenseInfo : ActiveConnectionLicenseInfo
|
||||
{
|
||||
public UserCountLicenseInfo()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
public override void track(string clientId, string docId, int isAlive)
|
||||
{
|
||||
trackInfo.track(clientId, "", isAlive);
|
||||
}
|
||||
protected override string getDocumentId(LicenseMetaData metaData)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
protected override ActiveConnectionsLicenseReader createLicenseReader(string licensePath)
|
||||
{
|
||||
return new UserCountLicenseReader(licensePath);
|
||||
}
|
||||
protected override ITrackingInfo createTrackingInfo()
|
||||
{
|
||||
return new TrackingInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public class UserCount2LicenseInfo : UserCountLicenseInfo
|
||||
{
|
||||
public UserCount2LicenseInfo()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
protected override ActiveConnectionsLicenseReader createLicenseReader(string licensePath)
|
||||
{
|
||||
return new UserCount2LicenseReader(licensePath);
|
||||
}
|
||||
protected override ITrackingInfo createTrackingInfo()
|
||||
{
|
||||
return new UserCount2TrackingInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public class DocumentSessionLicenseInfo : LicenseInfo
|
||||
{
|
||||
DocumentSessionLicenseReader license;
|
||||
|
||||
public DocumentSessionLicenseInfo()
|
||||
{
|
||||
string licensePath = ConfigurationSettings.AppSettings["license.file.path"];
|
||||
license = new DocumentSessionLicenseReader(licensePath);
|
||||
}
|
||||
public string getTrackingUrl()
|
||||
{
|
||||
return null == license ? null : license.GetTrackingUrl();
|
||||
}
|
||||
public string getLicenseId()
|
||||
{
|
||||
return null == license ? null : license.getId();
|
||||
}
|
||||
|
||||
public override LicenseRights getRights(LicenseMetaData metaData, out ErrorTypes errorCode)
|
||||
{
|
||||
errorCode = ErrorTypes.NoError;
|
||||
|
||||
LicenseRights oRights = new LicenseRights();
|
||||
|
||||
if (null == license
|
||||
|| !license.isLicenseFound()
|
||||
|| !license.isLicenseCorrect())
|
||||
{
|
||||
errorCode = ErrorTypes.LicenseErrorFile;
|
||||
return oRights;
|
||||
}
|
||||
|
||||
bool bValidDate = false;
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
DateTime start = license.getStartDate();
|
||||
DateTime end = license.getEndDate();
|
||||
DateTime treshold = license.getEndDateThreshold();
|
||||
|
||||
if (start < now && end > now)
|
||||
{
|
||||
|
||||
bValidDate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
errorCode = ErrorTypes.LicenseErrorInvalidDate;
|
||||
|
||||
if (now < treshold)
|
||||
bValidDate = true;
|
||||
}
|
||||
|
||||
if (bValidDate)
|
||||
{
|
||||
oRights.CanSave = true;
|
||||
oRights.CanCoAuthoring = true;
|
||||
oRights.CanExport = true;
|
||||
}
|
||||
|
||||
return oRights;
|
||||
}
|
||||
public override LicenseCustomerInfo getCustomerInfo()
|
||||
{
|
||||
if (null == license)
|
||||
return null;
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
bool found = license.isLicenseFound();
|
||||
bool correct = license.isLicenseCorrect();
|
||||
bool notStarted = (license.getStartDate() > now);
|
||||
bool expired = (license.getEndDate() < now) && (license.getEndDateThreshold() > now);
|
||||
bool fully_expired = notStarted || (license.getEndDateThreshold() < now);
|
||||
|
||||
if (notStarted && found && correct)
|
||||
{
|
||||
LicenseCustomerInfo infoUnreg = new LicenseCustomerInfo();
|
||||
infoUnreg.customer = license.getCustomer();
|
||||
infoUnreg.customer_addr = license.getCustomerAddr();
|
||||
infoUnreg.customer_www = license.getCustomerWww();
|
||||
infoUnreg.customer_mail = license.getCustomerMail();
|
||||
infoUnreg.customer_logo = license.getCustomerLogo();
|
||||
infoUnreg.customer_info = "License starts on " + license.getStartDate().ToUniversalTime().ToString("MM/dd/yyyy H:mm:ss zzz") + "(UTC)";
|
||||
}
|
||||
if (fully_expired || !found || !correct)
|
||||
{
|
||||
LicenseCustomerInfo infoUnreg = new LicenseCustomerInfo();
|
||||
infoUnreg.customer = "Unregistered";
|
||||
return infoUnreg;
|
||||
}
|
||||
|
||||
LicenseCustomerInfo info = new LicenseCustomerInfo();
|
||||
info.customer = license.getCustomer();
|
||||
info.customer_addr = license.getCustomerAddr();
|
||||
info.customer_www = license.getCustomerWww();
|
||||
info.customer_mail = license.getCustomerMail();
|
||||
info.customer_info = expired ? "License has expired" : license.getCustomerInfo();
|
||||
info.customer_logo = license.getCustomerLogo();
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -39,300 +39,5 @@ using System.Xml;
|
|||
|
||||
namespace FileConverterUtils2
|
||||
{
|
||||
#if !OPEN_SOURCE
|
||||
public class ActiveConnectionsLicenseReader : ILicenseReader
|
||||
{
|
||||
|
||||
protected List<ActiveConnectionsLicenseReaderSingle> m_licnenses = new List<ActiveConnectionsLicenseReaderSingle>();
|
||||
|
||||
protected virtual ActiveConnectionsLicenseReaderSingle createSingleFileReader(string licFileName)
|
||||
{
|
||||
return new ActiveConnectionsLicenseReaderSingle(licFileName);
|
||||
}
|
||||
public ActiveConnectionsLicenseReader (string ciphiredXmlPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
bool isFileExists = System.IO.File.Exists(ciphiredXmlPath);
|
||||
bool isDirExists = System.IO.Directory.Exists(ciphiredXmlPath);
|
||||
|
||||
if (isFileExists)
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(ciphiredXmlPath);
|
||||
string licFileName = fileInfo.FullName;
|
||||
ActiveConnectionsLicenseReaderSingle item = createSingleFileReader (licFileName);
|
||||
if (item.isLicenseFound() && item.isLicenseCorrect())
|
||||
{
|
||||
m_licnenses.Add(item);
|
||||
}
|
||||
}
|
||||
else if (isDirExists)
|
||||
{
|
||||
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(ciphiredXmlPath);
|
||||
FileInfo[] licFiles = rootDirectory.GetFiles("*.lic");
|
||||
if (null != licFiles)
|
||||
{
|
||||
foreach (FileInfo file in licFiles)
|
||||
{
|
||||
string licFileName = file.FullName;
|
||||
ActiveConnectionsLicenseReaderSingle item = createSingleFileReader (licFileName);
|
||||
if (item.isLicenseFound() && item.isLicenseCorrect())
|
||||
{
|
||||
|
||||
string licId = item.getId();
|
||||
bool unique = true;
|
||||
foreach (ActiveConnectionsLicenseReaderSingle lic_added in m_licnenses)
|
||||
{
|
||||
if (lic_added.getId() == licId)
|
||||
{
|
||||
unique = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (unique)
|
||||
m_licnenses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_found = _correct = (m_licnenses.Count() > 0);
|
||||
|
||||
if (_found)
|
||||
{
|
||||
DateTime minDate, maxDate, tresholdDate;
|
||||
minDate = m_licnenses[0].getStartDate ();
|
||||
maxDate = m_licnenses[0].getEndDate ();
|
||||
tresholdDate = m_licnenses[0].getEndDateThreshold();
|
||||
|
||||
foreach (ActiveConnectionsLicenseReaderSingle lic in m_licnenses)
|
||||
{
|
||||
DateTime startDate = lic.getStartDate();
|
||||
DateTime endDate = lic.getEndDate();
|
||||
DateTime endDateTres = lic.getEndDateThreshold();
|
||||
if (minDate > startDate)
|
||||
minDate = startDate;
|
||||
if (maxDate < endDate)
|
||||
maxDate = endDate;
|
||||
if (tresholdDate < endDateTres)
|
||||
tresholdDate = endDateTres;
|
||||
}
|
||||
_startDate = minDate;
|
||||
_endDate = maxDate;
|
||||
_endDateThreshold = tresholdDate;
|
||||
|
||||
_customer = m_licnenses[0].getCustomer();
|
||||
_customer_www = m_licnenses[0].getCustomerWww();
|
||||
_customer_addr = m_licnenses[0].getCustomerAddr();
|
||||
_customer_mail = m_licnenses[0].getCustomerMail();
|
||||
_customer_info = m_licnenses[0].getCustomerInfo();
|
||||
_customer_logo = m_licnenses[0].getCustomerLogo();
|
||||
}
|
||||
else
|
||||
{
|
||||
_customer = "Unregistered";
|
||||
_customer_www = null;
|
||||
_customer_addr = null;
|
||||
_customer_mail = null;
|
||||
_customer_info = null;
|
||||
_customer_logo = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public ErrorTypes GetAccessByInfo()
|
||||
{
|
||||
return ErrorTypes.NoError;
|
||||
}
|
||||
|
||||
public DateTime getStartDate()
|
||||
{
|
||||
return _startDate;
|
||||
}
|
||||
|
||||
public DateTime getEndDate()
|
||||
{
|
||||
return _endDate;
|
||||
}
|
||||
|
||||
public DateTime getEndDateThreshold()
|
||||
{
|
||||
return _endDateThreshold;
|
||||
}
|
||||
|
||||
public string getId()
|
||||
{
|
||||
|
||||
string id = "";
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, true);
|
||||
if (lics.Count() > 0)
|
||||
id = lics[0].getId();
|
||||
return id;
|
||||
}
|
||||
|
||||
public string getCustomer()
|
||||
{
|
||||
string res = null;
|
||||
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, true);
|
||||
if (lics.Count() > 0)
|
||||
res = lics[0].getCustomer();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public string getCustomerAddr()
|
||||
{
|
||||
string res = null;
|
||||
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, true);
|
||||
if (lics.Count() > 0)
|
||||
res = lics[0].getCustomerAddr();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public string getCustomerWww()
|
||||
{
|
||||
string res = null;
|
||||
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, true);
|
||||
if (lics.Count() > 0)
|
||||
res = lics[0].getCustomerWww();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public string getCustomerMail()
|
||||
{
|
||||
string res = null;
|
||||
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, true);
|
||||
if (lics.Count() > 0)
|
||||
res = lics[0].getCustomerMail();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public string getCustomerInfo()
|
||||
{
|
||||
string res = null;
|
||||
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, false);
|
||||
if (lics.Count() > 0)
|
||||
res = lics[0].getCustomerInfo();
|
||||
else
|
||||
res = "License has expired";
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public string getCustomerLogo()
|
||||
{
|
||||
string res = null;
|
||||
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, true);
|
||||
if (lics.Count() > 0)
|
||||
res = lics[0].getCustomerLogo();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public bool isLicenseFound()
|
||||
{
|
||||
return _found;
|
||||
}
|
||||
public bool isLicenseCorrect()
|
||||
{
|
||||
return _correct;
|
||||
}
|
||||
public int getUserQuota()
|
||||
{
|
||||
int res = 0;
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, true);
|
||||
foreach (ActiveConnectionsLicenseReaderSingle lic in lics)
|
||||
{
|
||||
res += lic.getUserQuota();
|
||||
}
|
||||
if (0 == res)
|
||||
res = 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
public uint getPermissions()
|
||||
{
|
||||
uint res = EditorPermissions.PERMISSION_NONE;
|
||||
|
||||
ActiveConnectionsLicenseReaderSingle[] lics = getLicensesByTime(DateTime.Now, true);
|
||||
if (lics.Count() > 0)
|
||||
res = lics[0].getPermissions();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
protected string _id;
|
||||
protected DateTime _startDate;
|
||||
protected DateTime _endDate;
|
||||
|
||||
protected string _customer;
|
||||
protected string _customer_addr;
|
||||
protected string _customer_www;
|
||||
protected string _customer_mail;
|
||||
protected string _customer_info;
|
||||
protected string _customer_logo;
|
||||
|
||||
protected DateTime _endDateThreshold;
|
||||
protected bool _correct;
|
||||
protected bool _found;
|
||||
protected int _quota;
|
||||
|
||||
protected ActiveConnectionsLicenseReaderSingle[] getLicensesByTime (DateTime time, bool useTreshold)
|
||||
{
|
||||
List<ActiveConnectionsLicenseReaderSingle> array = new List<ActiveConnectionsLicenseReaderSingle>();
|
||||
foreach (ActiveConnectionsLicenseReaderSingle item in m_licnenses)
|
||||
{
|
||||
DateTime startTime = item.getStartDate();
|
||||
DateTime endTime = item.getEndDate();
|
||||
DateTime endTimeTreshold = item.getEndDateThreshold();
|
||||
if ((startTime <= time)
|
||||
&& (useTreshold ? (time <= endTimeTreshold) : (time <= endTime)))
|
||||
{
|
||||
array.Add(item);
|
||||
}
|
||||
}
|
||||
return array.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class UserCountLicenseReader : ActiveConnectionsLicenseReader
|
||||
{
|
||||
protected override ActiveConnectionsLicenseReaderSingle createSingleFileReader(string licFileName)
|
||||
{
|
||||
return new UserCountLicenseReaderSingle(licFileName);
|
||||
}
|
||||
|
||||
public UserCountLicenseReader(string ciphiredXmlPath)
|
||||
: base(ciphiredXmlPath)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class UserCount2LicenseReader : ActiveConnectionsLicenseReader
|
||||
{
|
||||
protected override ActiveConnectionsLicenseReaderSingle createSingleFileReader(string licFileName)
|
||||
{
|
||||
return new UserCount2LicenseReaderSingle(licFileName);
|
||||
}
|
||||
|
||||
public UserCount2LicenseReader(string ciphiredXmlPath)
|
||||
: base(ciphiredXmlPath)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -40,629 +40,5 @@ using System.Xml;
|
|||
|
||||
namespace FileConverterUtils2
|
||||
{
|
||||
#if !OPEN_SOURCE
|
||||
|
||||
public class LicenseReaderException: Exception
|
||||
{
|
||||
}
|
||||
public class LicenseReaderNotFoundException : LicenseReaderException
|
||||
{
|
||||
}
|
||||
public class LicenseReaderFormatException : LicenseReaderException
|
||||
{
|
||||
}
|
||||
public class LicenseReaderSigantureException : LicenseReaderException
|
||||
{
|
||||
}
|
||||
public static class LicenseReader
|
||||
{
|
||||
|
||||
private static string _copyright = "Copyright TeamLab.com. All Rights Reserved.";
|
||||
|
||||
private static byte[] _public = { 127, 61, 35, 56, 57, 12, 30, 62, 21, 76, 33, 0, 95, 81, 1, 14, 6, 91,
|
||||
15, 26, 30, 16, 22, 0, 32, 36, 115, 21, 12, 2, 42, 17, 67, 111, 96,
|
||||
38, 33, 81, 55, 30, 80, 33, 97, 21, 27, 51, 52, 0, 15, 82, 45, 69,
|
||||
18, 61, 33, 7, 35, 59, 21, 90, 120, 53, 58, 3, 79, 119, 8, 92, 37,
|
||||
74, 59, 3, 6, 60, 26, 39, 101, 4, 87, 35, 2, 25, 89, 14, 16, 105,
|
||||
20, 40, 7, 54, 56, 95, 30, 1, 58, 22, 28, 36, 82, 2, 37, 48, 19,
|
||||
95, 42, 12, 7, 97, 82, 0, 39, 67, 98, 28, 48, 3, 49, 63, 57, 72,
|
||||
49, 43, 58, 4, 22, 49, 22, 55, 94, 50, 11, 25, 48, 27, 81, 37, 95,
|
||||
53, 65, 24, 15, 11, 94, 35, 21, 42, 95, 41, 88, 40, 89, 25, 53, 95,
|
||||
92, 72, 125, 29, 95, 37, 16, 70, 89, 0, 21, 20, 40, 54, 1, 28, 53,
|
||||
120, 13, 0, 56, 55, 33, 94, 41, 1, 91, 116, 109, 84, 88, 59, 40, 24,
|
||||
40, 84, 55, 87, 6, 107, 23, 36, 41, 30, 70, 27, 15, 35, 61, 2, 70,
|
||||
15, 23, 44, 26, 81, 39, 64, 52, 79, 69, 39, 68, 20, 12, 65, 26, 86,
|
||||
24, 76, 25, 2, 63, 52, 30, 24, 37, 87, 108, 50, 46, 27, 102, 89, 114,
|
||||
4, 67, 25, 32, 45, 10, 7, 50, 48, 87, 121, 22, 6, 35, 40, 17, 80, 85,
|
||||
124, 15, 2, 30, 20, 20, 30, 52, 42, 68, 22, 50, 35, 13, 10, 36, 20,
|
||||
50, 66, 12, 33, 88, 28, 108, 44, 24, 62, 19, 101, 14, 85, 33, 53, 52,
|
||||
73, 37, 85, 49, 43, 68, 32, 14, 81, 94, 38, 41, 68, 8, 16, 16, 43,
|
||||
30, 48, 73, 54, 23, 8, 10, 32, 18, 47, 1, 41, 41, 1, 76, 16, 121,
|
||||
57, 58, 16, 7, 80, 51, 56, 5, 30, 21, 63, 13, 50, 60, 65, 33, 32,
|
||||
38, 107, 14, 8, 5, 15, 56, 70, 37, 45, 63, 82, 53, 4, 2, 33, 45,
|
||||
37, 13, 1, 91, 62, 80, 19, 28, 110, 33, 3, 68, 39, 5, 18, 27, 74,
|
||||
79, 101, 42, 21, 28, 11, 23, 24, 17, 90, 111, 18, 46, 50, 69, 93,
|
||||
44, 31, 24, 27, 78, 49, 11, 21, 83, 112, 78, 48, 125, 34, 36, 8,
|
||||
87, 118, 32, 0, 25, 69, 108 };
|
||||
|
||||
public static XmlDocument Read (string path)
|
||||
{
|
||||
|
||||
byte[] ciphiredXml = File.ReadAllBytes(path);
|
||||
|
||||
return ParseLicenseXml (ciphiredXml);
|
||||
}
|
||||
private static XmlDocument ParseLicenseXml(byte[] ciphiredXml)
|
||||
{
|
||||
XmlDocument xmlDoc = null;
|
||||
|
||||
if (null == ciphiredXml)
|
||||
throw new ArgumentNullException("ciphiredXml is null");
|
||||
|
||||
string signaturedXml = LicenseUtils.symmetricDecrypt(ciphiredXml, _public);
|
||||
|
||||
string publicKey = makePublicKey(_public, _copyright);
|
||||
|
||||
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider();
|
||||
rsaKey.PersistKeyInCsp = false;
|
||||
|
||||
rsaKey.FromXmlString(publicKey);
|
||||
|
||||
xmlDoc = new XmlDocument();
|
||||
|
||||
xmlDoc.PreserveWhitespace = true;
|
||||
|
||||
xmlDoc.LoadXml(signaturedXml);
|
||||
|
||||
bool res = LicenseUtils.VerifyXml(xmlDoc, rsaKey);
|
||||
|
||||
rsaKey.Clear();
|
||||
rsaKey = null;
|
||||
|
||||
if (!res)
|
||||
{
|
||||
throw new LicenseReaderSigantureException();
|
||||
}
|
||||
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
private static string makePublicKey(byte[] unread, string copyright)
|
||||
{
|
||||
|
||||
int copyrightLength = _copyright.Length;
|
||||
int unreadLength = unread.Length;
|
||||
int index_unread = 0;
|
||||
int index_copyright = 0;
|
||||
|
||||
string result = "";
|
||||
while (index_unread < unreadLength)
|
||||
{
|
||||
int byteCopyright = (int)(Convert.ToByte(_copyright[index_copyright]));
|
||||
int byteUnread = (int)unread[index_unread];
|
||||
int resultByte = byteUnread ^ byteCopyright;
|
||||
|
||||
result += (char)(resultByte & 0x00FF);
|
||||
|
||||
++index_unread;
|
||||
++index_copyright;
|
||||
|
||||
if (index_copyright >= copyrightLength)
|
||||
index_copyright = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EditorPermissions
|
||||
{
|
||||
public const uint PERMISSION_NONE = 0;
|
||||
public const uint PERMISSION_WRITER = 1;
|
||||
public const uint PERMISSION_SPREADSHEET = 2;
|
||||
public const uint PERMISSION_PRESENTATION = 4;
|
||||
public const uint PERMISSION_ALL = PERMISSION_WRITER | PERMISSION_SPREADSHEET | PERMISSION_PRESENTATION;
|
||||
}
|
||||
public interface ILicenseReader
|
||||
{
|
||||
ErrorTypes GetAccessByInfo();
|
||||
|
||||
DateTime getStartDate();
|
||||
DateTime getEndDate();
|
||||
DateTime getEndDateThreshold();
|
||||
|
||||
string getId();
|
||||
string getCustomer();
|
||||
string getCustomerAddr();
|
||||
string getCustomerWww();
|
||||
string getCustomerMail();
|
||||
string getCustomerInfo();
|
||||
string getCustomerLogo();
|
||||
|
||||
uint getPermissions();
|
||||
|
||||
bool isLicenseFound();
|
||||
bool isLicenseCorrect();
|
||||
}
|
||||
|
||||
public class AllRightsLicenseReader : ILicenseReader
|
||||
{
|
||||
public ErrorTypes GetAccessByInfo()
|
||||
{
|
||||
return ErrorTypes.NoError;
|
||||
}
|
||||
|
||||
#region Standard license fields getters
|
||||
public DateTime getStartDate()
|
||||
{
|
||||
return DateTime.Now;
|
||||
}
|
||||
public DateTime getEndDate()
|
||||
{
|
||||
return DateTime.Now.AddDays(10.0);
|
||||
}
|
||||
public DateTime getEndDateThreshold()
|
||||
{
|
||||
return DateTime.Now.AddDays(20.0);
|
||||
}
|
||||
|
||||
public string getId()
|
||||
{
|
||||
return "fake";
|
||||
}
|
||||
public string getCustomer()
|
||||
{
|
||||
return "fake_customer";
|
||||
}
|
||||
public string getCustomerAddr()
|
||||
{
|
||||
return "fake_addr";
|
||||
}
|
||||
public string getCustomerWww()
|
||||
{
|
||||
return "fake_www";
|
||||
}
|
||||
public string getCustomerMail()
|
||||
{
|
||||
return "fake_mail";
|
||||
}
|
||||
public string getCustomerInfo()
|
||||
{
|
||||
return "fake_info";
|
||||
}
|
||||
public string getCustomerLogo()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
#endregion
|
||||
public bool isLicenseFound()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool isLicenseCorrect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public uint getPermissions()
|
||||
{
|
||||
return EditorPermissions.PERMISSION_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class LicenseReaderBase: ILicenseReader
|
||||
{
|
||||
protected string _id;
|
||||
|
||||
protected string _license_type;
|
||||
protected string _ciphiredXmlPath;
|
||||
|
||||
protected DateTime _startDate;
|
||||
protected DateTime _endDate;
|
||||
|
||||
protected string _customer;
|
||||
protected string _customer_addr;
|
||||
protected string _customer_www;
|
||||
protected string _customer_mail;
|
||||
protected string _customer_info;
|
||||
protected string _customer_logo;
|
||||
|
||||
protected DateTime _endDateThreshold;
|
||||
protected bool _correct;
|
||||
protected bool _found;
|
||||
|
||||
protected uint _permissions = EditorPermissions.PERMISSION_NONE;
|
||||
|
||||
public LicenseReaderBase(string ciphiredXmlPath)
|
||||
{
|
||||
|
||||
_startDate = DateTime.Now;
|
||||
_endDate = _startDate.AddDays(10.0);
|
||||
_endDateThreshold = _endDate.AddDays(1.0);
|
||||
|
||||
_found = false;
|
||||
_correct = false;
|
||||
|
||||
try
|
||||
{
|
||||
_ciphiredXmlPath = ciphiredXmlPath;
|
||||
XmlDocument xmlDoc = LicenseReader.Read (ciphiredXmlPath);
|
||||
|
||||
_found = true;
|
||||
|
||||
bool res = FillMembersBase(xmlDoc);
|
||||
if (!res)
|
||||
{
|
||||
throw new LicenseReaderFormatException();
|
||||
}
|
||||
|
||||
_correct = true;
|
||||
}
|
||||
catch (LicenseReaderSigantureException ex)
|
||||
{
|
||||
_correct = false;
|
||||
}
|
||||
catch (LicenseReaderNotFoundException ex)
|
||||
{
|
||||
_found = false;
|
||||
}
|
||||
catch (LicenseReaderFormatException ex)
|
||||
{
|
||||
_correct = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_found = false;
|
||||
_correct = false;
|
||||
}
|
||||
}
|
||||
|
||||
public ErrorTypes GetAccessByInfo()
|
||||
{
|
||||
return ErrorTypes.NoError;
|
||||
}
|
||||
|
||||
#region Standard license fields getters
|
||||
public DateTime getStartDate()
|
||||
{
|
||||
return _startDate;
|
||||
}
|
||||
public DateTime getEndDate()
|
||||
{
|
||||
return _endDate;
|
||||
}
|
||||
public DateTime getEndDateThreshold()
|
||||
{
|
||||
return _endDateThreshold;
|
||||
}
|
||||
public string getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
public string getCustomer()
|
||||
{
|
||||
return _customer;
|
||||
}
|
||||
public string getCustomerAddr()
|
||||
{
|
||||
return _customer_addr;
|
||||
}
|
||||
public string getCustomerWww()
|
||||
{
|
||||
return _customer_www;
|
||||
}
|
||||
public string getCustomerMail()
|
||||
{
|
||||
return _customer_mail;
|
||||
}
|
||||
public string getCustomerInfo()
|
||||
{
|
||||
return _customer_info;
|
||||
}
|
||||
public string getCustomerLogo()
|
||||
{
|
||||
return _customer_logo;
|
||||
}
|
||||
#endregion
|
||||
public bool isLicenseFound()
|
||||
{
|
||||
return _found;
|
||||
}
|
||||
public bool isLicenseCorrect()
|
||||
{
|
||||
return _correct;
|
||||
}
|
||||
public uint getPermissions()
|
||||
{
|
||||
return _permissions;
|
||||
}
|
||||
|
||||
private bool FillMembersBase(XmlDocument xmlDoc)
|
||||
{
|
||||
bool res = false;
|
||||
try
|
||||
{
|
||||
|
||||
XmlNodeList list = xmlDoc.GetElementsByTagName("teamlaboffice").Item(0).ChildNodes;
|
||||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||
foreach (XmlNode node in list)
|
||||
{
|
||||
if (node.NodeType == XmlNodeType.Element && node.HasChildNodes)
|
||||
{
|
||||
dict.Add(node.Name, node.FirstChild.Value);
|
||||
}
|
||||
}
|
||||
|
||||
string license_type;
|
||||
string startDate;
|
||||
string endDate;
|
||||
string endDateThreshold;
|
||||
string id;
|
||||
string customer;
|
||||
string customer_addr;
|
||||
string customer_www;
|
||||
string customer_mail;
|
||||
string customer_info;
|
||||
string customer_logo;
|
||||
string permissions;
|
||||
|
||||
if (!dict.TryGetValue("startdate", out startDate))
|
||||
startDate = null;
|
||||
if (!dict.TryGetValue("enddate", out endDate))
|
||||
endDate = null;
|
||||
if (!dict.TryGetValue("enddatethreshold", out endDateThreshold))
|
||||
endDateThreshold = null;
|
||||
if (!dict.TryGetValue("id", out id))
|
||||
id = null;
|
||||
if (!dict.TryGetValue("customer", out customer))
|
||||
customer = "";
|
||||
if (!dict.TryGetValue("customer_addr", out customer_addr))
|
||||
customer_addr = "";
|
||||
if (!dict.TryGetValue("customer_www", out customer_www))
|
||||
customer_www = "";
|
||||
if (!dict.TryGetValue("customer_mail", out customer_mail))
|
||||
customer_mail = "";
|
||||
if (!dict.TryGetValue("customer_info", out customer_info))
|
||||
customer_info = "";
|
||||
if (!dict.TryGetValue("customer_logo", out customer_logo))
|
||||
customer_logo = "";
|
||||
if (!dict.TryGetValue("lictype", out license_type))
|
||||
license_type = "";
|
||||
|
||||
if (!dict.TryGetValue("permissions", out permissions))
|
||||
{
|
||||
_permissions = EditorPermissions.PERMISSION_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
string perm_lo = permissions.ToLower();
|
||||
_permissions |= perm_lo.Contains("w") ? EditorPermissions.PERMISSION_WRITER : EditorPermissions.PERMISSION_NONE;
|
||||
_permissions |= perm_lo.Contains("e") ? EditorPermissions.PERMISSION_SPREADSHEET : EditorPermissions.PERMISSION_NONE;
|
||||
_permissions |= perm_lo.Contains("p") ? EditorPermissions.PERMISSION_PRESENTATION : EditorPermissions.PERMISSION_NONE;
|
||||
}
|
||||
|
||||
if (null == startDate
|
||||
|| null == endDate
|
||||
|| null == id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._startDate = DateTime.Parse(startDate);
|
||||
this._endDate = DateTime.Parse(endDate);
|
||||
if (null == endDateThreshold || endDateThreshold == "")
|
||||
this._endDateThreshold = _endDate.AddMonths(1);
|
||||
else
|
||||
this._endDateThreshold = DateTime.Parse(endDateThreshold);
|
||||
this._id = id;
|
||||
this._customer = customer;
|
||||
this._customer_addr = customer_addr;
|
||||
this._customer_www = customer_www;
|
||||
this._customer_mail = customer_mail;
|
||||
this._customer_info = customer_info;
|
||||
this._customer_logo = customer_logo;
|
||||
this._license_type = license_type;
|
||||
|
||||
res = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
return res & FillMembers(xmlDoc);
|
||||
}
|
||||
|
||||
protected abstract bool FillMembers(XmlDocument xmlDoc);
|
||||
}
|
||||
|
||||
public class LicenseReaderSimple : LicenseReaderBase
|
||||
{
|
||||
|
||||
protected LicenseReaderSimple(string ciphiredXmlPath)
|
||||
: base(ciphiredXmlPath)
|
||||
{
|
||||
}
|
||||
protected override bool FillMembers(XmlDocument xmlDoc)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static ILicenseReader GetLicenseReaderObject(string ciphiredXmlPath, LicenseInfo.LicenseType licenseType)
|
||||
{
|
||||
ILicenseReader result = null;
|
||||
|
||||
switch (licenseType)
|
||||
{
|
||||
|
||||
case LicenseInfo.LicenseType.ByUserCount:
|
||||
result = new UserCountLicenseReader (ciphiredXmlPath);
|
||||
break;
|
||||
|
||||
case LicenseInfo.LicenseType.ByDocumentSessions:
|
||||
result = new DocumentSessionLicenseReader(ciphiredXmlPath);
|
||||
break;
|
||||
|
||||
case LicenseInfo.LicenseType.ByUserCount2:
|
||||
result = new UserCount2LicenseReader(ciphiredXmlPath);
|
||||
break;
|
||||
|
||||
case LicenseInfo.LicenseType.ByActiveConnections:
|
||||
result = new ActiveConnectionsLicenseReader(ciphiredXmlPath);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
||||
LicenseReaderSimple simple = new LicenseReaderSimple(ciphiredXmlPath);
|
||||
|
||||
if (null != simple && simple.isLicenseFound() && simple.isLicenseCorrect())
|
||||
{
|
||||
if (simple._license_type == "ActiveConnections")
|
||||
result = new ActiveConnectionsLicenseReader(ciphiredXmlPath);
|
||||
else if (simple._license_type == "UserCount")
|
||||
result = new UserCountLicenseReader(ciphiredXmlPath);
|
||||
else if (simple._license_type == "UserCount2")
|
||||
result = new UserCount2LicenseReader(ciphiredXmlPath);
|
||||
else if (simple._license_type == "DocumentSessions")
|
||||
result = new DocumentSessionLicenseReader(ciphiredXmlPath);
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class ActiveConnectionsLicenseReaderSingle : LicenseReaderBase
|
||||
{
|
||||
|
||||
protected int _quota;
|
||||
|
||||
public int getUserQuota()
|
||||
{
|
||||
return _quota;
|
||||
}
|
||||
|
||||
public ActiveConnectionsLicenseReaderSingle(string ciphiredXmlPath)
|
||||
: base(ciphiredXmlPath)
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool FillMembers(XmlDocument xmlDoc)
|
||||
{
|
||||
bool res = false;
|
||||
try
|
||||
{
|
||||
|
||||
XmlNodeList list = xmlDoc.GetElementsByTagName("teamlaboffice").Item(0).ChildNodes;
|
||||
Dictionary <string, string> dict = new Dictionary<string,string> ();
|
||||
foreach (XmlNode node in list)
|
||||
{
|
||||
if (node.NodeType == XmlNodeType.Element && node.HasChildNodes)
|
||||
{
|
||||
dict.Add(node.Name, node.FirstChild.Value);
|
||||
}
|
||||
}
|
||||
|
||||
string connectionQuota = dict["connectionquota"];
|
||||
string licType = dict["lictype"];
|
||||
|
||||
if (null == connectionQuota
|
||||
|| null == licType
|
||||
|| licType != getLicenseTypeName())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this._quota = int.Parse (connectionQuota);
|
||||
res = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
protected virtual string getLicenseTypeName()
|
||||
{
|
||||
return "ActiveConnections";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class UserCountLicenseReaderSingle : ActiveConnectionsLicenseReaderSingle
|
||||
{
|
||||
protected override string getLicenseTypeName()
|
||||
{
|
||||
return "UserCount";
|
||||
}
|
||||
public UserCountLicenseReaderSingle(string ciphiredXmlPath)
|
||||
: base(ciphiredXmlPath)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class UserCount2LicenseReaderSingle : ActiveConnectionsLicenseReaderSingle
|
||||
{
|
||||
protected override string getLicenseTypeName()
|
||||
{
|
||||
return "UserCount2";
|
||||
}
|
||||
public UserCount2LicenseReaderSingle(string ciphiredXmlPath)
|
||||
: base(ciphiredXmlPath)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class DocumentSessionLicenseReader : LicenseReaderBase
|
||||
{
|
||||
protected string _trackingUrl = "";
|
||||
|
||||
public string GetTrackingUrl()
|
||||
{
|
||||
return _trackingUrl;
|
||||
}
|
||||
|
||||
public DocumentSessionLicenseReader (string ciphiredXmlPath)
|
||||
: base(ciphiredXmlPath)
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool FillMembers(XmlDocument xmlDoc)
|
||||
{
|
||||
bool res = false;
|
||||
try
|
||||
{
|
||||
|
||||
XmlNodeList list = xmlDoc.GetElementsByTagName("teamlaboffice").Item(0).ChildNodes;
|
||||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||
foreach (XmlNode node in list)
|
||||
{
|
||||
if (node.NodeType == XmlNodeType.Element && node.HasChildNodes)
|
||||
{
|
||||
dict.Add(node.Name, node.FirstChild.Value);
|
||||
}
|
||||
}
|
||||
|
||||
string trackingUrl = dict["trackingurl"];
|
||||
string licType = dict["lictype"];
|
||||
|
||||
if (null == trackingUrl
|
||||
|| null == licType
|
||||
|| licType != "DocumentSessions")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._trackingUrl = trackingUrl;
|
||||
|
||||
res = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return res;
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -43,91 +43,7 @@ namespace FileConverterUtils2
|
|||
|
||||
public class LicenseUtils
|
||||
{
|
||||
#if !OPEN_SOURCE
|
||||
|
||||
public static Boolean VerifyXml(XmlDocument Doc, RSA Key)
|
||||
{
|
||||
|
||||
if (Doc == null)
|
||||
throw new ArgumentException("Doc");
|
||||
if (Key == null)
|
||||
throw new ArgumentException("Key");
|
||||
|
||||
SignedXml signedXml = new SignedXml(Doc);
|
||||
|
||||
XmlNodeList nodeList = Doc.GetElementsByTagName("Signature");
|
||||
|
||||
if (nodeList.Count <= 0)
|
||||
{
|
||||
throw new CryptographicException("Verification failed: No Signature was found in the document.");
|
||||
}
|
||||
|
||||
if (nodeList.Count >= 2)
|
||||
{
|
||||
throw new CryptographicException("Verification failed: More that one signature was found for the document.");
|
||||
}
|
||||
|
||||
signedXml.LoadXml((XmlElement)nodeList[0]);
|
||||
|
||||
return signedXml.CheckSignature(Key);
|
||||
}
|
||||
|
||||
public static string symmetricDecrypt(byte[] content, byte[] keyAndIv)
|
||||
{
|
||||
RijndaelManaged RMCrypto = new RijndaelManaged();
|
||||
KeySizes[] keySizes = RMCrypto.LegalKeySizes;
|
||||
|
||||
if (keySizes.Length == 0)
|
||||
throw new InvalidOperationException("No Rijndael key sizes");
|
||||
|
||||
int keySize = (keySizes[0].MaxSize / 8);
|
||||
int blockSize = (RMCrypto.BlockSize / 8);
|
||||
|
||||
byte[] Key = new byte[keySize];
|
||||
byte[] IV = new byte[blockSize];
|
||||
|
||||
for (int i = 0; i < keySize; ++i)
|
||||
{
|
||||
Key[i] = (byte)i;
|
||||
}
|
||||
for (int i = 0; i < blockSize; ++i)
|
||||
{
|
||||
IV[i] = (byte)i;
|
||||
}
|
||||
|
||||
if (keyAndIv.Length >= keySize)
|
||||
{
|
||||
Array.Copy(keyAndIv, Key, keySize);
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(keyAndIv, Key, keyAndIv.Length);
|
||||
}
|
||||
|
||||
if (keyAndIv.Length >= blockSize)
|
||||
{
|
||||
Array.Copy(keyAndIv, IV, blockSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(keyAndIv, IV, keyAndIv.Length);
|
||||
}
|
||||
|
||||
MemoryStream stream = new MemoryStream(content);
|
||||
CryptoStream cryptStream = new CryptoStream(stream
|
||||
, RMCrypto.CreateDecryptor(Key, IV)
|
||||
, CryptoStreamMode.Read);
|
||||
|
||||
StreamReader sReader = new StreamReader (cryptStream);
|
||||
string res = sReader.ReadToEnd();
|
||||
|
||||
sReader.Close();
|
||||
cryptStream.Close();
|
||||
stream.Close();
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,477 +37,5 @@ using System.Configuration;
|
|||
|
||||
namespace FileConverterUtils2
|
||||
{
|
||||
#if !OPEN_SOURCE
|
||||
public interface ITrackingInfo
|
||||
{
|
||||
void setLicense (ILicenseReader lic);
|
||||
void track(string clientId, string docId, int isAlive);
|
||||
void getUserCount(out int active, out int inactive);
|
||||
ILicenseReader getLicense();
|
||||
bool isQuotaExceed(string userId, string docId);
|
||||
void Cleanup();
|
||||
bool isLicenseFileValid();
|
||||
bool isLicenseDateValid();
|
||||
bool isLicenseDateTresholdExpired();
|
||||
bool isLicenseEndDateGreater(DateTime time);
|
||||
}
|
||||
|
||||
public class TrackingInfo: ITrackingInfo
|
||||
{
|
||||
|
||||
public static double sdCleanupExpiredMinutes = 2.0;
|
||||
|
||||
private DateTime oLastCleanupTime = DateTime.Now;
|
||||
public class TrackingValue
|
||||
{
|
||||
public int inactiveTicks;
|
||||
public DateTime lastTrackingTime;
|
||||
}
|
||||
public class TrackingDictionary
|
||||
{
|
||||
Dictionary<string, TrackingValue> dict;
|
||||
Object sync;
|
||||
|
||||
public TrackingDictionary ()
|
||||
{
|
||||
dict = new Dictionary<string, TrackingValue> ();
|
||||
sync = new Object ();
|
||||
|
||||
try
|
||||
{
|
||||
int periods = int.Parse (ConfigurationManager.AppSettings["license.activeconnections.tracking.cleanupperiods"] ?? "2");
|
||||
int tracking_time = int.Parse(ConfigurationManager.AppSettings["license.activeconnections.tracking.interval"] ?? "300");
|
||||
sdCleanupExpiredMinutes = ((double) (periods * tracking_time)) / 60.0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
sdCleanupExpiredMinutes = 5.0;
|
||||
}
|
||||
}
|
||||
public void Add (string key, TrackingValue value)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
dict.Add (key, value);
|
||||
}
|
||||
}
|
||||
public void Remove (string key)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
dict.Remove (key);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveOldItems (DateTime lastTime)
|
||||
{
|
||||
Dictionary<string, TrackingValue> toSave = new Dictionary<string, TrackingValue>();
|
||||
|
||||
lock (sync)
|
||||
{
|
||||
for (int i = 0; i < dict.Count; ++i)
|
||||
{
|
||||
KeyValuePair<string, TrackingValue> element;
|
||||
|
||||
element = dict.ElementAt(i);
|
||||
if (element.Value.lastTrackingTime > lastTime)
|
||||
toSave.Add (element.Key, element.Value);
|
||||
|
||||
}
|
||||
if (toSave.Count != dict.Count)
|
||||
dict = toSave;
|
||||
}
|
||||
}
|
||||
public bool TryGetValue (string key, out TrackingValue value)
|
||||
{
|
||||
bool bRes = false;
|
||||
lock (sync)
|
||||
{
|
||||
bRes = dict.TryGetValue (key, out value);
|
||||
}
|
||||
return bRes;
|
||||
}
|
||||
|
||||
public int GetCount()
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
return dict.Count;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TrackingDictionary activeUsers;
|
||||
private TrackingDictionary inactiveUsers;
|
||||
|
||||
private ILicenseReader license;
|
||||
|
||||
public TrackingInfo()
|
||||
{
|
||||
activeUsers = new TrackingDictionary();
|
||||
inactiveUsers = new TrackingDictionary();
|
||||
}
|
||||
public void setLicense(ILicenseReader lic)
|
||||
{
|
||||
this.license = lic;
|
||||
}
|
||||
public ILicenseReader getLicense()
|
||||
{
|
||||
return license;
|
||||
}
|
||||
|
||||
public void getUserCount(out int active, out int inactive)
|
||||
{
|
||||
active = activeUsers.GetCount();
|
||||
inactive = inactiveUsers.GetCount();
|
||||
}
|
||||
public virtual void track(string clientId, string docId, int isAlive)
|
||||
{
|
||||
|
||||
if (null == clientId)
|
||||
clientId = "";
|
||||
|
||||
if (null == docId)
|
||||
docId = "";
|
||||
|
||||
TrackingValue value;
|
||||
string key = clientId + docId;
|
||||
if (key == "")
|
||||
key = "empty";
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
if (0 == isAlive)
|
||||
{
|
||||
|
||||
if (inactiveUsers.TryGetValue(key, out value))
|
||||
{
|
||||
|
||||
value.lastTrackingTime = now;
|
||||
value.inactiveTicks++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (activeUsers.TryGetValue(key, out value))
|
||||
{
|
||||
|
||||
activeUsers.Remove(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
value = new TrackingValue();
|
||||
}
|
||||
|
||||
value.inactiveTicks = 1;
|
||||
value.lastTrackingTime = now;
|
||||
inactiveUsers.Add(key, value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (activeUsers.TryGetValue(key, out value))
|
||||
{
|
||||
|
||||
value.lastTrackingTime = now;
|
||||
value.inactiveTicks = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (inactiveUsers.TryGetValue(key, out value))
|
||||
{
|
||||
|
||||
inactiveUsers.Remove(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
value = new TrackingValue();
|
||||
}
|
||||
value.inactiveTicks = 0;
|
||||
value.lastTrackingTime = now;
|
||||
|
||||
activeUsers.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (now.AddDays(1.0) > oLastCleanupTime)
|
||||
{
|
||||
Cleanup();
|
||||
oLastCleanupTime = now;
|
||||
}
|
||||
|
||||
}
|
||||
public bool isQuotaExceed (string userId, string docId)
|
||||
{
|
||||
if (null == userId)
|
||||
userId = "";
|
||||
|
||||
if (null == docId)
|
||||
docId = "";
|
||||
|
||||
if (null == license)
|
||||
return false;
|
||||
|
||||
int count = activeUsers.GetCount();
|
||||
|
||||
if (count < ((ActiveConnectionsLicenseReader)license).getUserQuota())
|
||||
return false;
|
||||
|
||||
string key = userId + docId;
|
||||
if (key == "")
|
||||
key = "empty";
|
||||
|
||||
TrackingValue value;
|
||||
|
||||
if (activeUsers.TryGetValue(key, out value))
|
||||
return false;
|
||||
|
||||
if (inactiveUsers.TryGetValue(key, out value))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
public bool isLicenseFileValid()
|
||||
{
|
||||
return (null != license
|
||||
&& license.isLicenseFound()
|
||||
&& license.isLicenseCorrect());
|
||||
}
|
||||
public bool isLicenseDateValid()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
DateTime start = license.getStartDate();
|
||||
DateTime end = license.getEndDate();
|
||||
if (start < now && end > now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public bool isLicenseEndDateGreater (DateTime time)
|
||||
{
|
||||
DateTime end = license.getEndDate();
|
||||
return (end > time);
|
||||
}
|
||||
public bool isLicenseDateTresholdExpired()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
DateTime treshold = license.getEndDateThreshold();
|
||||
|
||||
return now > treshold;
|
||||
}
|
||||
public void Cleanup()
|
||||
{
|
||||
int active_count = activeUsers.GetCount();
|
||||
int inactive_count = inactiveUsers.GetCount();
|
||||
int quota = (null == license) ? 2048 : ((ActiveConnectionsLicenseReader)license).getUserQuota();
|
||||
|
||||
if (active_count >= (quota - 1))
|
||||
{
|
||||
|
||||
CleanupTrackingDictionary(activeUsers, sdCleanupExpiredMinutes);
|
||||
}
|
||||
if (inactive_count >= quota)
|
||||
{
|
||||
|
||||
CleanupTrackingDictionary(inactiveUsers, sdCleanupExpiredMinutes);
|
||||
}
|
||||
}
|
||||
private void CleanupTrackingDictionary(TrackingDictionary dict, double minutes)
|
||||
{
|
||||
dict.RemoveOldItems (DateTime.Now.AddMinutes (-1.0 * minutes));
|
||||
}
|
||||
|
||||
}
|
||||
public class UserCount2TrackingInfo : ITrackingInfo
|
||||
{
|
||||
public class UserTrackingDictionary
|
||||
{
|
||||
Dictionary<string, DateTime> dict;
|
||||
Object sync;
|
||||
DateTime lastCleanupTime;
|
||||
|
||||
public UserTrackingDictionary()
|
||||
{
|
||||
dict = new Dictionary<string, DateTime>();
|
||||
sync = new Object();
|
||||
|
||||
lastCleanupTime = DateTime.Now.Date;
|
||||
|
||||
}
|
||||
public void Add(string key, DateTime value)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
dict.Add(key, value);
|
||||
}
|
||||
}
|
||||
public void Remove(string key)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
dict.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveItems ()
|
||||
{
|
||||
DateTime currentTime = DateTime.Now;
|
||||
TimeSpan timeDelta = currentTime - lastCleanupTime;
|
||||
double hoursDelta = timeDelta.TotalHours;
|
||||
|
||||
if (hoursDelta < 24.0)
|
||||
return;
|
||||
|
||||
lock (sync)
|
||||
{
|
||||
dict.Clear();
|
||||
}
|
||||
|
||||
lastCleanupTime = currentTime.Date;
|
||||
}
|
||||
public bool TryGetValue(string key, out DateTime value)
|
||||
{
|
||||
bool bRes = false;
|
||||
lock (sync)
|
||||
{
|
||||
bRes = dict.TryGetValue(key, out value);
|
||||
}
|
||||
return bRes;
|
||||
}
|
||||
|
||||
public int GetCount()
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
return dict.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ILicenseReader license;
|
||||
private UserTrackingDictionary activeUsers;
|
||||
|
||||
public UserCount2TrackingInfo()
|
||||
{
|
||||
activeUsers = new UserTrackingDictionary();
|
||||
}
|
||||
|
||||
public void setLicense(ILicenseReader lic)
|
||||
{
|
||||
this.license = lic;
|
||||
}
|
||||
public void track(string clientId, string docId, int isAlive)
|
||||
{
|
||||
|
||||
if (null == clientId)
|
||||
clientId = "";
|
||||
|
||||
if (null == docId)
|
||||
docId = "";
|
||||
|
||||
DateTime value;
|
||||
string key = clientId + docId;
|
||||
if (key == "")
|
||||
key = "empty";
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
{
|
||||
|
||||
if (activeUsers.TryGetValue(key, out value))
|
||||
{
|
||||
value = now;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
activeUsers.Add(key, now);
|
||||
}
|
||||
}
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
public void getUserCount(out int active, out int inactive)
|
||||
{
|
||||
active = activeUsers.GetCount();
|
||||
inactive = 0;
|
||||
}
|
||||
public ILicenseReader getLicense()
|
||||
{
|
||||
return license;
|
||||
}
|
||||
public bool isQuotaExceed(string userId, string docId)
|
||||
{
|
||||
if (null == userId)
|
||||
userId = "";
|
||||
|
||||
docId = "";
|
||||
|
||||
if (null == license)
|
||||
return false;
|
||||
|
||||
int count = activeUsers.GetCount();
|
||||
|
||||
if (count < ((ActiveConnectionsLicenseReader)license).getUserQuota())
|
||||
return false;
|
||||
|
||||
string key = userId + docId;
|
||||
if (key == "")
|
||||
key = "empty";
|
||||
|
||||
DateTime value;
|
||||
|
||||
if (activeUsers.TryGetValue(key, out value))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
public void Cleanup()
|
||||
{
|
||||
activeUsers.RemoveItems();
|
||||
}
|
||||
public bool isLicenseFileValid()
|
||||
{
|
||||
return (null != license
|
||||
&& license.isLicenseFound()
|
||||
&& license.isLicenseCorrect());
|
||||
}
|
||||
public bool isLicenseDateValid()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
DateTime start = license.getStartDate();
|
||||
DateTime end = license.getEndDate();
|
||||
if (start < now && end > now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public bool isLicenseDateTresholdExpired()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
DateTime treshold = license.getEndDateThreshold();
|
||||
|
||||
return now > treshold;
|
||||
}
|
||||
public bool isLicenseEndDateGreater(DateTime time)
|
||||
{
|
||||
DateTime end = license.getEndDate();
|
||||
return (end > time);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue