1147 lines
42 KiB
C#
1147 lines
42 KiB
C#
using KDCS.Utils;
|
|
using KMBIM.Revit.Tools.Properties;
|
|
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace KMBIM.Revit.Tools.License
|
|
{
|
|
public partial class FormAuth : Form
|
|
{
|
|
private string _CDKEY;
|
|
private string _AC;
|
|
public string strSerialNo { get; set; }
|
|
private string permission_uuid;
|
|
private bool _IsValid = false;
|
|
private DateTime _dtStart;
|
|
private DateTime _dtEnd;
|
|
private int _nDaysLeft; // 남은 일수
|
|
private bool _IsUserRegistered;
|
|
private bool _AuthState;
|
|
private bool _HasAC; // 인증키를 가지고 있는가?
|
|
private bool _Init;
|
|
private bool _use_newfeature;
|
|
|
|
|
|
public FormAuth()
|
|
{
|
|
InitializeComponent();
|
|
_Init = false;
|
|
_use_newfeature = false;
|
|
}
|
|
|
|
public bool IsValid()
|
|
{
|
|
return _IsValid;
|
|
}
|
|
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
public void GetDate(string strDate, ref string strYear, ref string strMonth, ref string strDay, string strSeparator)
|
|
{
|
|
if (string.Compare(strDate, string.Empty, true) == 0 || string.Compare(strDate, "", true) == 0) return;
|
|
if (string.Compare(strDate, strSeparator, true) == 0)
|
|
{
|
|
int nCount = 0;
|
|
int nFind = strDate.IndexOf(strSeparator);
|
|
while (nFind >= 0)
|
|
{
|
|
string strVal = strDate.Substring(1, nFind);
|
|
if (nCount == 0) { strYear = strVal; }//end of if
|
|
else if (nCount == 1) { strMonth = strVal; }//end of else if
|
|
strVal = strDate.Substring(nFind + 1);
|
|
nFind = strDate.IndexOf(strSeparator);
|
|
}//end of while
|
|
if (string.Compare(strDate, "", true) == 0) { strDay = strDate; }//end of if
|
|
}//end of if
|
|
return;
|
|
}
|
|
public bool IsAvailableIdCall(string lpszId)
|
|
{
|
|
string strParam = string.Empty;
|
|
strParam = string.Format("{0}={1}|{2}={3}|",
|
|
Define.STRING_ID_TAG, lpszId,
|
|
Define.STRING_FUNCTION_TAG, "IsAvailableId");
|
|
List<string> strArray = new List<string>();
|
|
bool bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
string strMsg = CommonFunc.StrArrayValue(ref strArray, Define.STRING_MSG_TAG);
|
|
if (!string.IsNullOrEmpty(strMsg))
|
|
{
|
|
MessageBox.Show(strMsg);
|
|
}
|
|
return bOk;
|
|
}
|
|
|
|
public bool RequestLogoutCall(string lpszId, string lpszPass, string lpszDate, string lpszMac)
|
|
{
|
|
string strParam = string.Empty;
|
|
strParam = string.Format("{0}={1}|{2}={3}|{4}={5}|{6}={7}|{8}={9}|{10}={11}|{12}={13}|{14}={15}|{16}={17}|",
|
|
Define.STRING_PRODUCTNAME_TAG, "KMBIM",
|
|
//Define.STRING_CURVER_TAG, Properties.Resources.Version,
|
|
Define.STRING_CURVER_TAG, Define.STRING_CUR_VERSION,
|
|
Define.STRING_PLATFORM_TAG, "Windows",
|
|
Define.STRING_ID_TAG, lpszId,
|
|
Define.STRING_PASS_TAG, lpszPass,
|
|
"strDate", lpszDate,
|
|
"strMac", lpszMac,
|
|
Define.STRING_FUNCTION_TAG, "InternetLogOut");
|
|
List<string> strArray = new List<string>();
|
|
bool bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
string strMsg = CommonFunc.StrArrayValue(ref strArray, Define.STRING_MSG_TAG);
|
|
if (!string.IsNullOrEmpty(strMsg))
|
|
{
|
|
MessageBox.Show(strMsg);
|
|
}
|
|
return bOk;
|
|
}
|
|
|
|
public bool RequestTrialCall(string lpszId, string lpszPass, string lpszBusiness, string lpszUserName, string lpszAddress,
|
|
string lpszTel, string lpszFax, string lpszHel, string lpszMail, string lpszDate, string lpszMac)
|
|
{
|
|
string strParam = string.Empty;
|
|
strParam = string.Format("{0}={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}|",
|
|
Define.STRING_PRODUCTNAME_TAG, "KMBIM",
|
|
Define.STRING_CURVER_TAG, Define.STRING_CUR_VERSION,
|
|
Define.STRING_PLATFORM_TAG, "Revit",
|
|
Define.STRING_ID_TAG, lpszId,
|
|
Define.STRING_PASS_TAG, lpszPass,
|
|
"strBusiness", lpszBusiness,
|
|
"strUserName", lpszUserName,
|
|
"strAddress", lpszAddress,
|
|
"strTel", lpszTel,
|
|
"strFax", lpszFax,
|
|
"strHp", lpszHel,
|
|
"strMail", lpszMail,
|
|
"strDate", lpszDate,
|
|
"strMac", lpszMac,
|
|
Define.STRING_FUNCTION_TAG, "RequestTrial");
|
|
List<string> strArray = new List<string>();
|
|
bool bOk = false;
|
|
try
|
|
{
|
|
bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
string strMsg = CommonFunc.StrArrayValue(ref strArray, Define.STRING_MSG_TAG);
|
|
if (!string.IsNullOrEmpty(strMsg))
|
|
{
|
|
if (bOk)
|
|
{
|
|
MessageBox.Show("인증키(평가판) 신청이 완료되었습니다.");
|
|
|
|
}
|
|
else MessageBox.Show(strMsg, Resources.ProductName);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string strErr = ex.Message;
|
|
}
|
|
return bOk;
|
|
}
|
|
|
|
|
|
public bool RegisterAuthenticationKey(string cdkey, string serialno, string authKey)
|
|
{
|
|
string strParam = string.Empty;
|
|
strParam = string.Format("{0}={1}|{2}={3}|{4}={5}|{6}={7}|{8}={9}|{10}={11}|{12}={13}|{14}={15}|{16}={17}||{18}={19}|",
|
|
Define.STRING_PRODUCTNAME_TAG, "KMBIM",
|
|
Define.STRING_CURVER_TAG, Define.STRING_CUR_VERSION,
|
|
Define.STRING_PLATFORM_TAG, "Revit",
|
|
Define.STRING_ID_TAG, cdkey,
|
|
Define.STRING_MAC_TAG, serialno,
|
|
"strAuthenticationKey", authKey,
|
|
"strmail", textBox_Email.Text,
|
|
Define.STRING_USERNAME_TAG, textBox_UserName.Text,
|
|
Define.STRING_TEL_TAG, textBox_TEL.Text,
|
|
Define.STRING_FUNCTION_TAG, "RegisterAuthenticationKey");
|
|
List<string> strArray = new List<string>();
|
|
bool bOk = false;
|
|
try
|
|
{
|
|
bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
if (bOk)
|
|
{
|
|
// 인증키 등록
|
|
if (GetPermissionUser(cdkey, serialno))
|
|
{
|
|
Reg.setReg("CDKEY", authKey.ToUpper());
|
|
Reg.setReg("company", textBox_Business.Text);
|
|
Reg.setReg("username", textBox_UserName.Text);
|
|
Reg.setReg("tel", textBox_TEL.Text);
|
|
Reg.setReg("email", textBox_Email.Text);
|
|
|
|
_HasAC = true;
|
|
Reg.setReg("AuthState", "1"); // 인증키 등록됨
|
|
_AuthState = true;
|
|
_IsValid = _AuthState;
|
|
WorkMain.GetInstance().IsValid = _AuthState;
|
|
UpdateCDKEY();
|
|
MessageBox.Show(Resources.RegisterAuthCodeSuccess);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string strMsg = CommonFunc.StrArrayValue(ref strArray, Define.STRING_MSG_TAG);
|
|
if (!string.IsNullOrEmpty(strMsg))
|
|
{
|
|
MessageBox.Show(strMsg, Resources.ProductName);
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
bOk = false;
|
|
string strErr = ex.Message;
|
|
}
|
|
return bOk;
|
|
}
|
|
|
|
public bool RemoveAuthenticationKey(string strcdkey, string strserialno, string authKey)
|
|
{
|
|
string strParam = string.Empty;
|
|
strParam = string.Format("{0}={1}|{2}={3}|{4}={5}|{6}={7}|{8}={9}|{10}={11}|{12}={13}|{14}={15}|{16}={17}|",
|
|
|
|
Define.STRING_PRODUCTNAME_TAG, "KMBIM",
|
|
Define.STRING_CURVER_TAG, Define.STRING_CUR_VERSION,
|
|
Define.STRING_PLATFORM_TAG, "Revit",
|
|
Define.STRING_ID_TAG, strcdkey,
|
|
Define.STRING_USERNAME_TAG, textBox_UserName.Text,
|
|
Define.STRING_TEL_TAG, textBox_TEL.Text,
|
|
Define.STRING_MAC_TAG, strserialno,
|
|
"strAuthenticationKey", authKey.ToLower(),
|
|
Define.STRING_FUNCTION_TAG, "RemoveAuthenticationKey");
|
|
List<string> strArray = new List<string>();
|
|
bool bOk = false;
|
|
try
|
|
{
|
|
bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
if (bOk)
|
|
{
|
|
WorkMain.GetInstance().IsValid = false;
|
|
ClearKMBIM();
|
|
// 인증키 삭제
|
|
|
|
MessageBox.Show(Resources.RemoveAuthCodeSuccess);
|
|
}
|
|
else
|
|
{
|
|
string strMsg = CommonFunc.StrArrayValue(ref strArray, Define.STRING_MSG_TAG);
|
|
if (!string.IsNullOrEmpty(strMsg))
|
|
{
|
|
MessageBox.Show(strMsg, Resources.ProductName);
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
bOk = false;
|
|
string strErr = ex.Message;
|
|
}
|
|
return bOk;
|
|
}
|
|
|
|
// 현재 등록된 퍼미션을 가져와 저장한다.
|
|
public bool GetUserInfo(string cdkey, string serialNo)
|
|
{
|
|
string strParam = string.Empty;
|
|
strParam = string.Format("{0}={1}|{2}={3}|{4}={5}|{6}={7}|{8}={9}|{10}={11}|",
|
|
Define.STRING_PRODUCTNAME_TAG, "KMBIM",
|
|
Define.STRING_CURVER_TAG, Define.STRING_CUR_VERSION,
|
|
Define.STRING_PLATFORM_TAG, "Revit",
|
|
Define.STRING_ID_TAG, cdkey, // 사용자ID
|
|
Define.STRING_MAC_TAG, serialNo, // mac address
|
|
Define.STRING_FUNCTION_TAG, "GetUserInfo");
|
|
List<string> strArray = new List<string>();
|
|
bool bOk = false;
|
|
try
|
|
{
|
|
bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
if (bOk)
|
|
{
|
|
string user_uuid = CommonFunc.StrArrayValue(ref strArray, "user_uuid");
|
|
textBox_Business.Text = CommonFunc.StrArrayValue(ref strArray, "Company_name");
|
|
textBox_UserName.Text = CommonFunc.StrArrayValue(ref strArray, "userName");
|
|
textBox_TEL.Text = CommonFunc.StrArrayValue(ref strArray, "tel");
|
|
textBox_Email.Text = CommonFunc.StrArrayValue(ref strArray, "mail");
|
|
|
|
if (string.IsNullOrEmpty(user_uuid))
|
|
{
|
|
bOk = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string strErr = ex.Message;
|
|
}
|
|
return bOk;
|
|
}
|
|
|
|
|
|
|
|
// 현재 등록된 퍼미션의 CD키(인증키)를 요청한다.
|
|
public bool RequestCDKey(string user_id, string user_passwd)
|
|
{
|
|
string strParam = string.Empty;
|
|
strParam = string.Format("{0}={1}|{2}={3}|{4}={5}|{6}={7}|{8}={9}|{10}={11}",
|
|
Define.STRING_PRODUCTNAME_TAG, "KMBIM",
|
|
Define.STRING_CURVER_TAG, Define.STRING_CUR_VERSION,
|
|
Define.STRING_PLATFORM_TAG, "Revit",
|
|
Define.STRING_ID_TAG, user_id, // 사용자ID
|
|
Define.STRING_PASS_TAG, user_passwd, // 사용자PWD
|
|
Define.STRING_FUNCTION_TAG, "RequestCDKey");
|
|
List<string> strArray = new List<string>();
|
|
bool bOk = false;
|
|
try
|
|
{
|
|
bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string strErr = ex.Message;
|
|
}
|
|
return bOk;
|
|
}
|
|
|
|
public bool GetUseNewFeature()
|
|
{
|
|
return _use_newfeature;
|
|
}
|
|
|
|
// 현재 등록된 퍼미션을 가져와 저장한다.
|
|
public bool GetPermissionUser(string cdkey, string serialNo , bool UpdateControl = true)
|
|
{
|
|
string strParam = string.Empty;
|
|
strParam = string.Format("{0}={1}|{2}={3}|{4}={5}|{6}={7}|{8}={9}|{10}={11}",
|
|
Define.STRING_PRODUCTNAME_TAG, "KMBIM",
|
|
Define.STRING_CURVER_TAG, Define.STRING_CUR_VERSION,
|
|
Define.STRING_PLATFORM_TAG, "Revit",
|
|
Define.STRING_ID_TAG, cdkey, // cdkey
|
|
Define.STRING_MAC_TAG, serialNo, // 고유식별코드
|
|
Define.STRING_FUNCTION_TAG, "GetPermissionUser");
|
|
List<string> strArray = new List<string>();
|
|
bool bOk = false;
|
|
try
|
|
{
|
|
bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
if (bOk)
|
|
{
|
|
string perm_uuid = CommonFunc.StrArrayValue(ref strArray, "permision_uuid");
|
|
|
|
string cdkey_certification = CommonFunc.StrArrayValue(ref strArray, "cdkey_certification");
|
|
string purchase_name = CommonFunc.StrArrayValue(ref strArray, "purchase_name");
|
|
|
|
// 새 기능을 테스트할 수 있는 권한 부여
|
|
string use_newfeature = CommonFunc.StrArrayValue(ref strArray, "use_newfeature");
|
|
if (use_newfeature.CompareTo("1") == 0) _use_newfeature = true;
|
|
else _use_newfeature = false;
|
|
|
|
permission_uuid = perm_uuid;
|
|
string start_date = CommonFunc.StrArrayValue(ref strArray, "start_date");
|
|
string end_date = CommonFunc.StrArrayValue(ref strArray, "end_date");
|
|
|
|
_dtStart = new DateTime(); // 시작일
|
|
_dtEnd = new DateTime(); // 종료일
|
|
|
|
|
|
DateTime.TryParse(start_date, out _dtStart);
|
|
DateTime.TryParse(end_date, out _dtEnd);
|
|
|
|
// 일단 영구버전은 무시
|
|
if (purchase_name == "LifeTime")
|
|
{
|
|
_dtEnd = _dtStart.AddYears(120); // 120년
|
|
}
|
|
|
|
|
|
|
|
var dtDelta = _dtEnd - DateTime.Now;
|
|
_nDaysLeft = dtDelta.Days;
|
|
|
|
|
|
if (_nDaysLeft <= 0) // dtDelta.Days => 남은 일수
|
|
{
|
|
_IsValid = false;
|
|
}
|
|
else _IsValid = true;
|
|
|
|
WorkMain.GetInstance().IsValid = _IsValid;
|
|
|
|
string st = _dtStart.ToBinary().ToString();
|
|
string et = _dtEnd.ToBinary().ToString();
|
|
string lt = st;
|
|
string identification_code = CommonFunc.StrArrayValue(ref strArray, "identification_code");
|
|
string Company_name = CommonFunc.StrArrayValue(ref strArray, "Company_name");
|
|
string mail = CommonFunc.StrArrayValue(ref strArray, "mail");
|
|
string name = CommonFunc.StrArrayValue(ref strArray, "name");
|
|
string contact = CommonFunc.StrArrayValue(ref strArray, "contact");
|
|
|
|
|
|
Reg.setReg("CDKEY", cdkey.ToUpper());
|
|
Reg.setReg("company", Company_name);
|
|
Reg.setReg("username", mail);
|
|
Reg.setReg("tel", name);
|
|
Reg.setReg("email", contact);
|
|
|
|
|
|
string expired = CommonFunc.StrArrayValue(ref strArray, "expired");
|
|
bool bexpired = expired == "1" ? true : false;
|
|
bool bcdkey_certification = cdkey_certification == "1" ? true : false;
|
|
|
|
|
|
if (identification_code != serialNo || !bcdkey_certification || bexpired)
|
|
{
|
|
MessageBox.Show("정보가 일치 하지 않으므로 권한이 없습니다.");
|
|
WorkMain.GetInstance().IsValid = false ;
|
|
Reg.setReg("CDKEY", "");
|
|
Reg.setReg("company", "");
|
|
Reg.setReg("username", "");
|
|
Reg.setReg("tel", "");
|
|
Reg.setReg("email", "");
|
|
_AuthState = false;
|
|
Reg.setReg("AuthState", "0");
|
|
|
|
//권한삭제
|
|
InitKMBIM(identification_code, st, st, st, UpdateControl);
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// 등록 가능
|
|
InitKMBIM(identification_code, st, et, lt, UpdateControl);
|
|
|
|
}
|
|
else
|
|
{
|
|
// 인증키가 승인되지 않은 경우
|
|
WorkMain.GetInstance().IsValid = _IsValid;
|
|
// 레지스트리에 저장하지 않는다.
|
|
string strMsg = CommonFunc.StrArrayValue(ref strArray, Define.STRING_MSG_TAG);
|
|
if (!string.IsNullOrEmpty(strMsg))
|
|
{
|
|
MessageBox.Show(strMsg, Resources.ProductName);
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
bOk = false;
|
|
string strErr = ex.Message;
|
|
}
|
|
return bOk;
|
|
}
|
|
|
|
|
|
|
|
private void RegisterUser(string user_id, string user_passwd, string macAddress)
|
|
{
|
|
// string strID = user_id;
|
|
// string strPWD = user_passwd;
|
|
// string strTel = textBox_TEL.Text;
|
|
//
|
|
// Guid guid = Guid.NewGuid();
|
|
//
|
|
// string strErr = string.Empty;
|
|
// if (string.IsNullOrEmpty(strID)) strErr += "요청코드,";
|
|
// if (string.IsNullOrEmpty(strPWD)) strErr += "인증키,";
|
|
// if (string.IsNullOrEmpty(textBox_Business.Text)) strErr += "업체명,";
|
|
// if (string.IsNullOrEmpty(textBox_UserName.Text)) strErr += "담당자명,";
|
|
// if (string.IsNullOrEmpty(textBox_TEL.Text)) strErr += "전화번호,";
|
|
// if (string.IsNullOrEmpty(textBox_Email.Text)) strErr += "이메일주소,";
|
|
//
|
|
// if (strErr != "")
|
|
// {
|
|
// String strMsg;
|
|
// if (strErr.Substring(strErr.Length - 1, 1) == ",") strErr = strErr.TrimEnd(',');
|
|
// strMsg = string.Format("{0}가 없습니다.", strErr);
|
|
// MessageBox.Show(strMsg);
|
|
// return;
|
|
// }//end of if
|
|
//
|
|
// //////////////////////////////////////////////////////////////////////////////////
|
|
// //2006-4-18 등록하는 날짜를 추가할 수 있도록 하자.
|
|
// //EntStr eStr;
|
|
// var st = DateTime.Now;
|
|
// List<int> nArr = new List<int>();
|
|
// nArr.Add(st.Year);//;Year
|
|
// nArr.Add(st.Month);//;Month
|
|
// nArr.Add(st.Day);//;Day
|
|
// //////////////////////////////////////////////////////////////////////////////////
|
|
// string[] strArrSeparator = new string[] { "_ ", "_ ", "" };
|
|
// //////////////////////////////////////////////////////////////////////////////////
|
|
// string strDate = string.Empty;
|
|
// string strTemp = string.Empty;
|
|
// int nLen = nArr.Count;
|
|
// for (int i = 0; i < nLen; i++)
|
|
// {
|
|
// strTemp = string.Format("{0}{1}", nArr[i], strArrSeparator[i]);
|
|
// strDate += strTemp;
|
|
// }//;end of for
|
|
// strDate.Replace(",", "");
|
|
// //////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
//
|
|
// bool bOk = RequestTrialCall(strID, strPWD, textBox_Business.Text, textBox_UserName.Text, "",
|
|
// strTel, "", "", textBox_Email.Text, strDate, _SN);
|
|
// if (bOk)
|
|
// {
|
|
// //RequestCDKey(strID, strPWD); // 인증키 발송
|
|
//
|
|
// }
|
|
}
|
|
|
|
string DomainMapper(Match match)
|
|
{
|
|
// Use IdnMapping class to convert Unicode domain names.
|
|
var idn = new IdnMapping();
|
|
|
|
// Pull out and process domain name (throws ArgumentException on invalid)
|
|
string domainName = idn.GetAscii(match.Groups[2].Value);
|
|
|
|
return match.Groups[1].Value + domainName;
|
|
}
|
|
public bool IsValidEmail(string email)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(email))
|
|
return false;
|
|
|
|
try
|
|
{
|
|
// Normalize the domain
|
|
email = Regex.Replace(email, @"(@)(.+)$", DomainMapper, RegexOptions.None, TimeSpan.FromMilliseconds(200));
|
|
|
|
// Examines the domain part of the email and normalizes it.
|
|
|
|
}
|
|
catch (RegexMatchTimeoutException e)
|
|
{
|
|
return false;
|
|
}
|
|
catch (ArgumentException e)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
try
|
|
{
|
|
return Regex.IsMatch(email,
|
|
@"^[^@\s]+@[^@\s]+\.[^@\s]+$",
|
|
RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));
|
|
}
|
|
catch (RegexMatchTimeoutException)
|
|
{
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void btnAuthorization_Click(object sender, EventArgs e)
|
|
{
|
|
string strcdkey = textBoxCDKey.Text; // cdkey
|
|
|
|
|
|
Regex regex1 = new Regex("^[a-zA-Z]+[a-zA-Z0-9]+[[a-zA-Z0-9-_.!#$%'*+/=?^]{1,20}@[a-zA-Z0-9]{1,20}.[a-zA-Z]{2,3}$");
|
|
|
|
|
|
Reg.setReg("company", textBox_Business.Text);
|
|
Reg.setReg("username", textBox_UserName.Text);
|
|
Reg.setReg("tel", textBox_TEL.Text);
|
|
Reg.setReg("email", textBox_Email.Text);
|
|
|
|
if (!IsValidEmail(textBox_Email.Text))
|
|
{
|
|
|
|
MessageBox.Show("E-mail 주소를 입력하십시오.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
|
|
AuthKey auth = new AuthKey();
|
|
string serialNO = string.Empty;
|
|
auth.GetSerialNumber(ref serialNO);
|
|
|
|
if (this.GetUserInfo(strcdkey, serialNO) == false)
|
|
{
|
|
// this.RegisterUser(strID, strPWD, _SN);
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void InitKMBIM(string strSerialNo, string st, string et, string lt, bool UpdateControl)
|
|
{
|
|
try
|
|
{
|
|
byte[] k2 = Convert.FromBase64String("p0NGShDC/ONmkbHWMcNJaQ==");
|
|
AESEncryption aesenc = new AESEncryption();
|
|
|
|
byte[] baDpsKey = Convert.FromBase64String("ybpAFYG/XbjTG6gKJSJfHw==");
|
|
var strKey = aesenc.DecryptString(baDpsKey, null, k2);
|
|
|
|
|
|
string tt = st + "|" + et + "|" + lt;
|
|
|
|
byte[] abTT = aesenc.EncryptString(tt, null, k2);
|
|
var strTTB64 = Convert.ToBase64String(abTT);
|
|
|
|
string strTmp2 = strSerialNo + "|" + strTTB64;
|
|
Reg.SetAuthRegistry(Registry.CurrentUser, strKey, strTmp2);
|
|
|
|
if (UpdateControl)
|
|
{
|
|
textBoxCDKey.Enabled = true;
|
|
UpdateCDKEY();
|
|
}
|
|
|
|
}
|
|
catch (AccessViolationException e)
|
|
{
|
|
string strMsg = e.Message;
|
|
}
|
|
|
|
}
|
|
|
|
private string GetKMBIM()
|
|
{
|
|
byte[] k2 = Convert.FromBase64String("p0NGShDC/ONmkbHWMcNJaQ==");
|
|
AESEncryption aesenc = new AESEncryption();
|
|
byte[] baDpsKey = Convert.FromBase64String("ybpAFYG/XbjTG6gKJSJfHw==");
|
|
var strKey = aesenc.DecryptString(baDpsKey, null, k2);
|
|
return Reg.GetAuthRegistry(Registry.CurrentUser, strKey);
|
|
}
|
|
|
|
private void ClearKMBIM(bool bUpdateControl = true)
|
|
{
|
|
try
|
|
{
|
|
Reg.setReg("AuthState", "0"); // 인증키 제거됨
|
|
_AuthState = false; // 인증키 제거됨
|
|
|
|
byte[] k2 = Convert.FromBase64String("p0NGShDC/ONmkbHWMcNJaQ==");
|
|
AESEncryption aesenc = new AESEncryption();
|
|
byte[] baDpsKey = Convert.FromBase64String("ybpAFYG/XbjTG6gKJSJfHw==");
|
|
var strKey = aesenc.DecryptString(baDpsKey, null, k2);
|
|
Reg.SetAuthRegistry(Registry.CurrentUser, strKey, "");
|
|
|
|
var strTmp2 = Reg.GetAuthRegistry(Registry.CurrentUser, strKey);
|
|
string[] lstString = strTmp2.Split('|');
|
|
|
|
if (lstString.Length == 2)
|
|
{
|
|
|
|
// 레지스트리에서 가져온 권한코드메타
|
|
string strAuthCodeReg = lstString[0];
|
|
|
|
var strTT = lstString[1];
|
|
var decTT = aesenc.DecryptString(Convert.FromBase64String(strTT), null, k2);
|
|
|
|
var lstTT = decTT.Split('|');
|
|
if (lstTT.Length == 3)
|
|
{
|
|
var decST = lstTT[0];
|
|
var decET = lstTT[1];
|
|
var decLT = lstTT[2]; // 마지막 갱신일
|
|
long lTmp = 0;
|
|
if (long.TryParse(decST, out lTmp))
|
|
{
|
|
_dtStart = DateTime.FromBinary(lTmp);
|
|
_dtEnd = _dtStart;
|
|
string st = _dtStart.ToBinary().ToString();
|
|
string et = _dtEnd.ToBinary().ToString();
|
|
string lt = st;
|
|
// 등록 가능
|
|
AuthKey auth = new AuthKey();
|
|
string sn = string.Empty;
|
|
auth.GetSerialNumber(ref sn);
|
|
strSerialNo = sn;
|
|
InitKMBIM(strSerialNo, st, et, lt, bUpdateControl);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
_IsValid = false;
|
|
WorkMain.GetInstance().IsValid = _IsValid;
|
|
_nDaysLeft = 0; // 남은일수 초기화
|
|
textBoxCDKey.Enabled = true;
|
|
UpdateCDKEY();
|
|
|
|
}
|
|
catch (AccessViolationException e)
|
|
{
|
|
string strMsg = e.Message;
|
|
}
|
|
|
|
}
|
|
|
|
private void GetRegAuth(string strSerialNumber, ref string strAC, ref string strAuthCodeReg)
|
|
{
|
|
DateTime dtStart = DateTime.MinValue;
|
|
DateTime dtEnd = DateTime.MinValue;
|
|
DateTime dtLatest = DateTime.MinValue;
|
|
AESEncryption aesenc = new AESEncryption();
|
|
|
|
byte[] k2 = Convert.FromBase64String("p0NGShDC/ONmkbHWMcNJaQ==");
|
|
byte[] baDpsKey = Convert.FromBase64String("ybpAFYG/XbjTG6gKJSJfHw==");
|
|
var strKey = aesenc.DecryptString(baDpsKey, null, k2);
|
|
|
|
|
|
var strTmp2 = Reg.GetAuthRegistry(Registry.CurrentUser, strKey);
|
|
string[] lstString = strTmp2.Split('|');
|
|
|
|
if (lstString.Length == 2)
|
|
{
|
|
|
|
// 레지스트리에서 가져온 권한코드메타
|
|
strAuthCodeReg = lstString[0];
|
|
|
|
var strTT = lstString[1];
|
|
var decTT = aesenc.DecryptString(Convert.FromBase64String(strTT), null, k2);
|
|
|
|
var lstTT = decTT.Split('|');
|
|
if (lstTT.Length == 3)
|
|
{
|
|
var decST = lstTT[0];
|
|
var decET = lstTT[1];
|
|
var decLT = lstTT[2]; // 마지막 갱신일
|
|
long lTmp = 0;
|
|
if (long.TryParse(decST, out lTmp))
|
|
{
|
|
dtStart = DateTime.FromBinary(lTmp);
|
|
}
|
|
|
|
if (long.TryParse(decET, out lTmp))
|
|
{
|
|
dtEnd = DateTime.FromBinary(lTmp);
|
|
}
|
|
|
|
if (long.TryParse(decLT, out lTmp))
|
|
{
|
|
dtLatest = DateTime.FromBinary(lTmp);
|
|
}
|
|
|
|
_dtStart = dtStart;
|
|
_dtEnd = dtEnd;
|
|
|
|
|
|
var dtDelta = dtEnd - DateTime.Now;
|
|
_nDaysLeft = dtDelta.Days;
|
|
|
|
_IsValid = true;
|
|
if (_nDaysLeft <= 0) // dtDelta.Days => 남은 일수
|
|
{
|
|
_IsValid = false;
|
|
strAC = string.Empty;
|
|
if (_AuthState == true) // 인증키가 등록된 상태에서만 표시
|
|
{
|
|
MessageBox.Show("KMBIM 사용기간이 지났습니다.");
|
|
}
|
|
}
|
|
|
|
// 오늘 날짜를 앞으로 옮겼다면 인증 취소
|
|
var dtDelta2 = DateTime.Today - dtLatest;
|
|
if (dtDelta2.Days < 0)
|
|
{
|
|
_IsValid = false;
|
|
strAC = string.Empty;
|
|
}
|
|
|
|
|
|
}
|
|
else strAC = string.Empty;
|
|
}
|
|
else strAC = string.Empty;
|
|
|
|
WorkMain.GetInstance().IsValid = _IsValid;
|
|
if(_IsValid)
|
|
{
|
|
|
|
// 인증완료 -> 최근접속일 기록
|
|
strSerialNo = strSerialNumber;
|
|
DateTime dtL = DateTime.Now; // 마지막 체크 일
|
|
|
|
string st = dtStart.ToBinary().ToString();
|
|
string et = dtEnd.ToBinary().ToString();
|
|
string lt = dtL.ToBinary().ToString(); // 마지막 체크일
|
|
|
|
string tt = st + "|" + et + "|" + lt;
|
|
|
|
AESEncryption enc = new AESEncryption();
|
|
byte[] abTT = enc.EncryptString(tt, null, k2);
|
|
var strTTB64 = Convert.ToBase64String(abTT);
|
|
|
|
strTmp2 = strAuthCodeReg + "|" + strTTB64;
|
|
Reg.SetAuthRegistry(Registry.CurrentUser, strKey, strTmp2);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public void Init(bool showDlg)
|
|
{
|
|
try
|
|
{
|
|
_Init = true;
|
|
string strAuthCodeIn = string.Empty;
|
|
_IsValid = false;
|
|
|
|
_HasAC = false;
|
|
var cdKey = Reg.getReg("CDKEY");
|
|
if (string.IsNullOrEmpty(cdKey) == false)
|
|
{
|
|
if (cdKey.Length > 30) _HasAC = true;
|
|
}
|
|
|
|
AuthKey auth = new AuthKey();
|
|
string strSerialNumber = string.Empty, strAuthCodeReg = string.Empty;
|
|
string strAC = string.Empty;
|
|
auth.GetSerialNumber(ref strSerialNumber);
|
|
|
|
|
|
strAC = auth.GetAuthCode(strSerialNumber);
|
|
if (strSerialNumber == "")
|
|
{
|
|
System.Windows.Forms.MessageBox.Show(Resources.AuthenticationFailed + "-1!");
|
|
return;
|
|
}
|
|
|
|
if (strSerialNumber.Length < 3)
|
|
{
|
|
System.Windows.Forms.MessageBox.Show(Resources.AuthenticationFailed + "-2!");
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
// 레지스트리에 기록된 권한 확인
|
|
GetRegAuth(strSerialNumber, ref strAC, ref strAuthCodeReg);
|
|
|
|
|
|
if (strAC.CompareTo(strAuthCodeReg) != 0 || string.IsNullOrEmpty(strAC) || string.IsNullOrEmpty(strAuthCodeReg))
|
|
{
|
|
if (showDlg)
|
|
{
|
|
FormAuth dlg = new FormAuth(); // 3Q(대한기계설비건설협회)
|
|
// dlg.strPWD = auth.GetAuthCode(strSerialNumber);
|
|
|
|
dlg.ShowDialog();
|
|
GetRegAuth(strSerialNumber, ref strAC, ref strAuthCodeReg);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
// 최종적으로 웹권한이 있는지 확인한다.
|
|
// 인테넷 권한 확인이 필요한 제품만 여기서 진행한다.
|
|
// 인터넷 연결 불가능한 제품은 인증키 제거 기능을 숨긴다.
|
|
//----------------------------------------------
|
|
if (_IsValid) // 현재 사용 가능한 경우
|
|
{
|
|
if (string.IsNullOrEmpty(strAC))
|
|
{
|
|
auth.GetSerialNumber(ref strSerialNumber);
|
|
strAC = auth.GetAuthCode(strSerialNumber);
|
|
}
|
|
if(IsInternetConnected())
|
|
{
|
|
var client = new HttpClient();
|
|
client.Timeout = TimeSpan.FromMilliseconds(300);
|
|
|
|
string URL = "http://newlicense.ticket.co.kr/ping.php";
|
|
|
|
var result = client.GetAsync(URL).Result;
|
|
string json = result.Content.ReadAsStringAsync().Result;
|
|
if (json == "1")
|
|
{
|
|
// 인터넷 접속하여 사용권한 재 확인
|
|
_IsValid = GetPermissionUser(cdKey.ToString(), strSerialNumber);
|
|
}
|
|
}
|
|
|
|
|
|
WorkMain.GetInstance().IsValid = _IsValid;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.ToString(), "KMBIM.Revit.Tools");
|
|
}
|
|
}
|
|
public bool IsInternetConnected()
|
|
{
|
|
const string NCSI_TEST_URL = "http://www.msftncsi.com/ncsi.txt";
|
|
const string NCSI_TEST_RESULT = "Microsoft NCSI";
|
|
const string NCSI_DNS = "dns.msftncsi.com";
|
|
const string NCSI_DNS_IP_ADDRESS = "131.107.255.255";
|
|
|
|
try
|
|
{
|
|
// Check NCSI test link
|
|
var webClient = new System.Net.WebClient();
|
|
string result = webClient.DownloadString(NCSI_TEST_URL);
|
|
if (result != NCSI_TEST_RESULT)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Check NCSI DNS IP
|
|
var dnsHost = Dns.GetHostEntry(NCSI_DNS);
|
|
if (dnsHost.AddressList.Count() < 0 || dnsHost.AddressList[0].ToString() != NCSI_DNS_IP_ADDRESS)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//Debug.WriteLine(ex);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void pictureBox1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void UpdateCDKEY()
|
|
{
|
|
int nUsePeriod = _nDaysLeft - 1;
|
|
if (nUsePeriod < 0) nUsePeriod = 0;
|
|
|
|
if (nUsePeriod == 0)
|
|
{
|
|
_IsValid = false;
|
|
WorkMain.GetInstance().IsValid = _IsValid;
|
|
labelDaysLeft.Text = Resources.UsePeriodExpiredMsg;
|
|
}
|
|
else labelDaysLeft.Text = string.Format(Resources.UsePeriodMsg, nUsePeriod);
|
|
|
|
|
|
var cdkey = Reg.getReg("CDKEY");
|
|
textBoxCDKey.Text = cdkey;
|
|
buttonRegisterAC.Enabled = !_AuthState;
|
|
buttonRemoveAC.Enabled = _AuthState;
|
|
|
|
}
|
|
|
|
|
|
private void FormAuth_Load(object sender, EventArgs e)
|
|
{
|
|
textBox_Business.Text = Reg.getReg("company");
|
|
textBox_UserName.Text = Reg.getReg("username");
|
|
textBox_TEL.Text = Reg.getReg("tel");
|
|
textBox_Email.Text = Reg.getReg("email");
|
|
|
|
|
|
if (_Init == false) Init(false);
|
|
string cdkey = string.Empty;
|
|
AuthKey auth = new AuthKey();
|
|
string serial = string.Empty;
|
|
auth.GetSerialNumber(ref serial);
|
|
strSerialNo = serial;
|
|
cdkey = Reg.getReg("CDKEY");
|
|
textBoxCDKey.Text = cdkey;
|
|
|
|
|
|
|
|
var authState = Reg.getReg("AuthState");
|
|
if (authState == "1") _AuthState = true; // 키등록
|
|
else _AuthState = false; // 키제거
|
|
_IsUserRegistered = this.GetUserInfo(cdkey, strSerialNo);
|
|
|
|
UpdateCDKEY();
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 인증키 등록
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void buttonRegisterAC_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(textBoxCDKey.Text) == true)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string strSerialNumber = string.Empty;
|
|
string cdkey = textBoxCDKey.Text.ToLower(); // 퍼미션 uuid
|
|
AuthKey auth = new AuthKey();
|
|
auth.GetSerialNumber(ref strSerialNumber);
|
|
|
|
// CDKEY를 이용하여 퍼미션 테이블에 userID(요청코드), userPWD(인증코드)를 등록한다.
|
|
// 인증성공한 경우
|
|
|
|
string strErr = string.Empty;
|
|
if (string.IsNullOrEmpty(cdkey)) strErr += "시디키";
|
|
|
|
|
|
if (strErr != "")
|
|
{
|
|
String strMsg;
|
|
if (strErr.Substring(strErr.Length - 1, 1) == ",") strErr = strErr.TrimEnd(',');
|
|
strMsg = string.Format("{0}가 없습니다.", strErr);
|
|
MessageBox.Show(strMsg);
|
|
return;
|
|
}//end of if
|
|
|
|
|
|
|
|
RegisterAuthenticationKey(cdkey, strSerialNumber, cdkey);
|
|
|
|
}
|
|
|
|
private void btnRemoveAC_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(textBoxCDKey.Text) == true)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var resultAnswer = MessageBox.Show(this, Resources.YesNoDelAuthCode, Resources.ProductName, MessageBoxButtons.YesNo);
|
|
if (resultAnswer != System.Windows.Forms.DialogResult.Yes) return;
|
|
|
|
|
|
|
|
string cdkey = textBoxCDKey.Text.ToLower(); // 퍼미션 uuid
|
|
|
|
// CDKEY를 이용하여 퍼미션 테이블에 userID(요청코드), userPWD(인증코드)를 등록한다.
|
|
// 인증성공한 경우
|
|
|
|
string strErr = string.Empty;
|
|
if (string.IsNullOrEmpty(cdkey)) strErr += "시디키";
|
|
|
|
if (strErr != "")
|
|
{
|
|
String strMsg;
|
|
if (strErr.Substring(strErr.Length - 1, 1) == ",") strErr = strErr.TrimEnd(',');
|
|
strMsg = string.Format("{0}가 없습니다.", strErr);
|
|
MessageBox.Show(strMsg);
|
|
return;
|
|
}//end of if
|
|
|
|
|
|
|
|
bool bOk = RemoveAuthenticationKey(cdkey,strSerialNo, cdkey);
|
|
if (bOk)
|
|
{
|
|
textBox_Business.Text = "";
|
|
textBox_UserName.Text = "";
|
|
textBox_TEL.Text = "";
|
|
textBox_Email.Text = "";
|
|
Reg.setReg("company", textBox_Business.Text);
|
|
Reg.setReg("username", textBox_UserName.Text);
|
|
Reg.setReg("tel", textBox_TEL.Text);
|
|
Reg.setReg("email", textBox_Email.Text);
|
|
UpdateCDKEY();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void buttonTestRequestCDKey_Click(object sender, EventArgs e)
|
|
{
|
|
// AuthKey auth = new AuthKey();
|
|
// string strAC = auth.GetAuthCode(_SN);
|
|
//
|
|
// //RequestCDKey(_SN, auth.GetAuthCode(_SN));
|
|
// string strParam = string.Empty;
|
|
// strParam = string.Format("{0}={1}|{2}={3}|{4}={5}|{6}={7}|{8}={9}|{10}={11}",
|
|
// Define.STRING_PRODUCTNAME_TAG, "KMBIM",
|
|
// Define.STRING_CURVER_TAG, Define.STRING_CUR_VERSION,
|
|
// Define.STRING_PLATFORM_TAG, "Revit",
|
|
// Define.STRING_ID_TAG, strSN, // 사용자ID
|
|
// Define.STRING_PASS_TAG, strAC, // 사용자PWD
|
|
// Define.STRING_FUNCTION_TAG, "GetPermissionUser");
|
|
// List<string> strArray = new List<string>();
|
|
// bool bOk = false;
|
|
// try
|
|
// {
|
|
// // 처음 사용자에게 할당된 'user_uuid', 'CD키', '제폼', '버전번호', '플랫폼' 으로 퍼미션을 가져온다.
|
|
// // 만약 사용자가 퍼미션에서 인능키제거(user_uuid)를 삭제
|
|
// // 여기서 한가지 문제점은 사용자가 CDKEY 코드를
|
|
// bOk = CommonFunc.CallAspx(strParam, ref strArray); // [ iknow 2012-5-29 ]
|
|
// if (bOk)
|
|
// {
|
|
// string cdkey = CommonFunc.StrArrayValue(ref strArray, "cdkey");
|
|
//
|
|
//
|
|
// string cdkey_certification = CommonFunc.StrArrayValue(ref strArray, "cdkey_certification");
|
|
// if (cdkey_certification == "1")
|
|
// {
|
|
// textBoxCDKey.Text = cdkey.ToUpper();
|
|
// }
|
|
//
|
|
//
|
|
// string start_date = CommonFunc.StrArrayValue(ref strArray, "start_date");
|
|
// string end_date = CommonFunc.StrArrayValue(ref strArray, "end_date");
|
|
//
|
|
// //DateTime dtS1 = new DateTime(); // 시작일
|
|
// //DateTime dtE1 = new DateTime(); // 종료일
|
|
// }
|
|
// else
|
|
// {
|
|
// string strMsg = CommonFunc.StrArrayValue(ref strArray, Define.STRING_MSG_TAG);
|
|
// if (!string.IsNullOrEmpty(strMsg))
|
|
// {
|
|
// MessageBox.Show(strMsg, Resources.ProductName);
|
|
// }
|
|
// }
|
|
//
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// MessageBox.Show(ex.ToString(), "KMBIM.Revit.Tools");
|
|
//
|
|
//
|
|
// }
|
|
//
|
|
}
|
|
}
|
|
}
|