Хранилища Subversion ant

Редакция

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

Редакция 502 Редакция 504
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
            case 'innerhtml':
-
 
153
                $show = "<select id='".$name."' name='".$name."'>\n";
-
 
154
                while ($rq->fetchInto($element)) {
-
 
155
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
-
 
156
                }
-
 
157
                $show .= "</select>";
-
 
158
                break;
152
        }
159
        }
153
        return $show;
160
        return $show;
154
    }
161
    }
155
162
156
    /**
163
    /**
157
     * Получение названия дистрибутива
164
     * Получение названия дистрибутива
158
     *
165
     *
159
     * @author Alexander Wolf
166
     * @author Alexander Wolf
160
     * @category Core
167
     * @category Core
161
     *
168
     *
162
     * @param integer $distID
169
     * @param integer $distID
163
     * @return array
170
     * @return array
164
     */
171
     */
165
    public function getDistName($distID) {
172
    public function getDistName($distID) {
166
        $result = array();
173
        $result = array();
167
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
174
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
168
        $rq =& $this->db->query($query);
175
        $rq =& $this->db->query($query);
169
        if (PEAR::isError($this->db)) {
176
        if (PEAR::isError($this->db)) {
170
            $result["ERR"] = 1;
177
            $result["ERR"] = 1;
171
            $result["ERRINFO"] = $this->db->getMessage();
178
            $result["ERRINFO"] = $this->db->getMessage();
172
        } else {
179
        } else {
173
            $rq->fetchInto($element);
180
            $rq->fetchInto($element);
174
            $result["ERR"] = 0;
181
            $result["ERR"] = 0;
175
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
182
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
176
        }
183
        }
177
184
178
        return $result;
185
        return $result;
179
    }
186
    }
180
187
181
    /**
188
    /**
182
     * Получение названия программы, ее версии и описания
189
     * Получение названия программы, ее версии и описания
183
     *
190
     *
184
     * @author Alexander Wolf
191
     * @author Alexander Wolf
185
     * @category Core
192
     * @category Core
186
     *
193
     *
187
     * @param string $attr
194
     * @param string $attr
188
     * @return string
195
     * @return string
189
     */
196
     */
190
    public function getEngineAttr($attr = 'codename') {
197
    public function getEngineAttr($attr = 'codename') {
191
        $cname = $this->getOption($attr);
198
        $cname = $this->getOption($attr);
192
        return $this->secure->checkStr($cname["OptValue"],1);
199
        return $this->secure->checkStr($cname["OptValue"],1);
193
    }
200
    }
194
201
195
    /**
202
    /**
196
     * Получение и отображение списка версий дистрибутива
203
     * Получение и отображение списка версий дистрибутива
197
     *
204
     *
198
     * @author Alexander Wolf
205
     * @author Alexander Wolf
199
     * @category Core
206
     * @category Core
200
     *
207
     *
201
     * @param string $name
208
     * @param string $name
202
     * @param integer $distID
209
     * @param integer $distID
203
     * @param string $format
210
     * @param string $format
204
     * @return string
211
     * @return string
205
     */
212
     */
206
    public function showDistVersionsList($name, $distID, $format = 'html') {
213
    public function showDistVersionsList($name, $distID, $format = 'html') {
207
        $distname = $this->getDistName($distID);
214
        $distname = $this->getDistName($distID);
208
        $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
215
        $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
209
        $rq =& $this->db->query($query);
216
        $rq =& $this->db->query($query);
210
        switch ($format) {
217
        switch ($format) {
211
            case 'html':
218
            case 'html':
212
                $show  = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
219
                $show  = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
213
                $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
220
                $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
214
                while ($rq->fetchInto($element)) {
221
                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";
222
                    $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
216
                }
223
                }
217
                $show .= "</select></fieldset>";
224
                $show .= "</select></fieldset>";
218
                break;
225
                break;
219
            case 'json':
226
            case 'json':
220
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
227
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
221
                while ($rq->fetchInto($element)) {
228
                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).'"}';
229
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
223
                }
230
                }
224
                $show .= ']';
231
                $show .= ']';
225
                break;
232
                break;
226
        }
233
        }
227
        return $show;
234
        return $show;
228
    }
235
    }
229
236
230
    /**
237
    /**
231
     * Получение и отображение списка секций основного (официального) репозитория
238
     * Получение и отображение списка секций основного (официального) репозитория
232
     *
239
     *
233
     * @author Alexander Wolf
240
     * @author Alexander Wolf
234
     * @category Core
241
     * @category Core
235
     *
242
     *
236
     * @param integer $version
243
     * @param integer $version
237
     * @param string $format
244
     * @param string $format
238
     * @return string
245
     * @return string
239
     */
246
     */
240
    public function showBranchesList($version, $format = 'html') {
247
    public function showBranchesList($version, $format = 'html') {
241
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
248
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
242
        $rq =& $this->db->query($query);
249
        $rq =& $this->db->query($query);
243
        $rq->fetchInto($types);
250
        $rq->fetchInto($types);
244
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
251
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
245
        $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
252
        $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 ";
253
        $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 ";
254
        $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)."'";
255
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
249
        $rq =& $this->db->query($query);
256
        $rq =& $this->db->query($query);
250
        switch ($format) {
257
        switch ($format) {
251
            case 'html':
258
            case 'html':
252
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
259
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
253
                while ($rq->fetchInto($element)) {
260
                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";
261
                    $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
                }
262
                }
256
                $show .= "</fieldset>\n";
263
                $show .= "</fieldset>\n";
257
                break;
264
                break;
258
            case 'json':
265
            case 'json':
259
                //TODO Доделать JSON-вывод списка секций основного репозитория
266
                //TODO Доделать JSON-вывод списка секций основного репозитория
260
                break;
267
                break;
261
        }
268
        }
262
269
263
        return $show;
270
        return $show;
264
    }
271
    }
265
272
266
    /**
273
    /**
267
     * Получение и отображение списка репозиториев
274
     * Получение и отображение списка репозиториев
268
     *
275
     *
269
     * @author Alexander Wolf
276
     * @author Alexander Wolf
270
     * @category Core
277
     * @category Core
271
     *
278
     *
272
     * @param integer $version
279
     * @param integer $version
273
     * @param integer $reptype
280
     * @param integer $reptype
274
     * @param string $format
281
     * @param string $format
275
     * @return string
282
     * @return string
276
     */
283
     */
277
    public function showRepList($version, $reptype, $format = 'html') {
284
    public function showRepList($version, $reptype, $format = 'html') {
278
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
285
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
279
        $rq =& $this->db->query($query);
286
        $rq =& $this->db->query($query);
280
        $rq->fetchInto($types);
287
        $rq->fetchInto($types);
281
        $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
288
        $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);
289
        $rq =& $this->db->query($query);
283
        switch ($format) {
290
        switch ($format) {
284
            case 'html':
291
            case 'html':
285
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
292
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
286
                while ($rq->fetchInto($types)) {
293
                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";
294
                    $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
                }
295
                }
289
                $show .= "</fieldset>\n";
296
                $show .= "</fieldset>\n";
290
                break;
297
                break;
291
            case 'json':
298
            case 'json':
292
                //TODO Доделать JSON-вывод списка репозиториев
299
                //TODO Доделать JSON-вывод списка репозиториев
293
                break;
300
                break;
294
        }
301
        }
295
302
296
        return $show;
303
        return $show;
297
    }
304
    }
298
305
299
    /**
306
    /**
300
     * Добавление поддержки нового apt-дистрибутива
307
     * Добавление поддержки нового apt-дистрибутива
301
     *
308
     *
302
     * @author Alexander Wolf
309
     * @author Alexander Wolf
303
     * @category Core
310
     * @category Core
304
     *
311
     *
305
     * @param string $distname
312
     * @param string $distname
306
     * @param integer $disttype
313
     * @param integer $disttype
307
     * @param string $distua
314
     * @param string $distua
308
     * @param byte $distlogo
315
     * @param byte $distlogo
309
     * @return array
316
     * @return array
310
     */
317
     */
311
    public function addDistribution($distname, $disttype, $distua = 1, $distlogo = 0) {
318
    public function addDistribution($distname, $disttype, $distua = 1, $distlogo = 0) {
312
        $result = array();
319
        $result = array();
313
        $sDName = $this->secure->checkStr($distname);
320
        $sDName = $this->secure->checkStr($distname);
314
        $sDType = $this->secure->checkInt($disttype);
321
        $sDType = $this->secure->checkInt($disttype);
315
        $sDUAgt = $this->secure->checkStr($distua);
322
        $sDUAgt = $this->secure->checkStr($distua);
316
        $sDLogo = $this->secure->checkInt($distname);
323
        $sDLogo = $this->secure->checkInt($distname);
317
324
318
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
325
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
319
        $rq =& $this->db->query($query);
326
        $rq =& $this->db->query($query);
320
        if (PEAR::isError($this->db)) {
327
        if (PEAR::isError($this->db)) {
321
            $result["ERR"] = 1;
328
            $result["ERR"] = 1;
322
            $result["ERRINFO"] = $this->db->getMessage();
329
            $result["ERRINFO"] = $this->db->getMessage();
323
        } else {
330
        } else {
324
            $rq->fetchInto($element);
331
            $rq->fetchInto($element);
325
            $result["ERR"] = 0;
332
            $result["ERR"] = 0;
326
        }
333
        }
327
334
328
        return $result;
335
        return $result;
329
    }
336
    }
330
337
331
    /**
338
    /**
332
     * Добавление поддержки новой версии apt-дистрибутива
339
     * Добавление поддержки новой версии apt-дистрибутива
333
     *
340
     *
334
     * @author Alexander Wolf
341
     * @author Alexander Wolf
335
     * @category Core
342
     * @category Core
336
     *
343
     *
337
     * @param integer $distID
344
     * @param integer $distID
338
     * @param integer $version
345
     * @param integer $version
339
     * @param string $vname
346
     * @param string $vname
340
     * @param integer $vcodename
347
     * @param integer $vcodename
341
     * @return array
348
     * @return array
342
     */
349
     */
343
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
350
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
344
        $result = array();
351
        $result = array();
345
        $sDistID    = $this->secure->checkInt($distID);
352
        $sDistID    = $this->secure->checkInt($distID);
346
        $sDVersion  = $this->secure->checkStr($version);
353
        $sDVersion  = $this->secure->checkStr($version);
347
        $sDVName    = $this->secure->checkStr($vname);
354
        $sDVName    = $this->secure->checkStr($vname);
348
        $sDVCName   = $this->secure->checkInt($vcodename);
355
        $sDVCName   = $this->secure->checkInt($vcodename);
349
356
350
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
357
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
351
        $rq =& $this->db->query($query);
358
        $rq =& $this->db->query($query);
352
        if (PEAR::isError($this->db)) {
359
        if (PEAR::isError($this->db)) {
353
            $result["ERR"] = 1;
360
            $result["ERR"] = 1;
354
            $result["ERRINFO"] = $this->db->getMessage();
361
            $result["ERRINFO"] = $this->db->getMessage();
355
        } else {
362
        } else {
356
            $rq->fetchInto($element);
363
            $rq->fetchInto($element);
357
            $result["ERR"] = 0;
364
            $result["ERR"] = 0;
358
        }
365
        }
359
366
360
        return $result;
367
        return $result;
361
    }
368
    }
362
369
363
    /**
370
    /**
364
     * Отображение типа дистрибутива
371
     * Отображение типа дистрибутива
365
     *
372
     *
366
     * @author Alexander Wolf
373
     * @author Alexander Wolf
367
     * @category Core
374
     * @category Core
368
     *
375
     *
369
     * @param string $name
376
     * @param string $name
370
     * @param byte $type
377
     * @param byte $type
371
     * @return string
378
     * @return string
372
     */
379
     */
373
    public function showDistTypeForm($name = "dtype",$type = 0) {
380
    public function showDistTypeForm($name = "dtype",$type = 0) {
374
        $query = "SELECT * FROM ".$this->prefix."dtype";
381
        $query = "SELECT * FROM ".$this->prefix."dtype";
375
        $rq =& $this->db->query($query);
382
        $rq =& $this->db->query($query);
376
        $show = "<select name='".$name."' id='".$name."'>\n";
383
        $show = "<select name='".$name."' id='".$name."'>\n";
377
        while ($rq->fetchInto($element)) {
384
        while ($rq->fetchInto($element)) {
378
            if ($element["type_id"] == $type) {
385
            if ($element["type_id"] == $type) {
379
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
386
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
380
            } else {
387
            } else {
381
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
388
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
382
            }
389
            }
383
        }
390
        }
384
        $show .= "</select>";
391
        $show .= "</select>";
385
392
386
        return $show;
393
        return $show;
387
    }
394
    }
388
395
389
    /**
396
    /**
390
     * Отображение формы создания и редактирования apt-дистрибутива
397
     * Отображение формы создания и редактирования apt-дистрибутива
391
     *
398
     *
392
     * @author Alexander Wolf
399
     * @author Alexander Wolf
393
     * @category Core
400
     * @category Core
394
     *
401
     *
395
     * @param integer $distID
402
     * @param integer $distID
396
     * @return string
403
     * @return string
397
     */
404
     */
398
    public function showDistributionForm($distID = 0) {
405
    public function showDistributionForm($distID = 0) {
399
        $sDistID = $this->secure->checkInt($distID);
406
        $sDistID = $this->secure->checkInt($distID);
400
        if ($sDistID != 0) {
407
        if ($sDistID != 0) {
401
            // Режим редактирования
408
            // Режим редактирования
402
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
409
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
403
            $rq =& $this->db->query($query);
410
            $rq =& $this->db->query($query);
404
            $rq->fetchInto($element);
411
            $rq->fetchInto($element);
405
        }
412
        }
406
413
407
        if ($element["distlogo"] == 1) {
414
        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)."'>";
415
            $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 {
416
        } else {
410
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
417
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
411
        }
418
        }
412
419
413
        $show  = "<fieldset><legend>Дистрибутив</legend>\n";
420
        $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";
421
        $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";
422
        $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";
423
        $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";
424
        $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";
425
        $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";
426
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
420
427
421
        return $show;
428
        return $show;
422
    }
429
    }
423
430
424
    // sourses.list
431
    // sourses.list
425
    public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
432
    public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
426
       //TODO Написать генератор sources.list       
433
       //TODO Написать генератор sources.list       
427
    }
434
    }
428
   
435
   
429
    /**
436
    /**
430
     * Проверка пароля (из формы авторизации)
437
     * Проверка пароля (из формы авторизации)
431
     *
438
     *
432
     * @author Alexander Wolf
439
     * @author Alexander Wolf
433
     * @category Core
440
     * @category Core
434
     *
441
     *
435
     * @param string $word
442
     * @param string $word
436
     * @return array
443
     * @return array
437
     */
444
     */
438
    public function checkSign($word) {
445
    public function checkSign($word) {
439
        $result = array();
446
        $result = array();
440
447
441
        $sHash = $this->secure->encryptStr($word);
448
        $sHash = $this->secure->encryptStr($word);
442
        $pwd   = $this->getOption("passwd");
449
        $pwd   = $this->getOption("passwd");
443
        if ($sHash == $pwd["OptValue"]) {
450
        if ($sHash == $pwd["OptValue"]) {
444
            $result["ERR"] = 0;
451
            $result["ERR"] = 0;
445
            $result["Location"] = "manager.php";
452
            $result["Location"] = "manager.php";
446
            setcookie($this->cookie, $sHash);
453
            setcookie($this->cookie, $sHash);
447
        } else {
454
        } else {
448
            $result["ERR"] = 1;
455
            $result["ERR"] = 1;
449
            $result["ERRINFO"] = "Password not valid";
456
            $result["ERRINFO"] = "Password not valid";
450
            $result["Location"] = "manager.php?error=1";
457
            $result["Location"] = "manager.php?error=1";
451
        }
458
        }
452
459
453
        return $result;
460
        return $result;
454
    }
461
    }
455
462
456
    /**
463
    /**
457
     * Проверка пароля (из cookies)
464
     * Проверка пароля (из cookies)
458
     *
465
     *
459
     * @author Alexander Wolf
466
     * @author Alexander Wolf
460
     * @category Core
467
     * @category Core
461
     *
468
     *
462
     * @param string $hash
469
     * @param string $hash
463
     * @return array
470
     * @return array
464
     */
471
     */
465
    public function checkCookieSign($hash) {
472
    public function checkCookieSign($hash) {
466
        $result = array();
473
        $result = array();
467
474
468
        $pwd = $this->getOption("passwd");
475
        $pwd = $this->getOption("passwd");
469
        if ($hash == $pwd["OptValue"]) {
476
        if ($hash == $pwd["OptValue"]) {
470
            $result["ERR"] = 0;
477
            $result["ERR"] = 0;
471
        } else {
478
        } else {
472
            $result["ERR"] = 1;
479
            $result["ERR"] = 1;
473
            $result["ERRINFO"] = "Hash not valid";
480
            $result["ERRINFO"] = "Hash not valid";
474
            $result["Location"] = "manager.php";
481
            $result["Location"] = "manager.php";
475
        }
482
        }
476
483
477
        return $result;
484
        return $result;
478
    }
485
    }
479
486
480
    /**
487
    /**
481
     * Форма ввода пароля
488
     * Форма ввода пароля
482
     *
489
     *
483
     * @author Alexander Wolf
490
     * @author Alexander Wolf
484
     * @category Core
491
     * @category Core
485
     *
492
     *
486
     * @return string
493
     * @return string
487
     */
494
     */
488
    public function showSigninForm() {
495
    public function showSigninForm() {
489
        $show  = "<div id='regform'>";
496
        $show  = "<div id='regform'>";
490
        $show .= "<form action='process.php' method='post'>\n";
497
        $show .= "<form action='process.php' method='post'>\n";
491
        $show .= "<fieldset><legend>Пароль</legend>\n";
498
        $show .= "<fieldset><legend>Пароль</legend>\n";
492
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
499
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
493
        $show .= "<input type='password' name='word' value=''>\n";
500
        $show .= "<input type='password' name='word' value=''>\n";
494
        $show .= "<input type='submit' value=' Войти '>\n";
501
        $show .= "<input type='submit' value=' Войти '>\n";
495
        $show .= "</fieldset>\n</form></div>\n";
502
        $show .= "</fieldset>\n</form></div>\n";
496
503
497
        return $show;
504
        return $show;
498
    }
505
    }
499
506
500
    /**
507
    /**
501
     * Обновление пароля
508
     * Обновление пароля
502
     *
509
     *
503
     * @author Alexander Wolf
510
     * @author Alexander Wolf
504
     * @category Core
511
     * @category Core
505
     *
512
     *
506
     * @param string $word1
513
     * @param string $word1
507
     * @param string $word2
514
     * @param string $word2
508
     * @return array
515
     * @return array
509
     */
516
     */
510
    public function updatePassword($word1, $word2) {
517
    public function updatePassword($word1, $word2) {
511
        $result = array();
518
        $result = array();
512
519
513
        if ($word1 == $word2) {
520
        if ($word1 == $word2) {
514
            $sWord = $this->secure->encryptStr($word1);
521
            $sWord = $this->secure->encryptStr($word1);
515
            $r = $this->setOption("passwd", $sWord);
522
            $r = $this->setOption("passwd", $sWord);
516
            $result = $r;
523
            $result = $r;
517
        } else {
524
        } else {
518
            $result["ERR"] = 1;
525
            $result["ERR"] = 1;
519
            $result["ERRINFO"] = "Passwords is mismatch";
526
            $result["ERRINFO"] = "Passwords is mismatch";
520
        }
527
        }
521
528
522
        return $result;
529
        return $result;
523
    }
530
    }
524
531
-
 
532
    /**
-
 
533
     * Показ формы редактирования версии дистрибутива или его списка
-
 
534
     *
-
 
535
     * @author Alexander Wolf
-
 
536
     * @category Core
-
 
537
     *
-
 
538
     * @param string $name
-
 
539
     * @param string $actor
-
 
540
     * @param integer $versionID
-
 
541
     * @return string
-
 
542
     */
525
    public function showDistVerstionsEditor($name, $actor, $versionID = 0) {
543
    public function showDistVersionsEditor($name, $actor, $versionID = 0) {
526
        if ($versionID == 0) {
544
        if ($versionID == 0) {
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";
545
            $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);
546
            $rq =& $this->db->query($query);
529
            $show = "<ul>\n";
547
            $show = "<ul>\n";
530
            while ($rq->fetchInto($element)) {
548
            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)." &#8220;<em>".$this->secure->checkStr($element["vname"],1)."</em>&#8221;</li>\n";
549
                $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)." &#8220;<em>".$this->secure->checkStr($element["vname"],1)."</em>&#8221;</li>\n";
532
            }
550
            }
533
            $show .= "</ul>";
551
            $show .= "</ul>";
534
        } else {
552
        } else {
535
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$versionID."'";
553
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$versionID."'";
536
            $rq =& $this->db->query($query);
554
            $rq =& $this->db->query($query);
537
            $rq->fetchInto($element);
555
            $rq->fetchInto($element);
538
            $show  = "<form action='".$actor."' method='post'>\n";
556
            $show  = "<form action='".$actor."' method='post'>\n";
539
            $show .= "<fieldset><legend>Редактирование описания версии дистрибутива</legend>\n";
557
            $show .= "<fieldset><legend>Редактирование описания версии дистрибутива</legend>\n";
540
            $show .= "<input type='hidden' name='mode' value='".$name."-edit'>\n";
558
            $show .= "<input type='hidden' name='mode' value='".$name."-edit'>\n";
541
            $show .= "<input type='hidden' name='".$name."ID' value='".$versionID."'>\n";
559
            $show .= "<input type='hidden' name='".$name."ID' value='".$versionID."'>\n";
542
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
560
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
543
            $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
561
            $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
544
            $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
562
            $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
545
            $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
563
            $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
546
            $show .= "<div class='inputbox'><input type='submit' value=' Править '></div></fieldset></form>\n";
564
            $show .= "<div class='inputbox'><input type='submit' value=' Править '></div></fieldset></form>\n";
547
        }
565
        }
548
        return $show;
566
        return $show;
-
 
567
    }
-
 
568
-
 
569
    public function showDistVersionsForm($name, $actor, $versionID = 0) {
-
 
570
        $show  = "<form action='".$actor."' method='post'>";
-
 
571
        if ($versionID == 0) {
-
 
572
            $show .= "<fieldset><legend>Добавить описание новой версии дистрибутива</legend>\n";
-
 
573
            $show .= "<input type='hidden' name='mode' value='".$name."-add'>\n";
-
 
574
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml") ."</div>\n";
-
 
575
            $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value=''></div>\n";
-
 
576
            $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value=''></div>\n";
-
 
577
            $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value=''></div>\n";
-
 
578
            $show .= "<div class='inputbox'><input type='submit' value=' Добавить '></div></fieldset>\n";
-
 
579
        } else {
-
 
580
            $show .= "<fieldset><legend>Удалить описание существующей версии дистрибутива</legend>\n";
-
 
581
            $show .= "<input type='hidden' name='mode' value='".$name."-delete'>\n";
-
 
582
            $show .= "<input type='hidden' name='".$name."ID' value='".$versionID."'>\n";
-
 
583
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
-
 
584
            $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."' readonly='readonly'></div>\n";
-
 
585
            $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."' readonly='readonly'></div>\n";
-
 
586
            $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."' readonly='readonly'></div>\n";
-
 
587
            $show .= "<div class='inputbox'><input type='submit' value=' Удалить '></div></fieldset>\n";
-
 
588
        }
-
 
589
        $show .= "</form>";
-
 
590
-
 
591
        return $show;
549
    }
592
    }
550
593
551
}
594
}
552
595
553
?>
596
?>