~ubuntu-branches/ubuntu/raring/extplorer/raring-proposed

« back to all changes in this revision

Viewing changes to include/ftp_authentication.php

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Goirand
  • Date: 2010-07-05 19:53:12 UTC
  • Revision ID: james.westby@ubuntu.com-20100705195312-i92s1udelus7gl52
Tags: upstream-2.1.0b6+dfsg
ImportĀ upstreamĀ versionĀ 2.1.0b6+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// ensure this file is being included by a parent file
 
3
if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
 
4
/**
 
5
 * @version $Id: ftp_authentication.php 143 2009-04-01 18:48:16Z soeren $
 
6
 * @package eXtplorer
 
7
 * @copyright soeren 2007-2009
 
8
 * @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
 
9
 * @author The  The QuiX project (http://quixplorer.sourceforge.net)
 
10
 * 
 
11
 * @license
 
12
 * The contents of this file are subject to the Mozilla Public License
 
13
 * Version 1.1 (the "License"); you may not use this file except in
 
14
 * compliance with the License. You may obtain a copy of the License at
 
15
 * http://www.mozilla.org/MPL/
 
16
 * 
 
17
 * Software distributed under the License is distributed on an "AS IS"
 
18
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 
19
 * License for the specific language governing rights and limitations
 
20
 * under the License.
 
21
 * 
 
22
 * Alternatively, the contents of this file may be used under the terms
 
23
 * of the GNU General Public License Version 2 or later (the "GPL"), in
 
24
 * which case the provisions of the GPL are applicable instead of
 
25
 * those above. If you wish to allow use of your version of this file only
 
26
 * under the terms of the GPL and not to allow others to use
 
27
 * your version of this file under the MPL, indicate your decision by
 
28
 * deleting  the provisions above and replace  them with the notice and
 
29
 * other provisions required by the GPL.  If you do not delete
 
30
 * the provisions above, a recipient may use your version of this file
 
31
 * under either the MPL or the GPL."
 
32
 * 
 
33
 */
 
34
 
 
35
/**
 
36
 * This file handles ftp authentication
 
37
 *
 
38
 */
 
39
class ext_ftp_authentication {
 
40
        function execAction() {
 
41
                $ftp_login = extGetParam( $_POST, 'ftp_login_name', '' );
 
42
                $ftp_pass = extGetParam( $_POST, 'ftp_login_pass', '' );
 
43
                global $dir, $mosConfig_live_site;
 
44
 
 
45
                if( $ftp_login != '' || $ftp_pass != '' ) {
 
46
 
 
47
                        $ftp_host = extGetParam( $_POST, 'ftp_hostname_port', 'localhost:21' );
 
48
                        $url = @parse_url( 'ftp://' . $ftp_host);
 
49
                        if( empty( $url )) {
 
50
                                ext_Result::sendResult('ftp_authentication', false, 'Unable to parse the specified Host Name. Please use a hostname in this format: hostname:21' );
 
51
                        }
 
52
                        $port = empty($url['port']) ? 21 : $url['port'];
 
53
                        $ftp = new Net_FTP( $url['host'], $port, 20 );
 
54
 
 
55
                        $res = $ftp->connect();
 
56
                        if( PEAR::isError( $res )) {
 
57
                                ext_Result::sendResult('ftp_authentication', false, $GLOBALS['messages']['ftp_connection_failed'].' ('.$url['host'].')' );
 
58
                        }
 
59
                        else {
 
60
                                $res = $ftp->login( $ftp_login, $ftp_pass );
 
61
                                $ftp->disconnect();
 
62
                                if( PEAR::isError( $res )) {
 
63
                                        ext_Result::sendResult('ftp_authentication', false, $GLOBALS['messages']['ftp_login_failed'] );
 
64
 
 
65
                                }
 
66
 
 
67
                                $_SESSION['ftp_login'] = $ftp_login;
 
68
                                $_SESSION['ftp_pass'] = $ftp_pass;
 
69
                                $_SESSION['ftp_host'] = $ftp_host;
 
70
                                $_SESSION['file_mode'] = 'ftp';
 
71
 
 
72
                                session_write_close();
 
73
 
 
74
                                ext_Result::sendResult('ftp_authentication', true, ext_Lang::msg('actlogin_success') );
 
75
                        }
 
76
 
 
77
                }
 
78
                else {
 
79
                        ?>
 
80
        {
 
81
                "xtype": "form",
 
82
                "id": "simpleform",
 
83
                "labelWidth": 125,
 
84
                "url":"<?php echo basename( $GLOBALS['script_name']) ?>",
 
85
                "dialogtitle": "<?php echo $GLOBALS["messages"]["ftp_header"] ?>",
 
86
                "title": "<?php echo $GLOBALS["messages"]["ftp_login_lbl"] ?>",
 
87
                "frame": true,
 
88
                "keys": {
 
89
                    "key": Ext.EventObject.ENTER,
 
90
                    "fn" : function(){
 
91
                                if (Ext.getCmp("simpleform").getForm().isValid()) {
 
92
                                        statusBarMessage( '<?php echo ext_Lang::msg('ftp_login_check', true ) ?>', true );
 
93
                                        Ext.getCmp("simpleform").getForm().submit({
 
94
                                                "reset": false,
 
95
                                                "success": function(form, action) { location.reload() },
 
96
                                                "failure": function(form, action) {
 
97
                                                        if( !action.result ) return;
 
98
                                                        Ext.Msg.alert('<?php echo ext_Lang::err( 'error', true ) ?>', action.result.error);
 
99
                                                        statusBarMessage( action.result.error, false, false );
 
100
                                                },
 
101
                                                "scope": Ext.getCmp("simpleform").getForm(),
 
102
                                                "params": {
 
103
                                                        "option": "com_extplorer", 
 
104
                                                        "action": "ftp_authentication"
 
105
                                                }
 
106
                                        });
 
107
                } else {
 
108
                        return false;
 
109
                }
 
110
            }
 
111
                },
 
112
                "items": [{
 
113
                        "xtype": "textfield",
 
114
                        "fieldLabel": "<?php echo ext_Lang::msg('ftp_login_name', true ) ?>",
 
115
                        "name": "ftp_login_name",
 
116
                        "width":175,
 
117
                        "allowBlank":false
 
118
                },{
 
119
                        "xtype": "textfield",
 
120
                        "fieldLabel": "<?php echo ext_Lang::msg('ftp_login_pass', true ) ?>",
 
121
                        "name": "ftp_login_pass",
 
122
                        "inputType": "password",
 
123
                        "width":175,
 
124
                        "allowBlank":false
 
125
                },{
 
126
                        "xtype": "textfield",
 
127
                        "fieldLabel": "<?php echo ext_Lang::msg('ftp_hostname_port', true ) ?>",
 
128
                        "name": "ftp_hostname_port",
 
129
                        "value": "<?php echo extGetParam($_SESSION,'ftp_host', 'localhost:21') ?>",
 
130
                        "width":175,
 
131
                        "allowBlank":false
 
132
                }],
 
133
                "buttons": [{
 
134
                        "text": "<?php echo ext_Lang::msg( 'btnlogin', true ) ?>", 
 
135
                        "type": "submit",
 
136
                        "handler": function() {
 
137
                                statusBarMessage( '<?php echo ext_Lang::msg('ftp_login_check', true ) ?>', true );
 
138
                                Ext.getCmp("simpleform").getForm().submit({
 
139
                                        "reset": false,
 
140
                                        "success": function(form, action) { location.reload() },
 
141
                                        "failure": function(form, action) {
 
142
                                                if( !action.result ) return;
 
143
                                                Ext.Msg.alert('<?php echo ext_Lang::err( 'error', true ) ?>', action.result.error);
 
144
                                                statusBarMessage( action.result.error, false, false );
 
145
                                        },
 
146
                                        "scope": Ext.getCmp("simpleform").getForm(),
 
147
                                        "params": {
 
148
                                                "option": "com_extplorer", 
 
149
                                                "action": "ftp_authentication"
 
150
                                        }
 
151
                                });
 
152
                        }
 
153
                },{
 
154
                        "text": "<?php echo ext_Lang::msg( 'btncancel', true ) ?>", 
 
155
                        "handler": function() { Ext.getCmp("dialog").destroy(); }
 
156
                }]
 
157
        }
 
158
                <?php
 
159
                }
 
160
        }
 
161
}
 
162
function ftp_logout() {
 
163
        unset($_SESSION['ftp_login']);
 
164
        unset($_SESSION['ftp_pass']);
 
165
        unset($_SESSION['ftp_host']);
 
166
        session_write_close();
 
167
        extRedirect( make_link(null, null, null, null, null, null, '&file_mode=file') );
 
168
}
 
 
b'\\ No newline at end of file'