- using System;
- using System.Collections;
- using System.Data;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.NetworkInformation;
- using System.ServiceProcess;
- using System.Text;
- using System.Threading;
- using MySql.Data.MySqlClient;
- namespace ZQDLL
- {
- // Token: 0x0200001D RID: 29
- public class SHOPFW_SERVICE
- {
- // Token: 0x0600018D RID: 397 RVA: 0x0001AD70 File Offset: 0x00018F70
- public bool chushi_connset(MySqlCommand mysqlCom, string database)
- {
- MySqlConnection mySqlConnection = new MySqlConnection();
- bool flag = true;
- string connectionString = "";
- string text = "127.0.0.1";
- string text2 = "";
- string text3 = "root";
- string text4 = "Wu#Ve%Xi@Nfd&B(o!Y";
- string text5 = text4;
- string format = "server={0};Port={1};user id={2};password={3};database={4};Charset=utf8;Allow User Variables=True";
- try
- {
- string path = AppDomain.CurrentDomain.BaseDirectory + "zq_config\\data\\config.ini";
- bool flag2 = File.Exists(path);
- if (flag2)
- {
- StringBuilder stringBuilder = new StringBuilder();
- FileStream stream = new FileStream(path, FileMode.Open);
- StreamReader streamReader = new StreamReader(stream, Encoding.Default);
- stringBuilder.Length = 0;
- stringBuilder.Append(streamReader.ReadToEnd());
- streamReader.Close();
- string[] array = stringBuilder.ToString().Split(new string[]
- {
- "\r\n"
- }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < array.Count<string>(); i++)
- {
- bool flag3 = array[i].IndexOf(":") > 0;
- if (flag3)
- {
- string text6 = array[i].Substring(0, array[i].IndexOf(":"));
- string text7 = array[i].Substring(array[i].IndexOf(":") + 1);
- bool flag4 = text6 == "数据库地址";
- if (flag4)
- {
- text = text7;
- }
- else
- {
- bool flag5 = text6 == "数据库端口";
- if (flag5)
- {
- text2 = text7;
- }
- else
- {
- bool flag6 = text6 == "数据库用户名";
- if (flag6)
- {
- text3 = text7;
- }
- else
- {
- bool flag7 = text6 == "数据库密码";
- if (flag7)
- {
- text5 = text7;
- }
- }
- }
- }
- }
- }
- bool flag8 = string.IsNullOrEmpty(text5);
- if (flag8)
- {
- text5 = "''";
- }
- connectionString = string.Format(format, new object[]
- {
- text,
- text2,
- text3,
- text5,
- database
- });
- mySqlConnection = new MySqlConnection(connectionString);
- mySqlConnection.Open();
- flag = true;
- }
- else
- {
- flag = false;
- }
- }
- catch
- {
- flag = false;
- }
- bool flag9 = !flag;
- if (flag9)
- {
- text2 = this.Service_Install_Mysql();
- text = "127.0.0.1";
- text3 = "root";
- text5 = text4;
- connectionString = string.Format(format, new object[]
- {
- text,
- text2,
- text3,
- text5,
- database
- });
- for (int j = 1; j < 50; j++)
- {
- try
- {
- Thread.Sleep(1000);
- mySqlConnection = new MySqlConnection(connectionString);
- mySqlConnection.Open();
- bool flag10 = mySqlConnection.State.ToString() == "Open";
- if (flag10)
- {
- flag = true;
- break;
- }
- }
- catch
- {
- flag = false;
- }
- }
- }
- bool flag11 = flag;
- if (flag11)
- {
- mySqlConnection = new MySqlConnection(connectionString);
- mySqlConnection.Open();
- mysqlCom.CommandType = CommandType.Text;
- mysqlCom.Connection = mySqlConnection;
- mysqlCom.CommandTimeout = 0;
- string path2 = AppDomain.CurrentDomain.BaseDirectory + "zq_config\\data\\config.ini";
- bool flag12 = File.Exists(path2);
- if (flag12)
- {
- mysqlCom.CommandText = "SET sql_mode = ''";
- mysqlCom.ExecuteNonQuery();
- mysqlCom.CommandText = "SET GLOBAL group_concat_max_len=4294967295";
- mysqlCom.ExecuteNonQuery();
- mysqlCom.CommandText = "SET GLOBAL wait_timeout=1814400";
- mysqlCom.ExecuteNonQuery();
- mysqlCom.CommandText = "SET GLOBAL interactive_timeout=1814400";
- mysqlCom.ExecuteNonQuery();
- }
- }
- return flag;
- }
- // Token: 0x06000190 RID: 400 RVA: 0x0001B3E8 File Offset: 0x000195E8
- public void delete_mysql_tmp()
- {
- bool flag = Directory.Exists(this.f + "data/");
- if (flag)
- {
- ArrayList arrayList = new ArrayList();
- arrayList.Add("auto.cnf");
- arrayList.Add("ib_logfile");
- arrayList.Add("ibdata");
- arrayList.Add(".err");
- DirectoryInfo directoryInfo = new DirectoryInfo(this.f + "data/");
- FileInfo[] files = directoryInfo.GetFiles();
- for (int i = 0; i < files.Length; i++)
- {
- FileInfo fileInfo = files[i];
- foreach (object current in arrayList)
- {
- bool flag2 = fileInfo.Name.IndexOf(current.ToString()) >= 0;
- if (flag2)
- {
- File.Delete(this.f + "data/" + fileInfo.Name);
- }
- }
- }
- }
- }
- // Token: 0x0600019B RID: 411 RVA: 0x0001BBF8 File Offset: 0x00019DF8
- public string Execute(string command, int seconds)
- {
- string result = "";
- bool flag = command != null && !command.Equals("");
- if (flag)
- {
- Process process = new Process();
- process.StartInfo = new ProcessStartInfo
- {
- FileName = "cmd.exe",
- Arguments = "/C " + command,
- UseShellExecute = false,
- RedirectStandardInput = false,
- RedirectStandardOutput = true,
- CreateNoWindow = true
- };
- try
- {
- bool flag2 = process.Start();
- if (flag2)
- {
- bool flag3 = seconds == 0;
- if (flag3)
- {
- process.WaitForExit();
- }
- else
- {
- process.WaitForExit(seconds);
- }
- process.Close();
- }
- }
- catch
- {
- }
- finally
- {
- bool flag4 = process != null;
- if (flag4)
- {
- process.Close();
- }
- }
- }
- return result;
- }
- // Token: 0x06000198 RID: 408 RVA: 0x0001B9A8 File Offset: 0x00019BA8
- public string Get_Port_Mysql()
- {
- string result = "";
- string path = this.f + "my.ini";
- bool flag = File.Exists(path);
- if (flag)
- {
- StringBuilder stringBuilder = new StringBuilder();
- FileStream stream = new FileStream(path, FileMode.Open);
- StreamReader streamReader = new StreamReader(stream, Encoding.Default);
- stringBuilder.Length = 0;
- stringBuilder.Append(streamReader.ReadToEnd());
- streamReader.Close();
- try
- {
- stringBuilder.Remove(0, stringBuilder.ToString().IndexOf("port=") + 5).ToString();
- result = stringBuilder.ToString().Substring(0, stringBuilder.ToString().IndexOf("\r\n"));
- }
- catch
- {
- result = "";
- }
- }
- return result;
- }
- // Token: 0x06000199 RID: 409 RVA: 0x0001BA7C File Offset: 0x00019C7C
- public string Get_Port_Nginx()
- {
- string result = "";
- string path = this.g + "conf/web-listen-nginx.conf";
- bool flag = File.Exists(path);
- if (flag)
- {
- StringBuilder stringBuilder = new StringBuilder();
- FileStream stream = new FileStream(path, FileMode.Open);
- StreamReader streamReader = new StreamReader(stream, Encoding.Default);
- stringBuilder.Length = 0;
- stringBuilder.Append(streamReader.ReadToEnd());
- streamReader.Close();
- try
- {
- stringBuilder.Replace("listen", "");
- stringBuilder.Replace(";", "");
- stringBuilder.Replace(" ", "");
- result = stringBuilder.ToString();
- }
- catch
- {
- result = "";
- }
- }
- return result;
- }
- // Token: 0x06000196 RID: 406 RVA: 0x0001B8F4 File Offset: 0x00019AF4
- public void Kill_Process(string processName)
- {
- try
- {
- Process[] processesByName = Process.GetProcessesByName(processName);
- bool flag = processesByName.Length != 0;
- if (flag)
- {
- int num;
- for (int i = 0; i < processesByName.Length; i = num + 1)
- {
- bool flag2 = !processesByName[i].CloseMainWindow();
- if (flag2)
- {
- processesByName[i].Kill();
- }
- num = i;
- }
- }
- }
- catch
- {
- }
- }
- // Token: 0x0600019A RID: 410 RVA: 0x0001BB4C File Offset: 0x00019D4C
- public string Port_In_Use(int port)
- {
- try
- {
- IPGlobalProperties iPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
- IPEndPoint[] activeTcpListeners = iPGlobalProperties.GetActiveTcpListeners();
- for (int i = port; i <= 65534; i++)
- {
- int num = 1;
- port = 0;
- IPEndPoint[] array = activeTcpListeners;
- for (int j = 0; j < array.Length; j++)
- {
- IPEndPoint iPEndPoint = array[j];
- bool flag = iPEndPoint.Port == i;
- if (flag)
- {
- num = 0;
- break;
- }
- }
- bool flag2 = num == 1;
- if (flag2)
- {
- port = i;
- break;
- }
- }
- }
- catch
- {
- port = 0;
- }
- return port.ToString();
- }
- // Token: 0x06000197 RID: 407 RVA: 0x0001B968 File Offset: 0x00019B68
- public bool Process_Is_being(string processName)
- {
- bool result;
- try
- {
- Process[] processesByName = Process.GetProcessesByName(processName);
- bool flag = processesByName.Length != 0;
- if (flag)
- {
- result = true;
- }
- else
- {
- result = false;
- }
- }
- catch
- {
- result = false;
- }
- return result;
- }
- // Token: 0x0600018E RID: 398 RVA: 0x0001B114 File Offset: 0x00019314
- public string Service_Install_Mysql()
- {
- int num = 1;
- string text = "";
- string result;
- try
- {
- bool flag = this.Service_Is_Installed(this.b);
- if (flag)
- {
- text = this.Service_Start_Mysql();
- bool flag2 = string.IsNullOrEmpty(text);
- if (flag2)
- {
- text = "";
- }
- result = text;
- return result;
- }
- try
- {
- string text2 = "[mysqld]\r\n";
- text2 += "port=replace_port\r\n";
- text2 += "basedir=replace_basedir\r\n";
- text2 += "datadir=replace_basedirdata\r\n";
- text2 += "default-storage-engine=MyISAM\r\n";
- text2 += "wait_timeout=1814400\r\n";
- text2 += "interactive_timeout=1814400\r\n";
- text2 += "group_concat_max_len=4294967295\r\n";
- text2 += "explicit_defaults_for_timestamp=true\r\n";
- text = this.Port_In_Use(9307);
- text2 = text2.Replace("replace_basedir", this.f);
- text2 = text2.Replace("replace_port", text);
- File.WriteAllText(this.f + "my.ini", text2, new UTF8Encoding(false));
- this.delete_mysql_tmp();
- Process process = Process.Start(new ProcessStartInfo
- {
- FileName = this.f + "bin/" + this.d,
- Arguments = string.Concat(new string[]
- {
- " --install ",
- this.b,
- " --defaults-file="",
- this.f,
- "my.ini""
- }),
- WindowStyle = ProcessWindowStyle.Minimized,
- UseShellExecute = false,
- RedirectStandardInput = false,
- RedirectStandardOutput = true,
- CreateNoWindow = true
- });
- for (int i = 1; i <= 10; i++)
- {
- bool flag3 = this.Service_Is_Installed(this.b);
- if (flag3)
- {
- break;
- }
- Thread.Sleep(500);
- }
- }
- catch
- {
- num = 0;
- }
- bool flag4 = num == 1;
- if (flag4)
- {
- text = this.Service_Start_Mysql();
- bool flag5 = string.IsNullOrEmpty(text);
- if (flag5)
- {
- text = "";
- }
- }
- else
- {
- text = "";
- }
- }
- catch
- {
- text = "";
- }
- result = text;
- return result;
- }
- // Token: 0x06000191 RID: 401 RVA: 0x0001B510 File Offset: 0x00019710
- public bool Service_Is_Installed(string Service_Name)
- {
- bool result;
- try
- {
- ServiceController[] services = ServiceController.GetServices();
- ServiceController[] array = services;
- for (int i = 0; i < array.Length; i++)
- {
- ServiceController serviceController = array[i];
- bool flag = serviceController.ServiceName == Service_Name;
- if (flag)
- {
- result = true;
- return result;
- }
- }
- result = false;
- }
- catch
- {
- result = false;
- }
- return result;
- }
- // Token: 0x06000192 RID: 402 RVA: 0x0001B574 File Offset: 0x00019774
- public string Service_Start_Mysql()
- {
- string result = "";
- try
- {
- bool flag = this.Service_Is_Installed(this.b);
- if (flag)
- {
- ServiceController serviceController = new ServiceController(this.b);
- bool flag2 = serviceController.Status.ToString() == "Stopped" || serviceController.Status.ToString() == "StopPending";
- if (flag2)
- {
- serviceController.Start();
- serviceController.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 180));
- serviceController.Refresh();
- }
- bool flag3 = serviceController.Status.ToString() == "Running";
- if (flag3)
- {
- result = this.Get_Port_Mysql();
- }
- else
- {
- result = "";
- }
- }
- else
- {
- result = "";
- }
- }
- catch
- {
- result = "";
- }
- return result;
- }
- // Token: 0x06000194 RID: 404 RVA: 0x0001B740 File Offset: 0x00019940
- public string Service_Start_Nginx()
- {
- string result = "";
- try
- {
- bool flag = this.Process_Is_being(this.c);
- if (flag)
- {
- result = this.Get_Port_Nginx();
- }
- else
- {
- this.a.createdir(this.g.Replace("/", "\") + "temp\");
- Process process = Process.Start(new ProcessStartInfo
- {
- FileName = this.g + this.e,
- Arguments = "",
- WorkingDirectory = this.g,
- WindowStyle = ProcessWindowStyle.Minimized,
- UseShellExecute = false,
- RedirectStandardInput = false,
- RedirectStandardOutput = true,
- CreateNoWindow = true
- });
- for (int i = 1; i <= 10; i++)
- {
- bool flag2 = this.Process_Is_being(this.c);
- if (flag2)
- {
- break;
- }
- Thread.Sleep(500);
- }
- bool flag3 = this.Process_Is_being(this.c);
- if (flag3)
- {
- result = this.Get_Port_Nginx();
- }
- else
- {
- result = "";
- }
- }
- }
- catch
- {
- }
- return result;
- }
- // Token: 0x06000193 RID: 403 RVA: 0x0001B67C File Offset: 0x0001987C
- public bool Service_Stop_Mysql()
- {
- bool result;
- try
- {
- bool flag = this.Service_Is_Installed(this.b);
- if (flag)
- {
- ServiceController serviceController = new ServiceController(this.b);
- bool flag2 = serviceController.Status.ToString() == "Running";
- if (flag2)
- {
- serviceController.Stop();
- serviceController.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 180));
- serviceController.Refresh();
- }
- bool flag3 = serviceController.Status.ToString() == "Stopped";
- if (flag3)
- {
- result = true;
- }
- else
- {
- result = false;
- }
- }
- else
- {
- result = false;
- }
- }
- catch
- {
- result = false;
- }
- return result;
- }
- // Token: 0x06000195 RID: 405 RVA: 0x0001B894 File Offset: 0x00019A94
- public bool Service_Stop_Nginx()
- {
- bool result = false;
- this.Kill_Process(this.c);
- for (int i = 1; i <= 10; i++)
- {
- bool flag = !this.Process_Is_being(this.c);
- if (flag)
- {
- result = true;
- break;
- }
- Thread.Sleep(500);
- }
- return result;
- }
- // Token: 0x0600018F RID: 399 RVA: 0x0001B384 File Offset: 0x00019584
- public void Service_Unstall_Mysql()
- {
- try
- {
- bool flag = this.Service_Is_Installed(this.b);
- if (flag)
- {
- this.Service_Stop_Mysql();
- string command = "sc delete " + this.b;
- this.Execute(command, 1);
- }
- this.delete_mysql_tmp();
- }
- catch
- {
- }
- }
- // Token: 0x0400009D RID: 157
- private ZQGJ a = new ZQGJ();
- // Token: 0x0400009E RID: 158
- private string b = "shopfw-mysql";
- // Token: 0x0400009F RID: 159
- private string c = "shopfw-nginx";
- // Token: 0x040000A0 RID: 160
- private string d = "shopfw-mysql.exe";
- // Token: 0x040000A1 RID: 161
- private string e = "shopfw-nginx.exe";
- // Token: 0x040000A2 RID: 162
- private string f = "C:/ProgramData/shopfw/service/zqdata/";
- // Token: 0x040000A3 RID: 163
- private string g = "C:/ProgramData/shopfw/service/web/";
- }
- }
复制代码
|