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XrhfkkNIGjFKadmyhRll64MJuBJrSrUgcWvcUc+CjAw+4vhn71vSaPCvQ9WKSZJ
PqxXrCULo0A8xnqoaRBgbuL8qMVdz+Vem1/6fyaKzLf8anC/BFW48TuRWReKaWPs
bfgowXzZ0rlslapcddFQaxTR
-----END CERTIFICATE-----


text:
Windows Setup
---

### Editing

Opening up the `userscript.user.js` file from the root of the repository you'll be presented with the code for the userscript, the main two lines you need to edit are:

	var baseUrl = 'http://your.archive.url.com/';
	var key = 'changeme';

For `baseUrl` you'll want to change it to whatever URL your local server is addressed to, the case of the Windows and Linux guides it's `https://exhen.localhost/`.
The Vagrant guide it is meerly just `https://localhost/`

For `key` this is the value you configured in your `config.json` file.

### Installing

Now to install the userscript just drag and drop it into your browser, this will open it prompting what ever userscript engine you have to ask if you want to install it.

Or you can click File -> Open and then open the file, either way the file will be open.


text:
Docker Setup
---

###
* Docker
* Docker-compose
* e-hentai account with ExHentai access
* GP to download galleries

Docker is generally the easiest way to get a compatible environment started as it contains all the required packages and configurations to get started.

#### Getting started
The easiest way to get a local (dev/test) environment up and running is by copying the `docker-compose.override.yml` to `docker-compose.override.yml`.
This file will override the default values for configuration.

After copying the override YAML, make sure to replace the `environment` parameters under the `app` section.

* The `CONF_ACCESSKEY` option is a password used for deleting and adding galleries.
* The `CONF_MEMBERID` and `CONF_PASSHASH` should be changed to match your ExHentai cookie.
* The `db` block should stay as it is in most cases, with the exception of `pass`, which you should input whatever password you used for the MySQL setup step.
* On first run add `INIT_DB: 1` to the `environment:` list for `web`. This will run the sql script to create the database
* SphinxQL and memcache should stay as-is.

Run: `docker-compose up`
Use `-d` flag to detach console and continue running in the background. Note, you will not get the log output by default if you run in detached mode. You'll have to use `docker logs` to check logs in that case, the instructions for that are out of scope for this guide.

Visit `http://localhost` to see the webpage.

#### Adding galleries

Adding galleries is done via a userscript. Open the provided `userscript.js` file in a text editor and change the two values at the top of the code. The `baseUrl` in this example would be http://exhen.localhost and `key` would be the `accessKey` value in the config.json file.

Once edited, add to your browser via Greasemonkey/Tampermonkey.

The script will add a "Send to archive" link to the search results page (in thumbnails view) and on the gallery detail page. Clicking it will send it to the archive to be marked for download. Galleries added to the database will be marked in green on the search results page.

After you have added a few galleries, you can now run the `Archive` task that will download them.

    cd /var/www/vhosts/exhen
    php TaskRunner.php Archive

The task should download the galleries and reindex Sphinx.

Once completed, reload http://exhen.localhost and you should see your galleries appear!

#### Cron

For ideal automation, tasks should be setup in the crontab of your system. Below is an example I use.

    */10 * * * * cd /var/www/vhosts/exhen/ && php TaskRunner.php Archive >> log.txt 2>&1
    0 4 * * * cd /var/www/vhosts/exhen/ && php TaskRunner.php Thumbnails >> log.txt 2>&1
    0 5 * * * cd /var/www/vhosts/exhen/ && php TaskRunner.php Audit >> log.txt 2>&1

There are 3 main tasks in use.

* **Archive** - downloads pending galleries in the database;
* **Audit** - updates meta data for added galleries. Will typically update each gallery periodically for new tags, or add newer versions of that gallery to the database.
* **Thumbnails** - generates thumbs for galleries instead of doing it on-the-fly on the frontend.

#### Extras

If you find the search results are out of sync with the database, you may need to connect to the sphinx container and reindex Sphinx:

    docker-compose run --rm sphinx "sudo -u sphinxsearch indexer --rotate --all"

##### Feeds

Feeds are ways of adding galleries to the database automatically through search terms. The Archive task will run through all feeds in the database, adding new galleries, and optionally downloading these galleries. Support for managing these in a friendly way does not exist.

If you wish to play around with feeds, get a MySQL database admin tool (MySQL Workbench) and take a look at the feeds table. Create a new row with the `term` matching the search term you want (i.e "comic x-ero"), then `download` should be 1 or 0, depending on if you want the archiver to also download the gallery zips.


text:
Windows Setup
---

### Requirements

 * VirtualBox ( [https://www.virtualbox.org/wiki/Downloads](https://www.virtualbox.org/wiki/Downloads) )
 * Vagrant ( [https://www.vagrantup.com/downloads.html](https://www.vagrantup.com/downloads.html) )
 * ExHentai-Archive ( [https://github.com/Sn0wCrack/ExHentai-Archive/archive/master.zip](https://github.com/Sn0wCrack/ExHentai-Archive/archive/master.zip) )

### How-To

Extract the contents of ExHentai-Archive in a safe place, this will be the program's home and will stay there and where it will download all your archives. So I reccomend a drive with a large storage space.

First we're going to edit some configuration files, the ones we want to focus on have the ```.linux``` extension, mainly the config.json.linux file.

```
{
	"base": {
		"accessKey": "changeme",
        "autoReadPercentage": 80,
		"viewType": "mpv",
		"cookie": {
            "ipb_member_id": "changeme",
            "ipb_pass_hash": "changeme",
            "hath_perks": "m1.m2.m3.tf.t1.t2.t3.p1.p2.s-210aa44613",
			"sp": "changeme",
			"sk": "changeme"
        },
		"tempDir": "./temp",
        "archiveDir": "./archive",
        "imagesDir": "./images"
	},
	"default": {
		"db": {
			"dsn": "mysql:host=localhost;dbname=exhen",
			"user": "root",
			"pass": "changeme"
		},
		"sphinxql": {
			"dsn": "mysql:host=127.0.0.1;port=9306;dbname=exhen",
			"user": "root",
			"pass": ""
		},
		"memcache": {
			"host": "localhost",
			"port": 11211
		},
		"indexer": {
			"full": "sudo indexer --rotate galleries suggested"
		}
	}
}
```

Inside the configuration file you'll see this, the three major things you need to edit are ```"accessKey"```, ```"ipb_member_id"```, ```"ipb_pass_hash"``` and ```sk```.
accessKey will be password used to confirm you wish to delete archives as well as a passphrase between the browser and server to make sure you're sending a gallery to be archived.
So you can really change this to anything you want, or keep it as changeme, all other changeme instances, can remain the same if you wish. (This is extra setup, chaning all configuration files to make this password.)

To get ipb_member_id and ipb_pass_hash you have to find your exhentai.org cookie, to find this you have to browse through your browsers cookies.

Under the ExHetai settings page you need to create a second profile that must use the "List View" settings for the "Front Page Settings" section, this is needed if you wish to view feeds correctly. Now set the "sp" in the "cookie" section to "2". If you  don't wish to use feeds in any capacity, please change the cookie to be either blank, or remove it entirely.

* On firefox you can access this under the options menu under the Privacy tab then clicking "remove individual cookies" and searching for e-hentai and copy pasting the "Content" section into the sections of the configuration file needed

After that, install Vagrant to your system, and make sure to have restarted your computer after installing it (this may or may not be an issue, just do it just in case.)

Open a command prompt window and type in ```vagrant plugin install vagrant-vbguest``` and then close the command prompt window after it has finished downloading the plugin.

If you've changed any other passwords in the config.json.linux file please change the following to the be the same:
 * sphinx.conf.linux under ```source connect``` option called ```sql_pass```
 * bootstrap.sh option called ```MYSQL_PASSWORD```

Open a new command prompt winodw in the directory where your extracted ExHentai-Archive to and type in ```vagrant up``` this will begin a lengthy process of installing and downloading updates so please give it some time.

After ```vagrant up``` finishes running, you'll need to run ```vagrant halt``` and then ```vagrant up``` once more, this fixes an issues with certain services that may not be running correctly, etc.

Afterwards everything should be running smoothly and your vagrant box should be up and running, you can check this by going to ```https://localhost``` in your web browser of choice. **The https is highly important.**

After this you can proceed to [userscript setup](https://github.com/Sn0wCrack/ExHentai-Archive/blob/master/setup/Userscript-Setup.md) using the baseUrl as "https://localhost/" and key as whatever you set previously.

If you're on Windows (I assume most using this guide would be) then you can schedule a task to run to open the vagrant box at start up so you don't have to it manually by making a batch file called ```startup.bat``` in the ExHentai-Archive folder similar to the following:
```
@echo off
vagrant up
exit
```
Then opening "Task Scheduler" and pressing "Action" and "Create Basic Action" setting a name for it, then the rest is self explanatory, when it ask for a program file the .bat file you just made.\

Now you can access https://localhost without doing a thing.

### Archiving

After the initial setup is complete and you've setup your userscript in your browser of choice, to download your archives you'll want to goto ```https://localhost/vagrant/TaskRunner.php?task=Full``` in your browser, this will invoke the Archive, Thumbnails and Auit actions, however due to some limitations you won't be able to get amazingly formatted output.

After sending galleries to archive, you **NEED** to do this, this is what actually downloads and archives the files to your computer.

Enjoy it.


text:
Linux Setup
---

### Requirements

* Apache or nginx (other servers are untested, but should work)
* PHP 5.4+
* MySQL 5.5+ or MariaDB 5.5+
* memcached
* Sphinx
* e-hentai account with ExHentai access
* GP to download galleries

This "guide" is a copy and paste-tier walkthough of setup on a vanilla Debian Wheezy system. This site uses standard software, and should run on almost anything. If you have experience in the technologies involved then you will not need to follow this word-for-word.

Windows is generally fine (minus memcache support), though it is outside the scope of this guide.

Most of the following commands will require running as root.

#### Inital setup

First, install dependencies.

    apt-get install apache2 php5 mysql-server php5-memcached php5-mysql php5-curl php5-gd git

If you don't already have MySQL setup, the configurator will ask you to create a password. Note this password for later.

Create the path to hold the site files.

    mkdir -p /var/www/vhosts/exhen
    cd /var/www/vhosts

Clone the directory from git.

    git clone https://github.com/kimoi/ExHentai-Archive.git exhen

Enter the directory and clone the example configuration.

    cd exhen
    cp config.json.example config.json

Open the `config.json.linux` in a text editor an edit the following values.

* The `accessKey` option is a password used for deleting and adding galleries.
* The `ipb_member_id` and `ipb_pass_hash` in the `cookie` block should be changed to match your ExHentai cookie.
* The `tempDir`, `archiveDir` and `imagesDir` all need to point to server-writable folders on your system.
* The `db` block should stay as it is in most cases, with the exception of `pass`, which you should input whatever password you used for the MySQL setup step.
* SphinxQL and memcache should stay as-is.

Afterwards rename `config.json.linux` to `config.json` and copy it into the `www` folder, making sure to keep both copies.

#### MySQL

Open up the MySQL console.

    mysql -u root -h localhost -p

You should be prompted for your MySQL password, enter it and you will be dropped into the console.

Create the database.

    create database exhen;
    exit;

Import the structure into the created database.

    mysql -u root -h localhost -p exhen < /var/www/vhosts/exhen/db.sql

#### Sphinx

On Debian there are two ways of doing this. You can use the repo version, which doesn't support random ordering, or you can compile the latest release from source.

If you can live without random ordering, grab the repo version.

    apt-get install sphinxsearch

Enable Sphinx to start on boot, edit `/etc/default/sphinxsearch` and change `START=yes`.

Copy the example Sphinx configuration.

    cp sphinx.conf.example /etc/sphinxsearch/sphinx.conf
    cd /etc/sphinxsearch

Open `sphinx.conf` in an editor and change the `sql_pass` parameter at the top to match your MySQL password.

Now create the directories to hold the generated indexes.

    mkdir -p /var/lib/sphinxsearch/data/exhen
    chown sphinxsearch:sphinxsearch /var/lib/sphinxsearch/data/exhen

Build the initial indexes.

    sudo -u sphinxsearch indexer --all --rotate

#### Apache

Enter `/etc/apache2/sites-enabled` and create a `exhen.localhost` config file.

Copy the following, you may need to change the /images alias and <Directory> directive to match the location of your images dir.

    <VirtualHost *:80>
        ServerName exhen.localhost
        ServerAlias exhen.localhost
        ServerAlias exhen.debian

        DocumentRoot /var/www/vhosts/exhen/www
        <Directory /var/www/vhosts/exhen/www>
            Options FollowSymLinks ExecCGI
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>

        Alias /images /var/www/vhosts/exhen/images
        <Directory /var/www/vhosts/exhen/images>
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/exhen-error.log
        CustomLog ${APACHE_LOG_DIR}/exhen-access.log combined

    </VirtualHost>

Restart apache.

    sudo apache2ctl -k graceful

Add the appropriate hostname to your `/etc/hosts` file.

    sudo sh -c 'echo "127.0.0.1 exhen.localhost" >> /etc/hosts'

Open up http://exhen.localhost/ in a browser and you should see the default layout with "Displaying 0 of 0 results".

#### Adding galleries

Adding galleries is done via a userscript. Open the provided `userscript.js` file in a text editor and change the two values at the top of the code. The `baseUrl` in this example would be http://exhen.localhost and `key` would be the `accessKey` value in the config.json file.

Once edited, add to your browser via Greasemonkey/Tampermonkey.

The script will add a "Send to archive" link to the search results page (in thumbnails view) and on the gallery detail page. Clicking it will send it to the archive to be marked for download. Galleries added to the database will be marked in green on the search results page.

After you have added a few galleries, you can now run the `Archive` task that will download them.

    cd /var/www/vhosts/exhen
    php TaskRunner.php Archive

The task should download the galleries and reindex Sphinx.

Once completed, reload http://exhen.localhost and you should see your galleries appear!

#### Cron

For ideal automation, tasks should be setup in the crontab of your system. Below is an example I use.

    */10 * * * * cd /var/www/vhosts/exhen/ && php TaskRunner.php Archive >> log.txt 2>&1
    0 4 * * * cd /var/www/vhosts/exhen/ && php TaskRunner.php Thumbnails >> log.txt 2>&1
    0 5 * * * cd /var/www/vhosts/exhen/ && php TaskRunner.php Audit >> log.txt 2>&1

There are 3 main tasks in use.

* **Archive** - downloads pending galleries in the database;
* **Audit** - updates meta data for added galleries. Will typically update each gallery periodically for new tags, or add newer versions of that gallery to the database.
* **Thumbnails** - generates thumbs for galleries instead of doing it on-the-fly on the frontend.

#### Extras

If you find the search results are out of sync with the database, you may need to reindex Sphinx:

    sudo -u sphinxsearch indexer --rotate --all

##### Feeds

Feeds are ways of adding galleries to the database automatically through search terms. The Archive task will run through all feeds in the database, adding new galleries, and optionally downloading these galleries. Support for managing these in a friendly way does not exist.

If you wish to play around with feeds, get a MySQL database admin tool (MySQL Workbench) and take a look at the feeds table. Create a new row with the `term` matching the search term you want (i.e "comic x-ero"), then `download` should be 1 or 0, depending on if you want the archiver to also download the gallery zips.


text:
Windows Setup
---

### Requirements

* Apache or nginx (other servers are untested, but should work)
* PHP 5.4+
* MySQL 5.5+ or MariaDB 5.5+
* memcached
* Sphinx
* phpMyAdmin
* Either Firefox or Chrome with Greasemonkey or Tampermonkey installed.
* e-hentai account with ExHentai access
* GP to download galleries

Guide is still a work in progress, use the Linux one as a skeleton if you know what you're doing.

#### Inital setup

First, install dependencies:

* Apache: [http://www.apachelounge.com/download/](http://www.apachelounge.com/download/) - Get the **win32 or win64 version**
* PHP: [http://windows.php.net/download/](http://windows.php.net/download/) - Get the **Thread Safe x86 or x64 version**
* If using PHP7 then PHP7-memcache.dll [https://github.com/nono303/PHP7-memcache-dll](https://github.com/nono303/PHP7-memcache-dll) - Get the version which matches yours (At the moment that would be VC15/x64/ts)
* MariaDB / MySQL: [https://downloads.mariadb.org/mariadb/](https://downloads.mariadb.org/mariadb/) - Get the **win32 or win64 zip verson**
* memcached: [https://commaster.net/content/installing-memcached-windows](https://commaster.net/content/installing-memcached-windows) - Get the **version 1.4.5 win32 or win64 zip version**
* Sphinx: [http://sphinxsearch.com/downloads/release/](http://sphinxsearch.com/downloads/release/)
* phpMyAdmin: [https://www.phpmyadmin.net/downloads/](https://www.phpmyadmin.net/downloads/)

Create a folder somewhere and call it whatever you want, for example `server` or `exhen`.
Extract Apache, PHP, MariaDB, memcached and Sphinx into their own folders with the same names.

Then extract the contents of this repo into the folder in the Apache folder `htdocs`

Open the `config.json.win32` in a text editor an edit the following values.

* The `accessKey` option is a password used for deleting and adding galleries.
* The `ipb_member_id`, `ipb_pass_hash` and `sk` in the `cookie` block should be changed to match your ExHentai cookie.
* Create a new Profile in the ExHentai settings page, make sure this profile set to use "List View" under the "Front Page Setttings" section.
* Change the `sp` in the `cookie` block to "2"
* The `tempDir`, `archiveDir` and `imagesDir` all need to point to server-writable folders on your system.
* The `db` block should stay as it is in most cases, with the exception of `pass`, which you should input whatever password you used for the phpMyAdmin setup step.
* SphinxQL change the `full` option to point to where ever you installed Sphinx too.
* memcached should stay the same.

Afterwards, rename `config.json.win32` to `config.json` and then copy it into the `www` directory as well, making sure to keep both copies.

#### Apache

Enter `apache\conf\` and open the `httpd.conf` file in your text editor.

Change any references of `c:/Apache##/` with the location of your Apache server's location.

Copy the following, you may need to change the /images alias and <Directory> directive to match the location of your images directory.

	DocumentRoot C:\path\to\apache\htdocs\exhen
	<Directory C:\path\to\apache\www\htcdocs\exhen>
    	Options FollowSymLinks ExecCGI
    	AllowOverride None
    	Order allow,deny
    	allow from all
 	</Directory>

	Alias /images C:\path\to\apache\htdocs\exhen\images
	<Directory C:\path\to\apache\htdocs\exhen\images>
    	AllowOverride None
    	Order allow,deny
    	allow from all
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/exhen-error.log
	CustomLog ${APACHE_LOG_DIR}/exhen-access.log combined

Restart Apache.

Add the appropriate hostname to your `C:\Windows\system32\drivers\etc\hosts` file.

Open it in the text editor of choice and add the line

	127.0.0.1 exhen.localhost

Change exhen.localhost with whatever your server's name is. You don't have to do this if you just want to keep localhost or use 127.0.0.1.

Open up http://exhen.localhost/ in a browser and you should see the default layout with "Displaying 0 of 0 results".

#### phpMyAdmin and MariaDB / MySQL

Extract the phpmyAdmin-version#-all.7z file into the Apache folder `htdocs` under a folder named `phpMyAdmin` (so `apache\htdocs\phpMyAdmin\...`)

Run `httpd.exe` and `mysqld.exe`. and go to `http://localhost/phpMyAdmin` in your browser.

Follow the prompts given my phpMyAdmin and it should all be setup.

Go to the import tab and click the Browse button, and find the `db.sql` file from the repo files and press go.

This will setup the database for you.

#### Sphinx

To setup Sphinx you must first rename the file `sphinx.conf.win32` to `sphinx.conf` and then open it.
Under the `source connect` structure change the `sql_user`, `sql_pass` and any other value to suit your MySQL / MariaDB setup.

On Windows you have the option to install Sphinx as a service, this way it will start with your computer whenever you turn it on.

This can be done by opening a command window in the `bin` directory of the Sphinx root folder and running this command:

	searchd.exe --install --config "C:\path\to\sphinx.conf"

Of course you can just open Sphinx manually every time you want to run it with this command:

	searchd.exe --config "C:\path\to\sphinx.conf"

After you have either setup a script to open Sphinx using the previous command or have installed it as a service, close it down / end the service and run this command from the `bin` directory

    indexer.exe --config "C:\path\to\sphinx.conf --all --rotate

This will setup all the needed indexes for Sphinx syncing with the data from the database.

#### memcahced

Open a command window in the memcached folder and type in the command:

	memcached.exe -d start

This will install memcached as a service on Windows and will start with your computer from now on.

You can change the memory pool size (currently defaults to 64MB, which seems fine for me) with the command:

	memcached.exe -m SIZE_IN_MBS

#### Adding galleries

Adding galleries is done via a userscript. Open the provided `userscript.js` file in a text editor and change the two values at the top of the code. The `baseUrl` in this example would be http://exhen.localhost and `key` would be the `accessKey` value in the config.json file.

Once edited, add to your browser via Greasemonkey/Tampermonkey.

The script will add a "Send to archive" link to the search results page (in thumbnails view) and on the gallery detail page. Clicking it will send it to the archive to be marked for download. Galleries added to the database will be marked in green on the search results page.

After you have added a few galleries, you can now run the `Archive` task that will download them.

    cd  C:\path\to\apache\htdocs\exhen\
    php TaskRunner.php Archive

The task should download the galleries and reindex Sphinx.

Once completed, reload http://exhen.localhost and you should see your galleries appear!

#### Task Scheduler

You can setup a Task through Windows built in Task Scheduler.

First create a simple script using Batch or any language of your choice that will automate the download process

Below is an example:

	@echo off
	E:\NPMDB\php\php.exe TaskRunner.php Archive
	E:\NPMDB\php\php.exe TaskRunner.php Thumbnails
	E:\NPMDB\php\php.exe TaskRunner.php Audit
	exit

Then opening up the Task Scheduler and right click and go to `Create Basic Task...` and follow the prompts. When asked for a script or program open the script you've created.

There are 3 main tasks in use.

* **Archive** - downloads pending galleries in the database;
* **Audit** - updates meta data for added galleries. Will typically update each gallery periodically for new tags, or add newer versions of that gallery to the database.
* **Thumbnails** - generates thumbs for galleries instead of doing it on-the-fly on the frontend.

#### Extras

If you find the search results are out of sync with the database, you may need to reindex Sphinx:

	indexer --config "C:\path\to\sphinx.conf --rotate --all

##### Feeds

**NOTE**: I've never used this personally, so this is the same as the old guide.

Feeds are ways of adding galleries to the database automatically through search terms. The Archive task will run through all feeds in the database, adding new galleries, and optionally downloading these galleries. Support for managing these in a friendly way does not exist.

If you wish to play around with feeds, get a MySQL database admin tool (MySQL Workbench or phpMyAdmin) and take a look at the feeds table. Create a new row with the `term` matching the search term you want (i.e "comic x-ero"), then `download` should be 1 or 0, depending on if you want the archiver to also download the gallery zips.