1<?php
2/* Copyright (C) 2011-2013 Laurent Destailleur  <eldy@users.sourceforge.net>
3 * Copyright (C) 2013      Juanjo Menent		<jmenent@2byte.es>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19/**
20 *   	\file       htdocs/admin/proxy.php
21 *      \ingroup    core
22 *		\brief      Page  setup proxy to use for external web access
23 */
24
25require '../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
28
29// Load translation files required by the page
30$langs->loadLangs(array("other", "users", "admin"));
31
32if (!$user->admin) accessforbidden();
33
34$upload_dir = $conf->admin->dir_temp;
35
36
37/*
38 * Actions
39 */
40
41if (GETPOST('action', 'aZ09') == 'set_proxy')
42{
43	if (GETPOST("MAIN_USE_CONNECT_TIMEOUT") && !is_numeric(GETPOST("MAIN_USE_CONNECT_TIMEOUT")))
44	{
45		setEventMessages($langs->trans("ErrorValueMustBeInteger"), null, 'errors');
46		$error++;
47	}
48	if (GETPOST("MAIN_USE_RESPONSE_TIMEOUT") && !is_numeric(GETPOST("MAIN_USE_RESPONSE_TIMEOUT")))
49	{
50		setEventMessages($langs->trans("ErrorValueMustBeInteger"), null, 'errors');
51		$error++;
52	}
53
54	if (!$error)
55	{
56		$result = 0;
57		$result += dolibarr_set_const($db, 'MAIN_USE_CONNECT_TIMEOUT', GETPOST("MAIN_USE_CONNECT_TIMEOUT"), 'chaine', 0, '', $conf->entity);
58		$result += dolibarr_set_const($db, 'MAIN_USE_RESPONSE_TIMEOUT', GETPOST("MAIN_USE_RESPONSE_TIMEOUT"), 'chaine', 0, '', $conf->entity);
59		$result += dolibarr_set_const($db, 'MAIN_PROXY_USE', GETPOST("MAIN_PROXY_USE"), 'chaine', 0, '', $conf->entity);
60		$result += dolibarr_set_const($db, 'MAIN_PROXY_HOST', GETPOST("MAIN_PROXY_HOST"), 'chaine', 0, '', $conf->entity);
61		$result += dolibarr_set_const($db, 'MAIN_PROXY_PORT', GETPOST("MAIN_PROXY_PORT"), 'chaine', 0, '', $conf->entity);
62		$result += dolibarr_set_const($db, 'MAIN_PROXY_USER', GETPOST("MAIN_PROXY_USER"), 'chaine', 0, '', $conf->entity);
63		$result += dolibarr_set_const($db, 'MAIN_PROXY_PASS', GETPOST("MAIN_PROXY_PASS"), 'chaine', 0, '', $conf->entity);
64		if ($result < 5) dol_print_error($db);
65	}
66
67	if (!$error)
68	{
69		setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
70	}
71}
72
73
74/*
75 * View
76 */
77
78$form = new Form($db);
79
80$wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
81llxHeader('', $langs->trans("Proxy"), $wikihelp);
82
83print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
84
85print '<span class="opacitymedium">'.$langs->trans("ProxyDesc")."</span><br>\n";
86print "<br>\n";
87
88
89
90print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
91print '<input type="hidden" name="token" value="'.newToken().'">';
92print '<input type="hidden" name="action" value="set_proxy">';
93
94
95$head = security_prepare_head();
96
97print dol_get_fiche_head($head, 'proxy', '', -1);
98
99
100if ($conf->use_javascript_ajax)
101{
102	print "\n".'<script type="text/javascript" language="javascript">';
103	print 'jQuery(document).ready(function () {
104                function initfields()
105                {
106                    if (jQuery("#MAIN_PROXY_USE").val()==\'1\')
107                    {
108                        jQuery(".drag").show();
109                    }
110                    if (jQuery("#MAIN_PROXY_USE").val()==\'0\')
111                    {
112                        jQuery(".drag").hide();
113                    }
114                }
115                initfields();
116                jQuery("#MAIN_PROXY_USE").change(function() {
117                    initfields();
118                });
119           })';
120	print '</script>'."\n";
121}
122
123
124// Timeout
125
126print '<table width="100%" class="noborder">';
127
128print '<tr class="liste_titre">';
129print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
130print '<td width="200">'.$langs->trans("Value").'</td>';
131print "</tr>\n";
132
133
134print '<tr class="oddeven">';
135print '<td>'.$langs->trans("ConnectionTimeout").'</td><td class="right">';
136print '</td>';
137print '<td class="nowrap">';
138print '<input class="flat" name="MAIN_USE_CONNECT_TIMEOUT" type="text" size="4" value="'.(GETPOSTISSET("MAIN_USE_CONNECT_TIMEOUT") ? GETPOST("MAIN_USE_CONNECT_TIMEOUT") : $conf->global->MAIN_USE_CONNECT_TIMEOUT).'">';
139print ' '.strtolower($langs->trans("Seconds"));
140print '</td>';
141print '</tr>';
142
143
144print '<tr class="oddeven">';
145print '<td>'.$langs->trans("ResponseTimeout").'</td><td class="right">';
146print '</td>';
147print '<td class="nowrap">';
148print '<input class="flat" name="MAIN_USE_RESPONSE_TIMEOUT" type="text" size="4" value="'.$conf->global->MAIN_USE_RESPONSE_TIMEOUT.'">';
149print ' '.strtolower($langs->trans("Seconds"));
150print '</td>';
151print '</tr>';
152
153
154print '<tr class="oddeven">';
155print '<td>'.$langs->trans("MAIN_PROXY_USE").'</td><td class="right">';
156print '</td>';
157print '<td class="nowrap">';
158print $form->selectyesno('MAIN_PROXY_USE', $conf->global->MAIN_PROXY_USE, 1);
159print '</td>';
160print '</tr>';
161
162
163print '<tr class="oddeven">';
164print '<td>'.$langs->trans("MAIN_PROXY_HOST").'</td><td class="right">';
165print '</td>';
166print '<td class="nowrap">';
167print '<input class="flat" name="MAIN_PROXY_HOST" type="text" size="16" value="'.$conf->global->MAIN_PROXY_HOST.'">';
168print '</td>';
169print '</tr>';
170
171
172print '<tr class="oddeven">';
173print '<td>'.$langs->trans("MAIN_PROXY_PORT").'</td><td class="right">';
174print '</td>';
175print '<td class="nowrap">';
176print '<input class="flat" name="MAIN_PROXY_PORT" type="text" size="4" value="'.$conf->global->MAIN_PROXY_PORT.'">';
177print '</td>';
178print '</tr>';
179
180
181print '<tr class="oddeven">';
182print '<td>'.$langs->trans("MAIN_PROXY_USER").'</td><td class="right">';
183print '</td>';
184print '<td class="nowrap">';
185print '<input class="flat" name="MAIN_PROXY_USER" type="text" size="16" value="'.$conf->global->MAIN_PROXY_USER.'">';
186print '</td>';
187print '</tr>';
188
189
190print '<tr class="oddeven">';
191print '<td>'.$langs->trans("MAIN_PROXY_PASS").'</td><td class="right">';
192print '</td>';
193print '<td class="nowrap">';
194print '<input class="flat" name="MAIN_PROXY_PASS" type="text" size="16" value="'.$conf->global->MAIN_PROXY_PASS.'">';
195print '</td>';
196print '</tr>';
197
198print '</table>';
199
200print dol_get_fiche_end();
201
202print '<div class="center">';
203print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
204print '</div>';
205
206print '</form>';
207
208// End of page
209llxFooter();
210$db->close();
211