📜 ⬆️ ⬇️

We build Sypex Dumper into our admin area

Many popular CMS, both open source and commercial, incorporate backup modules. But the problem is that, most often, these modules are made on the residual principle, and are very primitive, do not take into account many of the subtleties of creating a dump. Also, most often these modules are simply not tested by anyone for large volumes (they drove it to the test half-empty database and are happy).

Unlike similar modules, Sypex Dumper is a script sharpened exclusively for MySQL backup and recovery. And without problems working with databases, even a few gigabytes. But, besides the fact that the dumper works as a separate application, it was possible to embed it in third-party software.

In this article I will tell you how quickly and quite simply to integrate Sypex Dumper into the administrative panel of your CMS (forum, blog, etc.). And also consider some undocumented features of such integration.
')

Introduction


For embedding a dumper, I recommend the following scheme:

This scheme has the following advantages compared to the usual connection of the backup module with the help of include to your system:

Authorization file


The authorization file is a small script whose only task is to check if the user has access rights to the dumper. In the dumper, so-called authorization chains are used. Which indicates which authorization files to use and in what sequence. Let us analyze the file of authorization by the example of the recently created integration in ImageCMS.

The file name consists of the prefix “auth_”, the name of the authorization (consisting of English letters, numbers and an underscore) and the extension “php”.

The authorization file must contain a set of instructions, which, in the case of positive user authorization, must set the value of the $ auth variable to true (or 1 ). Also in the authorization file, you can change any properties from the config file (later they will fall into the virtual config). Access to the properties of the config file through the array $ this-> CFG .

<?php // Sypex Dumper 2 authorization file for ImageCMS 3 session_start(); if(!empty($_SESSION['DX_permission']['backup_create'])){ define('BASEPATH', 1); include '../application/config/config.php'; if($this->connect($db['default']['hostname'], '', $db['default']['username'], $db['default']['password'])){ $this->CFG['my_db'] = $db['default']['database']; $this->CFG['exitURL'] = '../admin/logout'; $auth = 1; } } ?> 

In ImageCMS, standard sessions are used for authorization, so at the beginning of the script we create a session, and get user data. In order to check the permissions in this CMS, we use the native property 'backup_create' , if it is true, then the user can use the dumper.

Next we connect the CMS config file to get the data for connecting to MySQL from there. And with the help of $ this-> connect () we connect to MySQL, in case of success, we memorize the database to which we will access in the dumper, and set up the 'exitURL' - the address to which the dumper will go when pressing the exit button. Well and the main thing $ auth we assign 1 , saying that authorization is successful.
After that you will need to add the name of the authorization file to the authorization chain. This can be done in the interface dumper Options -> Authorization chain, or in cfg.php in the line

 'auth' => 'mysql cfg', 

Now, if you are logged in to CMS, and you have the right to create backups, then no additional authorization is required to enter the dumper.

Interface Integration


It remains only to build a dumper in the admin area of ​​the CMS. What for the necessary admin page you need to insert the line:

 <iframe src="/sxd/" width="586" height="462" frameborder="0" style="margin:0;"></iframe> 

where in src substitute the address of the dumper (relative or full).

Undocumented features


Since the Sypex Dumper interface works entirely on JS, we can quite simply perform any dumper functions from our CMS, both with the help of buttons and automatically.

For example, to create a backup, you need to execute the command (by adding id = sxdframe to the iframe):

 sxdframe.sxd.runBackup(); 

Or this option:

 //    sxdframe.sxd.actions.tab_restore(); //   test1 sxdframe.sxd.combos.restore_db.select('test1'); //   sxdframe.sxd.combos.restore_file.select('test1_2012-11-17_10-02-34.sql.gz'); //   sxdframe.sxd.runRestore(); 


In connection with the preparation of the third version of the dumper, I wonder how much the demand for such a JS API is for it. We also accept suggestions on what else to add to the dumper. And of course, if there are any difficulties with integration, feel free to ask questions.

The documentation understands several more Sypex Dumper authorization files .
In addition, you can download ready-made integration files for the following popular systems: Drupal, ImageCMS, IPBoard, Joomla, MODx, phpBB, PHP-Fusion, vBulletin, WordPress, XenForo.

Source: https://habr.com/ru/post/159023/


All Articles