<commit_before>victims-web [![Build Status](https://travis-ci.org/victims/victims-web.png)](https://travis-ci.org/victims/victims-web)
===========
The victims web application.
## Report an Issue
If you find an issue with the service at http://victi.ms or the code, either
* Create a new issue at https://github.com/victims/victims-web/issues
* Email <EMAIL>

## Contributing
If you have a patch or a feature that you want considered to be added to the project, feel free to send us a pull request.
Make sure you run pep8 before committing.
```sh
pep8 --repeat src/
```
## Development
This is short guide on how to work on this code base.
### Requrements
Make sure the following are in your system-path:
* virtualenv (Python Virtual Environment)
* mongod (Mongo DB server)

### Set up the environment
Once you have cloned your repository, and changed into it you can just source the _start-dev-env.sh_ script. The first time you do this, it will take a bit as virtual environment setup will download all required dependices into a new env.
#### Activate the environment
```sh
source ./contrib/scripts/start-dev-env.sh
```
Once active, you should see _victims.dev_ prefixed to your terminal prompt. For example:
```sh
[abn@whippersnapper victims-web (master)]$ source ./contrib/scripts/start-dev-env.sh 
victims.dev[abn@whippersnapper victims-web (master)]$ 
```
#### Run the test suite to see if everything is in order
```sh
./contrib/scripts/run-tests.sh
```
#### Control the test database
The test database is loaded with one record, available at _test/mong_test.json_. The database can be _start/stop/restar_ using the provided script.
```sh
./contrib/scripts/mongo-db-ctl.sh <start|stop|restart>
```
This will create a new data base at _$(pwd)/testdb_ this will also contain the log files. The import only happens once. If you want to start from scratch again, just remove this directory.
#### Running the application
To test web-ui changes you might want to run the web-app on your local machine. You can do this by doing:
```sh
# Make sure the database is available, this will not do anything if it is already running
./contrib/scripts/mongo-db-ctl.sh start

# Run the app in the dev env
cd src/victims_web/
python application.py
```
You should be able to see the victims page at _http://localhost:5000/_ if everything was done correctly, with 1 hash record.

## Usage
### Secured API Access
Submission endpoints like ```/service/submit/archive/java``` are secured by an implementation similar to what is used by AWS. The authentication token is expected in a HTTP header configured via the ```VICTIMS_API_HEADER``` configuration (default: ```Victims-Api```). If this is not present or if validation/authentication fails, then it falls back to *BASIC AUTH*.

An example using curl is as follows:
```sh
$ curl -v -X PUT -H "X-Victims-Api: $APIKEY:$SIGNATURE" -H "Date: Thu, 22 Aug 2013 15:20:37 GMT" -F archive=@$ARCHIVE http://$VICTIMS_SERVER/service/submit/archive/java?version=VID\&groupId=GID\&artifactId=AID\&cves=CVE-2013-0000,CVE-2013-0001<commit_msg>X-Victims-Api is used from now on as the default<commit_after>victims-web [![Build Status](https://travis-ci.org/victims/victims-web.png)](https://travis-ci.org/victims/victims-web)
===========
The victims web application.
## Report an Issue
If you find an issue with the service at http://victi.ms or the code, either
* Create a new issue at https://github.com/victims/victims-web/issues
* Email <EMAIL>

## Contributing
If you have a patch or a feature that you want considered to be added to the project, feel free to send us a pull request.
Make sure you run pep8 before committing.
```sh
pep8 --repeat src/
```
## Development
This is short guide on how to work on this code base.
### Requrements
Make sure the following are in your system-path:
* virtualenv (Python Virtual Environment)
* mongod (Mongo DB server)

### Set up the environment
Once you have cloned your repository, and changed into it you can just source the _start-dev-env.sh_ script. The first time you do this, it will take a bit as virtual environment setup will download all required dependices into a new env.
#### Activate the environment
```sh
source ./contrib/scripts/start-dev-env.sh
```
Once active, you should see _victims.dev_ prefixed to your terminal prompt. For example:
```sh
[abn@whippersnapper victims-web (master)]$ source ./contrib/scripts/start-dev-env.sh 
victims.dev[abn@whippersnapper victims-web (master)]$ 
```
#### Run the test suite to see if everything is in order
```sh
./contrib/scripts/run-tests.sh
```
#### Control the test database
The test database is loaded with one record, available at _test/mong_test.json_. The database can be _start/stop/restar_ using the provided script.
```sh
./contrib/scripts/mongo-db-ctl.sh <start|stop|restart>
```
This will create a new data base at _$(pwd)/testdb_ this will also contain the log files. The import only happens once. If you want to start from scratch again, just remove this directory.
#### Running the application
To test web-ui changes you might want to run the web-app on your local machine. You can do this by doing:
```sh
# Make sure the database is available, this will not do anything if it is already running
./contrib/scripts/mongo-db-ctl.sh start

# Run the app in the dev env
cd src/victims_web/
python application.py
```
You should be able to see the victims page at _http://localhost:5000/_ if everything was done correctly, with 1 hash record.

## Usage
### Secured API Access
Submission endpoints like ```/service/submit/archive/java``` are secured by an implementation similar to what is used by AWS. The authentication token is expected in a HTTP header configured via the ```VICTIMS_API_HEADER``` configuration (default: ```X-Victims-Api```). If this is not present or if validation/authentication fails, then it falls back to *BASIC AUTH*.

An example using curl is as follows:
```sh
$ curl -v -X PUT -H "X-Victims-Api: $APIKEY:$SIGNATURE" -H "Date: Thu, 22 Aug 2013 15:20:37 GMT" -F archive=@$ARCHIVE http://$VICTIMS_SERVER/service/submit/archive/java?version=VID\&groupId=GID\&artifactId=AID\&cves=CVE-2013-0000,CVE-2013-0001
{'fraction_non_alphanumeric': 0.10534004220094141, 'fraction_numerical': 0.011361791916896609, 'mean_word_length': 4.48220640569395, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7069685', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1782, 'n_words': 803}