예제 #1
0
        public void run()
        {
            Cleaner  SmartCleaner = new Cleaner();
            Receiver CmdReceiver  = new Receiver();
            //Decrypter CmdDecrypter = new Decrypter(SERVER_PW);
            CommandFactory  CmdFactory           = new CommandFactory();
            SenderAssistant SmartSenderAssistant = new SenderAssistant();
            Authenticator   SmartAuthenticator   = new Authenticator();
            Killer          SmartKiller          = new Killer(SmartAuthenticator);
            Executor        SmartExecutor        = new Executor(SmartAuthenticator, SmartKiller);
            //Encrypter CmdEncrypter = new Encrypter(SERVER_PW);
            Sender SmartSender = new Sender();

            while (true)
            {
                //Read password everytime.. if changing..
                SERVER_PW = readPassword();
                //Clean following things before next round..
                SmartCleaner.clean(CmdReceiver.CurrentClient);
                Logger.getReady();
                //Receive an encrypted RequestCommandStr
                byte[] encryptedRequestComand = CmdReceiver.waitForCommand();
                Logger.incomingCommand();
                //Decrypt the encrypted RequestCommand
                byte[] decryptedRequestComand = Crypto.Decrypt(encryptedRequestComand, SERVER_PW);
                //If the encrypted RequestCommandStr has got a wrong encryption..
                if (decryptedRequestComand == null)
                {
                    Logger.wrongPassword(" just wrong..");
                    SmartSenderAssistant.sendWrongPassword(CmdReceiver.CurrentClient);
                    continue;
                }
                Logger.correctPassword();
                //Extract RequestCommandStr as Command-Instance
                Command requestCommand = CommandFactory.extractCommand(decryptedRequestComand);
                //If requestCommandStr has got the wrong format..
                if (requestCommand == null)
                {
                    Logger.wrongCmdFormat(" just wrong format..");
                    SmartSenderAssistant.sendWrongCommandFormat(CmdReceiver.CurrentClient);
                    continue;
                }
                Logger.correctCmdFormat();
                if (SmartKiller.clientEntreation(requestCommand) == 1)
                {
                    continue;
                }
                //If userid too old..
                if (SmartKiller.kill(requestCommand))
                {
                    Logger.userKilled();
                    SmartSenderAssistant.sendObituary(CmdReceiver.CurrentClient);
                    SmartAuthenticator.Login = false;
                    continue;
                }
                Logger.killerForgiven();
                //If there wasn't any login before..
                if (!SmartAuthenticator.isLogin())
                {
                    Logger.noActiveUser();
                    //Client don't want to connect.. F**K CLIENT!!
                    if (SmartAuthenticator.isNoLoginCommand(requestCommand))
                    {
                        Logger.isNoLoginCommand();
                        SmartSenderAssistant.sendLoginRequired(CmdReceiver.CurrentClient);
                        continue;
                    }
                    //Client want to connect! .. let him.. PW checked before..
                    else
                    {
                        SmartKiller.LastAlive = SmartKiller.GetCurrentUnixTimestampMillis();
                        //SmartSenderAssistant.sendLoginSucceed(CmdReceiver.CurrentClient);
                        Command loginSucceedResponse = CmdFactory.createLoginSuceedCommand(SmartAuthenticator);
                        Logger.loginSucceed(SmartAuthenticator.Id);
                        SmartSender.send(loginSucceedResponse, CmdReceiver.CurrentClient);
                        continue;
                    }
                }
                //If there was a login.. Check if the user has got the correct Session-ID.. if not do this if
                if (SmartAuthenticator.isCorrectId(requestCommand) == false)
                {
                    Logger.wrongId(requestCommand.Id);
                    SmartSenderAssistant.sendWrongId(CmdReceiver.CurrentClient);
                    continue;
                }
                Logger.correctId(requestCommand.Id);
                //All was allright.. now execute command
                Command responseCommand = SmartExecutor.execute(requestCommand);
                //Encrypt and send responseCommand to client
                SmartSender.send(responseCommand, CmdReceiver.CurrentClient);
                Logger.finishedCommand();
            }
        }
예제 #2
0
 private Command saveDataOnServer(Command cmd)
 {
     XmlManager xmlManager = new XmlManager();
     List<string> allRootPaths = xmlManager.getAllChilds();
     string category = cmd.Parameter;
     string filename = cmd.Filename;
     FileManager MyFileManager = new FileManager();
     CommandFactory cmdFactory = new CommandFactory();
     //TODO: IS PATH FOR SAVING DATA ALLOWED? (NOT SOOO IMPORTANT)
     MyFileManager.saveFile(filename, cmd.Data);
     Logger.saveDataOnServer(cmd);
     return CommandFactory.createCommand(cmd.Id, SERVERNAME, STATUS, filename, "saved file", new byte[1]);
 }
예제 #3
0
 private Command thumbnail(Command cmd)
 {
     CommandFactory cmdFactory = new CommandFactory();
     Security SmartSecurity = new Security();
     XmlManager xmlManager = new XmlManager();
     List<string> allRootPaths = xmlManager.getAllChilds();
     //TODO: IS IT A REAL IMAGE????
     Image image = Image.FromFile(cmd.Filename);
     Image thumb = image.GetThumbnailImage(120, 120, () => false, IntPtr.Zero);
     ImageConverter converter = new ImageConverter();
     byte[] imgArray = (byte[])converter.ConvertTo(thumb, typeof(byte[]));
     return CommandFactory.createCommand(this.SmartAuthenticator.Id, SERVERNAME, SEND_CLIENT_THUMBNAIL, cmd.Filename, "none", imgArray);
 }
예제 #4
0
 public void run()
 {
     Cleaner SmartCleaner = new Cleaner();
     Receiver CmdReceiver = new Receiver();
     //Decrypter CmdDecrypter = new Decrypter(SERVER_PW);
     CommandFactory CmdFactory = new CommandFactory();
     SenderAssistant SmartSenderAssistant = new SenderAssistant();
     Authenticator SmartAuthenticator = new Authenticator();
     Killer SmartKiller = new Killer(SmartAuthenticator);
     Executor SmartExecutor = new Executor(SmartAuthenticator, SmartKiller);
     //Encrypter CmdEncrypter = new Encrypter(SERVER_PW);
     Sender SmartSender = new Sender();
     while(true)
     {
         //Read password everytime.. if changing..
         SERVER_PW = readPassword();
         //Clean following things before next round..
         SmartCleaner.clean(CmdReceiver.CurrentClient);
         Logger.getReady();
         //Receive an encrypted RequestCommandStr
         byte[] encryptedRequestComand = CmdReceiver.waitForCommand();
         Logger.incomingCommand();
         //Decrypt the encrypted RequestCommand
         byte[] decryptedRequestComand = Crypto.Decrypt(encryptedRequestComand,SERVER_PW);
         //If the encrypted RequestCommandStr has got a wrong encryption..
         if(decryptedRequestComand== null)
         {
             Logger.wrongPassword(" just wrong..");
             SmartSenderAssistant.sendWrongPassword(CmdReceiver.CurrentClient);
             continue;
         }
         Logger.correctPassword();
         //Extract RequestCommandStr as Command-Instance
         Command requestCommand = CommandFactory.extractCommand(decryptedRequestComand);
         //If requestCommandStr has got the wrong format..
         if(requestCommand== null)
         {
             Logger.wrongCmdFormat(" just wrong format..");
             SmartSenderAssistant.sendWrongCommandFormat(CmdReceiver.CurrentClient);
             continue;
         }
         Logger.correctCmdFormat();
         if(SmartKiller.clientEntreation(requestCommand)==1)
         {
             continue;
         }
         //If userid too old..
         if(SmartKiller.kill(requestCommand))
         {
             Logger.userKilled();
             SmartSenderAssistant.sendObituary(CmdReceiver.CurrentClient);
             SmartAuthenticator.Login = false;
             continue;
         }
         Logger.killerForgiven();
         //If there wasn't any login before..
         if(!SmartAuthenticator.isLogin())
         {
             Logger.noActiveUser();
             //Client don't want to connect.. F**K CLIENT!!
             if (SmartAuthenticator.isNoLoginCommand(requestCommand))
             {
                 Logger.isNoLoginCommand();
                 SmartSenderAssistant.sendLoginRequired(CmdReceiver.CurrentClient);
                 continue;
             }
             //Client want to connect! .. let him.. PW checked before..
             else
             {
                 SmartKiller.LastAlive = SmartKiller.GetCurrentUnixTimestampMillis();
                 //SmartSenderAssistant.sendLoginSucceed(CmdReceiver.CurrentClient);
                 Command loginSucceedResponse = CmdFactory.createLoginSuceedCommand(SmartAuthenticator);
                 Logger.loginSucceed(SmartAuthenticator.Id);
                 SmartSender.send(loginSucceedResponse, CmdReceiver.CurrentClient);
                 continue;
             }
         }
         //If there was a login.. Check if the user has got the correct Session-ID.. if not do this if
         if (SmartAuthenticator.isCorrectId(requestCommand)==false)
         {
             Logger.wrongId(requestCommand.Id);
             SmartSenderAssistant.sendWrongId(CmdReceiver.CurrentClient);
             continue;
         }
         Logger.correctId(requestCommand.Id);
         //All was allright.. now execute command
         Command responseCommand = SmartExecutor.execute(requestCommand);
         //Encrypt and send responseCommand to client
         SmartSender.send(responseCommand,CmdReceiver.CurrentClient);
         Logger.finishedCommand();
     }
 }
예제 #5
0
 private Command deleteFileFromServer(Command cmd)
 {
     Security SmartSecurity = new Security();
     XmlManager xmlManager = new XmlManager();
     List<string> allRootPaths = xmlManager.getAllChilds();
     CommandFactory cmdFactory = new CommandFactory();
     //TODO: IS FILE PATH ALLOWED?
     //if (SmartSecurity.PathIsAllowed(allRootPaths,cmd.Filename))
     //{
     FileManager fileManager = new FileManager();
     fileManager.deleteFile(cmd.Filename);
     return CommandFactory.createCommand(SmartAuthenticator.Id,SERVERNAME,STATUS,cmd.Filename,"deleted file",new byte[1]);
     //}
     //return CommandFactory.createCommand(SmartAuthenticator.Id, SERVERNAME, STATUS, cmd.Filename, "not deleted file", new byte[1]);
 }
예제 #6
0
 internal void sendWrongId(Socket currentClient)
 {
     currentClient.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", WRONG_ID, new byte[1]).toByteArr(), SocketFlags.None);
 }
예제 #7
0
 internal void sendLoginRequired(Socket currentClient)
 {
     currentClient.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", LOGIN_REQUIRED, new byte[1]).toByteArr(), SocketFlags.None);
 }
예제 #8
0
 internal void sendObituary(Socket currentClient)
 {
     currentClient.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", KILLED_BY_KILLER, new byte[1]).toByteArr(), SocketFlags.None);
 }
예제 #9
0
 internal void sendWrongCommandFormat(Socket currentClient)
 {
     currentClient.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", WRONG_COMMAND_FORMAT, new byte[1]).toByteArr(), SocketFlags.None);
 }
예제 #10
0
 public void sendWrongPassword(Socket socket)
 {
     socket.Send(CommandFactory.createCommand(-1, "SERVER", 7, "none", WRONG_PASSWORD, new byte[1]).toByteArr(), SocketFlags.None);
 }