<?php
ini_set('include_path', '.');

require_once('env-parser.php');
require_once('file-util.php');
require_once('db-util.php');
require_once('app-util.php');
require_once('upgrade-app.php');

function admin_password_crypt($password)
{
return sha1("$password");
}
function user_password_crypt($password)
{
return sha1("$password");
}

$config_files = array( '/' => array( array('.htpasswd.autoindex.in', '.htpasswd.autoindex'), array('AutoIndex.conf.php.in', 'AutoIndex.conf.php')), '/cgi-bin' => array() );
$schema_files = array(  );
$reconf_schema_files = array(  );
$remove_schema_files = array(  );

$psa_params = array (  );
$db_ids = array (  );
$web_ids = array ( '.htpasswd.autoindex', '/' );
$settings_params = array ( 'admin_name', 'user_name', 'base_dir', 'days_new', 'thumbnail_height', 'bandwidth_limit', 'md5_show' );
$settings_enum_params = array ( 'locale' => array( 'sq-AL' => 'al', 'ar-EG' => 'ar', 'bg-BG' => 'bg', 'ca-ES' => 'ca', 'cz-CZ' => 'cz', 'da-DK' => 'da', 'nl-NL' => 'nl', 'en-US' => 'en', 'fr-FR' => 'fr', 'de-DE' => 'de', 'el-GR' => 'el', 'hu-HU' => 'hu', 'it-IT' => 'it', 'ja-JP' => 'ja', 'ko-KP' => 'ko', 'ms-MS' => 'ms', 'nb-NO' => 'no', 'pl-PL' => 'pl', 'pt-BR' => 'pt_BR', 'ru-RU' => 'ru', 'sk-SK' => 'sk', 'es-ES' => 'es', 'sv-SE' => 'sv', 'th-TH' => 'th', 'tr-TR' => 'tr' ), 'icon_path' => array( 'apache' => 'index_icons/apache/', 'kde' => 'index_icons/kde/', 'osx' => 'index_icons/osx/', 'winvista' => 'index_icons/winvista/', 'winxp' => 'index_icons/winxp/', 'none' => '' ), 'template' => array( 'default' => 'default', 'simple_image_gallery' => 'simple_image_gallery' ), 'show_dir_size' => array( 'true' => 'true', 'false' => 'false' ), 'search_enabled' => array( 'true' => 'true', 'false' => 'false' ), 'use_login_system' => array( 'true' => 'true', 'false' => 'false' ), 'must_login_to_download' => array( 'true' => 'true', 'false' => 'false' ), 'anti_leech' => array( 'true' => 'true', 'false' => 'false' ), 'archive' => array( 'true' => 'true', 'false' => 'false' ), 'parse_htaccess' => array( 'true' => 'true', 'false' => 'false' ) );
$crypt_settings_params = array ( 'admin_password', 'user_password' );

$psa_modify_hash = get_psa_modify_hash($psa_params);
$db_modify_hash = get_db_modify_hash($db_ids);
$web_modify_hash = get_web_modify_hash($web_ids);
$settings_modify_hash = get_settings_modify_hash($settings_params);
$settings_enum_modify_hash = get_settings_enum_modify_hash($settings_enum_params);
$crypt_settings_modify_hash = get_crypt_settings_modify_hash($crypt_settings_params);

$additional_modify_hash = get_additional_modify_hash();

if(count($argv) < 2)
{
    print "Usage: configure (install | upgrade <version> | configure | remove)\n";
    exit(1);
}

$command = $argv[1];

if($command == "upgrade")
{
    if($argv[2] && $argv[3]){
	upgrade_app($argv[2], $argv[3], $config_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash);
	exit(0);
    }
    else{
	print "Error: upgrade version or release not specified.\n";
	exit(1);
    }
}

if($command == "install")
{
    configure($config_files, $schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash);
    exit(0);
}

if($command == "remove")
{
    remove_app($remove_schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash);
    exit(0);
}

if($command == "configure")
{
    configure($config_files, $reconf_schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash);
    exit(0);
}

print "Error: unknown command $command.\n";
exit(1);

?>