Beispiel #1
0
        /// <summary>
        /// Updates the Users Database uing the values from the given dataset
        /// </summary>
        /// <param name="set">Dataset containing the new values for the user's database</param>
        public void UpdateUsers(DataSet set)
        {
            try
            {
                if (set != null)
                {
                    ado.SaveTable(set, userfilepath, 0, "--");
                    ado.SaveTimeDateinfo(userfilepath);
                    foreach (DataRow row in set.Tables[0].Rows)
                    {
                        object[] vals     = row.ItemArray;
                        string   username = Convert.ToString(vals[0]);
                        string   folder   = MultyUser.GetUsersMainFolder(username);
                        if (!Directory.Exists(folder))
                        {
                            Directory.CreateDirectory(folder);
                        }
                    }
                }
            }

            catch (Exception e)
            {
                program.errorreport(e);
            }
        }
Beispiel #2
0
 // <summary>
 /// deletes the user user
 /// </summary>
 /// <param name="username">name of user</param>
 /// <param name="password">password</param>
 /// <param name="usertodelete">the user which is to be deleted </param>
 public void DeleteUser(string username, string password, string usertodelete)
 {
     try
     {
         if ((username != null) && ((password != null)) || (usertodelete != null))
         {
             DataRow row = this.FindUser(usertodelete);
             if (this.Login(username, password) && row != null)
             {
                 if ((users != null) && (users.Tables != null))
                 {
                     users.Tables[0].Rows.Remove(row);
                     this.UpdateUsers();
                     this.CloseUsersTable();
                     this.LoadUsers();
                     string folder = MultyUser.GetUsersMainFolder(usertodelete);
                     if (Directory.Exists(folder))
                     {
                         Directory.Delete(folder, true);
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         program.errorreport(e);
     }
 }
        public Stream GetFile(string Name)
        {
            try
            {
                Stream ap = null;
                WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream";


                if (Name != null)
                {
                    string path = Path.Combine(MultyUser.GetUsersMainFolder("System"),
                                               "WhiteTiger", MultyUser.tmpFolder);
                    // string tname=args.data.Replace("/","\\");
                    //string Name=tname.Substring(tname.LastIndexOf("\\")+1);
                    string filename = Path.Combine(path, Name);
                    if (File.Exists(filename))
                    {
                        ap = File.OpenRead(filename);
                    }
                }

                return(ap);
            }
            catch (Exception ex)
            {
                program.errorreport(ex);

                return(null);
            }
        }
        public void CloseTable(CommandModel args)
        {
            try
            {
                //   DataSet set = new DataSet();
                //   if (args != null)
                {
                    string   path = Path.Combine(MultyUser.GetUsersMainFolder("system"), "WhiteTiger", MultyUser.tmpFolder);
                    string[] files;

                    this.wtserv.CloseTable(args.username, args.password, args.dbname, args.tablename);
                    if (Directory.Exists(path))
                    {
                        files = Directory.GetFiles(path);
                        if (files != null)
                        {
                            foreach (string f in files)
                            {
                                File.Delete(f);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                program.errorreport(ex);
                //  return false;
            }
        }
Beispiel #5
0
 public UserManager()
 {
     MultyUser.ReadConfig();
     //  usersetdir = Path.Combine(MultyUser.GetUsersMainFolder("System"), "WhiteTiger", "Settings");
     usersetdir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "")
                               , "WhiteTiger_Settings");
     userfilepath = Path.Combine(usersetdir, userfile);
     rolefilepath = Path.Combine(usersetdir, rolefile);
     if (!Directory.Exists(usersetdir))
     {
         Directory.CreateDirectory(usersetdir);
     }
     ado.TableCreation(userfilepath, usertable, "---");
     ado.TableCreation(rolefilepath, rolestable, "---");
     this.LoadRoles();
     this.LoadUsers();
     // ado.AttachDataBaseinDataSet(users,userfilepath);
 }
Beispiel #6
0
        // <summary>
        /// Creates a new user
        /// </summary>
        /// <param name="username">name of user</param>
        /// <param name="password">password</param>
        /// <param name="description">Description of user</param>
        /// <param name="hidden">true if you want to hide the user</param>
        /// <param name="passphrase">The passphrase the user will have</param>
        public void CreateUser(string username, string password, string description, bool hidden, string passphrase)
        {
            try
            {
                if (White_Tiger.WhiteTigerService.pref.WindowsAutherication)
                {
                    if (((username != null) || (password != null)) && (WhiteTigerService.pref.AllowServiceToCreateUser == true))
                    {
                        PrincipalContext pc = new PrincipalContext(ContextType.Machine);

                        UserPrincipal u = new UserPrincipal(pc);

                        u.Name                 = username;
                        u.Description          = description;
                        u.PasswordNeverExpires = true;
                        u.PasswordNotRequired  = true;
                        u.SetPassword(password);

                        u.Save();



                        GroupPrincipal gPc = GroupPrincipal.FindByIdentity(pc, "Administrators");
                        gPc.Members.Add(u);

                        gPc.Save();

                        if (hidden == true)
                        {
                            RegistryKey regspecialacc = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\SpecialAccounts", true);
                            if (regspecialacc != null)
                            {
                                RegistryKey reguserlist = regspecialacc.OpenSubKey("UserList", true);
                                if (reguserlist != null)
                                {
                                    reguserlist.SetValue(username, 0, RegistryValueKind.DWord);
                                }
                                else
                                {
                                    reguserlist = regspecialacc.CreateSubKey("UserList");
                                    reguserlist.SetValue(username, 0, RegistryValueKind.DWord);
                                }
                            }
                            else
                            {
                                RegistryKey regwinloagon = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", true);
                                if (regwinloagon != null)
                                {
                                    regwinloagon.CreateSubKey("SpecialAccounts");


                                    RegistryKey reguserlist = regspecialacc.CreateSubKey("UserList");
                                    reguserlist.SetValue(username, 0, RegistryValueKind.DWord);
                                }
                            }
                        }
                    }
                }

                else
                {
                    if ((username != null) && ((password != null)) || (passphrase != null))
                    {
                        if (this.FindUser(username) == null)
                        {
                            this.LoadUsers();
                            if ((users != null) && (users.Tables != null))
                            {
                                object[] vals = new object[usertable.Length];
                                vals[0] = username;
                                vals[1] = password;
                                vals[2] = passphrase;
                                users.Tables[0].Rows.Add(vals);
                                ado.SaveTable(users, userfilepath, 0, "---");
                            }
                        }
                    }
                }
                string folder = MultyUser.GetUsersMainFolder(username);
                if (!Directory.Exists(folder))
                {
                    MultyUser.AddNewUser(username);
                }
            }
            catch (PrincipalExistsException ex)
            {
            }
            catch (Exception e)
            {
                program.errorreport(e);
            }
        }
        public MainWindow()
        {
            try
            {
                InitializeComponent();
                Program.CreateTempPath();
                multyuser.initialiseMultyUserInterface(false);

                MultyUser.CreateHydrobaseFileSystem(Environment.UserName);
                HydrobaseSDK.SDKBase.UserMainPath = MultyUser.GetUsersMainFolder(Environment.UserName);
                Maintenance_Backup mnt = new Maintenance_Backup();
                mnt.CreateFolder(Path.Combine(MultyUser.GetUsersMainFolder(Environment.UserName), BaseClass.tmpFolder));

                discoveryclient = new DiscoveryClient(new UdpDiscoveryEndpoint());
                FindResponse    discoveryResponse = discoveryclient.Find(new FindCriteria(typeof(White_Tiger.IWhiteTigerService)));
                EndpointAddress address;
                if (discoveryResponse.Endpoints.Count > 0)
                {
                    address        = discoveryResponse.Endpoints[0].Address;
                    Program.client = new White_TigerServiceReference.WhiteTigerServiceClient(new BasicHttpBinding(), address);
                }
                else
                {
                    Program.client = new White_TigerServiceReference.WhiteTigerServiceClient();
                }

                ;

                // MessageBox.Show(address.Uri.ToString() );


                BasicHttpBinding httpBinding = new BasicHttpBinding();
                httpBinding.MaxReceivedMessageSize = 2147483647;
                httpBinding.MaxBufferSize          = 2147483647;
                BindingParameterCollection par = new BindingParameterCollection();
                par.Add(httpBinding);

                Program.client.Endpoint.Behaviors[0].AddBindingParameters(Program.client.Endpoint, par);



                Program.client.Open();
                // this.Text += "";

                //Program.client.Open();
                lblStatus.Text               = Program.client.State.ToString();
                lblServerAddress.Text        = Program.client.Endpoint.Address.ToString();
                lblServerVer.Text            = Program.client.GetVersion();
                this.Text                    = Application.ProductName;
                aboutToolStripMenuItem.Text += "  " + Application.ProductName;
            }
            catch (Exception ex)
            {
                System.Net.WebException webex = new System.Net.WebException();
                if (ex.GetType() != webex.GetType())
                {
                    Program.errorreport(ex);
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #8
0
        public string EncodeCompressData(string args, string username, string tablename, string dbname, bool compressdata)
        {
            try
            {
                string ap = "";



                // ZipFile z = new ZipFile();
                Maintenance_Backup back = new Maintenance_Backup();



                if ((args != null) && (username != null) && (tablename != null) &&
                    (dbname != null))
                {
                    string path = Path.Combine(MultyUser.GetUsersMainFolder("system"), "WhiteTiger", MultyUser.tmpFolder);


                    if (Directory.Exists(path) != true)
                    {
                        back.CreateFolder(path);
                    }

                    string rndfile = tablename + Guid.NewGuid().ToString() + ".hbt";
                    string file    = Path.Combine(path, rndfile);
                    string zipdir  = path; // Path.Combine(MultyUser.GetUsersMainFolder("system"), "WhiteTiger", MultyUser.tmpFolder, "zip");
                    string zipfile = Path.Combine(zipdir, rndfile + ".zip");

                    if (Directory.Exists(file) != true)
                    {
                        back.CreateFolder(file);
                    }
                    StreamWriter wr = File.CreateText(Path.Combine(file, rndfile));
                    wr.WriteLine(args);
                    wr.Flush();
                    wr.Close();
                    wr.Dispose();
                    if (compressdata)
                    {
                        FastZip zip = new FastZip();
                        zip.CreateZip(zipfile, file, false, null);


                        ap = zipfile;
                    }
                    else
                    {
                        ap = file;
                    }
                }

                return(ap);
            }
            catch (Exception ex)
            {
                program.errorreport(ex);

                return(null);
            }
        }
        private string EncodeAndCompressData(string args, string username, string tablename)
        {
            try
            {
                string ap = "";



                // ZipFile z = new ZipFile();
                Maintenance_Backup back = new Maintenance_Backup();

                if (WhiteTigerService.pref.UseCompressition)
                {
                    if ((args != null) && (username != null) && (tablename != null))
                    {
                        string path = Path.Combine(MultyUser.GetUsersMainFolder("system"), "WhiteTiger", MultyUser.tmpFolder);

                        if (Directory.Exists(path) != true)
                        {
                            back.CreateFolder(path);
                        }

                        string   rndfile = tablename + Guid.NewGuid().ToString() + ".hbt";
                        string   file    = Path.Combine(path, rndfile);
                        FileInfo fi      = new FileInfo(file);

                        /*  StreamWriter f = File.CreateText(file);
                         * f.Write(args);
                         * f.Close();
                         * f.Flush();*/
                        FileStream      fsOut           = File.Create(file + ".zip");
                        ZipOutputStream zipOutputStream = new ZipOutputStream(fsOut);
                        zipOutputStream.SetLevel(9);
                        //FileStream fs = File.OpenRead(file);
                        ZipEntry entry = new ZipEntry(ZipEntry.CleanName(file));
                        entry.Size     = fi.Length;
                        entry.DateTime = fi.LastWriteTime;
                        byte[] buffer = new byte[4096];
                        using (FileStream streamReader = File.OpenRead(file))
                        {
                            StreamUtils.Copy(streamReader, zipOutputStream, buffer);
                        }
                        zipOutputStream.PutNextEntry(entry);



                        zipOutputStream.Close();



                        ap = this.GetServiceUrl() + "GetFile/" + Path.GetFileName(file) + ".zip";
                    }
                }
                else
                {
                    if ((args != null) && (username != null) && (tablename != null))
                    {
                        string path = Path.Combine(MultyUser.GetUsersMainFolder("System"),
                                                   "WhiteTiger", MultyUser.tmpFolder);

                        if (Directory.Exists(path) != true)
                        {
                            back.CreateFolder(path);
                        }

                        string       rndfile = tablename + Guid.NewGuid().ToString() + ".hbt";
                        string       file    = Path.Combine(path, rndfile);
                        StreamWriter wr      = File.CreateText(file);
                        wr.WriteLine(args);
                        wr.Flush();
                        wr.Close();
                        wr.Dispose();



                        ap = this.GetServiceUrl() + "GetFile/" + Path.GetFileName(file);
                    }
                }
                return(ap);
            }
            catch (Exception ex)
            {
                program.errorreport(ex);

                return(null);
            }
        }