Хранилища Subversion ant

Редакция

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

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