root/trunk/gui/client/ftp_edit.php

Revision 1408, 7.5 kB (checked in by scitech, 4 days ago)

Add default user with password to statistics

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require '../include/ispcp-lib.php';
22 require '../include/class.vfs.php';
23
24 check_login(__FILE__);
25
26 if (isset($_GET['id'])) {
27     $ftp_acc = $_GET['id'];
28 } else if (isset($_POST['id'])) {
29     $ftp_acc = $_POST['id'];
30 } else {
31     user_goto('ftp_accounts.php');
32 }
33
34 $tpl = new pTemplate();
35 $tpl->define_dynamic('page', Config::get('CLIENT_TEMPLATE_PATH') . '/ftp_edit.tpl');
36 $tpl->define_dynamic('page_message', 'page');
37 $tpl->define_dynamic('logged_from', 'page');
38
39 // page functions.
40
41 function gen_page_dynamic_data(&$tpl, &$sql, $ftp_acc) {
42     $query = <<<SQL_QUERY
43         SELECT
44             homedir
45         FROM
46             ftp_users
47         WHERE
48             userid = ?
49 SQL_QUERY;
50
51     $rs = exec_query($sql, $query, array($ftp_acc));
52
53     $homedir = $rs->fields['homedir'];
54     $domain_ftp = $_SESSION['user_logged'];
55     $nftp_dir = Config::get('FTP_HOMEDIR') . "/" . $domain_ftp;
56
57     if ($nftp_dir == $homedir) {
58         $odir = "";
59         $oins = "";
60     } else {
61         $odir = " checked ";
62         $oins = substr($homedir, strlen($nftp_dir));
63     }
64
65     $tpl->assign(array('FTP_ACCOUNT' => $ftp_acc,
66             'ID' => $ftp_acc,
67             'USE_OTHER_DIR_CHECKED' => $odir,
68             'OTHER_DIR' => $oins
69             ));
70 }
71
72 function update_ftp_account(&$sql, $ftp_acc, $dmn_name) {
73     global $other_dir;
74
75     // Create a virtual filesystem (it's important to use =&!)
76     $vfs =& new vfs($dmn_name, $sql);
77
78     if (isset($_POST['uaction']) && $_POST['uaction'] === 'edit_user') {
79         if (!empty($_POST['pass']) || !empty($_POST['pass_rep'])) {
80             if ($_POST['pass'] !== $_POST['pass_rep']) {
81                 set_page_message(tr('Entered passwords differ!'));
82                 return;
83             }
84             if (!chk_password($_POST['pass'])) {
85                 if(Config::get('PASSWD_STRONG')){
86                   set_page_message(sprintf(tr('The password must be at least %s long and contain letters and numbers to be valid.'), Config::get('PASSWD_CHARS')));
87                 } else {
88                   set_page_message(sprintf(tr('Password data is shorter than %s signs or includes not permitted signs!'), Config::get('PASSWD_CHARS')));
89                 }
90                 return;
91             }
92
93             $pass = crypt_user_pass_with_salt($_POST['pass']);
94             if (isset($_POST['use_other_dir']) && $_POST['use_other_dir'] === 'on') {
95
96           $other_dir = clean_input($_POST['other_dir']);
97
98           $rs = $vfs->exists($other_dir);
99           if (!$rs) {
100                     set_page_message(tr('%s does not exist', clean_input($_POST['other_dir'])));
101                     return;
102                 } //domain_id
103
104          //append the full path (vfs is always checking per ftp so its logged in in the root of the user (no absolute paths are allowed here!)
105
106          $other_dir = Config::get('FTP_HOMEDIR') . "/" . $_SESSION['user_logged'] . clean_input($_POST['other_dir']);
107
108                 $query = <<<SQL_QUERY
109                     update
110                         ftp_users
111                     set
112                         passwd = ?,
113                         homedir = ?
114                     where
115                         userid = ?
116 SQL_QUERY;
117
118                 $rs = exec_query($sql, $query, array($pass, $other_dir, $ftp_acc));
119             } else {
120                 $query = <<<SQL_QUERY
121                     update
122                         ftp_users
123                     set
124                         passwd = ?
125                     where
126                         userid = ?
127 SQL_QUERY;
128                 $rs = exec_query($sql, $query, array($pass, $ftp_acc));
129             }
130
131             write_log($_SESSION['user_logged'] . ": updated FTP " . $ftp_acc . " account data");
132             set_page_message(tr('FTP account data updated!'));
133             user_goto('ftp_accounts.php');
134         } else {
135         if (isset($_POST['use_other_dir']) && $_POST['use_other_dir'] === 'on') {
136                 $other_dir = clean_input($_POST['other_dir']);
137                 // Strip possible double-slashes
138                 $other_dir = str_replace('//', '/', $other_dir);
139                 // Check for updirs ".."
140                 $res = preg_match("/\.\./", $other_dir);
141             if ($res !== 0) {
142             set_page_message(tr('Incorrect mount point length or syntax'));
143                 return;
144             }
145                 $ftp_home = Config::get('FTP_HOMEDIR') . "/$dmn_name/" . $other_dir;
146                 // Strip possible double-slashes
147                 $ftp_home = str_replace('//', '/', $other_dir);
148                 // Check for $other_dir existance
149                 // Create a virtual filesystem (it's important to use =&!)
150                 $vfs =& new vfs($dmn_name, $sql);
151                 // Check for directory existance
152                 $res = $vfs->exists($other_dir);
153                   if (!$res) {
154                      set_page_message(tr('%s does not exist', $other_dir));
155                      return;
156                 }
157             $other_dir = Config::get('FTP_HOMEDIR') . "/" . $_SESSION['user_logged'] . $other_dir;
158         } else { // End of user-specified mount-point
159
160         $other_dir = Config::get('FTP_HOMEDIR') . "/" . $_SESSION['user_logged'];
161
162         }
163             $query = <<<SQL_QUERY
164                     update
165                         ftp_users
166                     set
167                         homedir = ?
168                     where
169                         userid = ?
170 SQL_QUERY;
171
172             $rs = exec_query($sql, $query, array($other_dir, $ftp_acc));
173             set_page_message(tr('FTP account data updated!'));
174             user_goto('ftp_accounts.php');
175         }
176     }
177 }
178
179 // common page data.
180
181 $theme_color = Config::get('USER_INITIAL_THEME');
182
183 $tpl->assign(array(
184             'TR_CLIENT_EDIT_FTP_ACC_PAGE_TITLE' => tr('ispCP - Client/Edit FTP Account'),
185                 'THEME_COLOR_PATH' => "../themes/$theme_color",
186                 'THEME_CHARSET' => tr('encoding'),
187                 'ISP_LOGO' => get_logo($_SESSION['user_id'])
188         ));
189
190 // dynamic page data.
191
192
193 $query = <<<SQL_QUERY
194             SELECT
195                 domain_name
196             FROM
197                 domain
198             WHERE
199                 domain_admin_id = ?
200 SQL_QUERY;
201
202 $rs = exec_query($sql, $query, array($_SESSION['user_id']));
203
204 $dmn_name = $rs->fields['domain_name'];
205
206 check_ftp_perms($sql, $ftp_acc);
207 gen_page_dynamic_data($tpl, $sql, $ftp_acc);
208 update_ftp_account($sql, $ftp_acc, $dmn_name);
209
210 // static page messages.
211
212 gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_ftp_accounts.tpl');
213 gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_ftp_accounts.tpl');
214
215 gen_logged_from($tpl);
216
217 check_permissions($tpl);
218
219 $tpl->assign(array(
220                 'TR_EDIT_FTP_USER' => tr('Edit FTP user'),
221                 'TR_FTP_ACCOUNT' => tr('FTP account'),
222                 'TR_PASSWORD' => tr('Password'),
223                 'TR_PASSWORD_REPEAT' => tr('Repeat password'),
224                 'TR_USE_OTHER_DIR' => tr('Use other dir'),
225                 'TR_EDIT' => tr('Save changes'),
226                 'CHOOSE_DIR' => tr('Choose dir')
227             ));
228
229 gen_page_message($tpl);
230
231 $tpl->parse('PAGE', 'page');
232 $tpl->prnt();
233
234 if (Config::get('DUMP_GUI_DEBUG'))
235     dump_gui_debug();
236
237 unset_messages();
238
239 ?>
240
Note: See TracBrowser for help on using the browser.