From b80d41f524cfdd842f4309d61b1644d8e6f75f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20MANSON?= Date: Thu, 6 Oct 2016 09:27:13 +0200 Subject: [PATCH] add scripts and conf --- conf/config.php-example | 226 +++++++++++++++++++++++++++++++++++++ conf/nginx.conf | 22 ++++ conf/php-fpm.conf | 244 ++++++++++++++++++++++++++++++++++++++++ manifest.json | 100 ++++++++++++++++ scripts/install | 70 ++++++++++++ scripts/remove | 20 ++++ 6 files changed, 682 insertions(+) create mode 100644 conf/config.php-example create mode 100644 conf/nginx.conf create mode 100644 conf/php-fpm.conf create mode 100644 manifest.json create mode 100644 scripts/install create mode 100644 scripts/remove diff --git a/conf/config.php-example b/conf/config.php-example new file mode 100644 index 0000000..62bcf94 --- /dev/null +++ b/conf/config.php-example @@ -0,0 +1,226 @@ + Preferences -> Language in + * phpVirtualBox. + */ +var $language = 'LANGUAGE'; + +/* Set the standard VRDE Port Number / Range, e.g. 1010-1020 or 1027 */ +var $vrdeports = '9000-9100'; + +/* + * + * Not-so-common options / tweaking + * + */ + +// Multiple servers example config. Uncomment (remove /* and */) to use. +// Add ALL the servers you want to use. Even if you have the server set +// above. The default server will be the first one in the list. +/* +var $servers = array( + array( + 'name' => 'London', + 'username' => 'user', + 'password' => 'pass', + 'location' => 'http://192.168.1.1:18083/', + 'authMaster' => true // Use this server for authentication + ), + array( + 'name' => 'New York', + 'username' => 'user2', + 'password' => 'pass2', + 'location' => 'http://192.168.1.2:18083/' + ), +); +*/ + +// Disable authentication +var $noAuth = true; + +// Host / ip to use for console connections +var $consoleHost = 'VBOX_IP'; + +// Disable "preview" box +#var $noPreview = true; + +// Default preview box update interval in seconds +#var $previewUpdateInterval = 30; + +// Preview box pixel width +#var $previewWidth = 180; + +// Max number of progress operations to keep in list +var $maxProgressList = 5; + +// Change default preview aspect ratio to 1. +// http://www.wikipedia.org/wiki/Aspect_ratio_%28image%29#Previous_and_presently_used_aspect_ratios +#var $previewAspectRatio = 1.6; + +// Enable custom VM icons +#var $enableCustomIcons = true; + +/* +Exclusively use phpVirtualBox's groups configuration rather than VirtualBox groups. +This has the following effects: + +*) Group changes made in phpVirtualBox will not be reflected in VirtualBox programs such as + VirtualBox and VBoxManage +*) Group changes will not affect which folder a VM is placed in +*) You can rename groups that contain running VMs and move / copy running VMs to groups +*/ +#var $phpVboxGroups = true; + + +/* +Allow to prompt deletion hard disk files on removal from Virtual Media Manager. +If this is not set, files are always kept. If this is set, you will be PROMPTED +to decide whether or not you would like to delete the hard disk file(s) when you +remove a hard disk from virtual media manager. You may still choose not to delete +the file when prompted. +*/ +var $deleteOnRemove = true; + +/* + * File / Folder browser settings + */ + +// Restrict file types +var $browserRestrictFiles = array('.iso','.vdi','.vmdk','.img','.bin','.vhd','.hdd','.ovf','.ova','.xml','.vbox','.cdr','.dmg','.ima','.dsk','.vfd'); + +// Restrict locations / folders +#var $browserRestrictFolders = array('D:\\','C:\\Users\\Ian'); // Or something like array('/home/vbox','/var/ISOs') + +// Force use of local, web server based file browser instead of going through vboxwebsrv +#var $browserLocal = true; + +// Disable file / folder browser. +#var $browserDisable = true; + +// Disable Windows drive detection +#var $noWindowsDriveList = true; + +// Just list all drives from C:\ - Z:\ without checking if they exist or not. +// This may be required on older Windows systems with more than one drive. +#var $forceWindowsAllDriveList = true; + +/* + * Misc + */ + +/* + * Auto-refresh interval in seconds for VirtualBox host memory usage information. + * Any value below 3 will be ignored. + */ +var $hostMemInfoRefreshInterval = 5; + +/* Show % of free host memory instead of % used */ +#var $hostMemInfoShowFreePct = true; + +/* + * VM Memory warnings. + * + * If $vmMemoryStartLimitWarn is enabled, each time a VM is started through + * phpVirtualBox, it will check that the available host memory is greater than + * the base and video memory of the VM + 50MB (a little bit of overhead). If it + * is not, a confirmation dialog will be presented to confirm that you want to + * start the VM. + * + * If $vmMemoryOffset is set (and $vmMemoryStartLimitWarn), $vmMemoryOffset + * megabytes is subtracted from the available host memory before the check is + * performed by $vmMemoryStartLimitWarn logic. For instance it may be a good + * idea to always have VM memory requirements + 100MB free. 100 is the default. + */ +#var $vmMemoryStartLimitWarn = true; +#var $vmMemoryOffset = 100; + + +/* + * Display guest additions version of a running VM on its Details tab + */ +#var $enableGuestAdditionsVersionDisplay = true; + +/* Disable any of phpVirtualBox's main tabs */ +#var $disableTabVMSnapshots = true; // Snapshots tab +#var $disableTabVMConsole = true; // Console tab + +/* Screen resolutions for console tab */ +var $consoleResolutions = array('640x480','800x600','1024x768','1280x720','1440x900'); + +/* Console tab keyboard layout. Currently Oracle's RDP client only supports EN and DE. */ +var $consoleKeyboardLayout = 'LANGUAGE'; + +/* Max number of network cards per VM. Do not set above VirtualBox's limit (typically 8) or below 1 */ +var $nicMax = 4; + +/* Enable advanced configuration items (normally hidden in the VirtualBox GUI) + * Note that some of these items may not be translated to languages other than English. + */ +#var $enableAdvancedConfig = true; + +/* Enable startup / shutdown configuration. + * This only works in linux and you must add the vboxinit file to + * your startup scripts list. + */ +#var $startStopConfig = true; + +// Authentication library. +// var $authLib = 'Builtin'; + +// VM ownership +#var $enforceVMOwnership = true; + +// Per-user VM quota +#var $vmQuotaPerUser = 2; + + +// Allow VDE network configuration. This must be supported by the underlying VirtualBox installation! +// If you do not know what VDE networking is - you do not need it, it is probably not supported by your +// VirtualBox installation and will cause errors if enabled. +#var $enableVDE = true; + +// Disable setting SATA controllers port count to the max port number found when saving VMs. +#var $disableSataPortCount = true; + +/* Enable Parallel Port configuration - EXPERIMENTAL +LPT support may or may not work for you. +!!! VirtualBox LPT support only works in Linux. !!! +*/ +#var $enableLPTConfig = true; + +/* Enable HardDisk IgnoreFlush configuration. This controls the "ExtraData" setting + * in "VBoxInternal/Devices/[controller type]/0/LUN#[x]/Config/IgnoreFlush". See + * Responding to guest IDE/SATA flush requests at: + * http://www.virtualbox.org/manual/ch12.html#idp12757424 +*/ +#var $enableHDFlushConfig = true; + +/* + * Event listener timeout in seconds. This is an advanced option that most people will + * probably not need to change. + */ +#var $eventListenerTimeout = 20; + +/* END SETTINGS */ + + +} + + + diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..08b2fd3 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,22 @@ +location YNH_WWW_PATH { + alias YNH_WWW_ALIAS ; + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + index index.html; + client_max_body_size 50M; + try_files $uri $uri/ index.html; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php5-fpm-YNH_WWW_APP.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_read_timeout 600; + } + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf new file mode 100644 index 0000000..5b2a920 --- /dev/null +++ b/conf/php-fpm.conf @@ -0,0 +1,244 @@ +; Start a new pool named 'www'. +; the variable $pool can we used in any directive and will be replaced by the +; pool name ('www' here) +[YNH_WWW_APP] + +; Per pool prefix +; It only applies on the following directives: +; - 'slowlog' +; - 'listen' (unixsocket) +; - 'chroot' +; - 'chdir' +; - 'php_values' +; - 'php_admin_values' +; When not set, the global prefix (or /usr) applies instead. +; Note: This directive can also be relative to the global prefix. +; Default Value: none +;prefix = /path/to/pools/$pool + +; The address on which to accept FastCGI requests. +; Valid syntaxes are: +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on +; a specific port; +; 'port' - to listen on a TCP socket to all addresses on a +; specific port; +; '/path/to/unix/socket' - to listen on a unix socket. +; Note: This value is mandatory. +listen = /var/run/php5-fpm-YNH_WWW_APP.sock + +; Set listen(2) backlog. A value of '-1' means unlimited. +; Default Value: 128 (-1 on FreeBSD and OpenBSD) +;listen.backlog = -1 + +; List of ipv4 addresses of FastCGI clients which are allowed to connect. +; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original +; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address +; must be separated by a comma. If this value is left blank, connections will be +; accepted from any ip address. +; Default Value: any +;listen.allowed_clients = 127.0.0.1 + +; Set permissions for unix socket, if one is used. In Linux, read/write +; permissions must be set in order to allow connections from a web server. Many +; BSD-derived systems allow connections regardless of permissions. +; Default Values: user and group are set as the running user +; mode is set to 0666 +listen.owner = www-data +listen.group = www-data +listen.mode = 0600 + +; Unix user/group of processes +; Note: The user is mandatory. If the group is not set, the default user's group +; will be used. +user = www-data +group = www-data + +; Choose how the process manager will control the number of child processes. +; Possible Values: +; static - a fixed number (pm.max_children) of child processes; +; dynamic - the number of child processes are set dynamically based on the +; following directives: +; pm.max_children - the maximum number of children that can +; be alive at the same time. +; pm.start_servers - the number of children created on startup. +; pm.min_spare_servers - the minimum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is less than this +; number then some children will be created. +; pm.max_spare_servers - the maximum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is greater than this +; number then some children will be killed. +; Note: This value is mandatory. +pm = dynamic + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes to be created when pm is set to 'dynamic'. +; This value sets the limit on the number of simultaneous requests that will be +; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. +; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP +; CGI. +; Note: Used when pm is set to either 'static' or 'dynamic' +; Note: This value is mandatory. +pm.max_children = 6 + +; The number of child processes created on startup. +; Note: Used only when pm is set to 'dynamic' +; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 +pm.start_servers = 3 + +; The desired minimum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.min_spare_servers = 3 + +; The desired maximum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.max_spare_servers = 5 + +; The number of requests each child process should execute before respawning. +; This can be useful to work around memory leaks in 3rd party libraries. For +; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. +; Default Value: 0 +pm.max_requests = 500 + +; The URI to view the FPM status page. If this value is not set, no URI will be +; recognized as a status page. By default, the status page shows the following +; information: +; accepted conn - the number of request accepted by the pool; +; pool - the name of the pool; +; process manager - static or dynamic; +; idle processes - the number of idle processes; +; active processes - the number of active processes; +; total processes - the number of idle + active processes. +; max children reached - number of times, the process limit has been reached, +; when pm tries to start more children (works only for +; pm 'dynamic') +; The values of 'idle processes', 'active processes' and 'total processes' are +; updated each second. The value of 'accepted conn' is updated in real time. +; Example output: +; accepted conn: 12073 +; pool: www +; process manager: static +; idle processes: 35 +; active processes: 65 +; total processes: 100 +; max children reached: 1 +; By default the status page output is formatted as text/plain. Passing either +; 'html' or 'json' as a query string will return the corresponding output +; syntax. Example: +; http://www.foo.bar/status +; http://www.foo.bar/status?json +; http://www.foo.bar/status?html +; Note: The value must start with a leading slash (/). The value can be +; anything, but it may not be a good idea to use the .php extension or it +; may conflict with a real PHP file. +; Default Value: not set +pm.status_path = /fpm-status + +; The ping URI to call the monitoring page of FPM. If this value is not set, no +; URI will be recognized as a ping page. This could be used to test from outside +; that FPM is alive and responding, or to +; - create a graph of FPM availability (rrd or such); +; - remove a server from a group if it is not responding (load balancing); +; - trigger alerts for the operating team (24/7). +; Note: The value must start with a leading slash (/). The value can be +; anything, but it may not be a good idea to use the .php extension or it +; may conflict with a real PHP file. +; Default Value: not set +ping.path = /ping + +; This directive may be used to customize the response of a ping request. The +; response is formatted as text/plain with a 200 response code. +; Default Value: pong +;ping.response = pong + +; The timeout for serving a single request after which the worker process will +; be killed. This option should be used when the 'max_execution_time' ini option +; does not stop script execution for some reason. A value of '0' means 'off'. +; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) +; Default Value: 0 +request_terminate_timeout = 600s + +; The timeout for serving a single request after which a PHP backtrace will be +; dumped to the 'slowlog' file. A value of '0s' means 'off'. +; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) +; Default Value: 0 +request_slowlog_timeout = 5s + +; The log file for slow requests +; Default Value: not set +; Note: slowlog is mandatory if request_slowlog_timeout is set +slowlog = /var/log/nginx/YNH_WWW_APP.slow.log + +; Set open file descriptor rlimit. +; Default Value: system defined value +rlimit_files = 4096 + +; Set max core size rlimit. +; Possible Values: 'unlimited' or an integer greater or equal to 0 +; Default Value: system defined value +rlimit_core = 0 + +; Chroot to this directory at the start. This value must be defined as an +; absolute path. When this value is not set, chroot is not used. +; Note: you can prefix with '$prefix' to chroot to the pool prefix or one +; of its subdirectories. If the pool prefix is not set, the global prefix +; will be used instead. +; Note: chrooting is a great security feature and should be used whenever +; possible. However, all PHP paths will be relative to the chroot +; (error_log, sessions.save_path, ...). +; Default Value: not set +;chroot = + +; Chdir to this directory at the start. +; Note: relative path can be used. +; Default Value: current directory or / when chroot +chdir = YNH_WWW_ALIAS + +; Redirect worker stdout and stderr into main error log. If not set, stdout and +; stderr will be redirected to /dev/null according to FastCGI specs. +; Note: on highloaded environement, this can cause some delay in the page +; process time (several ms). +; Default Value: no +catch_workers_output = yes + +; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from +; the current environment. +; Default Value: clean env +;env[HOSTNAME] = $HOSTNAME +;env[PATH] = /usr/local/bin:/usr/bin:/bin +;env[TMP] = /tmp +;env[TMPDIR] = /tmp +;env[TEMP] = /tmp + +; Additional php.ini defines, specific to this pool of workers. These settings +; overwrite the values previously defined in the php.ini. The directives are the +; same as the PHP SAPI: +; php_value/php_flag - you can set classic ini defines which can +; be overwritten from PHP call 'ini_set'. +; php_admin_value/php_admin_flag - these directives won't be overwritten by +; PHP call 'ini_set' +; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. + +; Defining 'extension' will load the corresponding shared extension from +; extension_dir. Defining 'disable_functions' or 'disable_classes' will not +; overwrite previously defined php.ini values, but will append the new value +; instead. + +; Note: path INI options can be relative and will be expanded with the prefix +; (pool, global or /usr) + +; Default Value: nothing is defined by default except the values in php.ini and +; specified at startup with the -d argument +;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com +;php_flag[display_errors] = off +;php_admin_value[error_log] = /var/log/fpm-php.www.log +;php_admin_flag[log_errors] = on +;php_admin_value[memory_limit] = 32M + +php_value[upload_max_filesize] = 50M +php_value[post_max_size] = 50M +php_value[mail.add_x_header] = Off +php_value[max_execution_time] = 6000s diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..b62f383 --- /dev/null +++ b/manifest.json @@ -0,0 +1,100 @@ +{ + "name": "phpvirtualbox", + "id": "phpvirtualbox", + "packaging_format": 1, + "description": { + "en": "PhpVirtualBox for YunoHost.", + "fr": "PhpVirtualBox pour YunoHost." + }, + "url": "http://phpvirtualbox.sourceforge.net/", + "license": "free", + "maintainer": { + "name": "Jeremy MANSON", + "email": "jeremy.manson@jamson.fr", + "url": "http://www.jmanson.fr" + }, + "requirements": { + "yunohost": ">> 2.4.0" + }, + "multi_instance": false, + "services": [ + "nginx" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain name for phpvirtualbox", + "fr": "Choisissez un nom de domaine pour phpvirtualbox" + }, + "example": "example.com" + }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for phpvirtualbox", + "fr": "Choisissez un chemin pour phpvirtualbox" + }, + "example": "/example", + "default": "/example" + }, + { + "name": "admin", + "type": "user", + "ask": { + "en": "Choose an admin user", + "fr": "Choisissez l’administrateur" + }, + "example": "johndoe" + }, + { + "name": "vboxuser", + "ask": { + "en": "Enter the virtualbox's user name", + "fr": "Entrez le nom d'utilisateur de virtualbox" + }, + "example": "vbox" + }, + + { + "name": "vboxpassword", + "type": "password", + "ask": { + "en": "Enter the password of virtualbox's user", + "fr": "Entrez le mot de passe de l'utilisateur virtualbox" + }, + "example": "super_secret_password" + }, + { + "name": "vboxip", + "ask": { + "en": "Enter the virtualbox's host IP", + "fr": "Entrez l'ip de l'hote virtualbox" + }, + "example": "192.168.1.200" + }, + { + "name": "vboxport", + "ask": { + "en": "Enter the virtualbox's port", + "fr": "Entrez le port de virtualbox" + }, + "example": "18083", + "default": "18083" + }, + + { + "name": "language", + "ask": { + "en": "Choose the application language", + "fr": "Choisissez la langue de l'application" + }, + "choices": ["fr", "en"], + "default": "fr" + } + ] + } +} diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..78e815c --- /dev/null +++ b/scripts/install @@ -0,0 +1,70 @@ +#!/bin/bash +set -eu + +# Retrieve arguments +app=$YNH_APP_INSTANCE_NAME +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH +admin=$YNH_APP_ARG_ADMIN +language=$YNH_APP_ARG_LANGUAGE +vboxuser=$YNH_APP_ARG_VBOXUSER +vboxpassword=$YNH_APP_ARG_VBOXPASSWORD +vboxip=$YNH_APP_ARG_VBOXIP +vboxport=$YNH_APP_ARG_VBOXPORT + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +ynh_app_setting_set "$app" admin "$admin" +ynh_app_setting_set "$app" language "$language" + +# Check domain/path availability +sudo yunohost app checkurl "${domain}${path}" -a "$app" \ + || ynh_die "Path not available: ${domain}${path}" + + +# check dependances +if ! ynh_package_is_installed "php-pear" ; then + ynh_package_install "php-pear" +fi + +if ! ynh_package_is_installed "unzip" ; then + ynh_package_install "unzip" +fi + +# Copy source files +src_path=/var/www/$app +wget http://freefr.dl.sourceforge.net/project/phpvirtualbox/phpvirtualbox-5.0-5.zip +unzip phpvirtualbox-5.0-5.zip +sudo mkdir $src_path +sudo mv phpvirtualbox-5.0-5/* $src_path/ + +# Modifiy Phpvirtualbox conf +vbox_conf=../conf/config.php-example +sed -i "s@VBOX_IP@$vboxip@g" $vbox_conf +sed -i "s@VBOX_PORT@$vboxport@g" $vbox_conf +sed -i "s@VBOX_USER@$vboxuser@g" $vbox_conf +sed -i "s@VBOX_PASSWORD@$vboxpassword@g" $vbox_conf +sed -i "s@LANGUAGE@$language@g" $vbox_conf +sudo cp $vbox_conf $src_path/config.php +pwd + +# Modify Nginx configuration file and copy it to Nginx conf directory +nginx_conf=../conf/nginx.conf +sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf +sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf +sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf +sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf + +# Modify PHP-fpm +phpfpm_conf=../conf/php-fpm.conf +sed -i "s@YNH_WWW_APP@$app@g" $phpfpm_conf +sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $phpfpm_conf +finalphpconf=/etc/php5/fpm/pool.d/$app.conf +sudo cp ../conf/php-fpm.conf $finalphpconf +sudo chown root: $finalphpconf +sudo chmod 644 $finalphpconf +sudo chown -R www-data:www-data $src_path +# Reload services +sudo service php5-fpm reload +sudo service nginx reload diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..0ae97ef --- /dev/null +++ b/scripts/remove @@ -0,0 +1,20 @@ +#!/bin/bash + +# See comments in install script +app=$YNH_APP_INSTANCE_NAME + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Retrieve app settings +domain=$(ynh_app_setting_get "$app" domain) + +# Remove sources +sudo rm -rf /var/www/$app + +# Remove nginx configuration file +sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +sudo rm -f /etc/php5/fpm/pool.d/$app.conf +# Reload nginx service +sudo service php5-fpm reolad +sudo service nginx reload