Magento后端模块导致404


Magento Backend module causes 404

由于Magento中的super -5994补丁,我似乎在请求控制器内的函数时出现404错误,在此补丁之前,此函数工作正常。根据这篇文章,它必须与config.xml做一些事情,但据我所知,这并不适用于必须从控制器调用的adminhtml块。我也不知道这个错误是否是路由器需要定义的补丁导致的。

我尝试添加一个带有所有控制器和块的路由器,但即使在清除缓存,注销并再次登录后,该功能仍然是404。

这是我的代码:

app/代码/社区/MyModule里/高级/控制器/AjaxController.php

class Icepay_IceAdvanced_AjaxController extends Mage_Adminhtml_Controller_Action
{
    protected $webservice = null;
    public function iceWebservice()
    {
        if ($this->webservice == null)
            $this->webservice = new Icepay_IceAdvanced_Model_Paymentmethods();
        return $this->webservice;
    }
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
    public function get_paymentmethodsAction()
    {
        $this->getResponse()->setBody(Zend_Json::encode($this->iceWebservice()->retrieveAdminGrid($this->getRequest()->get("store"))));
    }
    public function save_paymentmethodAction()
    {
        $adv_sql = Mage::getSingleton('iceadvanced/mysql4_iceAdvanced');
        $reference = $this->getRequest()->getPost("reference");
        $scopeID = $this->getRequest()->getPost("store");
        if (!isset($reference))
            return;
        $adv_sql->setScope($scopeID);
        $settings = Mage::helper("iceadvanced")->getPaymentmethodExtraSettings();
        if ($this->getRequest()->getPost("active_issuers")) {
            $issuers = explode(",", $this->getRequest()->getPost("active_issuers"));
            if (count($issuers) >= 1)
                array_push($settings, "active_issuers"); //At least 1 issuer active is required
        }
        foreach ($settings as $setting) {
            $adv_sql->saveConfigValue($reference, $setting, $this->getRequest()->getPost($setting));
        }
        $this->getResponse()->setBody(sprintf($this->__("%s settings have been saved."), $this->getRequest()->getPost("name")));
    }
}

app/代码/社区/MyModule里/高级/块/Adminhtml/网格/Paymentmethods.php

class Icepay_IceAdvanced_Block_Adminhtml_Grid_PaymentMethods extends Mage_Adminhtml_Block_Widget implements Varien_Data_Form_Element_Renderer_Interface
{
    protected $_element;
    protected $_scope;
    protected $_ajaxLoadPaymentMethodURL;
    protected $_ajaxSavePaymentMethodURL;
    protected $_ajaxGetPaymentMethodsURL;
    protected $debug;
    public function __construct()
    {
        $this->_scope = Mage::app()->getStore(Mage::helper("icecore")->getStoreFromRequest())->getId();
        $this->_ajaxLoadPaymentMethodURL = Mage::helper('adminhtml')->getUrl('icepayadvanced/config/index/paymentmethod/{{pm_code}}', array('_secure' => true, 'scope' => $this->_scope));
        $this->_ajaxSavePaymentMethodURL = Mage::helper('adminhtml')->getUrl('icepayadvanced/ajax/save_paymentmethod', array('_secure' => true, 'scope' => $this->_scope));
        $this->_ajaxGetPaymentMethodsURL = Mage::helper('adminhtml')->getUrl('icepayadvanced/ajax/get_paymentmethods', array('_secure' => true));
        $this->setTemplate('icepayadvanced/grid_paymentmethods.phtml');
    }
    public function render(Varien_Data_Form_Element_Abstract $element)
    {
        $this->setElement($element);
        return $this->toHtml();
    }
    public function setElement(Varien_Data_Form_Element_Abstract $element)
    {
        $this->_element = $element;
        return $this;
    }
    public function getElement()
    {
        return $this->_element;
    }
    public function getJS($uri)
    {
        return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS, true) . $uri;
    }
    public function getPaymentmethods()
    {
        return Mage::getSingleton('iceadvanced/mysql4_iceAdvanced')->getAdminPaymentmethodConfigForStore($this->_scope);
    }
    public function getAddButtonHtml()
    {
        return $this->getChildHtml('add_button');
    }
    protected function _prepareLayout()
    {
        $button = $this->getLayout()->createBlock('adminhtml/widget_button')
            ->setData(array(
                'label' => Mage::helper('icecore')->__('Get paymentmethods'),
                'onclick' => 'return ICEPAY.retrieveFromICEPAY()',
                'class' => 'add'
            ));
        $button->setName('add_tier_price_item_button');
        $this->setChild('add_button', $button);
        if (version_compare(Mage::getVersion(), '1.7.0.0', '<')) {
            $this->getLayout()->getBlock('head')->addItem('js_css', 'prototype/windows/themes/magento.css');
        } else {
            $this->getLayout()->getBlock('head')->addItem('skin_css', 'lib/prototype/windows/themes/magento.css');
        }
        $this->getLayout()
            ->getBlock('head')
            ->addItem('js_css', 'prototype/windows/themes/default.css');
        return parent::_prepareLayout();
    }
}

这里我上传了config.xml和任何其他文件供审查。

编辑:在遵循BJ Hoffpauir指南之后;这是error.log

的输出

192.168.137.1 - - [17/Jul/2015:23:03:56 +0000] "POST/index.php/icepayadvanced/ajax/get_paymentmethods/key/21e4f55bb33ad6a323c50140bc5ef585/?isAjax=true HTTP/1.1" 404 16910 "http://192.168.137.124/index.php/admin/system_config/edit/section/icecore/key/e96d9f50648cad8168ebf376470196ad/" "Mozilla/5.0 (Windows NT 6.3;Win64;x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"

在应用最新的super -6285补丁后,这更有可能对adminhtml控制器进行另一个更改。

现在您必须在控制器中实现_isAllowed()方法,否则只有具有完全权限的admin用户才能访问

参见Magento。SE: https://magento.stackexchange.com/q/73646/243

Ricardo,有一些文件夹和文件在Magento最初创建时可能已经将其权限设置为777,这些权限被补丁更新。

我建议在Magento中运行以下文件和文件夹权限文档,以确保在安装补丁后,您可以确认所有文件和文件夹权限都设置为本指南中定义的推荐安全ACL。

注意:默认情况下,该指南基本上是让你禁用Magento Connect的功能,这对你的生产站点来说是个好主意——你不希望任何人在没有测试和存档的情况下直接将软件安装到你的生产系统中,比如git/hg/svn…如果您确实需要使用该功能,该指南提供了有关如何临时放松权限以使用该实用程序的说明,以及如何在完成后恢复更多安全设置。

遵循这个指南,它将最有可能解决你的404问题。如果不是,找到你的Apache或Nginx web服务器的日志文件,并grep它的404错误-例如,我的日志存储在
/var/log/apache2/access.log
/var/log/apache2/error.log

在我的Ubuntu 14.04系统中,当我运行命令

cat /var/log/apache2/error.log | grep 404
我可能会看到如下输出:
[Sun Jul 12 21:39:54.824860 2015] [:error] [pid 1234] [client 10.10.10.10:51404] script '/var/www/html/script.php' not found or unable to stat
[Sun Jul 12 21:39:54.824860 2015] [:error] [pid 1234] [client 10.10.10.10:51404] script '/var/www/html/script.php' not found or unable to stat

粘贴你发现当你运行cat命令取代/var/log/apache2/error.log与您的web服务器日志文件存储的地方。编辑你的问题&粘贴您在问题中发现的内容,我们可以帮助您找到404错误的来源以及产生错误的具体上下文。

根据提供的pastebin中的信息:

"192.168.137.1 - - [20/Jul/2015:08:39:03 +0000] "GET /index.php/admin/system_config/edit/section/icecore/key/e43339d0ca7181a8e347c7e991ef840f/ HTTP/1.1" 200 23324 "http://192.168.137.124/index.php/admin/system_config/index/key/d266293b931243779092e7c1d1c5f84d/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
"192.168.137.1 - - [20/Jul/2015:08:39:09 +0000] "POST /index.php/icepayadvanced/ajax/get_paymentmethods/key/743d139de39f76ead943a8651787de64/?isAjax=true HTTP/1.1" 404 16910 "http://192.168.137.124/index.php/admin/system_config/edit/section/icecore/key/e43339d0ca7181a8e347c7e991ef840f/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"

到达/index.php/admin/system_config/edit/section/icecore/key/e43339d0ca7181a8e347c7e991ef840f/端点的第一个调用(GET)成功返回了一个200响应。

第二个调用(POST)到达/index.php/icepayadvanced/ajax/get_paymentmethods/key/743d139de39f76ead943a8651787de64/?isAjax=true的端点失败,404

我认为发生这种情况的原因只有四个:

  1. 在xml配置中指定的位置没有底层文件
  2. 文件的权限不允许web服务器进程读取
  3. 您仍然需要在super -6285之后实现_isAllowed()方法。我同意凯尔对费边的回答的评论,因为你不应该只返回true,因为这会打开一个安全漏洞(不可否认,如果你不能登录到管理面板,很难访问)。此外,在审查GitHub源模块后,我同意Fabian对这个答案的评论,因为在当前的config.xml中没有Adminhtml.xml或任何现有的ACL,您必须自己实现它或请求供应商执行更新。

我不得不同意Fabian的观点,他在这方面比我更有经验:我不明白一个只在前端定义的路由如何能够提供一个Adminhtml接口。

这可能是有一些奇怪的怪癖,允许这个行为的功能,也关闭了最近的补丁之一,但即使是这种情况下,以某种方式增加对_isAllowed的支持可能仍然是需要的。

我在config.xml中添加了以下内容,它解决了问题:

<admin>
    <routers>
        <iceadvanced>
            <use>admin</use>
            <args>
                <module>Icepay_IceAdvanced</module>
                <frontName>icepayadvanced</frontName>
            </args>
        </iceadvanced>
    </routers>
</admin>

"