Хранилища Subversion ant

Редакция

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

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