forked from mailrelay/prestashop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailrelay.php
executable file
·137 lines (111 loc) · 3.78 KB
/
mailrelay.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
if (!defined('_PS_VERSION_'))
exit;
class MailRelay extends Module
{
public function __construct()
{
$this->name = 'mailrelay';
$this->tab = 'administration';
$this->version = 1.0;
$this->author = '';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Mailrelay');
$this->description = $this->l('');
}
public function install()
{
if ($id_tab = Tab::getIdFromClassName('AdminMailRelay'))
{
$tab = new Tab((int)$id_tab);
if (!$tab->delete())
$this->_errors[] = sprintf($this->l('Unable to delete outdated AdminMailRelay tab %d'), (int)$id_tab);
}
if (!$id_tab = Tab::getIdFromClassName('AdminMailRelay'))
{
$tab = new Tab();
$tab->class_name = 'AdminMailRelay';
$tab->module = 'mailrelay';
$tab->id_parent = (int)Tab::getIdFromClassName('AdminTools');
foreach (Language::getLanguages(false) as $lang)
$tab->name[(int)$lang['id_lang']] = 'Mailrelay';
if (!$tab->save())
return $this->_abortInstall($this->l('Unable to create the "AdminMailRelay" tab'));
}
else
$tab = new Tab((int)$id_tab);
/* Update the "AdminMailRelay" tab id in database or exit */
if (Validate::isLoadedObject($tab))
Configuration::updateValue('PS_AUTOUPDATE_MODULE_IDTAB', (int)$tab->id);
else
return $this->_abortInstall($this->l('Unable to load the "AdminMailRelay" tab'));
/* Check working directory is existing or create it */
$module_dir = _PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'mailrelay';
if (!file_exists($module_dir) && !@mkdir($module_dir, 0755))
return $this->_abortInstall(sprintf($this->l('Unable to create the directory "%s"'), $module_dir));
/* Make sure that the 1-click upgrade working directory is writeable */
if (!is_writable($module_dir))
return $this->_abortInstall(sprintf($this->l('Unable to write in the directory "%s"'), $module_dir));
Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'mailrelay` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` CHAR(50) NOT NULL,
`password` CHAR(50) NOT NULL,
`hostname` VARCHAR(255) NOT NULL,
`key` VARCHAR(255) NOT NULL,
`last_group` CHAR(20),
PRIMARY KEY(`id`)
) ENGINE='._MYSQL_ENGINE_.' default CHARSET=utf8');
return parent::install();
}
public function uninstall()
{
/* Delete Back-office tab */
if ($id_tab = Tab::getIdFromClassName('AdminMailRelay'))
{
$tab = new Tab((int)$id_tab);
$tab->delete();
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'mailrelay`');
}
/* Remove the working directory */
self::_removeDirectory(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'mailrelay');
return parent::uninstall();
}
public function getContent()
{
global $cookie;
header('Location: index.php?tab=AdminMailRelay&token='.md5(pSQL(_COOKIE_KEY_.'AdminMailRelay'.(int)Tab::getIdFromClassName('AdminMailRelay').(int)$cookie->id_employee)));
exit;
}
/**
* Set installation errors and return false
*
* @param string $error Installation abortion reason
* @return boolean Always false
*/
protected function _abortInstall($error)
{
if (version_compare(_PS_VERSION_, '1.5.0.0 ', '>='))
$this->_errors[] = $error;
else
echo '<div class="error">'.strip_tags($error).'</div>';
return false;
}
private static function _removeDirectory($dir)
{
if ($handle = @opendir($dir))
{
while (false !== ($entry = @readdir($handle)))
if ($entry != '.' && $entry != '..')
{
if (is_dir($dir.DIRECTORY_SEPARATOR.$entry) === true)
self::_removeDirectory($dir.DIRECTORY_SEPARATOR.$entry);
else
@unlink($dir.DIRECTORY_SEPARATOR.$entry);
}
@closedir($handle);
@rmdir($dir);
}
}
}