Tuesday, July 19, 2016

How To Format Write-Protected USB Drive and SD Card

How To Format Write-Protected USB Drive and SD Card

How to format USB drives and memory cards which are write protected. You cannot delete contents or make any new files on right protected USB drives and SD Cards. But there is a way to format USB drives which are right-protected. Let see how:
How to Remove Write-Protection of USB Using System Registry (regedit.exe)
  • Select “Start” then “RUN”, write “regedit.exe” and press Enter.
  • Click “Computer\HKEY_LOCAL_MACHINE\SYSTEM\”
  • Then select “CurrentControlSet\Control\StorageDevicePolicies”
  • Search “WriteProtect value” in the right-hand windows of Regedit.exe.
  • Double-click on it and change the Value data from 1 to 0
  • Click OK
  • Close regedit.exe and restart your computer
Now connect your USB drive and format the drive as it’s no longer write protected. To format the drive, right-clicking on it and select Format option. There may be a situation when you will not find “StorageDevicePolicies” in regedit.exe. Create the “StorageDevicePolicies” key. To create a new key, right-click in the white space and choose New > Key entering the name “StorageDevicePolicies” and restart your system.
How to Remove Write-Protection of USB Using Command Prompt (CMD)
  • Plug in your USB to your PC
  • Launch command prompt (in Windows XP, select “Start” then open “RUN”, write CMD and press Enter. In Windows 8 PC, select Start menu and search cmd.exe)
  • Once your CMD screen is open and ready to use.
Type the following commands (please press Enter key after your write each command)
diskpart
list disk
select disk x (x is the number of USB flash drive)
attributes disk clear readonly
clean
create partition primary
format fs=fat32
And you are done.
If you get an “access is denied” error message, run Command Prompt (cmd.exe) with administrator rights. To open Command Prompt (cmd.exe) with administrator rights, right-click on the CMD shortcut and choose Run as administrator (Windows XP).

Tuesday, April 26, 2016

Clear or Disable the Windows 7 Explorer Search History


The way you search for files and folder in Windows 7 is different from the way you do it in older versions of Windows like Windows XP where you used the search companion to help you find your files. Many people don't like the new feature and say it doesn't work as good as the older XP style of searching. That is up for debate and up to you to decide once you use the new Windows search method.
With Windows 7 you type your search word(s) in the search box in the upper right hand corner of Windows Explorer. Then you will notice a green status bar going across the top of the window as it searches. Finally your search results will be displayed in the main window along with other information such as the path to the file and so on. One thing you may have noticed that it keeps a history of your past searches and you may not want that search history to be kept. You may or may not want this history to be kept on your computer for whatever reason.
Windows 7 Search
If you want to clear the history of searched for items you will need to edit the registry. Always be careful when editing the registry since any changes are made instantly. It may be a good idea to export your registry first just in case you make a mistake which can be done from the File menu and then clicking on Export. To open the registry editor click on Start and then type in regedit in the search box and press Enter. Then navigate to
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\WordWheelQuery
Right click on WordWheelQuery and choose Delete and then you can close the Registry Editor. Now your search history will be deleted but any new searches will show up in the history again.
Registry Editor

If you want to disable the search history altogether then you can do so by using the Local Group Policy Editor which is used to define user and computer configurations for things such as policies, security options and software options etc. To open the Local Group Policy Editor, Click on Start and then type in gpedit.msc in the search box. Now navigate to
User Configuration\Administrative Templates\Windows Components\Windows Explorer
Then find the entry that says Turn off display of recent search entries in the Windows Explorer search box.
Local Group Policy Editor
Double click the entry and change the setting to Enabled and click OK. Now whenever you do a search in Windows explorer it will not keep your search history.

Wednesday, April 13, 2016

Configure Apache to enable cgi-bin user directories to run cgi, perl and python in UBUNTU

1. First enable cgi module using the below lines.
sudo a2enmod cgi
sudo service apache2 restart
After latest apache with cgi mod enabled. 
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

  Options +ExecCGI
  AddHandler cgi-script .cgi .pl .py
  Options FollowSymLinks
  Require all granted
3. Create CGI script CGI works with multiple languages, but for now we start with bash shell. We will show examples for some other languages later. Here is a simples version of the CGI bash example:
#!/bin/bash
echo "Content-type: text/html"
echo ''
echo 'CGI Bash Example'
Copy the above code and paste it to a new file in /usr/lib/cgi-bin/ called example-bash.sh. Once done make the file executable using thechmod command:
$ sudo chmod 755 /usr/lib/cgi-bin/example-bash.sh
4. View CGI script
All what remains is to navigate with your browser to host-name or IP address of your web server. In our case the URL will be: http://cgi-example.local/cgi-bin/example-bash.sh
CGI bash example
You can edit this example to display a disk usage of server's root partition "/". You are only limited by your imagination:
#!/bin/bash
echo "Content-type: text/html"
echo ''
echo 'CGI Bash example
'
echo `df -h / | grep -v Filesystem`
The above code will check for free disk space for a root partition and produce the following page:
CGI bash example 2

5. More CGI examples

As promised, here are more CGI examples for a few more programming languages to get you started.

5.1. Perl

Create and make executable the following /usr/lib/cgi-bin/example-perl.pl with a content:
#!/usr/bin/perl

print "Content-type: text/html\n\n";
print <

CGI Perl Example

CGI Perl Example

CGI Perl Example htmlcode

5.2. Python

Create and make executable the following /usr/lib/cgi-bin/example-python.py with a content:


CGI Python Example

CGI Python Example

CGI Python Example """

5.3. C

For C and C++ to work we will need to have a compiler installed. First, install compiler with:
$ sudo apt-get install build-essential
Once installed create a file example-c.c with the following code:
#include 
int main(void)
{
printf("Content-Type: text/plain \n\n");
printf("CGI C Example \n");
}
save the content of example-c.c file and compile it with the following command:
$ sudo gcc -o /usr/lib/cgi-bin/example-c example-c.c
now you should be able to access your C compiled CGI script with: http://cgi-example.local/cgi-bin/example-c

5.4. C++

For C and C++ to work we will need to have a compiler installed. First, install compiler with:
$ sudo apt-get install build-essential
Once installed create a file example-cpp.c with a following code:
#include 
using namespace std;

int main()
{
        cout << "content-type: text/html" << endl << endl;
        cout << "

CGI C++ example

" << endl; return 0; }
save the content of example-cpp.c file and compile it with the following command:
$ sudo g++ -o /usr/lib/cgi-bin/example-cpp example-cpp.c
now you should be able to access your C compiled CGI script with: http://cgi-example.local/cgi-bin/example-cpp

6. Conclusion

As mentioned earlier the CGI is quite old and was largely superseded by different programing languages such as PHP, etc. However, as you can see, it is still relatively simple tool to use to automate your Linux administration tasks such as a remote custom monitoring for your Linux servers using a web browser.

https://www.youtube.com/watch?v=ELFdP7eEZ5w

Saturday, March 19, 2016

Saturday, December 19, 2015

SETTING UP A LAN NETWORK in LUBUNTU using Webmin

SETTING UP A LAN NETWORK

In this module, we have created a Local Area Network.

Toolkit Used:

Workstation Operating System
Lubuntu 15.04
External Network Interface Cards
Quantity
1
Manufacturer
TP-LINK
Model Number
TF-3200
Switches
Quantity
1
Manufacturer
D-LINK
Model Number
DES-10008A


Below are the steps followed while setting up a LAN.

1.    Install DHCP Server:

Installedisc-dhcp-server to maintain server setup and configuration.
$ sudo apt-get install isc-dhcp-server.

2.    Install webmin:

            Installed webmin to configure and maintain theDHCP server.
a.     Installed required dependencies:
$ sudo apt-get install perl libnet-ssleay-perl libauthen-pam-perl libpam-runtime openssllibio-pty-perl apt-show-versions python.
b.     Downloaded Webmin:
$ wget http://prdownloads.sourceforge.net/webadmin/webmin_1.770_all.deb
c.     Installed Webmin:
$ sudo dpkg --install webmin_1.770_all.deb


3.    Renaming Network Cards

In the current workstation, eth1 is connected to the MSIT LANand eth0 is the external NIC which is going to be used for setting up a LAN for IS specialization purposes. So, for the better understanding and avoidconfusion, we have renamed eth1 to WAN and eth0 to LAN.

$ sudo leafpad /etc/udev/rules.d/70-persistent-net.rules










4.    DHCP & LAN Configuration

             I.        Editing Network Interfaces:
Edited the network interfaces in order to configure the eth0
$ sudo leafpad /etc/network/interfaces




















           II.        Check IP Configuration
Check the IP Configuration  of both LAN and WAN after editing interfaces.
            $ sudo ifconfig


















          III.        Listen for DHCP request
Because there is more than one network card in our workstation, we need to select the network card (WAN) on which our server will be listen for DHCP request.
$ sudo leafpad /etc/default/isc-dhcp-server.

         IV.        Configure the DHCP server’s config file
Edit the dhcp.conf file in order to make changes according to our convenience.

$ sudo nano /etc/dhcp/dhcpd.conf










           V.        Enable IP Forwarding
Edit the sysctl.conf file to forward packets from WAN to LAN.
Uncomment IPV4 packet forwarding line.

$ sudo nano /etc/sysctl.conf










         VI.        Login to Webmin
After configuring all our requirements, login to webmin (https://localhost:10000/) using root account.























        VII.        Add Firewall Rules

a.   Enable MASQUERADE(NAT):

·         Select Networking in the left menu bar.
·         Select the Linux firewall from the Networking drop down menu.
·         Configure the Linux Firewall such that it should do the network address translation for WAN interface.
·         So, select “Do network address translation on external interface” for WAN.
·         Select the “Setup firewall” finally.
















b.   Save IP Table rules
After the above step, save the rules to iptables.up.rules file by clicking on ‘Apply changes’ in IP Tables.























c.   Observe IP Table Changes
Observe the changes made to the iptables.up.rules result in modification of /etc/network/interfaces file

$ sudo cat /etc/network/interfaces
















d.   Activate Network Interfaces
Make sure that both LAN and WAN is up and running. If in case anyone of the interfaces is down, activate it before proceeding.
















      VIII.        Listen to WAN Interface













         IX.        Start the DHCP Server

 
























5.   Results:

Three personal workstations are connected to the switch which is connected the DHCP Server. The DHCP server automatically allocates IP Addresses to them.

IP address
WorkStation Name
192.168.0.11
Kittu
192.168.0.12
H3M4
192.168.0.13
HR

Details can be observed in the screenshot.
            It is the result of system log file (/var/log/syslog).
           
            $ sudo tail -50 /var/log/syslog
           









Friday, July 24, 2015

How to return multiple values from a C function

#include
void fun(int ,int ,int *,int *,int *);
int main()
{
int a=30,b=20,sum,sub,pro;
fun(a,b,&sum,&sub,&pro);
print("%d %d %d\n",sum,sub,pro);
return 0;
}
void fun(int x,int y,int *s,int *su,int *mu)
{
*s=x+y;
*su=x-y;
*mu=x*y;
}

Ex: 2

#include

int main()
{
    int a=3,b=5;
    
    int *c=&a, *d=&b;
    
    int sum,avg;
     
     fun(c,d,&sum,&avg);
     
    printf("%d %d",sum,avg);
    getch();
    
}

int fun(int *a, int *b, int *s, int *avg)
{
    *s=*a+*b;
    *avg=(*a+*b)/2;
}


---------------------------------------

#include <stdio.h>
#include <conio.h>

/* This function returns an array of N even numbers */
int* getEvenNumbers(int N){
    /* Declaration of a static local integer array */
    static int evenNumberArray[100];
    int i, even = 2;
    
    for(i=0; i<N; i++){
        evenNumberArray[i] = even;
        even += 2;
    }
    /* Returning base address of evenNumberArray array*/
    return evenNumberArray;
}

int main(){
   int *array, counter;
   array = getEvenNumbers(10);
   printf("Even Numbers\n");
   for(counter=0; counter<10; counter++){
       printf("%d\n", array[counter]);
   }
   
   getch();
   return 0;




Wednesday, July 22, 2015

Can't create a workable moodledata directory in centos 7 for moodle

First, put all your web content data under /var/www/html/. However, Fedora does not allow Apache to write anything anywhere by default, unless you explicitly permit that. For that, proper file/directory permissions are required, but not enough. Fedora uses SELinux (Security Enhanced Linux) to provide more robust security, and it doesn't allow Apache to write anything by default too.
Now, for each file and/or directory which should be writable (for which you receive ... is not writableerrors) you should set unconfined_u:object_r:httpd_sys_rw_content_t:s0 SELinux label to tell SELinux that these files/directories are allowed to be modified by Apache. For example, to make/var/www/moodledata and /var/www/html/moodle/theme writable, you should run (you can use -R so that this lable is set recursively if these directories contain subdirectories which should be writable):
chcon -R unconfined_u:object_r:httpd_sys_rw_content_t:s0 /var/www/moodledata /var/www/html/moodle/theme
Now, you can run setenforce 1 and see if the webiste is working properly. This is the solution.
But, what about setenforce 0 command? This command changes SELinux mode into permissivemode. In this mode, SELinux doesn't prevent any activity and only generates error messages in system's audit logs. This is why you didn't receive error messages anymore. However, putting SELinux in permissive mode is NOT a proper solution to make things work, I used it to see if your problem is related to SELinux. And, setenforce changes SELinux mode temporarily (until next shutdown/reboot). setenforce 1changes the SELinux mode to the default one, which is enforcing mode in which SELinux does actually prevent un-allowed activities.
This is the workflow that I would suggest when setting up a new thing in Fedora:
  1. Put SELinux into Permissive mode (setenforce 0)
  2. Set up the system as you like and make sure that it works correctly as intended
  3. Put SELinux back to Enforcing mode (setenforce 1)
  4. See if your system is still working fine. If not, check for SELinux errors in system audit logs (/var/log/audit) and try to solve the errors appropriately (it usually involves changing file/directory SELinux lables, or changing SELinux boolean parameters). A more user friendly approach is to useSELinux Troubleshooter GUI application rather than inspecting audit logs. It shows SELinux related errors along with suggested solutions.
Notice that you can modify SELinux configuration file (/etc/selinux/config) to completely disable SELinux or permanently set it into Permissive mode, but please don't. While many will suggest it as a solution to SELinux related problems, it is more like removing the problem rather than a solution for itu. However, for a development system where security is not important, you might decide to do that (In that case, I would personally prefer using permissive mode rather than completely disabling SELinux, so that you can still know about SELinux permission erros). When you decided to deploy your web application to production servers, you should know how to properly configure SELinux so that your web application works correctly even when SELinux is in Enfrocing mode.