예제 #1
0
        /// <summary>
        /// 检查更新,运行softupdate.exe
        /// </summary>
        protected void checkUpdate()
        {
            if (CheckForUpdate() > 0)
            {
                btn_Login.Enabled = true;
                btn_Login.Text    = "是否升级?";
                btn_Login.Enabled = false;

                EchoHelper.Echo("发现新内容,马上更新吗?", "软件更新", EchoHelper.EchoType.任务信息);
                string xmlFile = Application.StartupPath + @"\Temp\UpdateList.xml";
                string upStr   = new XmlFiles(xmlFile).GetNodeValue("//description");
                if (upStr.Contains("\n"))
                {
                    upStr = upStr.Split('\n')[2].ToString();
                    upStr = upStr.Trim();
                }
                DialogResult dre = MessageBox.Show("发现新内容,马上更新吗?\n" + upStr, "更新程序", MessageBoxButtons.OKCancel);
                if (dre == DialogResult.OK)
                {
                    string exe_path = Application.StartupPath;
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo.FileName         = "X_Update.exe";
                    process.StartInfo.WorkingDirectory = exe_path;
                    process.StartInfo.CreateNoWindow   = true;
                    process.Start();
                    Application.Exit();
                }
            }
            else
            {
                EchoHelper.Echo("恭喜您,您的版本已经是最新!", "软件更新", EchoHelper.EchoType.任务信息);
            }
            btn_Login.Text    = "登陆";
            btn_Login.Enabled = true;
        }
예제 #2
0
파일: Fetch.cs 프로젝트: zq535228/renzhex3
        public static void GetContentFromUrl(string url, ref string tmp_title, ref string tmp_content, string treg, string creg)
        {
            EchoHelper.EchoPickStart();

            tmp_title   = tmp_title.Replace("[标题]", "(.*?)");
            tmp_content = tmp_content.Replace("[正文]", "(.*?)");
            nextPages   = new ArrayList();

            while (url != "")
            {
                string html = FetchContent.GetDataFromUrl(url);
                nextPages.Add(url);
                if (string.IsNullOrEmpty(tmp_title))
                {
                    tmp_title = RegexHelper.getMatch(html, treg, 1);
                }
                //内容正则循环
                if (!string.IsNullOrEmpty(creg))
                {
                    string[] contentRegexs = creg.Split('\n');
                    for (int i = 0; i < contentRegexs.Length; i++)
                    {
                        string tmp = RegexHelper.getMatchs(html.Replace("\n", "`"), contentRegexs[i].ToString().Trim(), 1, "\r\n").Replace("`", "\n");
                        tmp_content += tmp;
                        tmp_content += Environment.NewLine;
                    }
                }
                url = FetchContent.GetNextPageUrl(html, url);
            }
            EchoHelper.EchoPickEnd();
        }
예제 #3
0
파일: Fetch.cs 프로젝트: zq535228/renzhex3
 public static void GetContentFromUrl(string url, ref string title, ref string content)
 {
     EchoHelper.EchoPickStart();
     try {
         url       = HttpUtility.UrlDecode(url);
         nextPages = new ArrayList();
         while (url != "")
         {
             string html = FetchContent.GetDataFromUrl(url);
             nextPages.Add(url);
             if (string.IsNullOrEmpty(title))
             {
                 title = RegexHelper.getHtmlRegexText(html, "{<title>(.*?)</title>}");
                 title = RegexHelper.regReplace(title, "_.*", "");
                 title = RegexHelper.regReplace(title, "-.*", "");
                 title = title.Replace("&nbsp;", "");
             }
             content += FetchContent.GetMainContent(html);
             url      = FetchContent.GetNextPageUrl(html, url);
             url.Trim();
         }
         if (title.Contains("<title>(.*"))
         {
             title = StringHelper.SubString(content, 0, 50);
         }
     } catch {
         title   = "";
         content = "";
         EchoHelper.Echo("采集跳过,原因可能是:该文章设置了密码、被删除、乱码等。", "采集出错", EchoHelper.EchoType.普通信息);
     }
     EchoHelper.EchoPickEnd();
 }
예제 #4
0
        private void StartSycReceive()
        {
            byte[] result = new byte[1024];//这个缓冲区,够大吗?

            if ((clientSocket = SocketHelper.GetSocket()) == null)
            {
                return;
            }

            //通过clientSocket接收数据
            int receiveLength = clientSocket.Receive(result);

            EchoHelper.Echo("接收服务端消息成功:" + Encoding.ASCII.GetString(result, 0, receiveLength), "系统登录", EchoHelper.EchoType.任务信息);
            //通过 clientSocket 发送数据
            try {
                member.strCommand = "login";
                byte[] bufs = db.ClasstoByte(member, "VCDS");
                SocketHelper.SendVarData(clientSocket, bufs);

                while (true)
                {
                    byte[]      rets     = SocketHelper.ReceiveVarData(clientSocket);
                    ModelMember remember = (ModelMember)db.BytetoClass(rets, "VCDS");

                    switch (remember.strCommand)
                    {
                    case "login":
                        if (remember.bLoginSuccess)
                        {
                            //MessageBox.Show("登录成功, 过期时间:" + ret.expire);//+ " 登录名:" + ret.netname + " 密码:" + ret.netpass);
                        }
                        else
                        {
                            MessageBox.Show(remember.strMessage);
                        }
                        break;

                    case "exit":
                        clientSocket.Shutdown(SocketShutdown.Both);
                        clientSocket.Close();
                        EchoHelper.Echo(remember.strMessage, "系统登录", EchoHelper.EchoType.错误信息);
                        Thread.Sleep(5000);
                        Environment.Exit(0);
                        break;

                    case "quit":
                        clientSocket.Shutdown(SocketShutdown.Both);
                        clientSocket.Close();
                        Environment.Exit(0);
                        return;
                    }
                }
            } catch (Exception ex) {
                //EchoHelper.EchoException(ex);
            } finally {
                clientSocket.Shutdown(SocketShutdown.Both);
                clientSocket.Close();
            }
        }
예제 #5
0
파일: Fetch.cs 프로젝트: zq535228/renzhex3
        /// <summary>
        /// 函数名称:GetDataFromUrl
        /// 功能说明:获取url指定的网页的源码
        /// 参数:string url用于指定 url
        /// 参数:ref Encoding encode用来获取网页中的字符集编码
        /// </summary>
        /// <param name="url"></param>
        /// <param name="encode"></param>
        /// <returns></returns>
        public static string GetDataFromUrl(string url)
        {
            EchoHelper.Echo("尝试链接:" + url + ",请稍等...", "内容下载", EchoHelper.EchoType.任务信息);
            CookieCollection cookies = new CookieCollection();
            string           html    = new xkHttp().httpGET(url, ref cookies);

            return(html);
        }
예제 #6
0
        public void debugVdb()
        {
            string bugs = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\把此文件发送给Qin.zip";

            ZipHelper.Zip(bugs, Application.StartupPath + @"\Config\");
            EchoHelper.Echo("数据加载出现了异常,为了分析异常数据,请上交给Qin处理!", "请提交异常数据", EchoHelper.EchoType.异常信息);
            EchoHelper.Echo("建议把桌面上的【把此文件发送给Qin.zip】文件,发送给Qin,让他来分析此数据包的问题!", "请提交异常数据", EchoHelper.EchoType.异常信息);
        }
예제 #7
0
        public X_Form_Login()
        {
            InitializeComponent();
            Form.CheckForIllegalCrossThreadCalls = false;
#if !DEBUG
            if (!new xkHttp().httpStatus())
            {
                EchoHelper.Echo("链接网络出错,请检查您的网络是否通畅!", "网络故障", EchoHelper.EchoType.错误信息);
            }
#endif
        }
예제 #8
0
        static void Main(string[] args)
        {
            int clientWidth = Screen.PrimaryScreen.Bounds.Width;

            if (clientWidth > 1000)
            {
                Console.SetWindowSize(120, 44 / 2);
            }
            else
            {
                EchoHelper.Echo("推荐使用的分辨率是:1024*800以上", null, EchoHelper.EchoType.普通信息);
            }

            DisClose();
            //设置标题
            Console.Title = "忍者X2智能站群系统 服务端状态监控中..."; //设置控制台窗口的标题
            //初始化内容
            Console.ForegroundColor = ConsoleColor.Magenta;

            #region 待更新的,美丽的CMD字体效果。
            Console.WriteLine("");
            Console.WriteLine("      ┏━┓      ┏━┓┏┓               ");
            Console.WriteLine("      ┃┃┃┏━┓┏━┓┣━┃┃┗┓┏━┓  ┏━┓┏┳┓┏━┓");
            Console.WriteLine("      ┃ ┫┃┻┫┃┃┃┃━┫┃┃┃┃┻┫┏┓┃┃┃┃┏┛┃┃┃");
            Console.WriteLine("      ┗┻┛┗━┛┗┻┛┗━┛┗┻┛┗━┛┗┛┗━┛┗┛ ┣┓┃");
            Console.WriteLine("                                  ┗━┛");


            #endregion

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("                                  --官方服务端:www.RenZhe.org");
            Console.WriteLine("");
            EchoHelper.Echo("忍者X2服务端控制台初始化完毕!", null, EchoHelper.EchoType.普通信息);


            //服务器IP地址
            IPAddress ip = IPAddress.Parse("116.255.139.227");//administrator,Zqowner3
            //IPAddress ip = IPAddress.Parse("223.4.173.93");
            //IPAddress ip = IPAddress.Parse("192.168.1.103");


            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            serverSocket.Bind(new IPEndPoint(ip, myProt)); //绑定IP地址:端口
            serverSocket.Listen(1000);                     //设定最多10个排队连接请求
            EchoHelper.Echo("启动监听9778端口成功!", "系统启动", EchoHelper.EchoType.普通信息);

            Thread myThread = new Thread(ListenClientConnect);
            myThread.IsBackground = true;
            myThread.Start();

            Console.ReadLine();
        }
예제 #9
0
 public object Read(string filePath, string key)
 {
     if (!string.IsNullOrEmpty(filePath) && !File.Exists(filePath))
     {
         EchoHelper.Echo("系统未发现数据库密钥文件,自动为您生成...", "", EchoHelper.EchoType.普通信息);
         FilesHelper.Write_File(filePath, "");
     }
     try {
         object obj = StringtoClass(FilesHelper.ReadFile(filePath, Encoding.UTF8), key);
         return(obj);
     } catch {
         return(null);
     }
 }
예제 #10
0
        public bool Delete(string classMemberObj, string fileName, mType mtype)
        {
            bool bl = false;

            try {
                bl = serv.Delete(classMemberObj, fileName, mtype);
            } catch (Exception ex) {
                ++retry;
                if (retry < 3)
                {
                    this.Delete(classMemberObj, fileName, mtype);
                }
                EchoHelper.EchoException(ex);
            }
            return(bl);
        }
예제 #11
0
        public ModelShopOne[] GetAllPutModules()
        {
            ModelShopOne[] slist = new ModelShopOne[] { };
            try {
                slist = serv.GetAllPutModules();
            } catch (Exception ex) {
                ++retry;

                if (retry < 3)
                {
                    this.GetAllPutModules();
                }
                EchoHelper.EchoException(ex);
            }
            return(slist);
        }
예제 #12
0
        public string GetClassStr(string filename, mType ty)
        {
            string str = "";

            try {
                str = serv.GetClassStr(filename, ty);
            } catch (Exception ex) {
                ++retry;

                if (retry < 3)
                {
                    this.GetClassStr(filename, ty);
                }
                EchoHelper.EchoException(ex);
            }
            return(str);
        }
예제 #13
0
        public bool UploadClassStr(string fileName, string fileClassStr, mType mtype)
        {
            bool bl = false;

            try {
                bl = serv.UploadClassStr(fileName, fileClassStr, mtype);
            } catch (Exception ex) {
                ++retry;

                if (retry < 3)
                {
                    this.UploadClassStr(fileName, fileClassStr, mtype);
                }
                EchoHelper.EchoException(ex);
            }
            return(bl);
        }
예제 #14
0
 public byte[] Decryption(byte[] data, string key)
 {
     byte[] by = new byte[0];
     if (data.Length > 0)
     {
         try {
             DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();   //实例化加解密类对象
             byte[]       KEY     = Encoding.Unicode.GetBytes(key);              //定义字节数组,用来存储密钥
             MemoryStream MStream = new MemoryStream();                          //实例化内存流对象
             //使用内存流实例化加密流对象
             CryptoStream CStream = new CryptoStream(MStream, descsp.CreateDecryptor(KEY, KEY), CryptoStreamMode.Write);
             CStream.Write(data, 0, data.Length);                              //向加密流中写入数据
             CStream.FlushFinalBlock();                                        //释放加密流
             by = MStream.ToArray();                                           //返回加密后的数组
         } catch (Exception ex) {
             EchoHelper.EchoException(ex);
         }
     }
     return(by);
 }
예제 #15
0
파일: LogUP.cs 프로젝트: zq535228/renzhex3
        /// <summary>
        ///
        /// </summary>
        /// <param name="title">文章标题</param>
        /// <param name="turl">文章地址</param>
        /// <param name="siteName">站点名</param>
        /// <param name="taskName">任务名</param>
        /// <param name="siteUrl">站点地址</param>
        public static void upToRenzheBBS(string title, string turl, string siteName, string taskName, string siteUrl)
        {
            if (turl.Contains("127.0.0.1") || turl.Contains("localhost"))
            {
                return;//如果是本机测试用的话,就不要去上传到论坛上了。
            }

            title = string.Format("【{0}-{1}】:{2}", Login_Base.member.group, Login_Base.member.netname, title);
            string content = string.Format("授权会员:{0}\n用户组别:{1}\n当前金币:{7}\n\n网站名称:{2}\n任务名称:{3}\n[hide=99999]网站地址:{4}\n\n文章标题:{5}\n文章地址:{6}[/hide]",
                                           Login_Base.member.netname,
                                           Login_Base.member.group,
                                           siteName,
                                           taskName,
                                           siteUrl,
                                           title,
                                           turl,
                                           Login_Base.member.userMoney.ToString()
                                           );

            if (title.Length > 40)
            {
                title = StringHelper.SubString(title, 0, 38);
            }
            content = content.Replace("&", "-");
            string purl   = "http://www.renzhe.org/forum.php?mod=post&action=newthread&fid=37&extra=&topicsubmit=yes";
            string pdata  = string.Format("formhash={0}&posttime=&wysiwyg=0&subject={1}&checkbox=0&message={2}&replycredit_extcredits=0&replycredit_times=1&replycredit_membertimes=1&replycredit_random=100&readperm=&price=&save=&usesig=1&allownoticeauthor=1", Login_Base.member.formhash, title, content);
            string reffer = "http://www.renzhe.org/forum.php";

            string html = new xkHttp().httpPost(purl, pdata, ref Login_Base.member.cookies, reffer, Encoding.UTF8);

            if (html.Contains("非常感谢,您的主题已发布"))
            {
                Login_Base.member.userMoney--;
                EchoHelper.Echo("上传日志成功!金币-1", "忍者X2日志系统", EchoHelper.EchoType.任务信息);
            }
            else
            {
                FilesHelper.WriteFile(Application.StartupPath + @"\Log\未知标识\【忍者X2日志】发布没有找到标志_" + DateTime.Now.Millisecond.ToString() + ".html", html, Encoding.UTF8);
                EchoHelper.Echo("跳过上传日志:随机抽取未选中。", "忍者X2日志系统", EchoHelper.EchoType.普通信息);
            }
        }
예제 #16
0
        public static string Read_File(FileInfo file)
        {
            string       tmp_result = "";
            Stream       mystream   = file.OpenRead();
            MemoryStream msTemp     = new MemoryStream();
            int          len        = 0;

            byte[] buff = new byte[512];

            while ((len = mystream.Read(buff, 0, 512)) > 0)
            {
                msTemp.Write(buff, 0, len);
            }

            if (msTemp.Length > 0)
            {
                msTemp.Seek(0, SeekOrigin.Begin);
                byte[] PageBytes = new byte[msTemp.Length];
                msTemp.Read(PageBytes, 0, PageBytes.Length);

                msTemp.Seek(0, SeekOrigin.Begin);
                int               DetLen     = 0;
                byte[]            DetectBuff = new byte[4096];
                UniversalDetector Det        = new UniversalDetector(null);
                while ((DetLen = msTemp.Read(DetectBuff, 0, DetectBuff.Length)) > 0 && !Det.IsDone())
                {
                    Det.HandleData(DetectBuff, 0, DetectBuff.Length);
                }
                Det.DataEnd();
                if (Det.GetDetectedCharset() != null)
                {
                    tmp_result = System.Text.Encoding.GetEncoding(Det.GetDetectedCharset()).GetString(PageBytes);
                }
                else
                {
                    EchoHelper.Echo("编码识别失败,请手工转码为UTF8保存到任务文件夹。文件:" + file.Name.ToLower(), "编码识别", EchoHelper.EchoType.任务信息);
                }
            }
            return(tmp_result);
        }
예제 #17
0
        /// <summary>
        /// 单击登陆按钮时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Login_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Text_PID.Text) || string.IsNullOrEmpty(Text_PWD.Text))
            {
                EchoHelper.Echo("用户名,密码不能为空,请填写!", "", EchoHelper.EchoType.普通信息);
                return;
            }
            wait.ShowMsg("2/10 准备连接服务端验证,请稍候...");
            if (ck提示更新.Checked)
            {
                ini.up("软件更新", "提示更新", ck提示更新.Checked.ToString());
            }
            //使用方法如下.
            Thread th = SearchThread("th_login");

            if (th == null)
            {
                th              = new Thread(new ThreadStart(Login));
                th.Name         = "th_login";
                th.IsBackground = true;
            }
            th.Start();
        }
예제 #18
0
        /// <summary>
        /// 窗体加载时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void X_Form_Login_Load(object sender, EventArgs e)
        {
            wait.ShowMsg("1/10 加载登录窗口中...");
            TabC_Login_SelectedIndexChanged(sender, e);
            EchoHelper.Echo("窗体加载完成!请输入忍者X2的论坛账户,论坛密码,然后登录!", null, 0);
            txtHardInfo.Text = HardWare.getHardCode();
            FileInfo file = new FileInfo(Application.ExecutablePath);

            cVer.Text         = file.LastWriteTime.ToLocalTime().ToString();
            Text_PID.Text     = ini.re("登录账户密码", "PID");
            Text_PWD.Text     = ini.re("登录账户密码", "PWD");
            btn_Login.Enabled = false;
            btn_Login.Text    = "补丁探测...";
            try {
                ck提示更新.Checked = Convert.ToBoolean(ini.re("软件更新", "提示更新"));
                if (ck提示更新.Checked)
                {
                    EchoHelper.Echo("系统正在检查是否有新版本,请您耐心等候...", "软件更新", EchoHelper.EchoType.任务信息);
                    //软件更新.
                    Thread th = SearchThread("th_update");
                    if (th == null)
                    {
                        th              = new Thread(new ThreadStart(checkUpdate));
                        th.Name         = "th_update";
                        th.IsBackground = true;
                    }
                    th.Start();
                }
            } catch (Exception ex) {
                EchoHelper.Echo(ex.Message, "加载INI出错", EchoHelper.EchoType.异常信息);
            }
            Text_PID.Focus();
            //wait.CloseMsg();
            Version v = System.Environment.Version;

            cVer.Text = v.ToString();
        }
예제 #19
0
        /// <summary>
        /// 下载更新文件到临时目录
        /// </summary>
        /// <returns></returns>
        protected void DownAutoUpdateFile(string downpath)
        {
            if (!System.IO.Directory.Exists(downpath))
            {
                System.IO.Directory.CreateDirectory(downpath);
            }
            string serverXmlFile = downpath + @"UpdateList.xml";

            try {
                WebRequest  req = WebRequest.Create(this.UpdaterUrl);
                WebResponse res = req.GetResponse();
                if (res.ContentLength > 0)
                {
                    try {
                        WebClient wClient = new WebClient();
                        wClient.DownloadFile(this.UpdaterUrl, serverXmlFile);
                    } catch (Exception ex) {
                        EchoHelper.EchoException(ex);
                    }
                }
            } catch {
                return;
            }
        }
예제 #20
0
파일: Fetch.cs 프로젝트: zq535228/renzhex3
        /// <summary>
        /// 函数名称:GetMainContent
        /// 函数功能:从内容页源码中获取正文
        /// 函数参数:html内容页源码
        /// 函数返回值:提纯后的文本
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        private static string GetMainContent(string html)
        {
            EchoHelper.Echo("哇,好大的页面,很努力的为你寻找正文内容ing,请稍等...", null, EchoHelper.EchoType.普通信息);
            string reg1 = @"<(p|br)[^<]*>";
            //string reg2 = @"(\[([^=]*)(=[^\]]*)?\][\s\S]*?\[/\1\])|(?<lj>(?<=[^\u4E00-\u9FA5\uFE30-\uFFA0,."");《])<a\s+[^>]*>[^<]{2,}</a>(?=[^\u4E00-\u9FA5\uFE30-\uFFA0,."");》]))|(?<Style><style[\s\S]+?/style>)|(?<select><select[\s\S]+?/select>)|(?<Script><script[\s\S]*?/script>)|(?<Explein><\!\-\-[\s\S]*?\-\->)|(?<li><li(\s+[^>]+)?>[\s\S]*?/li>)|(?<Html></?\s*[^> ]+(\s*[^=>]+?=['""]?[^""']+?['""]?)*?[^\[<]*>)|(?<Other>&[a-zA-Z]+;)|(?<Other2>\#[a-z0-9]{6})|(?<Space>\s+)|(\&\#\d+\;)";

            //1、获取网页的所有div标签
            List <string> list = GetTags(html, "div");

            List <string> needToRemove = new List <string>();

            foreach (string s in list)
            {
                Regex r = new Regex("[\u4e00-\u9fa5]");
                if (r.Matches(s).Count < 100)//2、去除汉字少于200字的div
                {
                    needToRemove.Add(s);
                }
                if (PercentageOfATag(s) > 0.6)//3、去除链接文字浓度过高(超过60%)的div段
                {
                    needToRemove.Add(s);
                }
            }
            //将非目标div从div链中摘除
            foreach (string s in needToRemove)
            {
                list.Remove(s);
            }

            //5、把剩下的div按汉字比例多少倒序排列,
            list.Sort(CompareDinosByChineseLength);//
            html = list[list.Count - 1];
            //6、把p和br替换成特殊的占位符[p][br]
            html = new Regex(reg1, RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(html, "[$1]");

            //7、去掉HTML标签,保留汉字
            //html = new Regex(reg2, RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(html, "");

            //8、把特殊占维护替换成回车和换行
            html = new Regex(@"\[p\]", RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(html, "\r\n  ");
            html = new Regex(@"\[br\]", RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(html, "\r\n");
            html = new Regex(@"</p>", RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(html, "\r\n");
            string[] aryReg =
            {
                @"&(quot|#34)",
                @"&(amp|#38)",
                @"&(lt|#60)",
                @"&(gt|#62)",
                @"&(nbsp|#160)",
                @"&(iexcl|#161)",
                @"&(cent|#162)",
                @"&(pound|#163)",
                @"&(copy|#169)",
                @"&#(\d+)",
            };

            string[] aryRep =
            {
                "\"",
                "&",
                "<",
                ">",
                "  ",
                "\xa1",               //chr(161),
                "\xa2",               //chr(162),
                "\xa3",               //chr(163),
                "\xa9",               //chr(169),
                "",
            };
            for (int i = 0; i < aryReg.Length; i++)
            {
                Regex regexfinal = new Regex(aryReg[i], RegexOptions.IgnoreCase);
                html = regexfinal.Replace(html, aryRep[i]);
            }
            //针对腾讯新闻内容页打的小补丁
            html = new Regex(@"(·[\s\S]+?\r\n|\[\])", RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(html, "");
            html = RegexHelper.regReplace(html, "2.*?年.*?月.*?日<br /><br />", "<br /><br />");

            EchoHelper.Echo("真不容易哇,提取成功了。...", "正文提取", EchoHelper.EchoType.普通信息);
            return(html);
        }
예제 #21
0
 private void txtHardInfo_Click(object sender, EventArgs e)
 {
     StringHelper.stringCopy(HardWare.getHardCode());
     EchoHelper.Show("复制成功:" + HardWare.getHardCode(), EchoHelper.MessageType.提示);
 }
예제 #22
0
        private bool ValidateUser(ref ModelMember member)
        {
            member.IS_X_PostKing = false;

            //验证是否具有发帖权限
            string testpostUrl = "http://www.renzhe.org/forum.php?mod=post&action=newthread&fid=36";

            string html = new xkHttp().httpGET(testpostUrl, ref member.cookies);

            if (html.Contains("发表帖子 - 忍者X2站群 -  忍者软件 -  RenZhe.org!"))
            {
                EchoHelper.Echo("恭喜您,权限核对成功,您已被授权使用忍者X2站群!", "用户验证", EchoHelper.EchoType.任务信息);
                member.strMessage    = "恭喜您,权限核对成功,您已被授权使用忍者X2站群!";
                member.IS_X_PostKing = true;
            }
            else if (html.Contains("抱歉,您需要设置自己的头像后才能进行本操作"))
            {
                EchoHelper.Echo("请完善您的(基本资料、头像),即在论坛上发个帖子激活一下。授权论坛:www.renzhe.org!", "用户验证", EchoHelper.EchoType.错误信息);
                member.strMessage = "请完善您的(基本资料、头像),即在论坛上发个帖子激活一下。授权论坛:www.renzhe.org!";
            }
            else if (html.Contains("请先绑定手机号码"))
            {
                EchoHelper.Echo("请先绑定手机号码,授权论坛:www.renzhe.org!", "用户验证", EchoHelper.EchoType.错误信息);
                member.strMessage = "请先绑定手机号码,授权论坛:www.renzhe.org!";
            }
            else if (html.Contains("<s>商业授权用户</s>"))
            {
                EchoHelper.Echo("您的账户已过期,请到论坛充值续费!", "用户验证", EchoHelper.EchoType.错误信息);
                member.strMessage = "您的账户已过期,请到论坛充值续费!";
            }
            else if (html.Contains("超时"))
            {
                EchoHelper.Echo("链接服务超时!", "用户验证", EchoHelper.EchoType.错误信息);
                member.strMessage = "链接服务超时!";
            }
            else if (html.Contains("没有权限在该版块发帖"))
            {
                EchoHelper.Echo("用户登录验证失败,请重新登录!", "用户验证", EchoHelper.EchoType.错误信息);
                member.strMessage = "用户登录验证失败,请重新登录!";
            }
            else if (html.Contains("无法解析此远程名称"))
            {
                EchoHelper.Echo("域名解析出现问题,请检查您的网络设置!", "用户验证", EchoHelper.EchoType.错误信息);
                member.strMessage = "域名解析出现问题,请检查您的网络设置!";
            }
            else
            {
                EchoHelper.Echo("验证失败,原因未知!", "用户验证", EchoHelper.EchoType.错误信息);
                member.strMessage = "验证失败,原因未知!";
            }

            if (member.group.Contains("商业授权用户"))
            {
                member.IS_X_WordPressBuild = true;
            }
            else
            {
                member.IS_X_WordPressBuild = false;
            }
            return(member.IS_X_PostKing);
        }
예제 #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="cookies"></param>
        /// <param name="refrere"></param>
        /// <param name="encoding">1gbk,2utf8,3auto</param>
        /// <param name="timeout"></param>
        /// <param name="isRedirect"></param>
        /// <returns></returns>
        public string httpGET(string url, ref CookieCollection cookies, string refrere, int encoding, int timeout, bool isRedirect)
        {
            url = getDealUrl(url);
            Stream          stream          = null;
            HttpWebResponse httpWebResponse = null;
            HttpWebRequest  httpWebRequest  = null;
            string          result;

            try {
                ServicePointManager.Expect100Continue      = false;
                ServicePointManager.DefaultConnectionLimit = 1000;
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                httpWebRequest.Headers.Clear();
                httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip;
                httpWebRequest.CookieContainer        = xkCookies.CookieContainer(cookies, url);
                httpWebRequest.KeepAlive         = true;
                httpWebRequest.ProtocolVersion   = HttpVersion.Version10;
                httpWebRequest.Method            = "GET";
                httpWebRequest.Referer           = refrere;
                httpWebRequest.Timeout           = timeout * 1000;
                httpWebRequest.AllowAutoRedirect = false;
                httpWebRequest.Accept            = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
                httpWebRequest.Headers.Add("Accept-Language", "zh-cn");
                httpWebRequest.UserAgent = useragent;
                string text = httpWebRequest.Headers.ToString();
                httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                stream          = httpWebResponse.GetResponseStream();
                xkCookies.UpCookie(ref cookies, url, httpWebResponse.Headers["Set-Cookie"], httpWebResponse.Cookies);
                string tmp_result = "";
                if (httpWebResponse.ContentEncoding.ToLower().Contains("gzip"))
                {
                    stream = new GZipStream(stream, CompressionMode.Decompress);
                }
                else
                {
                    if (httpWebResponse.ContentEncoding.ToLower().Contains("deflate"))
                    {
                        stream = new DeflateStream(stream, CompressionMode.Decompress);
                    }
                }

                Stream       mystream = httpWebResponse.GetResponseStream();
                MemoryStream msTemp   = new MemoryStream();
                int          len      = 0;
                byte[]       buff     = new byte[512];

                while ((len = mystream.Read(buff, 0, 512)) > 0)
                {
                    msTemp.Write(buff, 0, len);
                }
                httpWebResponse.Close();

                if (msTemp.Length > 0)
                {
                    msTemp.Seek(0, SeekOrigin.Begin);
                    byte[] PageBytes = new byte[msTemp.Length];
                    msTemp.Read(PageBytes, 0, PageBytes.Length);

                    msTemp.Seek(0, SeekOrigin.Begin);
                    int               DetLen     = 0;
                    byte[]            DetectBuff = new byte[4096];
                    UniversalDetector Det        = new UniversalDetector(null);
                    while ((DetLen = msTemp.Read(DetectBuff, 0, DetectBuff.Length)) > 0 && !Det.IsDone())
                    {
                        Det.HandleData(DetectBuff, 0, DetectBuff.Length);
                    }
                    Det.DataEnd();
                    if (Det.GetDetectedCharset() != null)
                    {
                        tmp_result = System.Text.Encoding.GetEncoding(Det.GetDetectedCharset()).GetString(PageBytes);
                    }
                    else
                    {
                        tmp_result = System.Text.Encoding.GetEncoding("GBK").GetString(PageBytes);
                    }
                }

                tmp_result = string.Concat(new object[]
                {
                    tmp_result,
                    "\r\n\r\n=================================================\r\n\r\n本次请求:",
                    url,
                    " 响应结果:",
                    httpWebResponse.StatusCode,
                    "\r\n\r\nCookie数量",
                    httpWebRequest.CookieContainer.Count,
                    "\r\n",
                    httpWebRequest.CookieContainer.GetCookieHeader(new Uri(url)),
                    "\r\nrequest:\r\n",
                    text,
                    "\r\nresponse:\r\n",
                    httpWebResponse.Headers.ToString(),
                    "\r\n\r\n=================================================\r\n\r\n"
                });
                if (isRedirect)
                {
                    if (httpWebResponse.Headers["Location"] != null && httpWebResponse.Headers["Location"].Length > 2)
                    {
                        string url_redirect = "";
                        if (httpWebResponse.Headers["Location"].ToLower().Contains("http://"))
                        {
                            url_redirect = httpWebResponse.Headers["Location"];
                        }
                        else
                        {
                            url_redirect = geturl(httpWebResponse.Headers["Location"], url);
                        }
                        tmp_result = httpGET(url_redirect, ref cookies, url, 3, 10, isRedirect) + tmp_result;
                    }
                    else
                    {
                        if (httpWebResponse.Headers["Refresh"] != null && httpWebResponse.Headers["Refresh"].Length > 2)
                        {
                            string text3 = httpWebResponse.Headers["Refresh"].ToLower().Replace("url=", "`").Split('`')[1];
                            if (!text3.Contains("http://"))
                            {
                                text3 = geturl(text3, url);
                            }
                            tmp_result = httpGET(text3, ref cookies, url, 3, 10, isRedirect) + tmp_result;
                        }
                    }
                    if (tmp_result.Contains("Refresh"))
                    {
                        Winista.Text.HtmlParser.Util.NodeList htmlNodes = new Parser(new Lexer(tmp_result)).Parse(new TagNameFilter("meta"));
                        if (htmlNodes.Count > 1)
                        {
                            for (int i = 0; i < htmlNodes.Count; i++)
                            {
                                MetaTag option = (MetaTag)htmlNodes.ElementAt(i);
                                if (option.GetAttribute("http-equiv") == "Refresh")
                                {
                                    string content = option.GetAttribute("content");
                                    string text3   = content.ToLower().Replace("url=", "`").Split('`')[1];

                                    if (!text3.Contains("http://"))
                                    {
                                        text3 = geturl(text3, url);
                                    }
                                    tmp_result = httpGET(text3, ref cookies, url, 3, 10, isRedirect) + tmp_result;
                                }
                            }
                        }
                    }
                }
                httpWebResponse.Close();
                httpWebRequest.Abort();
                result = tmp_result;

                if (!url.Contains(":8888") && !url.Contains("renzhe") && !url.Contains("zq535228") && !url.Contains("whoissoft") && !url.Contains("chinaz"))
                {
                    EchoHelper.Echo(string.Format("成功获取:{0}的HTML内容。", url), null, EchoHelper.EchoType.普通信息);
                }
            } catch (Exception ex) {
                result = ex.Message;
            } finally {
                if (stream != null)
                {
                    stream.Close();
                }
                if (httpWebResponse != null)
                {
                    httpWebResponse.Close();
                }
                if (httpWebRequest != null)
                {
                    httpWebRequest.Abort();
                }
            }
            return(result);
        }
예제 #24
0
        public Encoding getEncoding(string url)
        {
            lock ("getEncoding") {
                try {
                    Thread.Sleep(700);
                    if (!url.Contains("www.renzhe.org"))
                    {
                        EchoHelper.Echo("自动分析网页编码,请稍等...", null, EchoHelper.EchoType.普通信息);
                    }
                    Encoding encode;
                    //建立HTTP请求
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method      = "GET";
                    request.Timeout     = 30000;
                    request.ContentType = "text/plain";
                    //获取HTTP响应
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    //根据http应答的http头来判断编码
                    string characterSet = response.CharacterSet;

                    if (characterSet != "")
                    {
                        if (characterSet == "ISO-8859-1")
                        {
                            characterSet = "gb2312";
                        }
                        encode = Encoding.GetEncoding(characterSet);
                    }
                    else
                    {
                        encode = Encoding.Default;
                    }
                    //获取HTTP响应流
                    Stream       stream = response.GetResponseStream();
                    StreamReader sr     = new StreamReader(stream, encode);
                    string       text   = sr.ReadToEnd();//获取到html代码到text中

                    //第二次判断网页编码
                    Regex           reg = new Regex(@"<meta[\s\S]+?charset=(.*?)""[\s\S]+?>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    MatchCollection mc  = reg.Matches(text);
                    if (mc.Count > 0)
                    {
                        string tempCharSet = mc[0].Result("$1");
                        if (string.Compare(tempCharSet, characterSet, true) != 0)
                        {
                            encode = Encoding.GetEncoding(tempCharSet);
                        }
                    }

                    stream.Close();
                    if (!url.Contains("www.renzhe.org"))
                    {
                        EchoHelper.Echo("网页编码分析成功,该URL的编码是:" + encode.EncodingName + ",停顿1秒后继续...", null, EchoHelper.EchoType.普通信息);
                    }
                    Thread.Sleep(700);
                    return(encode);
                } catch {
                    return(Encoding.Default);
                }
            }
        }
예제 #25
0
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <param name="clientSocket"></param>
        private static void ReceiveMessage(object clientSocket)
        {
            Program p = new Program();
            Socket  myClientSocket = (Socket)clientSocket;

            byte[]      mmbytes = SocketHelper.ReceiveVarData(myClientSocket);
            ModelMember member  = null;

            try {
                member = (ModelMember)db.BytetoClass(mmbytes, "VCDS");
                string ipaddress = IPAddress.Parse(((IPEndPoint)myClientSocket.RemoteEndPoint).Address.ToString()).ToString();

                switch (member.strCommand)
                {
                case "login":
                    EchoHelper.Echo("接收客户端(" + ipaddress + ")登录名:" + member.netname + "密码:" + member.netpass, "接收信息", EchoHelper.EchoType.普通信息);

                    //用户cookies服务器端验证。
                    if (p.ValidateUser(ref member))
                    {
                        member.strCommand    = "login";
                        member.bLoginSuccess = true;
                    }
                    else
                    {
                        member.strCommand    = "exit";
                        member.bLoginSuccess = false;
                    }

                    ClientItem tmp = null;
                    if ((tmp = p.CheckUserExist(member)) != null && member.bLoginSuccess && member.ipaddress != tmp.clientMember.ipaddress)
                    {
                        //此时用户名和密码同时相同,开始踢客户端.
                        tmp.clientMember.strCommand = "exit";
                        tmp.clientMember.strMessage = "您的账户在另一地点登录:" + ipaddress + ",您被迫下线!建议您修改密码!";
                        byte[] senddata = db.ClasstoByte(tmp.clientMember, "VCDS");
                        if (!tmp.clientSocket.Connected)
                        {
                            tmp.clientSocket.Connect(tmp.clientSocket.RemoteEndPoint);
                        }
                        member = tmp.clientMember.CopyTo();
                        //删除前一客户端
                        clientList.Remove(tmp);
                        EchoHelper.Echo(member.netname + "(" + member.ipaddress + "),被踢下线了!", "用户验证", EchoHelper.EchoType.错误信息);
                        SocketHelper.SendVarData(tmp.clientSocket, senddata);
                        tmp.clientSocket.Shutdown(SocketShutdown.Both);
                        tmp.clientSocket.Close();
                    }

                    //记录当前客户端.
                    member.ipaddress = ipaddress;
                    ClientItem cur = new ClientItem()
                    {
                        clientMember = member, clientSocket = myClientSocket
                    };

                    byte[] curdata = db.ClasstoByte(member, "VCDS");
                    SocketHelper.SendVarData(myClientSocket, curdata);
                    if (member.bLoginSuccess)
                    {
                        clientList.Add(cur);
                    }
                    break;

                case "closeform":
                    member.ipaddress = ipaddress;
                    if ((tmp = p.GetUser(member)) != null)
                    {
                        clientList.Remove(tmp);
                        EchoHelper.Echo(member.netname + "(" + member.ipaddress + "),下线了.", "用户验证", EchoHelper.EchoType.任务信息);
                        //member.strCommand = "quit";
                        //byte[] quitdatas = db.ClasstoByte(member, "VCDS");
                        //SocketHelper.SendVarData(tmp.clientSocket, quitdatas);
                    }
                    break;

                default:
                    break;
                }
            } catch (Exception ex) {
                EchoHelper.Echo("quit" + ex.Message, "exception", EchoHelper.EchoType.异常信息);
            }
        }
예제 #26
0
        /// <summary>
        /// 验证用户,通过网络
        /// </summary>
        /// <param name="netname"></param>
        /// <param name="netpass"></param>
        /// <param name="hdinfo"></param>
        /// <returns></returns>
        protected ModelMember getUser(string netname, string netpass, string hdinfo)
        {
#if DEBUG
            member.netname             = "调试模式";
            member.group               = "商业授权用户";
            member.sitenum             = 9999;
            member.IS_X_WordPressBuild = true;
            member.IS_X_PostKing       = true;
            member.userMoney           = 9999;
            return(Login_Base.member);
#endif
            string           path    = Application.StartupPath + "\\Config\\RenZheMember.txt";
            string           html    = "";
            DbTools          db      = new DbTools();
            CookieCollection cookies = new CookieCollection();

            try {
                object obj = db.Read(path, "VCDS");
                if (obj != null)
                {
                    member = (ModelMember)obj;
                }

                EchoHelper.Echo("连接【忍者软件】用户服务端,进行通信。此过程稍慢,请稍候...", "系统登录", EchoHelper.EchoType.任务信息);

                //发现有不符的情况,将进行登录验证。
                if (member.logintime.Date < DateTime.Now.Date || member.netpass != netpass || member.netname != netname || member.hdinfo != HardWare.getHardCode())
                {
                    string purl  = "http://www.renzhe.org/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1";
                    string pdata = "fastloginfield=username&username="******"&password="******"&quickforward=yes&handlekey=ls";
                    html = new xkHttp().httpPost(purl, pdata, ref cookies, purl, Encoding.GetEncoding("utf-8"));

                    if (html.Contains(">window.location.href='"))
                    {
                        wait.ShowMsg("4/10 您的账户、密码验证成功!");
                        EchoHelper.Echo("论坛账户、密码验证成功!", "系统登录", EchoHelper.EchoType.任务信息);
                        purl = "http://www.renzhe.org/home.php?mod=spacecp&ac=credit";
                        html = new xkHttp().httpGET(purl, ref cookies);
                        if (html.Contains("[ 点击这里返回上一页 ]"))
                        {
                            EchoHelper.Echo("忍者服务端维护,暂时关闭,请稍后再试...", "系统登录", EchoHelper.EchoType.错误信息);
                            return(member);
                        }
                        if (html.Contains("您需要先登录才能继续本操作"))
                        {
                            EchoHelper.Echo("您的账号异常,请手工登录论坛检查账户问题!", "系统登录", EchoHelper.EchoType.错误信息);
                            return(member);
                        }
                        if (html.Contains("抱歉,您的 IP 地址不在被允许,或您的账号被禁用,无法访问本站点"))
                        {
                            EchoHelper.Echo("抱歉,您的 IP 地址不在被允许,或您的账号被禁用,无法访问本站点!", "系统登录", EchoHelper.EchoType.错误信息);
                            return(member);
                        }

                        wait.ShowMsg("5/10 您的用户基本信息,获取成功!");
                        EchoHelper.Echo("您的用户基本信息,获取成功!", "系统登录", EchoHelper.EchoType.任务信息);
                        member.UID           = RegexHelper.getHtmlRegexText(html, "{discuz_uid = '(.*?)'}");
                        member.netname       = RegexHelper.getHtmlRegexText(html, "{title=\"访问我的空间\">(.*?)</a>}");
                        member.sitenum       = Convert.ToInt32(RegexHelper.getHtmlRegexText(html, "{站点数:</em>(.*?) </li>}"));
                        member.group         = RegexHelper.getHtmlRegexText(html, "{showUpgradeinfo\\)\">(.*?)</a>}");
                        member.userMoney     = Convert.ToInt32(RegexHelper.getHtmlRegexText(html, "{金币:</em>(.*?)  &nbsp;}"));
                        member.formhash      = RegexHelper.getHtmlRegexText(html, "{formhash=(.*?)\">退出</a>}");
                        member.cookies       = cookies;
                        member.netpass       = netpass;
                        member.logintime     = DateTime.Now;
                        member.hdinfo        = HardWare.getHardCode();
                        member.IS_X_PostKing = true;
                        EchoHelper.Echo("链接服务端,判断应用授权状态...", "系统登录", EchoHelper.EchoType.任务信息);
                        wait.ShowMsg("6/10 链接服务端,判断应用授权状态!");
                    }
                    else
                    {
                        wait.ShowMsg("用户验证失败...");
                        string result = "未知,请重试,登录论坛联系管理员。www.renzhe.org";
                        if (html.Contains("登录失败"))
                        {
                            result = "请核对您的用户名密码!登录论坛联系管理员。www.renzhe.org";
                        }
                        if (html.Contains("showWindow('login', 'member.php?mod=logging&action="))
                        {
                            result = "发现安全问题,清除您的安全问题后,再尝试!www.renzhe.org";
                        }
                        if (html.Contains("密码错误次数过多"))
                        {
                            result = "密码错误次数过多,稍后再试!登录论坛联系管理员。www.renzhe.org";
                        }
                        if (html.Contains("无法解析此远程名称"))
                        {
                            result = "无法解析www.renzhe.org,请检查您的网络,稍后再试";
                        }

                        member.IS_X_PostKing       = false;
                        member.IS_X_WordPressBuild = false;

                        EchoHelper.Echo("登录失败:" + result, "系统登录", EchoHelper.EchoType.错误信息);
                        return(member);
                    }
                }
                else
                {
                    wait.ShowMsg("7/10 发现本地密钥,进行快捷登录...");
                    EchoHelper.Echo("发现本地登录密钥文件,进行验证,请稍后...", "系统登录", EchoHelper.EchoType.任务信息);
                }

#if !DEBUG
                //向服务端提交member序列化的类,然后验证是否为登录成功的状态。
                ValidateUser(ref member);
#else
                //ValidateUser(ref member);
#endif

                ini.up("登录账户密码", "INFO", member.netname);
                if (member.IS_X_PostKing == false)
                {
                    member.logintime = DateTime.Now.AddDays(-111);
                    FilesHelper.DeleteFile(path);
                }
                else
                {
                    wait.ShowMsg("8/10 恭喜,您的密钥经服务端验证成功!");
                    EchoHelper.Echo("恭喜,您的本地密钥,经服务端验证成功,通信一切正常!", "系统登录", EchoHelper.EchoType.任务信息);
                }
            } catch (Exception ex) {
                FilesHelper.DeleteFile(path);
                EchoHelper.Echo("与服务端通信失败!" + ex.Message, "系统登录", EchoHelper.EchoType.异常信息);
            } finally {
                if (member.group.Contains("商业"))
                {
                    member.IS_X_WordPressBuild = true;
                }

                if (member.IS_X_PostKing == true)
                {
                    wait.ShowMsg("9/10 密钥已保存,下次可快捷登录!");
                    Thread.Sleep(1200);
                    EchoHelper.Echo("您的本地密钥已保存,下次可快捷登录!", "系统登录", EchoHelper.EchoType.任务信息);
                    db.Save(path, "VCDS", member);
                }
            }
            return(Login_Base.member);
        }
예제 #27
0
        static void Main(string[] args)
        {
            //MainForm f = new MainForm();

#if DEBUG
            //             X_Form_MainFormBrowser f = new X_Form_MainFormBrowser();
            //             f.ShowDialog();
            //             return;
            //X_Form_MainFormBrowser x = new X_Form_MainFormBrowser();
            //x.GotoPage("http://www.baidu.com/");
            //return;
#endif
            int clientWidth = Screen.PrimaryScreen.Bounds.Width;
            if (clientWidth > 1000)
            {
                Console.SetWindowSize(120, 44 / 2);
            }
            else
            {
                EchoHelper.Echo("推荐使用的分辨率是:1024*800以上", null, EchoHelper.EchoType.普通信息);
            }

            //Qin添加的 只开一个实例
            bool Exist = false;
            System.Diagnostics.Process   CIP  = System.Diagnostics.Process.GetCurrentProcess( );
            System.Diagnostics.Process[] CIPR = System.Diagnostics.Process.GetProcesses( );
            foreach (System.Diagnostics.Process p in CIPR)
            {
                if (p.ProcessName == CIP.ProcessName && p.Id != CIP.Id)
                {
                    Exist = true;
                }
            }
            if (Exist)
            {
#if !DEBUG
                KryptonMessageBox.Show("对不起,应用程序正在运行中,请不要重复启动!");
                return;
#endif
            }

            DisClose( );
            //设置标题
            Console.Title = "忍者X2智能站群系统 运行状态监控中..."; //设置控制台窗口的标题
            //初始化内容
            Console.ForegroundColor = ConsoleColor.Magenta;

            #region 待更新的,美丽的CMD字体效果。
            Console.WriteLine("");
            Console.WriteLine("      ┏━┓      ┏━┓┏┓               ");
            Console.WriteLine("      ┃┃┃┏━┓┏━┓┣━┃┃┗┓┏━┓  ┏━┓┏┳┓┏━┓");
            Console.WriteLine("      ┃ ┫┃┻┫┃┃┃┃━┫┃┃┃┃┻┫┏┓┃┃┃┃┏┛┃┃┃");
            Console.WriteLine("      ┗┻┛┗━┛┗┻┛┗━┛┗┻┛┗━┛┗┛┗━┛┗┛ ┣┓┃");
            Console.WriteLine("                                  ┗━┛");


            #endregion

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("                                  --官方网站:www.RenZhe.org");
            Console.WriteLine("");
            EchoHelper.Echo("忍者X2控制台初始化完毕!", null, EchoHelper.EchoType.普通信息);

            //初始化窗体
            Application.EnableVisualStyles( );
            Application.SetCompatibleTextRenderingDefault(false);

            //检查是否具有可写入的权限
            try {
                X_Service.Files.FilesHelper.WriteFile(Application.StartupPath + @"\Temp\test.txt", "文件写入权限测试!", Encoding.UTF8);
            } catch {
                EchoHelper.Echo("此系统中,忍者站群写入权限不足,请以管理员的身份运行!", "系统权限不足", EchoHelper.EchoType.异常信息);
            }
            //初始化登陆
            X_Form_Login Login = new X_Form_Login( );

            DialogResult dr = Login.ShowDialog( );
            if (dr == DialogResult.OK)
            {
                //    Login.Dispose();//释放
                //    Login.Close();

                Application.Run(new X_Platform( ));    //运行主界面

                //    EchoHelper.Echo("保存信息中...", null, 0);
                //    Thread.Sleep(500);
                //    EchoHelper.Echo("保存成功!...系统退出...", null, EchoHelper.EchoType.普通信息);
                //}
                //else
                //{
                //    EchoHelper.Echo("登陆未完成...关闭窗体!", null, EchoHelper.EchoType.普通信息);
            }

            //Thread.Sleep(500);
            //CIP.Kill();
            //Application.ExitThread();
            //Application.Exit();
        }
예제 #28
0
        private List <SMB1Command> ProcessSMB1Command(SMB1Header header, SMB1Command command, SMB1ConnectionState state)
        {
            if (command is SessionSetupAndXRequest)
            {
                SessionSetupAndXRequest request = (SessionSetupAndXRequest)command;
                state.MaxBufferSize = request.MaxBufferSize;
                return(SessionSetupHelper.GetSessionSetupResponse(header, request, m_securityProvider, state));
            }
            else if (command is SessionSetupAndXRequestExtended)
            {
                SessionSetupAndXRequestExtended request = (SessionSetupAndXRequestExtended)command;
                state.MaxBufferSize = request.MaxBufferSize;
                return(SessionSetupHelper.GetSessionSetupResponseExtended(header, request, m_securityProvider, state));
            }
            else if (command is EchoRequest)
            {
                return(EchoHelper.GetEchoResponse((EchoRequest)command));
            }
            else
            {
                SMB1Session session = state.GetSession(header.UID);
                if (session == null)
                {
                    header.Status = NTStatus.STATUS_USER_SESSION_DELETED;
                    return(new ErrorResponse(command.CommandName));
                }

                if (command is TreeConnectAndXRequest)
                {
                    return(TreeConnectHelper.GetTreeConnectResponse(header, (TreeConnectAndXRequest)command, state, m_services, m_shares));
                }
                else if (command is LogoffAndXRequest)
                {
                    state.LogToServer(Severity.Information, "Logoff: User '{0}' logged off. (UID: {1})", session.UserName, header.UID);
                    m_securityProvider.DeleteSecurityContext(ref session.SecurityContext.AuthenticationContext);
                    state.RemoveSession(header.UID);
                    return(new LogoffAndXResponse());
                }
                else
                {
                    ISMBShare share = session.GetConnectedTree(header.TID);
                    if (share == null)
                    {
                        state.LogToServer(Severity.Verbose, "{0} failed. Invalid TID (UID: {1}, TID: {2}).", command.CommandName, header.UID, header.TID);
                        header.Status = NTStatus.STATUS_SMB_BAD_TID;
                        return(new ErrorResponse(command.CommandName));
                    }

                    if (command is CreateDirectoryRequest)
                    {
                        return(FileStoreResponseHelper.GetCreateDirectoryResponse(header, (CreateDirectoryRequest)command, share, state));
                    }
                    else if (command is DeleteDirectoryRequest)
                    {
                        return(FileStoreResponseHelper.GetDeleteDirectoryResponse(header, (DeleteDirectoryRequest)command, share, state));
                    }
                    else if (command is CloseRequest)
                    {
                        return(CloseHelper.GetCloseResponse(header, (CloseRequest)command, share, state));
                    }
                    else if (command is FlushRequest)
                    {
                        return(ReadWriteResponseHelper.GetFlushResponse(header, (FlushRequest)command, share, state));
                    }
                    else if (command is DeleteRequest)
                    {
                        return(FileStoreResponseHelper.GetDeleteResponse(header, (DeleteRequest)command, share, state));
                    }
                    else if (command is RenameRequest)
                    {
                        return(FileStoreResponseHelper.GetRenameResponse(header, (RenameRequest)command, share, state));
                    }
                    else if (command is QueryInformationRequest)
                    {
                        return(FileStoreResponseHelper.GetQueryInformationResponse(header, (QueryInformationRequest)command, share, state));
                    }
                    else if (command is SetInformationRequest)
                    {
                        return(FileStoreResponseHelper.GetSetInformationResponse(header, (SetInformationRequest)command, share, state));
                    }
                    else if (command is ReadRequest)
                    {
                        return(ReadWriteResponseHelper.GetReadResponse(header, (ReadRequest)command, share, state));
                    }
                    else if (command is WriteRequest)
                    {
                        return(ReadWriteResponseHelper.GetWriteResponse(header, (WriteRequest)command, share, state));
                    }
                    else if (command is CheckDirectoryRequest)
                    {
                        return(FileStoreResponseHelper.GetCheckDirectoryResponse(header, (CheckDirectoryRequest)command, share, state));
                    }
                    else if (command is WriteRawRequest)
                    {
                        // [MS-CIFS] 3.3.5.26 - Receiving an SMB_COM_WRITE_RAW Request:
                        // the server MUST verify that the Server.Capabilities include CAP_RAW_MODE,
                        // If an error is detected [..] the Write Raw operation MUST fail and
                        // the server MUST return a Final Server Response [..] with the Count field set to zero.
                        return(new WriteRawFinalResponse());
                    }
                    else if (command is SetInformation2Request)
                    {
                        return(FileStoreResponseHelper.GetSetInformation2Response(header, (SetInformation2Request)command, share, state));
                    }
                    else if (command is LockingAndXRequest)
                    {
                        return(LockingHelper.GetLockingAndXResponse(header, (LockingAndXRequest)command, share, state));
                    }
                    else if (command is OpenAndXRequest)
                    {
                        return(OpenAndXHelper.GetOpenAndXResponse(header, (OpenAndXRequest)command, share, state));
                    }
                    else if (command is ReadAndXRequest)
                    {
                        return(ReadWriteResponseHelper.GetReadResponse(header, (ReadAndXRequest)command, share, state));
                    }
                    else if (command is WriteAndXRequest)
                    {
                        return(ReadWriteResponseHelper.GetWriteResponse(header, (WriteAndXRequest)command, share, state));
                    }
                    else if (command is FindClose2Request)
                    {
                        return(CloseHelper.GetFindClose2Response(header, (FindClose2Request)command, state));
                    }
                    else if (command is TreeDisconnectRequest)
                    {
                        return(TreeConnectHelper.GetTreeDisconnectResponse(header, (TreeDisconnectRequest)command, share, state));
                    }
                    else if (command is TransactionRequest) // Both TransactionRequest and Transaction2Request
                    {
                        return(TransactionHelper.GetTransactionResponse(header, (TransactionRequest)command, share, state));
                    }
                    else if (command is TransactionSecondaryRequest) // Both TransactionSecondaryRequest and Transaction2SecondaryRequest
                    {
                        return(TransactionHelper.GetTransactionResponse(header, (TransactionSecondaryRequest)command, share, state));
                    }
                    else if (command is NTTransactRequest)
                    {
                        return(NTTransactHelper.GetNTTransactResponse(header, (NTTransactRequest)command, share, state));
                    }
                    else if (command is NTTransactSecondaryRequest)
                    {
                        return(NTTransactHelper.GetNTTransactResponse(header, (NTTransactSecondaryRequest)command, share, state));
                    }
                    else if (command is NTCreateAndXRequest)
                    {
                        return(NTCreateHelper.GetNTCreateResponse(header, (NTCreateAndXRequest)command, share, state));
                    }
                    else if (command is NTCancelRequest)
                    {
                        CancelHelper.ProcessNTCancelRequest(header, (NTCancelRequest)command, share, state);
                        // [MS-CIFS] The SMB_COM_NT_CANCEL command MUST NOT send a response.
                        return(new List <SMB1Command>());
                    }
                }
            }

            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
            return(new ErrorResponse(command.CommandName));
        }