Mage_Downloader - Version 1.6.1.0

Version Notes

1.6.1.0

Download this release

Release Info

Developer Magento Core Team
Extension Mage_Downloader
Version 1.6.1.0
Comparing to
See all releases


Version 1.6.1.0

Files changed (136) hide show
  1. .htaccess +186 -0
  2. downloader/.htaccess +11 -0
  3. downloader/Maged/Connect.php +467 -0
  4. downloader/Maged/Connect/Frontend.php +149 -0
  5. downloader/Maged/Controller.php +977 -0
  6. downloader/Maged/Exception.php +37 -0
  7. downloader/Maged/Model.php +99 -0
  8. downloader/Maged/Model/Config.php +84 -0
  9. downloader/Maged/Model/Config/Abstract.php +134 -0
  10. downloader/Maged/Model/Config/Community.php +112 -0
  11. downloader/Maged/Model/Config/Interface.php +90 -0
  12. downloader/Maged/Model/Connect.php +491 -0
  13. downloader/Maged/Model/Connect/Request.php +43 -0
  14. downloader/Maged/Model/Dowloader.php +30 -0
  15. downloader/Maged/Model/Session.php +224 -0
  16. downloader/Maged/View.php +155 -0
  17. downloader/config.ini +1 -0
  18. downloader/index.php +36 -0
  19. downloader/js/prototype.js +3277 -0
  20. downloader/lib/Mage/Archive.php +222 -0
  21. downloader/lib/Mage/Archive/Abstract.php +84 -0
  22. downloader/lib/Mage/Archive/Bz.php +79 -0
  23. downloader/lib/Mage/Archive/Gz.php +77 -0
  24. downloader/lib/Mage/Archive/Interface.php +53 -0
  25. downloader/lib/Mage/Archive/Tar.php +372 -0
  26. downloader/lib/Mage/Autoload/Simple.php +52 -0
  27. downloader/lib/Mage/Connect/Channel/Generator.php +63 -0
  28. downloader/lib/Mage/Connect/Channel/Parser.php +25 -0
  29. downloader/lib/Mage/Connect/Channel/VO.php +113 -0
  30. downloader/lib/Mage/Connect/Command.php +390 -0
  31. downloader/lib/Mage/Connect/Command/Channels.php +189 -0
  32. downloader/lib/Mage/Connect/Command/Channels_Header.php +104 -0
  33. downloader/lib/Mage/Connect/Command/Config.php +213 -0
  34. downloader/lib/Mage/Connect/Command/Config_Header.php +100 -0
  35. downloader/lib/Mage/Connect/Command/Install.php +567 -0
  36. downloader/lib/Mage/Connect/Command/Install_Header.php +237 -0
  37. downloader/lib/Mage/Connect/Command/Package.php +204 -0
  38. downloader/lib/Mage/Connect/Command/Package_Header.php +76 -0
  39. downloader/lib/Mage/Connect/Command/Registry.php +364 -0
  40. downloader/lib/Mage/Connect/Command/Registry_Header.php +84 -0
  41. downloader/lib/Mage/Connect/Command/Remote.php +231 -0
  42. downloader/lib/Mage/Connect/Command/Remote_Header.php +88 -0
  43. downloader/lib/Mage/Connect/Config.php +464 -0
  44. downloader/lib/Mage/Connect/Converter.php +336 -0
  45. downloader/lib/Mage/Connect/Frontend.php +251 -0
  46. downloader/lib/Mage/Connect/Frontend/CLI.php +456 -0
  47. downloader/lib/Mage/Connect/Ftp.php +523 -0
  48. downloader/lib/Mage/Connect/Loader.php +51 -0
  49. downloader/lib/Mage/Connect/Loader/Ftp.php +155 -0
  50. downloader/lib/Mage/Connect/Package.php +1499 -0
  51. downloader/lib/Mage/Connect/Package/Extension.php +1 -0
  52. downloader/lib/Mage/Connect/Package/Hotfix.php +137 -0
  53. downloader/lib/Mage/Connect/Package/Maintainer.php +1 -0
  54. downloader/lib/Mage/Connect/Package/Reader.php +150 -0
  55. downloader/lib/Mage/Connect/Package/Target.php +126 -0
  56. downloader/lib/Mage/Connect/Package/VO.php +96 -0
  57. downloader/lib/Mage/Connect/Package/Writer.php +177 -0
  58. downloader/lib/Mage/Connect/Packager.php +909 -0
  59. downloader/lib/Mage/Connect/Repository.php +1 -0
  60. downloader/lib/Mage/Connect/Repository/Abstract.php +1 -0
  61. downloader/lib/Mage/Connect/Repository/Channel.php +1 -0
  62. downloader/lib/Mage/Connect/Repository/Channel/Abstract.php +1 -0
  63. downloader/lib/Mage/Connect/Repository/Channel/Commercial.php +1 -0
  64. downloader/lib/Mage/Connect/Repository/Channel/Community.php +1 -0
  65. downloader/lib/Mage/Connect/Repository/Channel/Core.php +1 -0
  66. downloader/lib/Mage/Connect/Repository/Local.php +1 -0
  67. downloader/lib/Mage/Connect/Rest.php +366 -0
  68. downloader/lib/Mage/Connect/Singleconfig.php +934 -0
  69. downloader/lib/Mage/Connect/Structures/Graph.php +248 -0
  70. downloader/lib/Mage/Connect/Structures/Node.php +257 -0
  71. downloader/lib/Mage/Connect/Validator.php +440 -0
  72. downloader/lib/Mage/DB/Exception.php +36 -0
  73. downloader/lib/Mage/DB/Mysqli.php +532 -0
  74. downloader/lib/Mage/Exception.php +35 -0
  75. downloader/lib/Mage/HTTP/Client.php +84 -0
  76. downloader/lib/Mage/HTTP/Client/Curl.php +556 -0
  77. downloader/lib/Mage/HTTP/Client/Socket.php +537 -0
  78. downloader/lib/Mage/HTTP/IClient.php +145 -0
  79. downloader/lib/Mage/System/Args.php +102 -0
  80. downloader/lib/Mage/System/Dirs.php +104 -0
  81. downloader/lib/Mage/Xml/Generator.php +114 -0
  82. downloader/lib/Mage/Xml/Parser.php +115 -0
  83. downloader/mage.php +156 -0
  84. downloader/skin/boxes.css +217 -0
  85. downloader/skin/ie7boxes.css +27 -0
  86. downloader/skin/ieboxes.css +29 -0
  87. downloader/skin/images/Magento_Connect.jpg +0 -0
  88. downloader/skin/images/ajax-loader-tr.gif +0 -0
  89. downloader/skin/images/btn_bg.gif +0 -0
  90. downloader/skin/images/header_bg.gif +0 -0
  91. downloader/skin/images/logo.gif +0 -0
  92. downloader/skin/images/nav_bg.gif +0 -0
  93. downloader/skin/images/nav_separator.gif +0 -0
  94. downloader/skin/install/boxes.css +414 -0
  95. downloader/skin/install/clears.css +70 -0
  96. downloader/skin/install/ie7minus.css +40 -0
  97. downloader/skin/install/iestyles.css +78 -0
  98. downloader/skin/install/images/error_msg_icon.gif +0 -0
  99. downloader/skin/install/images/footer_bg.gif +0 -0
  100. downloader/skin/install/images/footer_container_bg.gif +0 -0
  101. downloader/skin/install/images/footer_info_separator.gif +0 -0
  102. downloader/skin/install/images/footer_informational_bg.gif +0 -0
  103. downloader/skin/install/images/footer_left.gif +0 -0
  104. downloader/skin/install/images/footer_legality_bg.gif +0 -0
  105. downloader/skin/install/images/footer_right.gif +0 -0
  106. downloader/skin/install/images/header_bg.gif +0 -0
  107. downloader/skin/install/images/header_nav_bg.gif +0 -0
  108. downloader/skin/install/images/header_top_bg.jpg +0 -0
  109. downloader/skin/install/images/header_top_container_bg.jpg +0 -0
  110. downloader/skin/install/images/logo.gif +0 -0
  111. downloader/skin/install/images/main_bg.gif +0 -0
  112. downloader/skin/install/images/main_container_bg.gif +0 -0
  113. downloader/skin/install/images/note_msg_icon.gif +0 -0
  114. downloader/skin/install/images/success_msg_icon.gif +0 -0
  115. downloader/skin/install/images/validation_advice_bg.gif +0 -0
  116. downloader/skin/install/reset.css +83 -0
  117. downloader/template/.htaccess +2 -0
  118. downloader/template/connect/iframe.phtml +121 -0
  119. downloader/template/connect/packages.phtml +221 -0
  120. downloader/template/connect/packages_prepare.phtml +78 -0
  121. downloader/template/exception.phtml +36 -0
  122. downloader/template/footer.phtml +40 -0
  123. downloader/template/header.phtml +73 -0
  124. downloader/template/index.phtml +36 -0
  125. downloader/template/install/download.phtml +184 -0
  126. downloader/template/install/footer.phtml +49 -0
  127. downloader/template/install/header.phtml +99 -0
  128. downloader/template/install/writable.phtml +40 -0
  129. downloader/template/login.phtml +43 -0
  130. downloader/template/messages.phtml +39 -0
  131. downloader/template/noroute.phtml +31 -0
  132. downloader/template/settings.phtml +166 -0
  133. downloader/template/writable.phtml +35 -0
  134. index.php +80 -0
  135. mage +54 -0
  136. package.xml +18 -0
.htaccess ADDED
@@ -0,0 +1,186 @@
1
+ ############################################
2
+ ## uncomment these lines for CGI mode
3
+ ## make sure to specify the correct cgi php binary file name
4
+ ## it might be /cgi-bin/php-cgi
5
+
6
+ # Action php5-cgi /cgi-bin/php5-cgi
7
+ # AddHandler php5-cgi .php
8
+
9
+ ############################################
10
+ ## GoDaddy specific options
11
+
12
+ # Options -MultiViews
13
+
14
+ ## you might also need to add this line to php.ini
15
+ ## cgi.fix_pathinfo = 1
16
+ ## if it still doesn't work, rename php.ini to php5.ini
17
+
18
+ ############################################
19
+ ## this line is specific for 1and1 hosting
20
+
21
+ #AddType x-mapp-php5 .php
22
+ #AddHandler x-mapp-php5 .php
23
+
24
+ ############################################
25
+ ## default index file
26
+
27
+ DirectoryIndex index.php
28
+
29
+ <IfModule mod_php5.c>
30
+
31
+ ############################################
32
+ ## adjust memory limit
33
+
34
+ # php_value memory_limit 64M
35
+ php_value memory_limit 256M
36
+ php_value max_execution_time 18000
37
+
38
+ ############################################
39
+ ## disable magic quotes for php request vars
40
+
41
+ php_flag magic_quotes_gpc off
42
+
43
+ ############################################
44
+ ## disable automatic session start
45
+ ## before autoload was initialized
46
+
47
+ php_flag session.auto_start off
48
+
49
+ ############################################
50
+ ## enable resulting html compression
51
+
52
+ #php_flag zlib.output_compression on
53
+
54
+ ###########################################
55
+ # disable user agent verification to not break multiple image upload
56
+
57
+ php_flag suhosin.session.cryptua off
58
+
59
+ ###########################################
60
+ # turn off compatibility with PHP4 when dealing with objects
61
+
62
+ php_flag zend.ze1_compatibility_mode Off
63
+
64
+ </IfModule>
65
+
66
+ <IfModule mod_security.c>
67
+ ###########################################
68
+ # disable POST processing to not break multiple image upload
69
+
70
+ SecFilterEngine Off
71
+ SecFilterScanPOST Off
72
+ </IfModule>
73
+
74
+ <IfModule mod_deflate.c>
75
+
76
+ ############################################
77
+ ## enable apache served files compression
78
+ ## http://developer.yahoo.com/performance/rules.html#gzip
79
+
80
+ # Insert filter on all content
81
+ ###SetOutputFilter DEFLATE
82
+ # Insert filter on selected content types only
83
+ #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
84
+
85
+ # Netscape 4.x has some problems...
86
+ #BrowserMatch ^Mozilla/4 gzip-only-text/html
87
+
88
+ # Netscape 4.06-4.08 have some more problems
89
+ #BrowserMatch ^Mozilla/4\.0[678] no-gzip
90
+
91
+ # MSIE masquerades as Netscape, but it is fine
92
+ #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
93
+
94
+ # Don't compress images
95
+ #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
96
+
97
+ # Make sure proxies don't deliver the wrong content
98
+ #Header append Vary User-Agent env=!dont-vary
99
+
100
+ </IfModule>
101
+
102
+ <IfModule mod_ssl.c>
103
+
104
+ ############################################
105
+ ## make HTTPS env vars available for CGI mode
106
+
107
+ SSLOptions StdEnvVars
108
+
109
+ </IfModule>
110
+
111
+ <IfModule mod_rewrite.c>
112
+
113
+ ############################################
114
+ ## enable rewrites
115
+
116
+ Options +FollowSymLinks
117
+ RewriteEngine on
118
+
119
+ ############################################
120
+ ## you can put here your magento root folder
121
+ ## path relative to web root
122
+
123
+ #RewriteBase /magento/
124
+
125
+ ############################################
126
+ ## workaround for HTTP authorization
127
+ ## in CGI environment
128
+
129
+ RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
130
+
131
+ ############################################
132
+ ## always send 404 on missing files in these folders
133
+
134
+ RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
135
+
136
+ ############################################
137
+ ## never rewrite for existing files, directories and links
138
+
139
+ RewriteCond %{REQUEST_FILENAME} !-f
140
+ RewriteCond %{REQUEST_FILENAME} !-d
141
+ RewriteCond %{REQUEST_FILENAME} !-l
142
+
143
+ ############################################
144
+ ## rewrite everything else to index.php
145
+
146
+ RewriteRule .* index.php [L]
147
+
148
+ </IfModule>
149
+
150
+
151
+ ############################################
152
+ ## Prevent character encoding issues from server overrides
153
+ ## If you still have problems, use the second line instead
154
+
155
+ AddDefaultCharset Off
156
+ #AddDefaultCharset UTF-8
157
+
158
+ <IfModule mod_expires.c>
159
+
160
+ ############################################
161
+ ## Add default Expires header
162
+ ## http://developer.yahoo.com/performance/rules.html#expires
163
+
164
+ ExpiresDefault "access plus 1 year"
165
+
166
+ </IfModule>
167
+
168
+ ############################################
169
+ ## By default allow all access
170
+
171
+ Order allow,deny
172
+ Allow from all
173
+
174
+ ###########################################
175
+ ## Deny access to release notes to prevent disclosure of the installed Magento version
176
+
177
+ <Files RELEASE_NOTES.txt>
178
+ order allow,deny
179
+ deny from all
180
+ </Files>
181
+
182
+ ############################################
183
+ ## If running in cluster environment, uncomment this
184
+ ## http://developer.yahoo.com/performance/rules.html#etags
185
+
186
+ #FileETag none
downloader/.htaccess ADDED
@@ -0,0 +1,11 @@
1
+ <IfModule mod_deflate.c>
2
+
3
+ RemoveOutputFilter DEFLATE
4
+ RemoveOutputFilter GZIP
5
+
6
+ </IfModule>
7
+
8
+ <Files ~ "\.(cfg|ini|xml)quot;>
9
+ order allow,deny
10
+ deny from all
11
+ </Files>
downloader/Maged/Connect.php ADDED
@@ -0,0 +1,467 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Connect
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ error_reporting(E_ALL & ~E_NOTICE);
28
+
29
+ // just a shortcut
30
+ if (!defined('DS')) {
31
+ define('DS', DIRECTORY_SEPARATOR);
32
+ }
33
+
34
+ // add Mage lib in include_path if needed
35
+ $_includePath = get_include_path();
36
+ $_libDir = dirname(dirname(__FILE__)) . DS . 'lib';
37
+ if (strpos($_includePath, $_libDir) === false) {
38
+ if (substr($_includePath, 0, 2) === '.' . PATH_SEPARATOR) {
39
+ $_includePath = '.' . PATH_SEPARATOR . $_libDir . PATH_SEPARATOR . substr($_includePath, 2);
40
+ } else {
41
+ $_includePath = $_libDir . PATH_SEPARATOR . $_includePath;
42
+ }
43
+ set_include_path($_includePath);
44
+ }
45
+
46
+ /**
47
+ * Class for connect
48
+ *
49
+ * @category Mage
50
+ * @package Mage_Connect
51
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
52
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
53
+ */
54
+ class Maged_Connect
55
+ {
56
+
57
+ /**
58
+ * Object of config
59
+ *
60
+ * @var Mage_Connect_Config
61
+ */
62
+ protected $_config;
63
+
64
+ /**
65
+ * Object of single config
66
+ *
67
+ * @var Mage_Connect_Singleconfig
68
+ */
69
+ protected $_sconfig;
70
+
71
+ /**
72
+ * Object of frontend
73
+ *
74
+ * @var Mage_Connect_Frontend
75
+ */
76
+ protected $_frontend;
77
+
78
+ /**
79
+ * Internal cache for command objects
80
+ *
81
+ * @var array
82
+ */
83
+ protected $_cmdCache = array();
84
+
85
+ /**
86
+ * Instance of class
87
+ *
88
+ * @var Maged_Connect
89
+ */
90
+ static protected $_instance;
91
+
92
+ /**
93
+ * Constructor
94
+ */
95
+ public function __construct()
96
+ {
97
+ $this->getConfig();
98
+ $this->getSingleConfig();
99
+ $this->getFrontend();
100
+ }
101
+
102
+ /**
103
+ * Initialize instance
104
+ *
105
+ * @return Maged_Connect
106
+ */
107
+ public static function getInstance()
108
+ {
109
+ if (!self::$_instance) {
110
+ self::$_instance = new self;
111
+ }
112
+ return self::$_instance;
113
+ }
114
+
115
+ /**
116
+ * Retrieve object of config and set it to Mage_Connect_Command
117
+ *
118
+ * @return Mage_Connect_Config
119
+ */
120
+ public function getConfig()
121
+ {
122
+ if (!$this->_config) {
123
+ $this->_config = new Mage_Connect_Config();
124
+ $ftp=$this->_config->__get('remote_config');
125
+ if(!empty($ftp)){
126
+ $packager = new Mage_Connect_Packager();
127
+ list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
128
+ $this->_config=$config;
129
+ $this->_sconfig=$cache;
130
+ }
131
+ $this->_config->magento_root = dirname(dirname(__FILE__)).DS.'..';
132
+ Mage_Connect_Command::setConfigObject($this->_config);
133
+ }
134
+ return $this->_config;
135
+ }
136
+
137
+ /**
138
+ * Retrieve object of single config and set it to Mage_Connect_Command
139
+ *
140
+ * @param bool $reload
141
+ * @return Mage_Connect_Singleconfig
142
+ */
143
+ public function getSingleConfig($reload = false)
144
+ {
145
+ if(!$this->_sconfig || $reload) {
146
+ $this->_sconfig = new Mage_Connect_Singleconfig($this->getConfig()->magento_root . DIRECTORY_SEPARATOR . $this->getConfig()->downloader_path . DIRECTORY_SEPARATOR . Mage_Connect_Singleconfig::DEFAULT_SCONFIG_FILENAME);
147
+ }
148
+ Mage_Connect_Command::setSconfig($this->_sconfig);
149
+ return $this->_sconfig;
150
+
151
+ }
152
+
153
+ /**
154
+ * Retrieve object of frontend and set it to Mage_Connect_Command
155
+ *
156
+ * @return Maged_Connect_Frontend
157
+ */
158
+ public function getFrontend()
159
+ {
160
+ if (!$this->_frontend) {
161
+ $this->_frontend = new Maged_Connect_Frontend();
162
+ Mage_Connect_Command::setFrontendObject($this->_frontend);
163
+ }
164
+ return $this->_frontend;
165
+ }
166
+
167
+ /**
168
+ * Retrieve lof from frontend
169
+ *
170
+ * @return array
171
+ */
172
+ public function getLog()
173
+ {
174
+ return $this->getFrontend()->getLog();
175
+ }
176
+
177
+ /**
178
+ * Retrieve output from frontend
179
+ *
180
+ * @return array
181
+ */
182
+ public function getOutput()
183
+ {
184
+ return $this->getFrontend()->getOutput();
185
+ }
186
+
187
+ /**
188
+ * Clean registry
189
+ *
190
+ * @return Maged_Connect
191
+ */
192
+ public function cleanSconfig()
193
+ {
194
+ $this->getSingleConfig()->clear();
195
+ return $this;
196
+ }
197
+
198
+ /**
199
+ * Delete directory recursively
200
+ *
201
+ * @param string $path
202
+ * @return Maged_Connect
203
+ */
204
+ public function delTree($path) {
205
+ if (@is_dir($path)) {
206
+ $entries = @scandir($path);
207
+ foreach ($entries as $entry) {
208
+ if ($entry != '.' && $entry != '..') {
209
+ $this->delTree($path.DS.$entry);
210
+ }
211
+ }
212
+ @rmdir($path);
213
+ } else {
214
+ @unlink($path);
215
+ }
216
+ return $this;
217
+ }
218
+
219
+ /**
220
+ * Run commands from Mage_Connect_Command
221
+ *
222
+ * @param string $command
223
+ * @param array $options
224
+ * @param array $params
225
+ * @return
226
+ */
227
+ public function run($command, $options=array(), $params=array())
228
+ {
229
+ @set_time_limit(0);
230
+ @ini_set('memory_limit', '256M');
231
+
232
+ if (empty($this->_cmdCache[$command])) {
233
+ Mage_Connect_Command::getCommands();
234
+ /**
235
+ * @var $cmd Mage_Connect_Command
236
+ */
237
+ $cmd = Mage_Connect_Command::getInstance($command);
238
+ if ($cmd instanceof Mage_Connect_Error) {
239
+ return $cmd;
240
+ }
241
+ $this->_cmdCache[$command] = $cmd;
242
+ } else {
243
+ /**
244
+ * @var $cmd Mage_Connect_Command
245
+ */
246
+ $cmd = $this->_cmdCache[$command];
247
+ }
248
+ $ftp=$this->getConfig()->remote_config;
249
+ if(strlen($ftp)>0){
250
+ $options=array_merge($options, array('ftp'=>$ftp));
251
+ }
252
+ $cmd->run($command, $options, $params);
253
+ if ($cmd->ui()->hasErrors()) {
254
+ return false;
255
+ } else {
256
+ return true;
257
+ }
258
+ }
259
+
260
+ public function setRemoteConfig($uri) #$host, $user, $password, $path='', $port=null)
261
+ {
262
+ #$uri = 'ftp://' . $user . ':' . $password . '@' . $host . (is_numeric($port) ? ':' . $port : '') . '/' . trim($path, '/') . '/';
263
+ //$this->run('config-set', array(), array('remote_config', $uri));
264
+ //$this->run('config-set', array('ftp'=>$uri), array('remote_config', $uri));
265
+ $this->getConfig()->remote_config=$uri;
266
+ return $this;
267
+ }
268
+
269
+ /**
270
+ *
271
+ * @param array $errors Error messages
272
+ * @return Maged_Connect
273
+ */
274
+ public function showConnectErrors($errors)
275
+ {
276
+ echo '<script type="text/javascript">';
277
+ $run = new Maged_Model_Connect_Request();
278
+ if ($callback = $run->get('failure_callback')) {
279
+ if (is_array($callback)) {
280
+ call_user_func_array($callback, array($result));
281
+ } else {
282
+ echo $callback;
283
+ }
284
+ }
285
+ echo '</script>';
286
+
287
+ return $this;
288
+ }
289
+
290
+ /**
291
+ * Run Mage_Connect_Command with html output console style
292
+ *
293
+ * @param array|Maged_Model $runParams command, options, params,
294
+ * comment, success_callback, failure_callback
295
+ */
296
+ public function runHtmlConsole($runParams)
297
+ {
298
+ if (function_exists('apache_setenv')) {
299
+ apache_setenv('no-gzip', '1');
300
+ }
301
+ @ini_set('zlib.output_compression', 0);
302
+ @ini_set('implicit_flush', 1);
303
+ for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
304
+ ob_implicit_flush();
305
+
306
+ $fe = $this->getFrontend();
307
+ $oldLogStream = $fe->getLogStream();
308
+ $fe->setLogStream('stdout');
309
+
310
+ if ($runParams instanceof Maged_Model) {
311
+ $run = $runParams;
312
+ } elseif (is_array($runParams)) {
313
+ $run = new Maged_Model_Connect_Request($runParams);
314
+ } elseif (is_string($runParams)) {
315
+ $run = new Maged_Model_Connect_Request(array('comment'=>$runParams));
316
+ } else {
317
+ throw Maged_Exception("Invalid run parameters");
318
+ }
319
+
320
+ if (!$run->get('no-header')) {
321
+ ?>
322
+ <html><head><style type="text/css">
323
+ body { margin:0px;
324
+ padding:3px;
325
+ background:black;
326
+ color:#2EC029;
327
+ font:normal 11px Lucida Console, Courier New, serif;
328
+ }
329
+ </style></head><body>
330
+ <script type="text/javascript">
331
+ if (parent && parent.disableInputs) {
332
+ parent.disableInputs(true);
333
+ }
334
+ if (typeof auto_scroll=='undefined') {
335
+ var auto_scroll = window.setInterval(console_scroll, 10);
336
+ }
337
+ function console_scroll()
338
+ {
339
+ if (typeof top.$ != 'function') {
340
+ return;
341
+ }
342
+ if (top.$('connect_iframe_scroll').checked) {
343
+ document.body.scrollTop+=3;
344
+ }
345
+ }
346
+ function show_message(message, newline)
347
+ {
348
+ var bodyElement = document.getElementsByTagName('body')[0];
349
+ if (typeof newline == 'undefined') {
350
+ newline = true
351
+ }
352
+ if (newline) {
353
+ bodyElement.innerHTML += '<br/>';
354
+ }
355
+ bodyElement.innerHTML += message;
356
+ }
357
+ function clear_cache(callbacks)
358
+ {
359
+ if (typeof top.Ajax != 'object') {
360
+ return;
361
+ }
362
+ var message = 'Exception during cache and session cleaning';
363
+ var url = window.location.href.split('?')[0] + '?A=cleanCache';
364
+ var intervalID = setInterval(function() {show_message('.', false); }, 500);
365
+ var clean = 0;
366
+ var maintenance = 0;
367
+ if (window.location.href.indexOf('clean_sessions') >= 0) {
368
+ clean = 1;
369
+ }
370
+ if (window.location.href.indexOf('maintenance') >= 0) {
371
+ maintenance = 1;
372
+ }
373
+
374
+ new top.Ajax.Request(url, {
375
+ method: 'post',
376
+ parameters: {clean_sessions:clean, maintenance:maintenance},
377
+ onCreate: function() {
378
+ show_message('Cleaning cache');
379
+ show_message('');
380
+ },
381
+ onSuccess: function(transport, json) {
382
+ var result = true;
383
+ try{
384
+ var response = eval('(' + transport.responseText + ')');
385
+ if (typeof response.result != 'undefined') {
386
+ result = response.result;
387
+ } else {
388
+ result = false;
389
+ }
390
+ if (typeof response.message != 'undefined') {
391
+ if (response.message.length > 0) {
392
+ message = response.message;
393
+ } else {
394
+ message = 'Cache cleaned successfully';
395
+ }
396
+ }
397
+ } catch (ex){
398
+ result = false;
399
+ }
400
+ if (result) {
401
+ callbacks.success();
402
+ } else {
403
+ callbacks.fail();
404
+ }
405
+ },
406
+ onFailure: function() {
407
+ callbacks.fail();
408
+ },
409
+ onComplete: function(transport) {
410
+ clearInterval(intervalID);
411
+ show_message(message);
412
+ }
413
+ });
414
+ }
415
+ </script>
416
+ <?php
417
+ }
418
+ echo htmlspecialchars($run->get('comment'));
419
+
420
+ if ($command = $run->get('command')) {
421
+ $result = $this->run($command, $run->get('options'), $run->get('params'));
422
+
423
+ if ($this->getFrontend()->hasErrors()) {
424
+ echo "<br/>CONNECT ERROR: ";
425
+ foreach ($this->getFrontend()->getErrors(false) as $error) {
426
+ echo nl2br($error[1]);
427
+ echo '<br/>';
428
+ }
429
+ }
430
+ echo '<script type="text/javascript">';
431
+ if ($this->getFrontend()->hasErrors()) {
432
+ if ($callback = $run->get('failure_callback')) {
433
+ if (is_array($callback)) {
434
+ call_user_func_array($callback, array($result));
435
+ } else {
436
+ echo $callback;
437
+ }
438
+ }
439
+ } else {
440
+ if (!$run->get('no-footer')) {
441
+ if ($callback = $run->get('success_callback')) {
442
+ if (is_array($callback)) {
443
+ call_user_func_array($callback, array($result));
444
+ } else {
445
+ echo $callback;
446
+ }
447
+ }
448
+ }
449
+ }
450
+ echo '</script>';
451
+ } else {
452
+ $result = false;
453
+ }
454
+ if ($this->getFrontend()->getErrors() || !$run->get('no-footer')) {
455
+ ?>
456
+ <script type="text/javascript">
457
+ if (parent && parent.disableInputs) {
458
+ parent.disableInputs(false);
459
+ }
460
+ </script>
461
+ </body></html>
462
+ <?php
463
+ $fe->setLogStream($oldLogStream);
464
+ }
465
+ return $result;
466
+ }
467
+ }
downloader/Maged/Connect/Frontend.php ADDED
@@ -0,0 +1,149 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Connect
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Class frontend
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Connect
32
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
33
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
+ */
35
+ class Maged_Connect_Frontend extends Mage_Connect_Frontend
36
+ {
37
+
38
+ /**
39
+ * Log stream or not
40
+ *
41
+ * @var string
42
+ */
43
+ protected $_logStream = null;
44
+
45
+ /**
46
+ * Output cache
47
+ *
48
+ * @var array
49
+ */
50
+ protected $_out = array();
51
+
52
+ /**
53
+ * Set log stream
54
+ *
55
+ * @param string|resource $stream 'stdout' or open php stream
56
+ */
57
+ public function setLogStream($stream)
58
+ {
59
+ $this->_logStream = $stream;
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * Retrieve log stream
65
+ *
66
+ * @return string
67
+ */
68
+ public function getLogStream()
69
+ {
70
+ return $this->_logStream;
71
+ }
72
+
73
+ /**
74
+ * Echo data from executed command
75
+ */
76
+ public function output($data)
77
+ {
78
+
79
+ $this->_out = $data;
80
+
81
+ if ('stdout'===$this->_logStream) {
82
+ if (is_string($data)) {
83
+ echo $data."<br/>".str_repeat(" ", 256);
84
+ } elseif (is_array($data)) {
85
+ $data = array_pop($data);
86
+ if (!empty($data['message']) && is_string($data['message'])) {
87
+ echo $data['message']."<br/>".str_repeat(" ", 256);
88
+ } elseif (!empty($data['data'])) {
89
+ if (is_string($data['data'])) {
90
+ echo $data['data']."<br/>".str_repeat(" ", 256);
91
+ } else {
92
+ if (isset($data['title'])) {
93
+ echo $data['title']."<br/>".str_repeat(" ", 256);
94
+ }
95
+ if (is_array($data['data'])) {
96
+ foreach ($data['data'] as $row) {
97
+ foreach ($row as $msg) {
98
+ echo "&nbsp;".$msg;
99
+ }
100
+ echo "<br/>".str_repeat(" ", 256);
101
+ }
102
+ } else {
103
+ echo "&nbsp;".$data['data'];
104
+ }
105
+ }
106
+ }
107
+ } else {
108
+ print_r($data);
109
+ }
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Method for ask client about rewrite all files.
115
+ *
116
+ * @param $string
117
+ */
118
+ public function confirm($string)
119
+ {
120
+ $formId = $_POST['form_id'];
121
+ echo <<<SCRIPT
122
+ <script type="text/javascript">
123
+ if (confirm("{$string}")) {
124
+ parent.document.getElementById('ignore_local_modification').value=1;
125
+ parent.onSuccess();
126
+ if (parent && parent.disableInputs) {
127
+ parent.disableInputs(false);
128
+ }
129
+ window.onload = function () {
130
+ parent.document.getElementById('{$formId}').submit();
131
+ parent.document.getElementById('ignore_local_modification').value='';
132
+ }
133
+ }
134
+ </script>
135
+ SCRIPT;
136
+ }
137
+
138
+ /**
139
+ * Retrieve output cache
140
+ *
141
+ * @return array
142
+ */
143
+ public function getOutput()
144
+ {
145
+ return $this->_out;
146
+ }
147
+
148
+ }
149
+
downloader/Maged/Controller.php ADDED
@@ -0,0 +1,977 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Connect
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Class Controller
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Connect
32
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
33
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
+ */
35
+ final class Maged_Controller
36
+ {
37
+ /**
38
+ * Request key of action
39
+ */
40
+ const ACTION_KEY = 'A';
41
+
42
+ /**
43
+ * Instance of class
44
+ *
45
+ * @var Maged_Controller
46
+ */
47
+ private static $_instance;
48
+
49
+ /**
50
+ * Current action name
51
+ *
52
+ * @var string
53
+ */
54
+ private $_action;
55
+
56
+ /**
57
+ * Controller is dispathed flag
58
+ *
59
+ * @var bool
60
+ */
61
+ private $_isDispatched = false;
62
+
63
+ /**
64
+ * Redirect to URL
65
+ *
66
+ * @var string
67
+ */
68
+ private $_redirectUrl;
69
+
70
+ /**
71
+ * Downloader dir path
72
+ *
73
+ * @var string
74
+ */
75
+ private $_rootDir;
76
+
77
+ /**
78
+ * Magento root dir path
79
+ *
80
+ * @var string
81
+ */
82
+ private $_mageDir;
83
+
84
+ /**
85
+ * View instance
86
+ *
87
+ * @var Maged_View
88
+ */
89
+ private $_view;
90
+
91
+ /**
92
+ * Connect config instance
93
+ *
94
+ * @var Mage_Connect_Config
95
+ */
96
+ private $_config;
97
+
98
+ /**
99
+ * Config instance
100
+ *
101
+ * @var Maged_Model_Config
102
+ */
103
+ private $_localConfig;
104
+
105
+ /**
106
+ * Session instance
107
+ *
108
+ * @var Maged_Model_Session
109
+ */
110
+ private $_session;
111
+
112
+ /**
113
+ * Root dir is writable flag
114
+ *
115
+ * @var bool
116
+ */
117
+ private $_writable;
118
+
119
+ /**
120
+ * Use maintenance flag
121
+ *
122
+ * @var bool
123
+ */
124
+ protected $_maintenance;
125
+
126
+ /**
127
+ * Maintenance file path
128
+ *
129
+ * @var string
130
+ */
131
+ protected $_maintenanceFile;
132
+
133
+ /**
134
+ * Register array for singletons
135
+ *
136
+ * @var array
137
+ */
138
+ protected $_singletons = array();
139
+
140
+ //////////////////////////// ACTIONS
141
+
142
+
143
+ /**
144
+ * Get ftp string from post data
145
+ *
146
+ * @param array $post post data
147
+ * @return string FTP Url
148
+ */
149
+ private function getFtpPost($post){
150
+ if (empty($post['ftp_host'])) {
151
+ $_POST['ftp'] = '';
152
+ return '';
153
+ }
154
+ $ftp = 'ftp://';
155
+ $post['ftp_proto'] = 'ftp://';
156
+
157
+ if (!empty($post['ftp_path']) && strlen(trim($post['ftp_path'], '\\/')) > 0) {
158
+ $post['ftp_path'] = '/' . trim($post['ftp_path'], '\\/') . '/';
159
+ } else {
160
+ $post['ftp_path'] = '/';
161
+ }
162
+
163
+ $start = stripos($post['ftp_host'],'ftp://');
164
+ if ($start !== false){
165
+ $post['ftp_proto'] = 'ftp://';
166
+ $post['ftp_host'] = substr($post['ftp_host'], $start + 6 - 1);
167
+ }
168
+ $start = stripos($post['ftp_host'],'ftps://');
169
+ if ($start !== false) {
170
+ $post['ftp_proto'] = 'ftps://';
171
+ $post['ftp_host'] = substr($post['ftp_host'], $start + 7 - 1);
172
+ }
173
+
174
+ $post['ftp_host'] = trim($post['ftp_host'], '\\/');
175
+
176
+ if (!empty($post['ftp_login']) && !empty($post['ftp_password'])){
177
+ $ftp = sprintf("%s%s:%s@%s%s",
178
+ $post['ftp_proto'],
179
+ $post['ftp_login'],
180
+ $post['ftp_password'],
181
+ $post['ftp_host'],
182
+ $post['ftp_path']
183
+ );
184
+ } elseif (!empty($post['ftp_login'])) {
185
+ $ftp = sprintf(
186
+ "%s%s@%s%s",
187
+ $post['ftp_proto'],
188
+ $post['ftp_login'],
189
+ $post['ftp_host'],
190
+ $post['ftp_path']
191
+ );
192
+ } else {
193
+ $ftp = $post['ftp_proto'] . $post['ftp_host'] . $post['ftp_path'];
194
+ }
195
+
196
+ $_POST['ftp'] = $ftp;
197
+ return $ftp;
198
+ }
199
+
200
+ /**
201
+ * NoRoute
202
+ */
203
+ public function norouteAction()
204
+ {
205
+ header("HTTP/1.0 404 Invalid Action");
206
+ echo $this->view()->template('noroute.phtml');
207
+ }
208
+
209
+ /**
210
+ * Login
211
+ */
212
+ public function loginAction()
213
+ {
214
+ $this->view()->set('username', !empty($_GET['username']) ? $_GET['username'] : '');
215
+ echo $this->view()->template('login.phtml');
216
+ }
217
+
218
+ /**
219
+ * Logout
220
+ */
221
+ public function logoutAction()
222
+ {
223
+ $this->session()->logout();
224
+ $this->redirect($this->url());
225
+ }
226
+
227
+ /**
228
+ * Index
229
+ */
230
+ public function indexAction()
231
+ {
232
+ $config = $this->config();
233
+ if (!$this->isInstalled()) {
234
+ $this->view()->set('mage_url', dirname(dirname($_SERVER['SCRIPT_NAME'])));
235
+ $this->view()->set(
236
+ 'use_custom_permissions_mode',
237
+ $config->__get('use_custom_permissions_mode')
238
+ ? $config->__get('use_custom_permissions_mode')
239
+ : '0'
240
+ );
241
+ $this->view()->set('mkdir_mode', decoct($config->__get('global_dir_mode')));
242
+ $this->view()->set('chmod_file_mode', decoct($config->__get('global_file_mode')));
243
+ $this->view()->set('protocol', $config->__get('protocol'));
244
+ $this->channelConfig()->setInstallView($config,$this->view());
245
+
246
+ echo $this->view()->template('install/download.phtml');
247
+ } elseif (!$config->sync_pear) {
248
+ $this->model('connect', true)->connect()->run('sync');
249
+ $this->forward('connectPackages');
250
+ } else {
251
+ $this->forward('connectPackages');
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Empty Action
257
+ */
258
+ public function emptyAction()
259
+ {
260
+ $this->model('connect', true)
261
+ ->connect()
262
+ ->runHtmlConsole('Please wait, preparing for updates...');
263
+ }
264
+
265
+ /**
266
+ * Install all magento
267
+ */
268
+ public function connectInstallAllAction()
269
+ {
270
+ $p = &$_POST;
271
+ $this->getFtpPost($p);
272
+ $errors = $this->model('connect', true)->validateConfigPost($p);
273
+ /* todo show errors */
274
+ if ($errors) {
275
+ $message = "CONNECT ERROR: ";
276
+ foreach ($errors as $err) {
277
+ $message .= $err . "\n";
278
+ }
279
+ $this->model('connect', true)->connect()->runHtmlConsole($message);
280
+ $this->model('connect', true)->connect()->showConnectErrors($errors);
281
+ return;
282
+ }
283
+
284
+ if( 1 == $p['inst_protocol']){
285
+ $this->model('connect', true)->connect()->setRemoteConfig($this->getFtpPost($p));
286
+ }
287
+
288
+ $this->channelConfig()->setPostData($this->config(),$p);
289
+
290
+ $chan = $this->config()->__get('root_channel');
291
+ $this->model('connect', true)->saveConfigPost($_POST);
292
+ $this->channelConfig()->setSettingsSession($_POST, $this->session());
293
+ $this->model('connect', true)->installAll(!empty($_GET['force']), $chan);
294
+ $p = null;
295
+ }
296
+
297
+ /**
298
+ * Connect packages
299
+ */
300
+ public function connectPackagesAction()
301
+ {
302
+ $connect = $this->model('connect', true);
303
+
304
+ if (isset($_GET['loggedin'])) {
305
+ $connect->connect()->run('sync');
306
+ }
307
+
308
+ $this->view()->set('connect', $connect);
309
+ $this->view()->set('channel_config', $this->channelConfig());
310
+ $remoteConfig = $this->config()->remote_config;
311
+ if (!$this->isWritable() && empty($remoteConfig)) {
312
+ $this->view()->set('writable_warning', true);
313
+ }
314
+
315
+ echo $this->view()->template('connect/packages.phtml');
316
+ }
317
+
318
+ /**
319
+ * Connect packages POST
320
+ */
321
+ public function connectPackagesPostAction()
322
+ {
323
+ $actions = isset($_POST['actions']) ? $_POST['actions'] : array();
324
+ if (isset($_POST['ignore_local_modification'])) {
325
+ $ignoreLocalModification = $_POST['ignore_local_modification'];
326
+ } else {
327
+ $ignoreLocalModification = '';
328
+ }
329
+ $this->model('connect', true)->applyPackagesActions($actions, $ignoreLocalModification);
330
+ }
331
+
332
+ /**
333
+ * Prepare package to install, get dependency info.
334
+ */
335
+ public function connectPreparePackagePostAction()
336
+ {
337
+ if (!$_POST) {
338
+ echo "INVALID POST DATA";
339
+ return;
340
+ }
341
+ $prepareResult = $this->model('connect', true)->prepareToInstall($_POST['install_package_id']);
342
+
343
+ $packages = isset($prepareResult['data']) ? $prepareResult['data'] : array();
344
+ $errors = isset($prepareResult['errors']) ? $prepareResult['errors'] : array();
345
+
346
+ $this->view()->set('packages', $packages);
347
+ $this->view()->set('errors', $errors);
348
+ $this->view()->set('package_id', $_POST['install_package_id']);
349
+
350
+ echo $this->view()->template('connect/packages_prepare.phtml');
351
+ }
352
+
353
+ /**
354
+ * Install package
355
+ */
356
+ public function connectInstallPackagePostAction()
357
+ {
358
+ if (!$_POST) {
359
+ echo "INVALID POST DATA";
360
+ return;
361
+ }
362
+ $this->model('connect', true)->installPackage($_POST['install_package_id']);
363
+ }
364
+
365
+ /**
366
+ * Install uploaded package
367
+ */
368
+ public function connectInstallPackageUploadAction()
369
+ {
370
+ if (!$_FILES) {
371
+ echo "No file was uploaded";
372
+ return;
373
+ }
374
+
375
+ if(empty($_FILES['file'])) {
376
+ echo "No file was uploaded";
377
+ return;
378
+ }
379
+
380
+ $info =& $_FILES['file'];
381
+
382
+ if(0 !== intval($info['error'])) {
383
+ echo "File upload problem";
384
+ return;
385
+ }
386
+
387
+ $target = $this->_mageDir . DS . "var/" . uniqid() . $info['name'];
388
+ $res = move_uploaded_file($info['tmp_name'], $target);
389
+ if(false === $res) {
390
+ echo "Error moving uploaded file";
391
+ return;
392
+ }
393
+
394
+ $this->model('connect', true)->installUploadedPackage($target);
395
+ @unlink($target);
396
+ }
397
+
398
+ /**
399
+ * Clean cache on ajax request
400
+ */
401
+ public function cleanCacheAction()
402
+ {
403
+ $result = $this->cleanCache();
404
+ echo json_encode($result);
405
+ }
406
+
407
+ /**
408
+ * Settings
409
+ */
410
+ public function settingsAction()
411
+ {
412
+ $config = $this->config();
413
+ $this->view()->set('preferred_state', $config->__get('preferred_state'));
414
+ $this->view()->set('protocol', $config->__get('protocol'));
415
+
416
+ $this->view()->set('use_custom_permissions_mode', $config->__get('use_custom_permissions_mode'));
417
+ $this->view()->set('mkdir_mode', decoct($config->__get('global_dir_mode')));
418
+ $this->view()->set('chmod_file_mode', decoct($config->__get('global_file_mode')));
419
+
420
+ $this->channelConfig()->setSettingsView($this->session(), $this->view());
421
+
422
+ $fs_disabled =! $this->isWritable();
423
+ $ftpParams = $config->__get('remote_config') ? @parse_url($config->__get('remote_config')) : '';
424
+
425
+ $this->view()->set('fs_disabled', $fs_disabled);
426
+ $this->view()->set('deployment_type', ($fs_disabled || !empty($ftpParams) ? 'ftp' : 'fs'));
427
+
428
+ if (!empty($ftpParams)) {
429
+ $this->view()->set('ftp_host', sprintf("%s://%s", $ftpParams['scheme'], $ftpParams['host']));
430
+ $this->view()->set('ftp_login', $ftpParams['user']);
431
+ $this->view()->set('ftp_password', $ftpParams['pass']);
432
+ $this->view()->set('ftp_path', $ftpParams['path']);
433
+ }
434
+ echo $this->view()->template('settings.phtml');
435
+ }
436
+
437
+ /**
438
+ * Settings post
439
+ */
440
+ public function settingsPostAction()
441
+ {
442
+ if ($_POST) {
443
+ $ftp = $this->getFtpPost($_POST);
444
+
445
+ /* clear startup messages */
446
+ $this->config();
447
+ $this->session()->getMessages();
448
+
449
+ $errors = $this->model('connect', true)->validateConfigPost($_POST);
450
+ if ($errors) {
451
+ foreach ($errors as $err) {
452
+ $this->session()->addMessage('error', $err);
453
+ }
454
+ $this->redirect($this->url('settings'));
455
+ return;
456
+ }
457
+ try {
458
+ if ('ftp' == $_POST['deployment_type'] && !empty($_POST['ftp_host'])) {
459
+ $this->model('connect', true)->connect()->setRemoteConfig($ftp);
460
+ } else {
461
+ $this->model('connect', true)->connect()->setRemoteConfig('');
462
+ $_POST['ftp'] = '';
463
+ }
464
+ $this->channelConfig()->setPostData($this->config(), $_POST);
465
+ $this->model('connect', true)->saveConfigPost($_POST);
466
+ $this->channelConfig()->setSettingsSession($_POST, $this->session());
467
+ $this->model('connect', true)->connect()->run('sync');
468
+ } catch (Exception $e) {
469
+ $this->session()->addMessage('error', "Unable to save settings: " . $e->getMessage());
470
+ }
471
+ }
472
+ $this->redirect($this->url('settings'));
473
+ }
474
+
475
+ //////////////////////////// ABSTRACT
476
+
477
+ /**
478
+ * Constructor
479
+ */
480
+ public function __construct()
481
+ {
482
+ $this->_rootDir = dirname(dirname(__FILE__));
483
+ $this->_mageDir = dirname($this->_rootDir);
484
+ }
485
+
486
+ /**
487
+ * Run
488
+ */
489
+ public static function run()
490
+ {
491
+ try {
492
+ self::singleton()->dispatch();
493
+ } catch (Exception $e) {
494
+ echo $e->getMessage();
495
+ //echo self::singleton()->view()->set('exception', $e)->template("exception.phtml");
496
+ }
497
+ }
498
+
499
+ /**
500
+ * Initialize object of class
501
+ *
502
+ * @return Maged_Controller
503
+ */
504
+ public static function singleton()
505
+ {
506
+ if (!self::$_instance) {
507
+ self::$_instance = new self;
508
+
509
+ if (self::$_instance->isDownloaded() && self::$_instance->isInstalled()) {
510
+ Mage::app('', 'store', array('global_ban_use_cache'=>true));
511
+ Mage::getSingleton('adminhtml/url')->turnOffSecretKey();
512
+ }
513
+ }
514
+ return self::$_instance;
515
+ }
516
+
517
+ /**
518
+ * Retrieve Downloader root dir
519
+ *
520
+ * @return string
521
+ */
522
+ public function getRootDir()
523
+ {
524
+ return $this->_rootDir;
525
+ }
526
+
527
+ /**
528
+ * Retrieve Magento root dir
529
+ *
530
+ * @return string
531
+ */
532
+ public function getMageDir()
533
+ {
534
+ return $this->_mageDir;
535
+ }
536
+
537
+ /**
538
+ * Retrieve Mage Class file path
539
+ *
540
+ * @return string
541
+ */
542
+ public function getMageFilename()
543
+ {
544
+ $ds = DIRECTORY_SEPARATOR;
545
+ return $this->getMageDir() . $ds . 'app' . $ds . 'Mage.php';
546
+ }
547
+
548
+ /**
549
+ * Retrieve path for Varien_Profiler
550
+ *
551
+ * @return string
552
+ */
553
+ public function getVarFilename()
554
+ {
555
+ $ds = DIRECTORY_SEPARATOR;
556
+ return $this->getMageDir() . $ds . 'lib' . $ds . 'Varien' . $ds . 'Profiler.php';
557
+ }
558
+
559
+ /**
560
+ * Retrieve downloader file path
561
+ *
562
+ * @param string $name
563
+ * @return string
564
+ */
565
+ public function filepath($name = '')
566
+ {
567
+ $ds = DIRECTORY_SEPARATOR;
568
+ return rtrim($this->getRootDir() . $ds . str_replace('/', $ds, $name), $ds);
569
+ }
570
+
571
+ /**
572
+ * Retrieve object of view
573
+ *
574
+ * @return Maged_View
575
+ */
576
+ public function view()
577
+ {
578
+ if (!$this->_view) {
579
+ $this->_view = new Maged_View;
580
+ }
581
+ return $this->_view;
582
+ }
583
+
584
+ /**
585
+ * Retrieve object of model
586
+ *
587
+ * @param string $model
588
+ * @param boolean $singleton
589
+ * @return Maged_Model
590
+ */
591
+ public function model($model = null, $singleton = false)
592
+ {
593
+ if ($singleton && isset($this->_singletons[$model])) {
594
+ return $this->_singletons[$model];
595
+ }
596
+
597
+ if (is_null($model)) {
598
+ $class = 'Maged_Model';
599
+ } else {
600
+ $class = 'Maged_Model_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $model)));
601
+ if (!class_exists($class, false)) {
602
+ include_once str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
603
+ }
604
+ }
605
+
606
+ $object = new $class();
607
+
608
+ if ($singleton) {
609
+ $this->_singletons[$model] = $object;
610
+ }
611
+
612
+ return $object;
613
+ }
614
+
615
+ /**
616
+ * Retrieve object of config
617
+ *
618
+ * @return Mage_Connect_Config
619
+ */
620
+ public function config()
621
+ {
622
+ if (!$this->_config) {
623
+ $this->_config = $this->model('connect', true)->connect()->getConfig();
624
+ if (!$this->_config->isLoaded()) {
625
+ $this->session()->addMessage('error', "Settings has not been loaded. Used default settings");
626
+ if ($this->_config->getError()) {
627
+ $this->session()->addMessage('error', $this->_config->getError());
628
+ }
629
+ }
630
+ }
631
+ return $this->_config;
632
+ }
633
+
634
+ /**
635
+ * Retrieve object of channel config
636
+ *
637
+ * @return Maged_Model_Config_Interface
638
+ */
639
+ public function channelConfig()
640
+ {
641
+ if (!$this->_localConfig) {
642
+ $this->_localConfig = $this->model('config', true)->getChannelConfig();
643
+ }
644
+ return $this->_localConfig;
645
+ }
646
+
647
+ /**
648
+ * Retrieve object of session
649
+ *
650
+ * @return Maged_Model_Session
651
+ */
652
+ public function session()
653
+ {
654
+ if (!$this->_session) {
655
+ $this->_session = $this->model('session')->start();
656
+ }
657
+ return $this->_session;
658
+ }
659
+
660
+ /**
661
+ * Set Controller action
662
+ *
663
+ * @param string $action
664
+ * @return Maged_Controller
665
+ */
666
+ public function setAction($action=null)
667
+ {
668
+ if (is_null($action)) {
669
+ if (!empty($this->_action)) {
670
+ return $this;
671
+ }
672
+ $action = !empty($_GET[self::ACTION_KEY]) ? $_GET[self::ACTION_KEY] : 'index';
673
+ }
674
+ if (empty($action) || !is_string($action) || !method_exists($this, $this->getActionMethod($action))) {
675
+ //$action = 'noroute';
676
+ $action = 'index';
677
+ }
678
+ $this->_action = $action;
679
+ return $this;
680
+ }
681
+
682
+ /**
683
+ * Retrieve Controller action name
684
+ *
685
+ * @return string
686
+ */
687
+ public function getAction()
688
+ {
689
+ return $this->_action;
690
+ }
691
+
692
+ /**
693
+ * Set Redirect to URL
694
+ *
695
+ * @param string $url
696
+ * @param bool $force
697
+ * @return Maged_Controller
698
+ */
699
+ public function redirect($url, $force = false)
700
+ {
701
+ $this->_redirectUrl = $url;
702
+ if ($force) {
703
+ $this->processRedirect();
704
+ }
705
+ return $this;
706
+ }
707
+
708
+ /**
709
+ * Precess redirect
710
+ *
711
+ * @return Maged_Controller
712
+ */
713
+ public function processRedirect()
714
+ {
715
+ if ($this->_redirectUrl) {
716
+ if (headers_sent()) {
717
+ echo '<script type="text/javascript">location.href="' . $this->_redirectUrl . '"</script>';
718
+ exit;
719
+ } else {
720
+ header("Location: " . $this->_redirectUrl);
721
+ exit;
722
+ }
723
+ }
724
+ return $this;
725
+ }
726
+
727
+ /**
728
+ * Forward to action
729
+ *
730
+ * @param string $action
731
+ * @return Maged_Controller
732
+ */
733
+ public function forward($action)
734
+ {
735
+ $this->setAction($action);
736
+ $this->_isDispatched = false;
737
+ return $this;
738
+ }
739
+
740
+ /**
741
+ * Retrieve action method by action name
742
+ *
743
+ * @param string $action
744
+ * @return string
745
+ */
746
+ public function getActionMethod($action = null)
747
+ {
748
+ $method = (!is_null($action) ? $action : $this->_action) . 'Action';
749
+ return $method;
750
+ }
751
+
752
+ /**
753
+ * Generate URL for action
754
+ *
755
+ * @param string $action
756
+ * @param array $params
757
+ */
758
+ public function url($action = '', $params = array())
759
+ {
760
+ $args = array();
761
+ foreach ($params as $k => $v) {
762
+ $args[] = sprintf('%s=%s', rawurlencode($k), rawurlencode($v));
763
+ }
764
+ $args = $args ? join('&', $args) : '';
765
+
766
+ return sprintf('%s?%s=%s%s', $_SERVER['SCRIPT_NAME'], self::ACTION_KEY, rawurlencode($action), $args);
767
+ }
768
+
769
+ /**
770
+ * Dispatch process
771
+ */
772
+ public function dispatch()
773
+ {
774
+ header('Content-type: text/html; charset=UTF-8');
775
+
776
+ $this->setAction();
777
+
778
+ if (!$this->isInstalled()) {
779
+ if (!in_array($this->getAction(), array('index', 'connectInstallAll', 'empty', 'cleanCache'))) {
780
+ $this->setAction('index');
781
+ }
782
+ } else {
783
+ $this->session()->authenticate();
784
+ }
785
+
786
+ while (!$this->_isDispatched) {
787
+ $this->_isDispatched = true;
788
+
789
+ $method = $this->getActionMethod();
790
+ $this->$method();
791
+ }
792
+
793
+ $this->processRedirect();
794
+ }
795
+
796
+ /**
797
+ * Check root dir is writable
798
+ *
799
+ * @return bool
800
+ */
801
+ public function isWritable()
802
+ {
803
+ if (is_null($this->_writable)) {
804
+ $this->_writable = is_writable($this->getMageDir() . DIRECTORY_SEPARATOR)
805
+ && is_writable($this->filepath())
806
+ && (!file_exists($this->filepath('config.ini') || is_writable($this->filepath('config.ini'))));
807
+ }
808
+ return $this->_writable;
809
+ }
810
+
811
+ /**
812
+ * Check is Magento files downloaded
813
+ *
814
+ * @return bool
815
+ */
816
+ public function isDownloaded()
817
+ {
818
+ return file_exists($this->getMageFilename()) && file_exists($this->getVarFilename());
819
+ }
820
+
821
+ /**
822
+ * Check is Magento installed
823
+ *
824
+ * @return bool
825
+ */
826
+ public function isInstalled()
827
+ {
828
+ if (!$this->isDownloaded()) {
829
+ return false;
830
+ }
831
+ if (!class_exists('Mage', false)) {
832
+ if (!file_exists($this->getMageFilename())) {
833
+ return false;
834
+ }
835
+ include_once $this->getMageFilename();
836
+ Mage::setIsDownloader();
837
+ }
838
+ return Mage::isInstalled();
839
+ }
840
+
841
+ /**
842
+ * Retrieve Maintenance flag
843
+ *
844
+ * @return bool
845
+ */
846
+ protected function _getMaintenanceFlag()
847
+ {
848
+ if (is_null($this->_maintenance)) {
849
+ $this->_maintenance = !empty($_REQUEST['maintenance']) && $_REQUEST['maintenance'] == '1' ? true : false;
850
+ }
851
+ return $this->_maintenance;
852
+ }
853
+
854
+ /**
855
+ * Retrieve Maintenance Flag file path
856
+ *
857
+ * @return string
858
+ */
859
+ protected function _getMaintenanceFilePath()
860
+ {
861
+ if (is_null($this->_maintenanceFile)) {
862
+ $path = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR;
863
+ $this->_maintenanceFile = $path . 'maintenance.flag';
864
+ }
865
+ return $this->_maintenanceFile;
866
+ }
867
+
868
+ /**
869
+ * Begin install package(s)
870
+ */
871
+ public function startInstall()
872
+ {
873
+ if ($this->_getMaintenanceFlag()) {
874
+ $maintenance_filename='maintenance.flag';
875
+ $config = $this->config();
876
+ if (!$this->isWritable() || strlen($config->__get('remote_config')) > 0) {
877
+ $ftpObj = new Mage_Connect_Ftp();
878
+ $ftpObj->connect($config->__get('remote_config'));
879
+ $tempFile = tempnam(sys_get_temp_dir(),'maintenance');
880
+ @file_put_contents($tempFile, 'maintenance');
881
+ $ftpObj->upload($maintenance_filename, $tempFile);
882
+ $ftpObj->close();
883
+ } else {
884
+ @file_put_contents($this->_getMaintenanceFilePath(), 'maintenance');
885
+ }
886
+ }
887
+ }
888
+
889
+ /**
890
+ * End install package(s)
891
+ */
892
+ public function endInstall()
893
+ {
894
+ //$connect
895
+ /** @var $connect Maged_Model_Connect */
896
+ $frontend = $this->model('connect', true)->connect()->getFrontend();
897
+ if (!($frontend instanceof Maged_Connect_Frontend)) {
898
+ $this->cleanCache();
899
+ }
900
+ }
901
+
902
+ protected function cleanCache()
903
+ {
904
+ $result = true;
905
+ $message = '';
906
+ try {
907
+ if ($this->isInstalled()) {
908
+ if (!empty($_REQUEST['clean_sessions'])) {
909
+ Mage::app()->cleanAllSessions();
910
+ $message .= 'Session cleaned successfully. ';
911
+ }
912
+ Mage::app()->cleanCache();
913
+
914
+ // reinit config and apply all updates
915
+ Mage::app()->getConfig()->reinit();
916
+ Mage_Core_Model_Resource_Setup::applyAllUpdates();
917
+ Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
918
+ $message .= 'Cache cleaned successfully';
919
+ } else {
920
+ $result = true;
921
+ }
922
+ } catch (Exception $e) {
923
+ $result = false;
924
+ $message = "Exception during cache and session cleaning: ".$e->getMessage();
925
+ $this->session()->addMessage('error', $message);
926
+ }
927
+
928
+ if ($result && $this->_getMaintenanceFlag()) {
929
+ $maintenance_filename='maintenance.flag';
930
+ $config = $this->config();
931
+ if (!$this->isWritable() && strlen($config->__get('remote_config')) > 0) {
932
+ $ftpObj = new Mage_Connect_Ftp();
933
+ $ftpObj->connect($config->__get('remote_config'));
934
+ $ftpObj->delete($maintenance_filename);
935
+ $ftpObj->close();
936
+ } else {
937
+ @unlink($this->_getMaintenanceFilePath());
938
+ }
939
+ }
940
+ return array('result' => $result, 'message' => $message);
941
+ }
942
+
943
+ /**
944
+ * Gets the current Magento Connect Manager (Downloader) version string
945
+ * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
946
+ *
947
+ * @return string
948
+ */
949
+ public static function getVersion()
950
+ {
951
+ $i = self::getVersionInfo();
952
+ return trim(
953
+ "{$i['major']}.{$i['minor']}.{$i['revision']}"
954
+ . ($i['patch'] != '' ? ".{$i['patch']}" : "")
955
+ . "-{$i['stability']}{$i['number']}",
956
+ '.-'
957
+ );
958
+ }
959
+
960
+ /**
961
+ * Gets the detailed Magento Connect Manager (Downloader) version information
962
+ * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
963
+ *
964
+ * @return array
965
+ */
966
+ public static function getVersionInfo()
967
+ {
968
+ return array(
969
+ 'major' => '1',
970
+ 'minor' => '5',
971
+ 'revision' => '0',
972
+ 'patch' => '0',
973
+ 'stability' => '',
974
+ 'number' => '',
975
+ );
976
+ }
977
+ }
downloader/Maged/Exception.php ADDED
@@ -0,0 +1,37 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Connect
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Class Exception
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Connect
32
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
33
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
+ */
35
+ class Maged_Exception extends Exception
36
+ {
37
+ }
downloader/Maged/Model.php ADDED
@@ -0,0 +1,99 @@