Tuesday, 27 December 2016

How To Connect Mongo DB Using RoboMongo.



1. Please visit the RoboMongo, and download the RoboMongo.
2. After extracting the zip file, execute the RoboMongo.exe, and you will find the screen as below:














3. Now, to connect a MongoDB, we need to provide connection string. For the same, we need to click on Create link and we get the a screen as follows:














4. Now, we will provide Connection Name, Address and Port for a database as highlighted. We provide user name and password in Authentication tab, and test the connection. It will look as follows:














5. Now, we will select the connection string and click connect.














6. Once connected, we will see the DB listed in Mongo DB, as follows:













Monday, 26 December 2016

The ICACLS Command



The icacls command enables a user to view and modify the ACLs(Access Control List) of a file. The icacls command is an external command and is available in the below Microsoft operating systems as icacls.exe.
  • Windows Vista
  • Windows 7
  • Windows 8
  • Windows 10
The Icacls command help can be found by using : icacls /?



ICACLS name /save aclfile [/T] [/C] [/L] [/Q]
    stores the DACLs for the files and folders that match the name
    into aclfile for later use with /restore. Note that SACLs,
    owner, or integrity labels are not saved.

ICACLS directory [/substitute SidOld SidNew [...]] /restore aclfile
                 [/C] [/L] [/Q]
    applies the stored DACLs to files in directory.

ICACLS name /setowner user [/T] [/C] [/L] [/Q]
    changes the owner of all matching names. This option does not
    force a change of ownership; use the takeown.exe utility for
    that purpose.

ICACLS name /findsid Sid [/T] [/C] [/L] [/Q]
    finds all matching names that contain an ACL
    explicitly mentioning Sid.

ICACLS name /verify [/T] [/C] [/L] [/Q]
    finds all files whose ACL is not in canonical form or whose
    lengths are inconsistent with ACE counts.

ICACLS name /reset [/T] [/C] [/L] [/Q]
    replaces ACLs with default inherited ACLs for all matching files.

ICACLS name [/grant[:r] Sid:perm[...]]
       [/deny Sid:perm [...]]
       [/remove[:g|:d]] Sid[...]] [/T] [/C] [/L] [/Q]
       [/setintegritylevel Level:policy[...]]

    /grant[:r] Sid:perm grants the specified user access rights. With :r,
        the permissions replace any previouly granted explicit permissions.
        Without :r, the permissions are added to any previously granted
        explicit permissions.

    /deny Sid:perm explicitly denies the specified user access rights.
        An explicit deny ACE is added for the stated permissions and
        the same permissions in any explicit grant are removed.

    /remove[:[g|d]] Sid removes all occurrences of Sid in the ACL. With
        :g, it removes all occurrences of granted rights to that Sid. With
        :d, it removes all occurrences of denied rights to that Sid.

    /setintegritylevel [(CI)(OI)]Level explicitly adds an integrity
        ACE to all matching files.  The level is to be specified as one
        of:
            L[ow]
            M[edium]
            H[igh]
        Inheritance options for the integrity ACE may precede the level
        and are applied only to directories.

    /inheritance:e|d|r
        e - enables inheritance
        d - disables inheritance and copy the ACEs
        r - remove all inherited ACEs


Note:
    Sids may be in either numerical or friendly name form. If a numerical
    form is given, affix a * to the start of the SID.

    /T indicates that this operation is performed on all matching
        files/directories below the directories specified in the name.

    /C indicates that this operation will continue on all file errors.
        Error messages will still be displayed.

    /L indicates that this operation is performed on a symbolic link
       itself versus its target.

    /Q indicates that icacls should supress success messages.

    ICACLS preserves the canonical ordering of ACE entries:
            Explicit denials
            Explicit grants
            Inherited denials
            Inherited grants

    perm is a permission mask and can be specified in one of two forms:
        a sequence of simple rights:
                N - no access
                F - full access
                M - modify access
                RX - read and execute access
                R - read-only access
                W - write-only access
                D - delete access
        a comma-separated list in parentheses of specific rights:
                DE - delete
                RC - read control
                WDAC - write DAC
                WO - write owner
                S - synchronize
                AS - access system security
                MA - maximum allowed
                GR - generic read
                GW - generic write
                GE - generic execute
                GA - generic all
                RD - read data/list directory
                WD - write data/add file
                AD - append data/add subdirectory
                REA - read extended attributes
                WEA - write extended attributes
                X - execute/traverse
                DC - delete child
                RA - read attributes
                WA - write attributes
        inheritance rights may precede either form and are applied
        only to directories:
                (OI) - object inherit
                (CI) - container inherit
                (IO) - inherit only
                (NP) - don't propagate inherit
                (I) - permission inherited from parent container

Examples:

        icacls c:\windows\* /save AclFile /T
        - Will save the ACLs for all files under c:\windows
          and its subdirectories to AclFile.

        icacls c:\windows\ /restore AclFile
        - Will restore the Acls for every file within
          AclFile that exists in c:\windows and its subdirectories.

        icacls file /grant Administrator:(D,WDAC)
        - Will grant the user Administrator Delete and Write DAC
          permissions to file.

        icacls file /grant *S-1-1-0:(D,WDAC)
        - Will grant the user defined by sid S-1-1-0 Delete and
          Write DAC permissions to file.


How To Control Running Services With The SC Command [Windows]




The "sc" command comes with numerous sub-commands. A list can be seen by entering "sc /?" into a command prompt. Altogether, 24 sub-commands are listed. Each sub-command in turn may have a subset of different commands. The table below shows a selection of the sub-commands and their functions that are of most relevance to a typical PC owner.

Command Function

sc config Configures service startup and login accounts

sc continue Resumes a paused service

sc enumdepend Lists the services that cannot run unless the specified service is running

sc failure Specifies what action to take upon failure of the service

sc pause Pauses a service

sc qc Displays the configuration of a particular service

sc query Displays information about the specified service, driver, type of service, or type of driver
sc start Starts a service running
sc stop Sends a STOP request to a service (not all will respond)

Sunday, 25 December 2016

Install Mongo Db Like a Pro



Mongo Db installation Guide:

1. Go to the URL : https://www.mongodb.com/download-center/community/releases/archive

2. Select software a sepecific version & for specific OS e.g: Windows selected below:



3. Select a binary in .zip format , from the link:

4. Download it into a repository, and extract it into an installation directory.

5. Create data directories for installation:

1. D:/Mongo/Data - for data files
2. D:/Mongo/Log - for log files
3. D:/Mongo/Config - for configuration files


6. Create a configuration file [mongod.conf] into Config[D:/Mongo/Config] and paste the below content into the file and save it:

storage:
   dbPath: "C:/Mongo/Data"

systemLog:
   destination: file
   path: "C:/Mongo/Log/mongod.log"


Note: it must be in YAML format that is 3 space from left end.

7. We need to give user(a service account) full access to this installation directory, form the same we will use this command:

Icacls d:\mongo /grant Avinash:(OI)(CI)F


8. Now, install mongo db as service on windows server , using command:

 mongod --install --config d:\mongo\config\mongod.conf --serviceUser Avinash --servicePassword ************

9. Now, we will verify whether it is installed or not.

sc qc mongodb

10. We will start the mongodb service now, by running the command:

net start mongodb

11. Create a db by following this command:

use test_dev_db

12. Provide permission to the a specific user using the following commmand:

db.createUser(
  {
    user: "avinashthakur",
    pwd: "Bangalore#12345",
    roles: [
       { role: "readWrite", db: "test_dev_db" },
       { role: "readWrite", db: "test" },
       { role: "readWrite", db: "admin" }       
    ]
  }
)

13. It is ready to use. You may follow my other article for CRUD operation in Mongodb 

CRUD Operation in Mongo DB

              

1.1. Go to the mongo db installation path, and open a console.

1.2. Write  mongo in the console and hit <<enter>>.

1.3. You will see your console as below:









1.4. You see a test database connected.

1.5. You may also type “db” and find the current database you are in, and hence you will find “test” database.

1.6. We may use, “cls” or “ctrl-l” to clean the screen.

1.7. You may switch from one database to another using “use <<dbname>>” command.

1.8. If we use a command “use avinash”, in the same console, then it will go to the “avinash” database.











1.9. If we want to see the list of databases, we can use “show databases” command,
      






2.0. In mongo db, data is stored in collection, in the format of document. To show the list of collection in a database, use command “show collections
       





2.1.To insert a document in a collection named “avi”, the command is:
   "db.avi.insert({ name:”avinash”, location:”bangalore”})"
          







2.2. To find a document inserted into a collection, the command is:
"db.avi.find()"
                  







 "db.avi.find({“_id :1”})"
   





2.3. To modify a document, we need to use save command:
   "db.avi.save({“_id”:1, pincode: 844502})"








  Note: If we use save , then it will modify the complete document with the new details provided by save command.

2.4. Hence, to update the document , we need to use update command:
   "db.avi.update{{_id:1}, { $set : { name: “avinash”}})"








2.5. To remove a document from a collection, we need to use remove command:
   "db.avi.remove({_id:1})"
             






2.6. To remove a collection from a db, need to use drop command:
   "db.avi.drop()"
          
2.7. To drop a database, we need to use dropdatabase command:
   "db.dropdatabase()"