Vous êtes sur la page 1sur 31

7

CHAPTER 1

INTRODUCTION

1.1 INTRODUCTION

As part of my DUT (equivalent to the OTC), before the 7 th semester a internship


or an industrial training is required. We have to do it in a company . This is the option I chose when the
opportunity was given to me to be able to go to Noida, a place which I am passionate about for many
years. So it is in the KVCH(Noida) that I did my industrial training. I was under the tutelage of Mr.
Tanay Kishore Mishra, who offered me a project to do an python. Python is an object oriented language
for software development and website scripting.

This project was conducted in two stages: the first is to familiarize myself with the
development in python (development tools, coding instructions, setting up the display). During this first
step I tried to do a Task Killer, because there is not task manager under python. For the second part of
my project, I needed a topic that can be useful and accessible for me. Under the proper guidance of my
mentor Mr. Tanay Kishore Mishra I am able to complete my project. The website I made is named as
Online Police Portal,in this a common person can launch online FIR if he/she is victim of some crime.

The problematic throughout this course will therefore: how to create a website that can be
useful for everyone?

I intend to improve the website once that my industrial training is ended, because there was
lack of time to finish my website. I have added few more features in my website so that it will look more
creative.
8

CHAPTER-2

WORK ENVIRONMENT

2.1 PRESENTATION OF THE WORK ENVIRONMENT

2.1.1 Noida

Figure 2.1-Noida

A Brief compendium of its achievements, in the years passed by, here we strive to present
you the matchless facilities available in NOIDA. NOIDA Constituted under the U.P. Industrial Area
Development Act, 1976, NOIDA has now emerged as a planned, integrated, modern Industrial City, well
connect to Delhi through a network of roads, national highways and the ultra - Morden DND flyover,
offering inter - road linkages to all parts of the country. Spread over 20,316 hectares, with many sectors
fully developed, NOIDA offers a pollution free high standard of living and highly supportive industrial
environment with its unique infrastructure providing numerous, matchless facilities. Today, it stands as
an enviable monument of the concept of integrated Industrial township in the world, with smooth and
wide roads, well developed land, uninterrupted power supply, clean and save drinking water, unfailing
telephony, and splendid.

One of the largest Industrial Townships of Asia Not very far from Delhi yet away from the
dirt, grime and pollution, part of the National Capital Region, Noida is the industrial fairy land of the
nation. New Okhla Industrial Development Authority - NOIDA is one of the largest planned industrial
townships of Asia. Set up in 1976, with a view to develop an Integrated Industrial Township for the
industrial growth of the area, under the Uttar Pradesh Industrial Area Development Act, it best
symbolizes harmony between human habitat and Industrial Enterprise.
9

2.1.2 AN IDEAL INDUSTRIAL AREA

Last year Noida has earmarked 7,10,000 sq.mtr. land for different Industries. There are 6014
manufacturing units here. With an investment of about 12710 crore rupees, these industries provide
employment to over 94736 people. To help establish industries, many industry-friendly simplified
measures have been introduced. As a result, now building plans conforming to by-laws need not wait for
approval for commencement of construction. Non-interested entrepreneurs can exercise the option of
post-allotment "surrender without tears". The requirement of seeking permission for mortgaging" fully
paid" industrial plots, have been done away with. At the time of transfer of industrial property, the
requirement of getting clearance certificate from other departments of the UP Government has been
removed.

The NOIDA Software Technology Park (STP) ranks second in the country in terms of export
turnover and the Infotech Park (ITP) on 100 acres of land with state-of-the-art infrastructure, housing
about 152-200 units make NOIDA the epicentre. NOIDA Export Processing Zone (NEPZ), a 100%
export oriented unit and the only land locked export processing zone in the country, housing industries
like Electronics, Textiles, Engineering, Computer Software, etc. recorded a turnover of Rs. 846.20 Crores
in the current year.

Realising NOIDA's potential, many reputed industrial houses both at home and abroad have made
NOIDA the pivot of their operations. M/s Motwane Laboratories, America (Known for their reputed
medicines) have been allotted 300 acres of land out of which 100 acres will be utilised by for establishing
a bio-tech university. This will be the first bio-tech university of Asia which will give a new lease of life
to the bio-tech students of our country.

2.1.3 KVCH
10

Figure 2.2-KVCH

KVCH is the largest training provider in the industry. KVCH is the global leader in the
training sector enabling students in more than 60 countries to generate value. Established in the year 1991
as KV Computer Home Private Limited (KVCH) has been rendering its services from past 26 years .In
the middle of the journey KVCH were joined by the leaders of the industry like TCS ,Tech Mahindra ,
HCL , CMC LTD. Working alongside big brands, helped us grow and prosper into a more dynamic firm.

KVCH very first journey partner was PCL. In 1990s when globalization was starting to
accelerate and there were very few organizations developing software in the market, KVCH managed to
develop a platform embedded on latest technology for various companies. Few years after it started
training people and employees of various big organizations to work and experience the world of
technology. In 2005, it supplied major chunk of professionally skilled engineers to HCL , Wipro and
Tech Mahindra.

What makes KVCH the Industry Leaders ?


 Quality of education
 Experienced staff and trainers
 Overall development program
 Major tie-ups with learning partners
 Certified courses from KVCH
 Dedicated Placement Assistance Cell

KVCH motto is quality education to all. KVCH believe in providing quality services to our
client and that is what has made it the industry leader. KVCH have panel of expert team for each
specialized domain. Its team of experts have industrial experience of more than 15 years. They have
handled more than 500 + Live Projects, making them highly efficient in their respective domains. Not
only they are concerned with providing the best service to our students but they have a specialized
placement cell that work tirelessly to search for the best opportunities in the market. KVCH have more
than 200,000 students placed in the industry. They offer an overall development program for the student
that helps them to compete and grab the best jobs in the market. They build individuals with technology
proficiency, integrity and professionalism.
11

2.2 EQUIPMENT AVAILABLE

To do my internship in good conditions, I had at my disposal the tools necessary for my


advancement. First I worked with my own laptop, which allowed me to work effectively immediately.
Then the teacher Mr.Tanay brought us a Website Development Platform, which serves to developers.
12

CHAPTER-3

PYTHON

3.1 WHAT IS PYTHON

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.


Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it
very attractive for Rapid Application Development, as well as for use as a scripting or glue language to
connect existing components together. Python's simple, easy to learn syntax emphasizes readability and
therefore reduces the cost of program maintenance. Python supports modules and packages, which
encourages program modularity and code reuse. The Python interpreter and the extensive standard
library are available in source or binary form without charge for all major platforms, and can be freely
distributed.

Often, programmers fall in love with Python because of the increased productivity it provides. Since
there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is
easy: a bug or bad input will never cause a segmentation fault. Instead, when the interpreter discovers
an error, it raises an exception. When the program doesn't catch the exception, the interpreter prints a
stack trace. A source level debugger allows inspection of local and global variables, evaluation of
arbitrary expressions, setting breakpoints, stepping through the code a line at a time, and so on. The
debugger is written in Python itself, testifying to Python's introspective power. On the other hand, often
the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-
debug cycle makes this simple approach very effective.
13

Fig 3.1-Python Logo

Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is


designed to be highly readable. It uses English keywords frequently where as other languages use
punctuation, and it has fewer syntactical constructions than other languages.

 Python is Interpreted: Python is processed at runtime by the interpreter. You do not need to
compile your program before executing it. This is similar to PERL and PHP.

 Python is Interactive: You can actually sit at a Python prompt and interact with the interpreter
directly to write your programs.

 Python is Object-Oriented: Python supports Object-Oriented style or technique of


programming that encapsulates code within objects.

 Python is a Beginner's Language: Python is a great language for the beginner-level


programmers and supports the development of a wide range of applications from simple text
processing to WWW browsers to games.

3.2 HISTORY OF PYTHON

Python was developed by Guido van Rossum in the late eighties and early nineties at the National
Research Institute for Mathematics and Computer Science in the Netherlands. Python is derived from
many other languages, including ABC, Modula-3, C, C++, Algol-68, SmallTalk, and Unix shell and
other scripting languages. Python is copyrighted. Like Perl, Python source code is now available under
14

the GNU General Public License (GPL). Python is now maintained by a core development team at the
institute, although Guido van Rossum still holds a vital role in directing its progress.

The major area where Python differs from C-like languages is in its use of dynamic typing. In C,
variables must always be explicitly declared and given a specific type such as int or double. This
information is then used to perform static compile-time checks of the program as well as for allocating
memory locations used for storing the variable’s value. In Python, variables are simply names that refer
to objects. Variables do not need to be declared before they are assigned and they can even change type
in the middle of a program. Like other dynamic languages, all type-checking is performed at run-time
by an interpreter instead of during a separate compilation step.

Python’s primitive built-in data types include Booleans, numbers (machine integers, arbitrary-precision
integers, and real and complex floating point numbers), and strings (8-bit and Unicode). These are all
immutable types, meaning that values are represented by objects that cannot be modified after their
creation. Compound built-in data types include tuples (immutable arrays), lists (resizable arrays) and
dictionaries (hash tables).

For organizing programs, Python supports packages (groups of modules and/or packages), modules
(related code grouped together in a single source file), classes, methods and functions. For flow control,
it provides if/else, while, and a high-level for statement that loops over any “iterable” object. For error
handling, Python uses (non-resumable) exceptions. A raise statement throws an exception, and
try/except/finally statements specify exception handlers. Built-in operations throw exceptions when
error conditions are encountered.

3.3 FEATURES OF PYTHON

Python's features include:

 Easy-to-learn: Python has few keywords, simple structure, and a clearly defined syntax. This
allows the student to pick up the language quickly.

 Easy-to-read: Python code is more clearly defined and visible to the eyes.

 Easy-to-maintain: Python's source code is fairly easy-to-maintain.

 A broad standard library: Python's bulk of the library is very portable and cross-platform
compatible on UNIX, Windows, and Macintosh.

 Interactive Mode:Python has support for an interactive mode which allows interactive testing
and debugging of snippets of code.

 Portable: Python can run on a wide variety of hardware platforms and has the same interface on
all platforms.
15

 Extendable: You can add low-level modules to the Python interpreter. These modules enable
programmers to add to or customize their tools to be more efficient.

 Databases: Python provides interfaces to all major commercial databases.

 GUI Programming: Python supports GUI applications that can be created and ported to many
system calls, libraries and windows systems, such as Windows MFC, Macintosh, and the X
Window system of Unix.

 Scalable: Python provides a better structure and support for large programs than shell scripting.

Fig 3.2-Features of Python

Apart from the above-mentioned features, Python has a big list of good features, few are listed below:

 It supports functional and structured programming methods as well as OOP.

 It can be used as a scripting language or can be compiled to byte-code for building large
applications.

 It provides very high-level dynamic data types and supports dynamic type checking.

 IT supports automatic garbage collection.

 It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
16

CHAPTER-4

WHY PYTHON IS BETTER

4.1 APPLICATIONS

1. GUI-Based Desktop Applications:

Python has simple syntax, modular architecture, rich text processing tools and the ability to
work on multiple operating systems which make it a desirable choice for developing desktop-
based applications. There are various GUI toolkits like wxPython, PyQt or PyGtk available
which help developers create highly functional Graphical User Interface (GUI). The various
applications developed using Python includes:

 Image Processing and Graphic Design Applications:

Python has been used to make 2D imaging software such as Inkscape, GIMP, Paint Shop Pro
and Scribus. Further, 3D animation packages, like Blender, 3ds Max, Cinema 4D, Houdini,
Lightwave and Maya, also use Python in variable proportions.

 Scientific and Computational Applications:

The higher speeds, productivity and availability of tools, such as Scientific Python and
Numeric Python, have resulted in Python becoming an integral part of applications involved
in computation and processing of scientific data. 3D modeling software, such as FreeCAD,
and finite element method software, such as Abaqus, are coded in Python.

 Games:

Python has various modules, libraries and platforms that support development of games. For
example, PySoy is a 3D game engine supporting Python 3, and PyGame provides
functionality and a library for game development. There have been numerous games built
using Python including Civilization-IV, Disney’s Toontown Online, Vega Strike etc.

2. Web Frameworks and Web Applications:

Python has been used to create a variety of web-frameworks including CherryPy, Django,
TurboGears, Bottle, Flask etc. These frameworks provide standard libraries and modules which
simplify tasks related to content management, interaction with database and interfacing with
different internet protocols such as HTTP, SMTP, XML-RPC, FTP and POP. Plone, a content
management system; ERP5, an open source ERP which is used in aerospace, apparel and
banking; Odoo – a consolidated suite of business applications; and Google App engine are a
few of the popular web applications based on Python.
17

3. Enterprise and Business Applications:

With features that include special libraries, extensibility, scalability and easily readable syntax,
Python is a suitable coding language for customizing larger applications. Reddit, which was
originally written in Common Lips, was rewritten in Python in 2005. Python also contributed in
a large part to functionality in YouTube.

4. Operating Systems:

Python is often an integral part of Linux distributions. For instance, Ubuntu’s Ubiquity Installer,
and Fedora’s and Red Hat Enterprise Linux’s Anaconda Installer are written in Python. Gentoo
Linux makes use of Python for Portage, its package management system.

5. Language Development:

Python’s design and module architecture has influenced development of numerous


languages. Boo language uses an object model, syntax and indentation, similar to Python.
Further, syntax of languages like Apple’s Swift, CoffeeScript, Cobra, and OCaml all share
similarity with Python.

6. Prototyping:

Besides being quick and easy to learn, Python also has the open source advantage of being free
with the support of a large community. This makes it the preferred choice for prototype
development. Further, the agility, extensibility and scalability and ease of refactoring code
associated with Python allow faster development from initial prototype.

Fig 4.1- Python as Web Development


18

4.2 Application Domains Used in Python


 The Python Package Index lists thousands of third party modules for Python.

Web and Internet Development

Python offers many choices for web development:

 Frameworks such as Django and Pyramid.


 Micro-frameworks such as Flask and Bottle.
 Advanced content management systems such as Plone and django CMS.

Python's standard library supports many Internet protocols:

 HTML and XML


 JSON
 E-mail processing.
 Support for FTP, IMAP, and other Internet protocols.
 Easy-to-use socket interface.

And the Package Index has yet more libraries:

 Requests, a powerful HTTP client library.


 BeautifulSoup, an HTML parser that can handle all sorts of oddball HTML.
 Feedparser for parsing RSS/Atom feeds.
 Paramiko, implementing the SSH2 protocol.
 Twisted Python, a framework for asynchronous network programming.

Scientific and Numeric

Python is widely used in scientific and numeric computing:


19

 SciPy is a collection of packages for mathematics, science, and engineering.


 Pandas is a data analysis and modeling library.
 IPython is a powerful interactive shell that features easy editing and recording of a work
session, and supports visualizations and parallel computing.
 The Software Carpentry Course teaches basic skills for scientific computing, running
bootcamps and providing open-access teaching materials.

Education

Python is a superb language for teaching programming, both at the introductory level and in
more advanced courses.

 Books such as How to Think Like a Computer Scientist, Python Programming: An


Introduction to Computer Science, and Practical Programming.
 The Education Special Interest Group is a good place to discuss teaching issues.
Desktop GUIs

The Tk GUI library is included with most binary distributions of Python.

Some toolkits that are usable on several platforms are available separately:

 wxWidgets
 Kivy, for writing multitouch applications.
 Qt via pyqt or pyside
Platform-specific toolkits are also available:

 GTK+
 Microsoft Foundation Classes through the win32 extensions

Software Development

Python is often used as a support language for software developers, for build control and
management, testing, and in many other ways.
20

 SCons for build control.


 Buildbot and Apache Gump for automated continuous compilation and testing.
 Roundup or Trac for bug tracking and project management.

Business Applications

Python is also used to build ERP and e-commerce systems:

 Odoo is an all-in-one management software that offers a range of business applications


that form a complete suite of enterprise management applications.
 Tryton is a three-tier high-level general purpose application platform.

Since its origin in 1989, Python has grown to become part of a plethora of web-based, desktop-
based, graphic design, scientific, and computational applications. With Python available for
Windows, Mac OS X and Linux / UNIX, it offers ease of development for enterprises.
Additionally, the latest release Python 3.4.3 builds on the existing strengths of the language,
with drastic improvement in Unicode support, among other new features. Thus, programming
in Python will continue to offer many benefits for organizations, based on their end objectives.

4.3 COMPARISON

Python is often compared to other interpreted languages such as Java, JavaScript, Perl,
Tcl, or Smalltalk. Comparisons to C++, Common Lisp and Scheme can also be enlightening.
In this section I will briefly compare Python to each of these languages. These comparisons
concentrate on language issues only. In practice, the choice of a programming language is
often dictated by other real-world constraints such as cost, availability, training, and prior
investment, or even emotional attachment. Since these aspects are highly variable, it seems a
waste of time to consider them much for this comparison.

Java
Python programs are generally expected to run slower than Java programs, but they also take
much less time to develop. Python programs are typically 3-5 times shorter than equivalent
Java programs. This difference can be attributed to Python's built-in high-level data types and
its dynamic typing. For example, a Python programmer wastes no time declaring the types of
arguments or variables, and Python's powerful polymorphic list and dictionary types, for
which rich syntactic support is built straight into the language, find a use in almost every
Python program. Because of the run-time typing, Python's run time must work harder than
Java's. For example, when evaluating the expression a+b, it must first inspect the objects a and
21

b to find out their type, which is not known at compile time. It then invokes the appropriate
addition operation, which may be an overloaded user-defined method. Java, on the other hand,
can perform an efficient integer or floating point addition, but requires variable declarations
for a and b, and does not allow overloading of the + operator for instances of user-defined
classes.

For these reasons, Python is much better suited as a "glue" language, while Java is better
characterized as a low-level implementation language. In fact, the two together make an
excellent combination. Components can be developed in Java and combined to form
applications in Python; Python can also be used to prototype components until their design can
be "hardened" in a Java implementation. To support this type of development, a Python
implementation written in Java is under development, which allows calling Python code from
Java and vice versa. In this implementation, Python source code is translated to Java bytecode
(with help from a run-time library to support Python's dynamic semantics).

Javascript
Python's "object-based" subset is roughly equivalent to JavaScript. Like JavaScript (and unlike
Java), Python supports a programming style that uses simple functions and variables without
engaging in class definitions. However, for JavaScript, that's all there is. Python, on the other
hand, supports writing much larger programs and better code reuse through a true object-
oriented programming style, where classes and inheritance play an important role.

Perl
Python and Perl come from a similar background (Unix scripting, which both have long
outgrown), and sport many similar features, but have a different philosophy. Perl emphasizes
support for common application-oriented tasks, e.g. by having built-in regular expressions, file
scanning and report generating features. Python emphasizes support for common
programming methodologies such as data structure design and object-oriented programming,
and encourages programmers to write readable (and thus maintainable) code by providing an
elegant but not overly cryptic notation. As a consequence, Python comes close to Perl but
rarely beats it in its original application domain; however Python has an applicability well
beyond Perl's niche.

Tcl
Like Python, Tcl is usable as an application extension language, as well as a stand-alone
programming language. However, Tcl, which traditionally stores all data as strings, is weak on
data structures, and executes typical code much slower than Python. Tcl also lacks features
needed for writing large programs, such as modular namespaces. Thus, while a "typical" large
application using Tcl usually contains Tcl extensions written in C or C++ that are specific to
that application, an equivalent Python application can often be written in "pure Python". Of
course, pure Python development is much quicker than having to write and debug a C or C++
component. It has been said that Tcl's one redeeming quality is the Tk toolkit. Python has
adopted an interface to Tk as its standard GUI component library.
22

Tcl 8.0 addresses the speed issuse by providing a bytecode compiler with limited data type
support, and adds namespaces. However, it is still a much more cumbersome programming
language.

Smalltalk
Perhaps the biggest difference between Python and Smalltalk is Python's more "mainstream"
syntax, which gives it a leg up on programmer training. Like Smalltalk, Python has dynamic
typing and binding, and everything in Python is an object. However, Python distinguishes
built-in object types from user-defined classes, and currently doesn't allow inheritance from
built-in types. Smalltalk's standard library of collection data types is more refined, while
Python's library has more facilities for dealing with Internet and WWW realities such as email,
HTML and FTP.

Python has a different philosophy regarding the development environment and distribution of
code. Where Smalltalk traditionally has a monolithic "system image" which comprises both
the environment and the user's program, Python stores both standard modules and user
modules in individual files which can easily be rearranged or distributed outside the system.
One consequence is that there is more than one option for attaching a Graphical User Interface
(GUI) to a Python program, since the GUI is not built into the system.

C++
Almost everything said for Java also applies for C++, just more so: where Python code is
typically 3-5 times shorter than equivalent Java code, it is often 5-10 times shorter than
equivalent C++ code! Anecdotal evidence suggests that one Python programmer can finish in
two months what two C++ programmers can't complete in a year. Python shines as a glue
language, used to combine components written in C++.

Common Lisp and Scheme


These languages are close to Python in their dynamic semantics, but so different in their
approach to syntax that a comparison becomes almost a religious argument: is Lisp's lack of
syntax an advantage or a disadvantage? It should be noted that Python has introspective
capabilities similar to those of Lisp, and Python programs can construct and execute program
fragments on the fly. Usually, real-world properties are decisive: Common Lisp is big (in
every sense), and the Scheme world is fragmented between many incompatible versions,
where Python has a single, free, compact implementation.
23

CHAPTER-5

SETTING UP PYTHON ON LINUX

Prerequisites:
 One Ubuntu 14.04 Droplet.
 A sudo non-root user, which you can set up by following this tutorial.

5.1 Step 1 — Making Python 3 the Default

In this step, we will set Python 3 as the default for our python command.

First, check your current Python version.

 python --version
On a fresh Ubuntu 14.04 server, this will output:

Python 2.7.6
We would like to have python run Python 3. So first, let's remove the old 2.7 binary.

 sudo rm /usr/bin/python
Next, create a symbolic link to the Python 3 binary in its place.

 sudo ln -s /usr/bin/python3 /usr/bin/python


If you run python --version again, you will now see Python 3.4.0.

5.2 Step 2 — Installing Pip

In this section, we will install Pip, the recommended package installer for Python.

First, update the system's package index. This will ensure that old or outdated packages do not
interfere with the installation.

 sudo apt-get update


24

Pip allows us to easily manage any Python 3 package we would like to have. To install it,
simply run the following:

 sudo apt-get install python3-pip


For an overview of Pip, you can read this tutorial.

5.3 Step 3 — Installing MySQL

In this section, we will install and configure MySQL.

Installing SQL is simple:

 sudo apt-get install mysql-server


Enter a strong password for the MySQL root user when prompted, and remember it, because
we will need it later.

The MySQL server will start once installation completes. After installation, run:

 mysql_secure_installation
This setup will take you through a series of self-explanatory steps. First, you'll need to enter
the root password you picked a moment ago. The first question will ask if you want to change
the root password, but because you just set it, enter n. For all other questions, press ENTER to
accept the default response.

Python 3 requires a way to connect with MySQL, however. There are a number of options,
like MySQLclient, but for the module's simplicity, this tutorial will use pymysql. Install it
using Pip:

 sudo pip3 install pymysql

5.4 Step 4 — Installing Apache 2

In this section, we will install Apache 2, and ensure that it recognizes Python files as
executables.
25

Install Apache using apt-get:

 sudo apt-get install apache2


Like MySQL, the Apache server will start once the installation completes.

Note: After installation, several ports are open to the internet. Make sure to see the conclusion
of this tutorial for resources on security.

We want to place our website's root directory in a safe location. The server is by default
at /var/www/html. To keep convention, we will create a new directory for testing purposes,
called test, in the same location.

 sudo mkdir /var/www/test


Finally, we must register Python with Apache. To start, we disable multithreading processes.

 sudo a2dismod mpm_event


Then, we give Apache explicit permission to run scripts.

 sudo a2enmod mpm_prefork cgi


Next, we modify the actual Apache configuration, to explicitly declare Python files as
runnable file and allow such executables. Open the configuration file using nano or your
favorite text editor.

 sudo nano /etc/apache2/sites-enabled/000-default.conf


Add the following right after the first line, which reads <VirtualHost *:80\>.

<Directory /var/www/test>
Options +ExecCGI
DirectoryIndex index.py
</Directory>
AddHandler cgi-script .py
Make sure that your <Directory> block is nested inside the <VirtualHost> block, like so.
Make sure to indent correctly with tabs, too.
26

/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
<Directory /var/www/test>
Options +ExecCGI
DirectoryIndex index.py
</Directory>
AddHandler cgi-script .py

...
This Directory block allows us to specify how Apache treats that directory. It tells Apache that
the /var/www/test directory contains executables, considers index.py to be the default file,
then defines the executables.

We also want to allow executables in our website directory, so we need to change the path
for DocumentRoot, too. Look for the line that reads DocumentRoot /var/www/html, a few
lines below the long comment at the top of the file, and modify it to
read /var/www/test instead.

DocumentRoot /var/www/test
Your file should now resemble the following.

/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
<Directory /var/www/test>
Options +ExecCGI
DirectoryIndex index.py
</Directory>
AddHandler cgi-script .py

...

DocumentRoot /var/www/test

...
27

Save and exit the file. To put these changes into effect, restart Apache.

 sudo service apache2 restart


Note: Apache 2 may throw a warning which says about the server's fully qualified domain
name; this can be ignored as the ServerName directive has little application as of this moment.
They are ultimately used to determine subdomain hosting, after the necessary records are
created.

If the last line of the output reads [ OK ], Apache has restarted successfully.

5.5 Step 5 — Testing the Final Product

In this section, we will confirm that individual components (Python, MySQL, and Apache)
can interact with one another by creating an example webpage and database.

First, let's create a database. Log in to MySQL. You'll need to enter the MySQL root password
you set earlier.

 mysql -u root -p
Add an example database called example.

 CREATE DATABASE example;


Switch to the new database.

 USE example;
Add a table for some example data that we'll have the Python app add.

 CREATE TABLE numbers (num INT, word VARCHAR(20));


Press CTRL+D to exit. For more background on SQL, you can read this MySQL tutorial.

Now, create a new file for our simple Python app.

 sudo nano /var/www/test/index.py


28

Copy and paste the following code in. The in-line comments describe what each piece of the
code does. Make sure to replace the passwd value with the root MySQL password you chose
earlier.

#!/usr/bin/python

# Turn on debug mode.


import cgitb
cgitb.enable()

# Print necessary headers.


print("Content-Type: text/html")
print()

# Connect to the database.


import pymysql
conn = pymysql.connect(
db='example',
user='root',
passwd='your_root_mysql_password',
host='localhost')
c = conn.cursor()

# Insert some example data.


c.execute("INSERT INTO numbers VALUES (1, 'One!')")
c.execute("INSERT INTO numbers VALUES (2, 'Two!')")
c.execute("INSERT INTO numbers VALUES (3, 'Three!')")
conn.commit()

# Print the contents of the database.


c.execute("SELECT * FROM numbers")
print([(r[0], r[1]) for r in c.fetchall()])

Save and exit.


29

Next, fix permissions on the newly-created file. For more information on the three-digit
permissions code, see the tutorial on Linux permissions.

 sudo chmod 755 /var/www/test/index.py


Now, access your server's by going to http://your_server_ip using your favorite browser. You
should see the following:

your_server_ip'>http://your_server_ip
[(1, 'One!'), (2, 'Two!'), (3, 'Three!')]
Congratulations! Your server is now online.
30

CHAPTER-6

PROJECT

6.1 THE PROJECT AIM

The project is all about making the more important formal things to happen, digitally.
The project is motivated from the one of the hottest topic of the decade “The Digital India”. So
in this way the project will allow the victim to report FIR more comfortably and easily against
the culprit rather going to the police station and then report it. So, my project i.e. “Indian Police
online system” helps in making also this process to happen in more formally and organized
way by making it online.

The objective of the project “Indian Police online system” is to report FIR online from any
restricted place/area irrespective of their location .

The major objectives of the project is as follows:

i) Providing simple, fast and easy way to the victim.

ii) Saves one’s time and money.

iii) Also providing an interactive interface for the administration to handle this work in the more
convenient way and at more common level.

The undergoing project mainly consists of a website , the webpage is coded in HTML and
scripted in PYTHON and consists of database, whatever the information about the user, goes to
that administration’s database connected to the server online. As we know that, internet is a
huge client server architecture. The client is the website in which the information/data is being
entered by the user anywhere, which then goes to the server and server has its own well-defined
already created database for this.
31

Fig 6.1- All files of the website

It offers the outstanding support for both user and administrators, providing the convenient
platform for all.

6.2 SECURITY MECHANISM

The most important and common type of security threats here (in this type of project) arises
when the information/data or any personal information about the user is revealed or is stolen
from database. So , there must be proper mechanism which will confirm the that the security of
the user and the user will not has any of the hesitation while using it. And then there will be the
proper utilization of any project , then the users will b satisfied to its full extend. So , by taking
in mind the all these above points , the considerable amount of time and efforts is given to
maintain the security of the project .

Firstly, all the information/data is stored in the well organized databases’ tables and that are
python and user information .

Secondly, these tables are contained in proper , specified database which is given the it’s own
name and it’s password. So to access any of the information of user, one should know the
32

database name and even after knowing the name the , one should also know the database’s
password .

And , in this way , the project is being protected from unauthorized users or accesses.

6.3 INTERNAL STRUCTURE/DESIGN OF WEBSITE

This website is hosted locally on server with the help of Apache 2 server.

Fig 6.2- Files present on server


33

6.3.1 Screenshots of Website

Fig 6.3- Homepage of Website


34

Fig 6.4- Registration Form to Sign Up

Fig 6.5- Information Fields to launch FIR


35

Fig 6.6- Page for Women Helpline

6.3.2 Screenshots of Coding

Fig 6.7- Source Code for Sign Up UI


36

Fig 6.8- Source code for SignIn

Fig 6.9- Source code to Launch FIR


37

6.4 WHAT DID I LEARN

Technically, First of all I gained skills in python language that was difficult for me
before. I learned also how to use a database and server when designing a website. Finally, this
project allowed me to use my knowledge acquired during my studies.

6.5 CONCLUSION

Thanks to this internship, which was also planned for this, I discovered a country, a
culture, and beautiful people also learned new skills, and used all the things that I learned for
two months. Python is not just a scripting language as I have presented in my project, rather it
is being used even for Artificial Intelligence and Machine Learning projects. I do not regret
anything in this experience and I thank all those who have allowed such a thing feasible. The
people I met here are not just classmates, roommates and professors, they are friends, and once
again I thank you all.

Vous aimerez peut-être aussi