Example #1
0
        private void doPush(int how,string fname)
        {
            string results="";
            string[] resAr;
            bool isMe = true;
            string theFileName = pushFileName;
            string extraPath = "";
            debugMessage("-Entering doPush");
            if (how == 1)
            {
                theFileName = fname;
                extraPath = "\\messages";
            }
            try
            {
                //System.IO.FileStream myFile = System.IO.File.Open(filePath + extraPath + "\\" + theFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
                //for (int i=0;i<myFile.Length;i++)
                results += systemInventory.readTextFile(filePath + extraPath + "\\" + theFileName);
                //myFile.Close();
            }
            catch (Exception e)
            {
                debugMessage("There was a problem receiving the package. The package file was opened by an application that won't share.");
            }
               // MessageBox.Show(theFileName);
            //MessageBox.Show(results);
            resAr = results.Split("\n".ToCharArray());
            string[] temp;
            string[] temp2;
            string file = "";
            string args = "";
            string notice = "";
            string es="";
            string message = "";
            string title = System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString();
            string dnsName = System.Net.Dns.GetHostName().ToLower()	;
            string cu = getCurrentUser().ToUpper().Replace("VeraciTek\\","").ToLower();
            string[] cua = getCurrentUser().ToUpper().ToLower().Split('\\');
            if (cua.Length > 1)
                cu = cua[1];
            bool foundMe = false;
            bool isMeViaMachineName = false;
            for (int i=0;i<resAr.Length && isMe;i++)
            {
                //MessageBox.Show(resAr[i]);
                temp = resAr[i].Split("=".ToCharArray());
                //MessageBox.Show(temp.Length + "");
                if (temp.Length > 1)
                {
                    if (temp[0].ToLower().Trim() == "users")
                        if (temp[1].ToLower().Trim() != "all" && temp[1].ToLower().Trim() != "allservers")
                        {
                            //MessageBox.Show(temp[0] +"-"+ temp[1]);
                            temp2 = temp[1].Split(",".ToCharArray());
                            for (int b=0;b<temp2.Length && !foundMe;b++)
                                if (temp2[b].ToLower().Trim() == dnsName || temp2[b].ToLower().Trim() == cu)
                                {
                                    if (temp2[b].ToLower().Trim() == dnsName)
                                        isMeViaMachineName = true;
                                    foundMe = true;
                                }
                            if (!foundMe)
                                isMe = false;
                        }
                        else
                        {
                            //MessageBox.Show("gotit");
                            isMe = false;
                            if (temp[1].ToLower().Trim() == "all")
                                if (!isserver(System.Environment.MachineName))
                                {
                                    isMe = true;
                                    isMeViaMachineName = true;
                                }
                            if (temp[1].ToLower().Trim() == "allservers")
                                if (isserver(System.Environment.MachineName))
                                {
                                    isMe = true;
                                    isMeViaMachineName = true;
                                }

                        }
                    if (temp[0].ToLower().Trim() == "file")
                    {
                        file = temp[1].Trim();
                        for (int c=2;c < temp.Length; c++)
                            file += "=" + temp[c];
                    }
                    if (temp[0].ToLower().Trim() == "arguments")
                        args = temp[1].Trim();

                    if (temp[0].ToLower().Trim() == "notice")
                        notice = temp[1].Trim();

                    if (temp[0].ToLower().Trim() == "kill")
                        if (temp[1].Trim().ToLower() == "true")
                            kill = true;

                    if (temp[0].ToLower().Trim() == "message")
                    {
                        for (int m=1;m<temp.Length;m++)
                        {
                            message +=  es + temp[m].Replace("{nl}","\r\n");
                            es = "=";
                        }
                        es="";
                        message = message.Trim();
                        message = message.Replace("\\n","\n");
                    }
                    if (temp[0].ToLower().Trim() == "title")
                    {
                        title = temp[1].Trim();
                    }
                    //MessageBox.Show(temp[0] +"-"+ temp[1]);

                }

            }
            if (isMe)
            {
                file = file.Replace("%windir%", System.Environment.SystemDirectory);
             //   MessageBox.Show(file);
                if (file.CompareTo("%sendFile%") == 0)
                {
                    if (System.Windows.Forms.DialogResult.Yes == MessageBox.Show(this,title + " is trying to send you a file. Would you like to accept it?","File Transfer",System.Windows.Forms.MessageBoxButtons.YesNo,System.Windows.Forms.MessageBoxIcon.Question,System.Windows.Forms.MessageBoxDefaultButton.Button1))
                    {
                        //MessageBox.Show("getting file: " + filePath + "\\messages\\fileTransfer\\" + message);
                        this.fileTransferName = filePath + "\\messages\\fileTransfer\\" + message;
                        saveFileDialog1.FileName = message;
                        saveFileDialog1.ShowDialog();
                    }
                }
                else
                    if (file.CompareTo("%showPopup%") == 0)
                {
                    gotMessage = true;
                    this.messageTimer.Enabled=false;
                    if (!this.doNotDisturb.Checked)
                    {
                        hideMeTimer.Enabled = false;
                        showMeTimer.Enabled = true;
                        debugMessage("Showing popup! " + title + " - " + message);
                    }
                    this.noButton.Visible=false;
                    this.confirmButton.Visible=false;
                    clearWindow();
                    messageCount++;
                    messageIndex = messageCount - 1;
                    if (how == 1 || how == 2)
                    {
                        this.replyLink.Visible=true;
                        if (messageCount > 1)
                            this.prevLink.Visible=true;
                        this.timeStamp.Visible=true;
                        senders.Add(title);
                        messages.Add(message);
                        this.timeStamps.Add(System.IO.File.GetLastWriteTime(filePath + extraPath + "\\" + theFileName));
                        this.timeStamp.Text=System.IO.File.GetLastWriteTime(filePath + extraPath + "\\" + theFileName).ToString();
                        //MessageBox.Show(filePath + extraPath + "\\" + theFileName);
                    }
                    this.userInfo.Text = title + ": " + message.Replace("{nl}","\r\n");
                    this.menuItem12.Enabled = true;
                    if (this.playSound.Checked)
                        playMessageSound();
                    if (this.doNotDisturb.Checked && (message != ddmess)  && title.ToLower().Trim() != dnsName.ToLower().Trim() && title.ToLower().Trim()!=cu)
                        sendMessage(title,ddmess);
                    this.lastSender = title;
                    bool doit = true;
                    for (int i = 0; i < sendTo.Items.Count && doit; i++)
                        if (sendTo.Items[i].ToString().ToUpper() == lastSender.ToUpper())
                            doit = false;
                    if (doit)
                        sendTo.Items.Add(lastSender);
                    this.Refresh();
                }
                else
                    if (!autoUpdate.Checked && isMeViaMachineName)
                    if (message.Length > 0)
                        //	if (file.CompareTo("%showPopup%") != 0)
                        MessageBox.Show(message.Replace("\\",""),"VeraciTek Workstation - " + title,System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Information,System.Windows.Forms.MessageBoxDefaultButton.Button1,System.Windows.Forms.MessageBoxOptions.ServiceNotification);
                if (file.CompareTo("%enableSpecialFunctions%") == 0)
                {
                    this.debugMode.Visible = true;
                    this.restartButton.Visible = true;
                }
                else
                if (file.CompareTo("%enableSendMessage%") == 0)
                    {
                    this.menuItem9.Enabled = true;
                    this.sendFileItem.Enabled = true;
                    }
                else
                    if (file.CompareTo("%identify%") == 0)
                {
                    string u = getCurrentUser();
                    if (u.Split('\\').Length > 1)
                        u = u.Split('\\')[1];

                    u = u + " on " + System.Net.Dns.GetHostName().ToUpper();
                    doIdentify(u);
                }
                else
                    if (file.CompareTo("%disableSendMessage%") == 0)
                    {
                        this.menuItem9.Enabled = false;
                        this.sendFileItem.Enabled = false;
                    }
                else
                    if (file.CompareTo("%autoHide%") == 0)
                    autoHide_Click();
                else
                    if (file.CompareTo("%autoUpdate%") == 0)
                    autoUpdate_Click();
                else
                    if (file.CompareTo("%autoCloseInOrder%") == 0)
                    autoCloseInOrder_Click();
                else
                    if (file.CompareTo("%disablePops%") == 0)
                    disablePops_Click();
                else
                    if (file.CompareTo("%disableASD%") == 0)
                        disableASD_Click();
                else
                    if (file.CompareTo("%enterSend%") == 0)
                    enterSend_Click();
                else
                    if (file.CompareTo("%debugMode%") == 0)
                    debugMode_Click();
                else
                    if (file.CompareTo("%closeApp%") == 0)
                    if (notice.Length < 1)
                        closeApp(args.Split(',')[0]);
                    else
                    {
                        int timeOut = 10;
                        if (args.Split(',').Length > 1)
                            if (si.strToInt(args.Split(',')[1]) > 0)
                                timeOut = si.strToInt(args.Split(',')[1]);
                        if (isAppRunning(args.Split(',')[0]) && !this.autoCloseInOrder.Checked)
                        {
                            notifyIcon1.ShowBalloon(notice.Split('~')[0],notice.Split('~')[1],CCMClient.NotifyIconEx.NotifyInfoFlags.Info,timeOut*1000);
                            this.appToClose = args.Split(',')[0];
                            this.closeProgramTimer.Interval = timeOut*1000;
                            this.closeProgramTimer.Enabled = true;
                        }
                        //this.showMeTimer.Enabled = true;
                        //MessageBox.Show("Enabled timer with: " + timeOut);
                    }
                else
                    if (notice.Length > 0 && isMeViaMachineName)
                {
                    waitingUpdates[0] = file;
                    waitingUpdates[1] = args;
                    //MessageBox.Show(notice);
                    if (notice.Split('~').Length > 1)
                    {
                        notifyIcon1.ShowBalloon(notice.Split('~')[0],notice.Split('~')[1],CCMClient.NotifyIconEx.NotifyInfoFlags.Info,9999999);
                        debugMessage("I showed the balloon: " + notice.Split('~')[0] + " - " + notice.Split('~')[1]);
                        notifyIcon1.Icon = notifyIcon1.Icon;
                    }
                    else
                        debugMessage("Invalid Package Syntax: Notice was used but was not split by '~' between the title and text.");
                }
                else
                    if (isMeViaMachineName)
                    {
                        doExecute(file, args);
                        if (title.Length > 23)
                            title = title.Substring(0, 23);
                        if (file.IndexOf("%") != 0)
                            this.notifyIcon1.Text = notifyText + "\n-" + title;
                        updateHistory += "\n" + title + ":" + message;
                    }
            }
        }