Хранилища Subversion ant

Редакция

Редакция 493 | Редакция 496 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 493 Редакция 495
1
<?php
1
<?php
2
2
3
/**
3
/**
4
 *  
4
 *  
5
 *  Codename: ant-ng - generator of sources.list for Debian and
5
 *  Codename: ant-ng - generator of sources.list for Debian and
6
 *  distributives, based on Debian
6
 *  distributives, based on Debian
7
 *  http://alex-w.org.ru/p/antng/
7
 *  http://alex-w.org.ru/p/antng/
8
 *
8
 *
9
 *  Copyright (c) 2009 Alexander Wolf
9
 *  Copyright (c) 2009 Alexander Wolf
10
 *  Dual licensed under the MIT and GNU LGPL licenses.
10
 *  Dual licensed under the MIT and GNU LGPL licenses.
11
 *  http://alex-w.org.ru/p/antng/license
11
 *  http://alex-w.org.ru/p/antng/license
12
 *
12
 *
13
 */
13
 */
14
14
15
class Core {
15
class Core {
16
    protected $db       = NULL;
16
    protected $db       = NULL;
17
    protected $prefix   = NULL;
17
    protected $prefix   = NULL;
18
    protected $secure   = NULL;    
18
    protected $secure   = NULL;    
19
    protected $cookie   = NULL;
19
    protected $cookie   = NULL;
20
20
21
    /**
21
    /**
22
     * Конструктор класса Core - ядро генератора
22
     * Конструктор класса Core - ядро генератора
23
     *
23
     *
24
     * @author Alexander Wolf
24
     * @author Alexander Wolf
25
     * @category Core
25
     * @category Core
26
     *
26
     *
27
     * @param string $database
27
     * @param string $database
28
     * @param string $prefix
28
     * @param string $prefix
29
     * @param object $secure
29
     * @param object $secure
30
     * @param string $cookie
30
     * @param string $cookie
31
     */
31
     */
32
    public function __construct($database, $prefix, $secure, $cookie) {
32
    public function __construct($database, $prefix, $secure, $cookie) {
33
        $this->db       = $database;
33
        $this->db       = $database;
34
        $this->prefix   = $prefix;
34
        $this->prefix   = $prefix;
35
        $this->secure   = $secure;
35
        $this->secure   = $secure;
36
        $this->cookie   = $cookie;
36
        $this->cookie   = $cookie;
37
    }
37
    }
38
38
39
    /**
39
    /**
40
     * Получение данных о настройке
40
     * Получение данных о настройке
41
     *
41
     *
42
     * @author Alexander Wolf
42
     * @author Alexander Wolf
43
     * @category Core
43
     * @category Core
44
     *
44
     *
45
     * @param string $attr
45
     * @param string $attr
46
     * @return array
46
     * @return array
47
     */
47
     */
48
    public function getOption($attr) {
48
    public function getOption($attr) {
49
        $result = array();
49
        $result = array();
50
        $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
50
        $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
51
        $rq =& $this->db->query($query);
51
        $rq =& $this->db->query($query);
52
        if ($rq->numRows()!=0) {
52
        if ($rq->numRows()!=0) {
53
            $rq->fetchInto($element);
53
            $rq->fetchInto($element);
54
            $result["ERR"] = 0;
54
            $result["ERR"] = 0;
55
            $result["OptValue"] = $element["optvalue"];
55
            $result["OptValue"] = $element["optvalue"];
56
        } else {
56
        } else {
57
            $result["ERR"] = 1;
57
            $result["ERR"] = 1;
58
            $result["ERRINFO"] = "Empty result";
58
            $result["ERRINFO"] = "Empty result";
59
        }
59
        }
60
        return $result;
60
        return $result;
61
    }
61
    }
62
62
63
    /**
63
    /**
64
     * Установка данных о настройке
64
     * Установка данных о настройке
65
     *
65
     *
66
     * @author Alexander Wolf
66
     * @author Alexander Wolf
67
     * @category Core
67
     * @category Core
68
     *
68
     *
69
     * @param string $attr
69
     * @param string $attr
70
     * @param string $value
70
     * @param string $value
71
     * @return array
71
     * @return array
72
     */
72
     */
73
    public function setOption($attr, $value) {
73
    public function setOption($attr, $value) {
74
        $result = array();
74
        $result = array();
75
75
76
        if ($attr != "passwd") {
76
        if ($attr != "passwd") {
77
            $sValue = $this->secure->checkStr($value);
77
            $sValue = $this->secure->checkStr($value);
78
        } else {
78
        } else {
79
            $sValue = $value;
79
            $sValue = $value;
80
        }
80
        }
81
81
82
        $query = "UPDATE ".$this->prefix."settings SET optvalue='".$sValue."' WHERE opt='".$attr."'";
82
        $query = "UPDATE ".$this->prefix."settings SET optvalue='".$sValue."' WHERE opt='".$attr."'";
83
        $rq =& $this->db->query($query);
83
        $rq =& $this->db->query($query);
84
        if (PEAR::isError($this->db)) {
84
        if (PEAR::isError($this->db)) {
85
            $result["ERR"] = 1;
85
            $result["ERR"] = 1;
86
            $result["ERRINFO"] = $this->db->getMessage();
86
            $result["ERRINFO"] = $this->db->getMessage();
87
        } else {
87
        } else {
88
            $result["ERR"] = 0;
88
            $result["ERR"] = 0;
89
        }
89
        }
90
90
91
        return $result;
91
        return $result;
92
    }
92
    }
93
93
94
    /**
94
    /**
95
     * Создание настройки
95
     * Создание настройки
96
     *
96
     *
97
     * @author Alexander Wolf
97
     * @author Alexander Wolf
98
     * @category Core
98
     * @category Core
99
     *
99
     *
100
     * @param string $attr
100
     * @param string $attr
101
     * @param string $value
101
     * @param string $value
102
     * @return array
102
     * @return array
103
     */
103
     */
104
    public function addOption($attr, $value) {
104
    public function addOption($attr, $value) {
105
        $result = array();
105
        $result = array();
106
        $sValue = $this->secure->checkStr($value);
106
        $sValue = $this->secure->checkStr($value);
107
107
108
        $query = "INSERT INTO ".$this->prefix."settings SET opt='".$attr."', optvalue='".$sValue."'";
108
        $query = "INSERT INTO ".$this->prefix."settings SET opt='".$attr."', optvalue='".$sValue."'";
109
        $rq =& $this->db->query($query);
109
        $rq =& $this->db->query($query);
110
        if (PEAR::isError($this->db)) {
110
        if (PEAR::isError($this->db)) {
111
            $result["ERR"] = 1;
111
            $result["ERR"] = 1;
112
            $result["ERRINFO"] = $this->db->getMessage();
112
            $result["ERRINFO"] = $this->db->getMessage();
113
        } else {
113
        } else {
114
            $result["ERR"] = 0;
114
            $result["ERR"] = 0;
115
        }
115
        }
116
116
117
        return $result;
117
        return $result;
118
    }
118
    }
119
       
119
       
120
    /**
120
    /**
121
     * Получение и отображение списка дистрибутвов
121
     * Получение и отображение списка дистрибутвов
122
     *
122
     *
123
     * @author Alexander Wolf
123
     * @author Alexander Wolf
124
     * @category Core
124
     * @category Core
125
     * @deprecated may be deprecated XXX
125
     * @deprecated may be deprecated XXX
126
     *
126
     *
127
     * @param string $name
127
     * @param string $name
128
     * @param string $heads
128
     * @param string $heads
129
     * @param string $info
129
     * @param string $info
130
     * @param string $format
130
     * @param string $format
131
     * @return string
131
     * @return string
132
     */
132
     */
133
    public function showDistributionList($name, $heads = "", $info = "", $format = 'html') {
133
    public function showDistributionList($name, $heads = "", $info = "", $format = 'html') {
134
        $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
134
        $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
135
        $rq =& $this->db->query($query);
135
        $rq =& $this->db->query($query);
136
        switch ($format) {
136
        switch ($format) {
137
            case 'html':
137
            case 'html':
138
                $show  = "<fieldset><legend>".$heads."</legend>\n<select id='".$name."' name='".$name."'>\n";
138
                $show  = "<fieldset><legend>".$heads."</legend>\n<select id='".$name."' name='".$name."'>\n";
139
                $show .= "<option value=''>".$info."</option>\n";
139
                $show .= "<option value=''>".$info."</option>\n";
140
                while ($rq->fetchInto($element)) {
140
                while ($rq->fetchInto($element)) {
141
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
141
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
142
                }
142
                }
143
                $show .= "</select></fieldset>";
143
                $show .= "</select></fieldset>";
144
                break;
144
                break;
145
            case 'json':
145
            case 'json':
146
                $show = '[{value:"",text:"'.$info.'"}';                
146
                $show = '[{value:"",text:"'.$info.'"}';                
147
                while ($rq->fetchInto($element)) {
147
                while ($rq->fetchInto($element)) {
148
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
148
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
149
                }
149
                }
150
                $show .= ']';
150
                $show .= ']';
151
                break;
151
                break;
152
        }
152
        }
153
        return $show;
153
        return $show;
154
    }
154
    }
155
155
156
    /**
156
    /**
157
     * Получение названия дистрибутива
157
     * Получение названия дистрибутива
158
     *
158
     *
159
     * @author Alexander Wolf
159
     * @author Alexander Wolf
160
     * @category Core
160
     * @category Core
161
     *
161
     *
162
     * @param integer $distID
162
     * @param integer $distID
163
     * @return array
163
     * @return array
164
     */
164
     */
165
    public function getDistName($distID) {
165
    public function getDistName($distID) {
166
        $result = array();
166
        $result = array();
167
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
167
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
168
        $rq =& $this->db->query($query);
168
        $rq =& $this->db->query($query);
169
        if (PEAR::isError($this->db)) {
169
        if (PEAR::isError($this->db)) {
170
            $result["ERR"] = 1;
170
            $result["ERR"] = 1;
171
            $result["ERRINFO"] = $this->db->getMessage();
171
            $result["ERRINFO"] = $this->db->getMessage();
172
        } else {
172
        } else {
173
            $rq->fetchInto($element);
173
            $rq->fetchInto($element);
174
            $result["ERR"] = 0;
174
            $result["ERR"] = 0;
175
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
175
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
176
        }
176
        }
177
177
178
        return $result;
178
        return $result;
179
    }
179
    }
180
180
181
    /**
181
    /**
182
     * Получение названия программы, ее версии и описания
182
     * Получение названия программы, ее версии и описания
183
     *
183
     *
184
     * @author Alexander Wolf
184
     * @author Alexander Wolf
185
     * @category Core
185
     * @category Core
186
     *
186
     *
187
     * @param string $attr
187
     * @param string $attr
188
     * @return string
188
     * @return string
189
     */
189
     */
190
    public function getEngineAttr($attr = 'codename') {
190
    public function getEngineAttr($attr = 'codename') {
191
        $cname = $this->getOption($attr);
191
        $cname = $this->getOption($attr);
192
        return $this->secure->checkStr($cname["OptValue"],1);
192
        return $this->secure->checkStr($cname["OptValue"],1);
193
    }
193
    }
194
194
195
    /**
195
    /**
196
     * Получение и отображение списка версий дистрибутива
196
     * Получение и отображение списка версий дистрибутива
197
     *
197
     *
198
     * @author Alexander Wolf
198
     * @author Alexander Wolf
199
     * @category Core
199
     * @category Core
200
     *
200
     *
201
     * @param string $name
201
     * @param string $name
202
     * @param integer $distID
202
     * @param integer $distID
203
     * @param string $format
203
     * @param string $format
204
     * @return string
204
     * @return string
205
     */
205
     */
206
    public function showDistVersionsList($name, $distID, $format = 'html') {
206
    public function showDistVersionsList($name, $distID, $format = 'html') {
207
        $distname = $this->getDistName($distID);
207
        $distname = $this->getDistName($distID);
208
        $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
208
        $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
209
        $rq =& $this->db->query($query);
209
        $rq =& $this->db->query($query);
210
        switch ($format) {
210
        switch ($format) {
211
            case 'html':
211
            case 'html':
212
                $show  = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
212
                $show  = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
213
                $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
213
                $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
214
                while ($rq->fetchInto($element)) {
214
                while ($rq->fetchInto($element)) {
215
                    $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
215
                    $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
216
                }
216
                }
217
                $show .= "</select></fieldset>";
217
                $show .= "</select></fieldset>";
218
                break;
218
                break;
219
            case 'json':
219
            case 'json':
220
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
220
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
221
                while ($rq->fetchInto($element)) {
221
                while ($rq->fetchInto($element)) {
222
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
222
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
223
                }
223
                }
224
                $show .= ']';
224
                $show .= ']';
225
                break;
225
                break;
226
        }
226
        }
227
        return $show;
227
        return $show;
228
    }
228
    }
229
229
230
    /**
230
    /**
231
     * Получение и отображение списка секций основного (официального) репозитория
231
     * Получение и отображение списка секций основного (официального) репозитория
232
     *
232
     *
233
     * @author Alexander Wolf
233
     * @author Alexander Wolf
234
     * @category Core
234
     * @category Core
235
     *
235
     *
236
     * @param integer $version
236
     * @param integer $version
237
     * @param string $format
237
     * @param string $format
238
     * @return string
238
     * @return string
239
     */
239
     */
240
    public function showBranchesList($version, $format = 'html') {
240
    public function showBranchesList($version, $format = 'html') {
241
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
241
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
242
        $rq =& $this->db->query($query);
242
        $rq =& $this->db->query($query);
243
        $rq->fetchInto($types);
243
        $rq->fetchInto($types);
244
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
244
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
245
        $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
245
        $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
246
        $query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
246
        $query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
247
        $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
247
        $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
248
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
248
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
249
        $rq =& $this->db->query($query);
249
        $rq =& $this->db->query($query);
250
        switch ($format) {
250
        switch ($format) {
251
            case 'html':
251
            case 'html':
252
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
252
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
253
                while ($rq->fetchInto($element)) {
253
                while ($rq->fetchInto($element)) {
254
                    $show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." &mdash; ".$this->secure->checkStr($element["sectinfo"],1)."</div>\n";
254
                    $show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." &mdash; ".$this->secure->checkStr($element["sectinfo"],1)."</div>\n";
255
                }
255
                }
256
                $show .= "</fieldset>\n";
256
                $show .= "</fieldset>\n";
257
                break;
257
                break;
258
            case 'json':
258
            case 'json':
259
                //TODO Доделать JSON-вывод списка секций основного репозитория
259
                //TODO Доделать JSON-вывод списка секций основного репозитория
260
                break;
260
                break;
261
        }
261
        }
262
262
263
        return $show;
263
        return $show;
264
    }
264
    }
265
265
266
    /**
266
    /**
267
     * Получение и отображение списка репозиториев
267
     * Получение и отображение списка репозиториев
268
     *
268
     *
269
     * @author Alexander Wolf
269
     * @author Alexander Wolf
270
     * @category Core
270
     * @category Core
271
     *
271
     *
272
     * @param integer $version
272
     * @param integer $version
273
     * @param integer $reptype
273
     * @param integer $reptype
274
     * @param string $format
274
     * @param string $format
275
     * @return string
275
     * @return string
276
     */
276
     */
277
    public function showRepList($version, $reptype, $format = 'html') {
277
    public function showRepList($version, $reptype, $format = 'html') {
278
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
278
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
279
        $rq =& $this->db->query($query);
279
        $rq =& $this->db->query($query);
280
        $rq->fetchInto($types);
280
        $rq->fetchInto($types);
281
        $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
281
        $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
282
        $rq =& $this->db->query($query);
282
        $rq =& $this->db->query($query);
283
        switch ($format) {
283
        switch ($format) {
284
            case 'html':
284
            case 'html':
285
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
285
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
286
                while ($rq->fetchInto($types)) {
286
                while ($rq->fetchInto($types)) {
287
                    $show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"],1)." &mdash; ".$this->secure->checkStr($element["repinfo"],1)."</div>\n";
287
                    $show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"],1)." &mdash; ".$this->secure->checkStr($element["repinfo"],1)."</div>\n";
288
                }
288
                }
289
                $show .= "</fieldset>\n";
289
                $show .= "</fieldset>\n";
290
                break;
290
                break;
291
            case 'json':
291
            case 'json':
292
                //TODO Доделать JSON-вывод списка репозиториев
292
                //TODO Доделать JSON-вывод списка репозиториев
293
                break;
293
                break;
294
        }
294
        }
295
295
296
        return $show;
296
        return $show;
297
    }
297
    }
298
298
299
    /**
299
    /**
300
     * Добавление поддержки нового apt-дистрибутива
300
     * Добавление поддержки нового apt-дистрибутива
301
     *
301
     *
302
     * @author Alexander Wolf
302
     * @author Alexander Wolf
303
     * @category Core
303
     * @category Core
304
     *
304
     *
305
     * @param string $distname
305
     * @param string $distname
306
     * @param integer $disttype
306
     * @param integer $disttype
307
     * @param string $distua
307
     * @param string $distua
308
     * @param byte $distlogo
308
     * @param byte $distlogo
309
     * @return array
309
     * @return array
310
     */
310
     */
311
    public function addDistribution($distname, $disttype, $distua = 1, $distlogo = 0) {
311
    public function addDistribution($distname, $disttype, $distua = 1, $distlogo = 0) {
312
        $result = array();
312
        $result = array();
313
        $sDName = $this->secure->checkStr($distname);
313
        $sDName = $this->secure->checkStr($distname);
314
        $sDType = $this->secure->checkInt($disttype);
314
        $sDType = $this->secure->checkInt($disttype);
315
        $sDUAgt = $this->secure->checkStr($distua);
315
        $sDUAgt = $this->secure->checkStr($distua);
316
        $sDLogo = $this->secure->checkInt($distname);
316
        $sDLogo = $this->secure->checkInt($distname);
317
317
318
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
318
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
319
        $rq =& $this->db->query($query);
319
        $rq =& $this->db->query($query);
320
        if (PEAR::isError($this->db)) {
320
        if (PEAR::isError($this->db)) {
321
            $result["ERR"] = 1;
321
            $result["ERR"] = 1;
322
            $result["ERRINFO"] = $this->db->getMessage();
322
            $result["ERRINFO"] = $this->db->getMessage();
323
        } else {
323
        } else {
324
            $rq->fetchInto($element);
324
            $rq->fetchInto($element);
325
            $result["ERR"] = 0;
325
            $result["ERR"] = 0;
326
        }
326
        }
327
327
328
        return $result;
328
        return $result;
329
    }
329
    }
330
330
331
    /**
331
    /**
332
     * Добавление поддержки новой версии apt-дистрибутива
332
     * Добавление поддержки новой версии apt-дистрибутива
333
     *
333
     *
334
     * @author Alexander Wolf
334
     * @author Alexander Wolf
335
     * @category Core
335
     * @category Core
336
     *
336
     *
337
     * @param integer $distID
337
     * @param integer $distID
338
     * @param integer $version
338
     * @param integer $version
339
     * @param string $vname
339
     * @param string $vname
340
     * @param integer $vcodename
340
     * @param integer $vcodename
341
     * @return array
341
     * @return array
342
     */
342
     */
343
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
343
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
344
        $result = array();
344
        $result = array();
345
        $sDistID    = $this->secure->checkInt($distID);
345
        $sDistID    = $this->secure->checkInt($distID);
346
        $sDVersion  = $this->secure->checkStr($version);
346
        $sDVersion  = $this->secure->checkStr($version);
347
        $sDVName    = $this->secure->checkStr($vname);
347
        $sDVName    = $this->secure->checkStr($vname);
348
        $sDVCName   = $this->secure->checkInt($vcodename);
348
        $sDVCName   = $this->secure->checkInt($vcodename);
349
349
350
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
350
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
351
        $rq =& $this->db->query($query);
351
        $rq =& $this->db->query($query);
352
        if (PEAR::isError($this->db)) {
352
        if (PEAR::isError($this->db)) {
353
            $result["ERR"] = 1;
353
            $result["ERR"] = 1;
354
            $result["ERRINFO"] = $this->db->getMessage();
354
            $result["ERRINFO"] = $this->db->getMessage();
355
        } else {
355
        } else {
356
            $rq->fetchInto($element);
356
            $rq->fetchInto($element);
357
            $result["ERR"] = 0;
357
            $result["ERR"] = 0;
358
        }
358
        }
359
359
360
        return $result;
360
        return $result;
361
    }
361
    }
362
362
363
    /**
363
    /**
364
     * Отображение типа дистрибутива
364
     * Отображение типа дистрибутива
365
     *
365
     *
366
     * @author Alexander Wolf
366
     * @author Alexander Wolf
367
     * @category Core
367
     * @category Core
368
     *
368
     *
369
     * @param string $name
369
     * @param string $name
370
     * @param byte $type
370
     * @param byte $type
371
     * @return string
371
     * @return string
372
     */
372
     */
373
    public function showDistTypeForm($name = "dtype",$type = 0) {
373
    public function showDistTypeForm($name = "dtype",$type = 0) {
374
        $query = "SELECT * FROM ".$this->prefix."dtype";
374
        $query = "SELECT * FROM ".$this->prefix."dtype";
375
        $rq =& $this->db->query($query);
375
        $rq =& $this->db->query($query);
376
        $show = "<select name='".$name."' id='".$name."'>\n";
376
        $show = "<select name='".$name."' id='".$name."'>\n";
377
        while ($rq->fetchInto($element)) {
377
        while ($rq->fetchInto($element)) {
378
            if ($element["type_id"] == $type) {
378
            if ($element["type_id"] == $type) {
379
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
379
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
380
            } else {
380
            } else {
381
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
381
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
382
            }
382
            }
383
        }
383
        }
384
        $show .= "</select>";
384
        $show .= "</select>";
385
385
386
        return $show;
386
        return $show;
387
    }
387
    }
388
388
389
    /**
389
    /**
390
     * Отображение формы создания и редактирования apt-дистрибутива
390
     * Отображение формы создания и редактирования apt-дистрибутива
391
     *
391
     *
392
     * @author Alexander Wolf
392
     * @author Alexander Wolf
393
     * @category Core
393
     * @category Core
394
     *
394
     *
395
     * @param integer $distID
395
     * @param integer $distID
396
     * @return string
396
     * @return string
397
     */
397
     */
398
    public function showDistributionForm($distID = 0) {
398
    public function showDistributionForm($distID = 0) {
399
        $sDistID = $this->secure->checkInt($distID);
399
        $sDistID = $this->secure->checkInt($distID);
400
        if ($sDistID != 0) {
400
        if ($sDistID != 0) {
401
            // Режим редактирования
401
            // Режим редактирования
402
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
402
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
403
            $rq =& $this->db->query($query);
403
            $rq =& $this->db->query($query);
404
            $rq->fetchInto($element);
404
            $rq->fetchInto($element);
405
        }
405
        }
406
406
407
        if ($element["distlogo"] == 1) {
407
        if ($element["distlogo"] == 1) {
408
            $image = "<img src='./img/d/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."' title='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."'>";
408
            $image = "<img src='./img/d/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."' title='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."'>";
409
        } else {
409
        } else {
410
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
410
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
411
        }
411
        }
412
412
413
        $show  = "<fieldset><legend>Дистрибутив</legend>\n";
413
        $show  = "<fieldset><legend>Дистрибутив</legend>\n";
414
        $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
414
        $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
415
        $show .= "<div class='inputbox'><label for='dua'>UA дистрибутива:</label> <input type='text' name='dua' id='dua' value='".$this->secure->checkStr($element["distua"],1)."'></div>\n";
415
        $show .= "<div class='inputbox'><label for='dua'>UA дистрибутива:</label> <input type='text' name='dua' id='dua' value='".$this->secure->checkStr($element["distua"],1)."'></div>\n";
416
        $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["dtype_id"])."</div>\n";
416
        $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["dtype_id"])."</div>\n";
417
        $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
417
        $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
418
        $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
418
        $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
419
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
419
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
420
420
421
        return $show;
421
        return $show;
422
    }
422
    }
423
423
424
    // sourses.list
424
    // sourses.list
425
    public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
425
    public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
426
       //TODO Написать генератор sources.list       
426
       //TODO Написать генератор sources.list       
427
    }
427
    }
428
   
428
   
429
    /**
429
    /**
430
     * Проверка пароля (из формы авторизации)
430
     * Проверка пароля (из формы авторизации)
431
     *
431
     *
432
     * @author Alexander Wolf
432
     * @author Alexander Wolf
433
     * @category Core
433
     * @category Core
434
     *
434
     *
435
     * @param string $word
435
     * @param string $word
436
     * @return array
436
     * @return array
437
     */
437
     */
438
    public function checkSign($word) {
438
    public function checkSign($word) {
439
        $result = array();
439
        $result = array();
440
440
441
        $sHash = $this->secure->encryptStr($word);
441
        $sHash = $this->secure->encryptStr($word);
442
        $pwd   = $this->getOption("passwd");
442
        $pwd   = $this->getOption("passwd");
443
        if ($sHash == $pwd["OptValue"]) {
443
        if ($sHash == $pwd["OptValue"]) {
444
            $result["ERR"] = 0;
444
            $result["ERR"] = 0;
445
            $result["Location"] = "manager.php";
445
            $result["Location"] = "manager.php";
446
            setcookie($this->cookie, $sHash);
446
            setcookie($this->cookie, $sHash);
447
        } else {
447
        } else {
448
            $result["ERR"] = 1;
448
            $result["ERR"] = 1;
449
            $result["ERRINFO"] = "Password not valid";
449
            $result["ERRINFO"] = "Password not valid";
450
            $result["Location"] = "manager.php?error=1";
450
            $result["Location"] = "manager.php?error=1";
451
        }
451
        }
452
452
453
        return $result;
453
        return $result;
454
    }
454
    }
455
455
456
    /**
456
    /**
457
     * Проверка пароля (из cookies)
457
     * Проверка пароля (из cookies)
458
     *
458
     *
459
     * @author Alexander Wolf
459
     * @author Alexander Wolf
460
     * @category Core
460
     * @category Core
461
     *
461
     *
462
     * @param string $hash
462
     * @param string $hash
463
     * @return array
463
     * @return array
464
     */
464
     */
465
    public function checkCookieSign($hash) {
465
    public function checkCookieSign($hash) {
466
        $result = array();
466
        $result = array();
467
467
468
        $pwd = $this->getOption("passwd");
468
        $pwd = $this->getOption("passwd");
469
        if ($hash == $pwd["OptValue"]) {
469
        if ($hash == $pwd["OptValue"]) {
470
            $result["ERR"] = 0;
470
            $result["ERR"] = 0;
471
        } else {
471
        } else {
472
            $result["ERR"] = 1;
472
            $result["ERR"] = 1;
473
            $result["ERRINFO"] = "Hash not valid";
473
            $result["ERRINFO"] = "Hash not valid";
474
            $result["Location"] = "manager.php";
474
            $result["Location"] = "manager.php";
475
        }
475
        }
476
476
477
        return $result;
477
        return $result;
478
    }
478
    }
479
479
480
    /**
480
    /**
481
     * Форма ввода пароля
481
     * Форма ввода пароля
482
     *
482
     *
483
     * @author Alexander Wolf
483
     * @author Alexander Wolf
484
     * @category Core
484
     * @category Core
485
     *
485
     *
486
     * @return string
486
     * @return string
487
     */
487
     */
488
    public function showSigninForm() {
488
    public function showSigninForm() {
489
        $show  = "<div id='regform'>";
489
        $show  = "<div id='regform'>";
490
        $show .= "<form action='process.php' method='post'>\n";
490
        $show .= "<form action='process.php' method='post'>\n";
491
        $show .= "<fieldset><legend>Пароль</legend>\n";
491
        $show .= "<fieldset><legend>Пароль</legend>\n";
492
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
492
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
493
        $show .= "<input type='password' name='word' value=''>\n";
493
        $show .= "<input type='password' name='word' value=''>\n";
494
        $show .= "<input type='submit' value=' Войти '>\n";
494
        $show .= "<input type='submit' value=' Войти '>\n";
495
        $show .= "</fieldset>\n</form></div>\n";
495
        $show .= "</fieldset>\n</form></div>\n";
496
496
497
        return $show;
497
        return $show;
498
    }
498
    }
499
499
500
    /**
500
    /**
501
     * Обновление пароля
501
     * Обновление пароля
502
     *
502
     *
503
     * @author Alexander Wolf
503
     * @author Alexander Wolf
504
     * @category Core
504
     * @category Core
505
     *
505
     *
506
     * @param string $word1
506
     * @param string $word1
507
     * @param string $word2
507
     * @param string $word2
508
     * @return array
508
     * @return array
509
     */
509
     */
510
    public function updatePassword($word1, $word2) {
510
    public function updatePassword($word1, $word2) {
511
        $result = array();
511
        $result = array();
512
512
513
        if ($word1 == $word2) {
513
        if ($word1 == $word2) {
514
            $sWord = $this->secure->encryptStr($word1);
514
            $sWord = $this->secure->encryptStr($word1);
515
            $r = $this->setOption("passwd", $sWord);
515
            $r = $this->setOption("passwd", $sWord);
516
            $result = $r;
516
            $result = $r;
517
        } else {
517
        } else {
518
            $result["ERR"] = 1;
518
            $result["ERR"] = 1;
519
            $result["ERRINFO"] = "Passwords is mismatch";
519
            $result["ERRINFO"] = "Passwords is mismatch";
520
        }
520
        }
521
521
522
        return $result;
522
        return $result;
523
    }
523
    }
524
524
-
 
525
    public function showDistVerstionsEditor($name, $actor, $list = 1) {
-
 
526
        if ($list == 1) {
-
 
527
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ORDER BY d.dist_id,v.version ASC";
-
 
528
            $rq =& $this->db->query($query);
-
 
529
            $show = "<ul>\n";
-
 
530
            while ($rq->fetchInto($element)) {
-
 
531
                $show .= "<li>[<a href='".$actor."?mode=versions&action=edit&uuid=".$this->secure->checkInt($element["version_id"])."'>править</a>][<a href='".$actor."?mode=versions&action=delete&uuid=".$this->secure->checkInt($element["version_id"])."'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)." ".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</li>\n";
-
 
532
            }
-
 
533
            $show .= "</ul>";
-
 
534
        } else {
-
 
535
-
 
536
        }
-
 
537
        return $show;
-
 
538
    }
525
539
526
}
540
}
527
541
528
?>
542
?>