Хранилища Subversion ant

Редакция

Редакция 540 | Редакция 546 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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
    /**
467 alex-w 121
     * Получение и отображение списка дистрибутвов
463 alex-w 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;
504 alex-w 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;
506 alex-w 159
            case 'list':
160
                $show = "<ul>";
161
                while ($rq->fetchInto($element)) {
509 alex-w 162
                    $show .= "<li>[<a href='".$heads."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["dist_id"])."'>править</a>][<a href='".$heads."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["dist_id"])."'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)."</li>\n";
506 alex-w 163
                }
164
                $show .= "</ul>";
165
                break;
315 alex-w 166
        }
167
        return $show;
168
    }
169
 
463 alex-w 170
    /**
171
     * Получение названия дистрибутива
172
     *
173
     * @author Alexander Wolf
174
     * @category Core
175
     *
176
     * @param integer $distID
177
     * @return array
178
     */
368 alex-w 179
    public function getDistName($distID) {
315 alex-w 180
        $result = array();
181
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
182
        $rq =& $this->db->query($query);
183
        if (PEAR::isError($this->db)) {
184
            $result["ERR"] = 1;
185
            $result["ERRINFO"] = $this->db->getMessage();
186
        } else {
187
            $rq->fetchInto($element);
188
            $result["ERR"] = 0;
189
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
190
        }
191
 
192
        return $result;
193
    }
194
 
463 alex-w 195
    /**
196
     * Получение названия программы, ее версии и описания
197
     *
198
     * @author Alexander Wolf
199
     * @category Core
200
     *
201
     * @param string $attr
202
     * @return string
203
     */
383 alex-w 204
    public function getEngineAttr($attr = 'codename') {
205
        $cname = $this->getOption($attr);
382 alex-w 206
        return $this->secure->checkStr($cname["OptValue"],1);
381 alex-w 207
    }
208
 
463 alex-w 209
    /**
210
     * Получение и отображение списка версий дистрибутива
211
     *
212
     * @author Alexander Wolf
213
     * @category Core
214
     *
215
     * @param string $name
216
     * @param integer $distID
217
     * @param string $format
218
     * @return string
219
     */
509 alex-w 220
    public function showDistVersionsList($name, $distID, $format = 'html', $actor = '') {
316 alex-w 221
        $distname = $this->getDistName($distID);
509 alex-w 222
        if ($distID == 0) {
223
            $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";
224
        } else {
225
            $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
226
        }
317 alex-w 227
        $rq =& $this->db->query($query);
315 alex-w 228
        switch ($format) {
229
            case 'html':
394 alex-w 230
                $show  = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
231
                $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
315 alex-w 232
                while ($rq->fetchInto($element)) {
316 alex-w 233
                    $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 234
                }
317 alex-w 235
                $show .= "</select></fieldset>";
315 alex-w 236
                break;
237
            case 'json':
317 alex-w 238
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
315 alex-w 239
                while ($rq->fetchInto($element)) {
316 alex-w 240
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
315 alex-w 241
                }
242
                $show .= ']';
243
                break;
509 alex-w 244
            case 'list':
245
                $show = "<ul>\n";
246
                while ($rq->fetchInto($element)) {
545 alex-w 247
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["version_id"])."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["version_id"])."' class='delete'>удалить</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";
509 alex-w 248
                }
249
                $show .= "</ul>";
250
                break;
315 alex-w 251
        }
252
        return $show;
253
    }
254
 
463 alex-w 255
    /**
256
     * Получение и отображение списка секций основного (официального) репозитория
257
     *
258
     * @author Alexander Wolf
259
     * @category Core
260
     *
261
     * @param integer $version
262
     * @param string $format
263
     * @return string
264
     */
368 alex-w 265
    public function showBranchesList($version, $format = 'html') {
317 alex-w 266
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
267
        $rq =& $this->db->query($query);
268
        $rq->fetchInto($types);
269
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
270
        $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
271
        $query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
272
        $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
273
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
274
        $rq =& $this->db->query($query);
275
        switch ($format) {
276
            case 'html':
277
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
278
                while ($rq->fetchInto($element)) {
493 alex-w 279
                    $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";
317 alex-w 280
                }
281
                $show .= "</fieldset>\n";
282
                break;
283
            case 'json':
284
                //TODO Доделать JSON-вывод списка секций основного репозитория
285
                break;
286
        }
318 alex-w 287
 
288
        return $show;
317 alex-w 289
    }
290
 
463 alex-w 291
    /**
292
     * Получение и отображение списка репозиториев
293
     *
294
     * @author Alexander Wolf
295
     * @category Core
296
     *
297
     * @param integer $version
298
     * @param integer $reptype
299
     * @param string $format
300
     * @return string
301
     */
368 alex-w 302
    public function showRepList($version, $reptype, $format = 'html') {
406 alex-w 303
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
317 alex-w 304
        $rq =& $this->db->query($query);
305
        $rq->fetchInto($types);
306
        $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
307
        $rq =& $this->db->query($query);
308
        switch ($format) {
309
            case 'html':
310
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
311
                while ($rq->fetchInto($types)) {
320 alex-w 312
                    $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 313
                }
314
                $show .= "</fieldset>\n";
315
                break;
316
            case 'json':
317
                //TODO Доделать JSON-вывод списка репозиториев
318
                break;
319
        }
318 alex-w 320
 
321
        return $show;
317 alex-w 322
    }
323
 
463 alex-w 324
    /**
325
     * Добавление поддержки нового apt-дистрибутива
326
     *
327
     * @author Alexander Wolf
328
     * @category Core
329
     *
330
     * @param string $distname
331
     * @param integer $disttype
332
     * @param string $distua
333
     * @param byte $distlogo
334
     * @return array
335
     */
514 alex-w 336
    public function addDistribution($distname, $disttype, $distua = '', $distlogo = 0) {
321 alex-w 337
        $result = array();
516 alex-w 338
        $sDName = $this->secure->checkStr($distname,1);
321 alex-w 339
        $sDType = $this->secure->checkInt($disttype);
516 alex-w 340
        $sDUAgt = $this->secure->checkStr($distua,1);
514 alex-w 341
        $sDLogo = $this->secure->checkInt($distlogo);
321 alex-w 342
 
343
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
344
        $rq =& $this->db->query($query);
345
        if (PEAR::isError($this->db)) {
346
            $result["ERR"] = 1;
347
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 348
        } else {            
321 alex-w 349
            $result["ERR"] = 0;
350
        }
351
 
352
        return $result;
353
    }
354
 
463 alex-w 355
    /**
514 alex-w 356
     * Обновление информации о дистрибутиве
357
     *
358
     * @author Alexander Wolf
359
     * @category Core
360
     *
361
     * @param integer $distID
362
     * @param string $distname
363
     * @param integer $disttype
364
     * @param string $distua
365
     * @param integer $distlogo
366
     * @return array
367
     */
538 alex-w 368
    public function updateDistribution($distID, $distname, $disttype, $distua, $distlogo = 0) {
514 alex-w 369
        $result = array();
370
        $sDID   = $this->secure->checkInt($distID);
516 alex-w 371
        $sDName = $this->secure->checkStr($distname,1);
514 alex-w 372
        $sDType = $this->secure->checkInt($disttype);
516 alex-w 373
        $sDUAgt = $this->secure->checkStr($distua,1);
514 alex-w 374
        $sDLogo = $this->secure->checkInt($distlogo);
375
 
538 alex-w 376
        if ($sDLogo!=0) {
377
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'";
378
        } else {
379
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."' WHERE dist_id='".$sDID."'";
380
        }
514 alex-w 381
        $rq =& $this->db->query($query);
382
        if (PEAR::isError($this->db)) {
383
            $result["ERR"] = 1;
384
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 385
        } else {            
514 alex-w 386
            $result["ERR"] = 0;
387
        }
388
 
389
        return $result;
390
    }
391
 
392
    /**
393
     * Удаление информации о дистрибутиве
394
     *
395
     * @author Alexander Wolf
396
     * @category Core
397
     *
398
     * @param integer $distID
399
     * @return array
400
     */
401
    public function dropDistribution($distID) {
402
        $result = array();
403
        $sDID   = $this->secure->checkInt($distID);
404
 
405
        // Удаление дистрибутива
406
        $query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'";
407
        $rq =& $this->db->query($query);
408
        if (PEAR::isError($this->db)) {
409
            $result["ERR"] = 1;
410
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 411
        } else {            
514 alex-w 412
            $result["ERR"] = 0;
413
        }
414
 
415
        // Удаление версий дистрибутива
416
        $query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'";
417
        $rq =& $this->db->query($query);
418
        if (PEAR::isError($this->db)) {
419
            $result["ERR"] = 1;
420
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 421
        } else {            
514 alex-w 422
            $result["ERR"] = 0;
423
        }
424
 
425
        return $result;
426
    }
427
 
428
    /**
463 alex-w 429
     * Добавление поддержки новой версии apt-дистрибутива
430
     *
431
     * @author Alexander Wolf
432
     * @category Core
433
     *
434
     * @param integer $distID
435
     * @param integer $version
436
     * @param string $vname
437
     * @param integer $vcodename
438
     * @return array
439
     */
368 alex-w 440
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
356 alex-w 441
        $result = array();
463 alex-w 442
        $sDistID    = $this->secure->checkInt($distID);
516 alex-w 443
        $sDVersion  = $this->secure->checkStr($version,1);
444
        $sDVName    = $this->secure->checkStr($vname,1);
445
        $sDVCName   = $this->secure->checkStr($vcodename,1);
356 alex-w 446
 
447
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
448
        $rq =& $this->db->query($query);
449
        if (PEAR::isError($this->db)) {
450
            $result["ERR"] = 1;
451
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 452
        } else {            
356 alex-w 453
            $result["ERR"] = 0;
454
        }
455
 
456
        return $result;
457
    }
358 alex-w 458
 
463 alex-w 459
    /**
514 alex-w 460
     * Редактирование информации о версии дистрибутива
461
     *
462
     * @author Alexander Wolf
463
     * @category Core
464
     *
465
     * @param integer $versionID
466
     * @param string $version
467
     * @param string $vname
468
     * @param string $vcodename
469
     * @return array
470
     */
471
    public function updateDistVersion($versionID, $version, $vname = "", $vcodename = "") {
472
        $result = array();
473
        $sVersID    = $this->secure->checkInt($versionID);
516 alex-w 474
        $sDVersion  = $this->secure->checkStr($version,1);
475
        $sDVName    = $this->secure->checkStr($vname,1);
476
        $sDVCName   = $this->secure->checkStr($vcodename,1);
514 alex-w 477
 
478
        $query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'";
479
        $rq =& $this->db->query($query);
480
        if (PEAR::isError($this->db)) {
481
            $result["ERR"] = 1;
482
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 483
        } else {            
514 alex-w 484
            $result["ERR"] = 0;
485
        }
486
 
487
        return $result;
488
    }
489
 
490
    /**
491
     * Удаление информации о версии дистрибутива
492
     *
493
     * @author Alexander Wolf
494
     * @category Core
495
     *
496
     * @param integer $versionID
497
     * @return array
498
     */
499
    public function dropDistVersion($versionID) {
500
        $result = array();
501
        $sVersID    = $this->secure->checkInt($versionID);
502
 
503
        // Удаление версии дистрибутива
504
        $query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'";
505
        $rq =& $this->db->query($query);
506
        if (PEAR::isError($this->db)) {
507
            $result["ERR"] = 1;
508
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 509
        } else {            
514 alex-w 510
            $result["ERR"] = 0;
511
        }
512
 
513
        // Удаление репозиториев этой версии дистрибутива
514
        $query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'";
515
        $rq =& $this->db->query($query);
516
        if (PEAR::isError($this->db)) {
517
            $result["ERR"] = 1;
518
            $result["ERRINFO"] = $this->db->getMessage();
517 alex-w 519
        } else {            
514 alex-w 520
            $result["ERR"] = 0;
521
        }
522
 
523
        return $result;
524
    }
525
 
526
    /**
463 alex-w 527
     * Отображение типа дистрибутива
528
     *
529
     * @author Alexander Wolf
530
     * @category Core
531
     *
532
     * @param string $name
533
     * @param byte $type
534
     * @return string
535
     */
368 alex-w 536
    public function showDistTypeForm($name = "dtype",$type = 0) {
329 alex-w 537
        $query = "SELECT * FROM ".$this->prefix."dtype";
538
        $rq =& $this->db->query($query);
539
        $show = "<select name='".$name."' id='".$name."'>\n";
540
        while ($rq->fetchInto($element)) {
347 alex-w 541
            if ($element["type_id"] == $type) {
542
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 543
            } else {
347 alex-w 544
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 545
            }
546
        }
547
        $show .= "</select>";
548
 
549
        return $show;
550
    }
551
 
463 alex-w 552
    /**
553
     * Отображение формы создания и редактирования apt-дистрибутива
554
     *
555
     * @author Alexander Wolf
556
     * @category Core
557
     *
558
     * @param integer $distID
559
     * @return string
560
     */
511 alex-w 561
    public function showDistributionForm($distID = 0, $info = '') {
329 alex-w 562
        $sDistID = $this->secure->checkInt($distID);
511 alex-w 563
        $sInfo = $this->secure->checkStr($info, 1);
564
        if ($sInfo == "") {
565
            $sInfo = "Дистрибутив";
566
        }
329 alex-w 567
        if ($sDistID != 0) {
568
            // Режим редактирования
569
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
570
            $rq =& $this->db->query($query);
571
            $rq->fetchInto($element);
572
        }
573
 
574
        if ($element["distlogo"] == 1) {
380 alex-w 575
            $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 576
        } else {
380 alex-w 577
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
329 alex-w 578
        }
579
 
511 alex-w 580
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
350 alex-w 581
        $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
582
        $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";
518 alex-w 583
        $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["disttype"])."</div>\n";
348 alex-w 584
        $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
329 alex-w 585
        $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
350 alex-w 586
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
329 alex-w 587
 
588
        return $show;
589
    }
590
 
358 alex-w 591
    // sourses.list
423 alex-w 592
    public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
593
       //TODO Написать генератор sources.list       
358 alex-w 594
    }
522 alex-w 595
 
463 alex-w 596
    /**
522 alex-w 597
     * Показывает список секций
598
     *
599
     * @author Alexander Wolf
600
     * @category Core
601
     *
602
     * @param string $name
603
     * @param string $actor
604
     * @return string
605
     */
606
    public function showSectionsList($name, $actor) {
607
        $query = "SELECT * FROM ".$this->prefix."section";
608
        $rq =& $this->db->query($query);
609
        $show = "<ul>\n";
610
        while ($rq->fetchInto($element)) {
545 alex-w 611
            $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sect_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sect_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["secname"],1)."</li>\n";
522 alex-w 612
        }
613
        $show .= "</ul>";
614
 
615
        return $show;
616
    }
617
 
523 alex-w 618
    /**
619
     * Вывод формы редактирования/добавления секций
620
     *
621
     * @author Alexander Wolf
622
     * @category Core
623
     *
624
     * @param integer $sectionID
625
     * @param string $info
626
     * @return string
627
     */
628
    public function showSectionsForm($sectionID = 0, $info = "") {
522 alex-w 629
        $sSectID = $this->secure->checkInt($sectionID);
630
        $sInfo = $this->secure->checkStr($info, 1);
631
        if ($sInfo == "") {
632
            $sInfo = "Секция";
633
        }
634
        if ($sSectID != 0) {
635
            // Режим редактирования
636
            $query = "SELECT * FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
637
            $rq =& $this->db->query($query);
638
            $rq->fetchInto($element);
639
        }
640
 
641
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
642
        $show .= "<div class='inputbox'><label for='sname'>Название секции:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["secname"],1)."'></div>\n";
643
        $show .= "<div class='inputbox'><label for='sinfo'>Описание секции:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sectinfo"],1)."'></div>\n";
644
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
645
 
646
        return $show;
647
    }
648
 
649
    /**
523 alex-w 650
     * Обновление информации о секции
651
     *
652
     * @author Alexander Wolf
653
     * @category Core
654
     *
655
     * @param integer $sectionID
656
     * @param string $sname
657
     * @param string $sinfo
658
     * @return array
659
     */
660
    public function updateSection($sectionID, $sname, $sinfo = "") {
661
        $result = array();
662
        $sSectID    = $this->secure->checkInt($sectionID);
663
        $sSName     = $this->secure->checkStr($sname,1);
664
        $sSInfo     = $this->secure->checkStr($sinfo,1);
665
 
666
        $query = "UPDATE ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."' WHERE sect_id='".$sSectID."'";
667
        $rq =& $this->db->query($query);
668
        if (PEAR::isError($this->db)) {
669
            $result["ERR"] = 1;
670
            $result["ERRINFO"] = $this->db->getMessage();
671
        } else {
672
            $result["ERR"] = 0;
673
        }
674
 
675
        return $result;
676
    }
677
 
678
    /**
679
     * Удаление информации о секции
680
     *
681
     * @author Alexander Wolf
682
     * @category Core
683
     *
684
     * @param integer $sectionID
685
     * @return array
686
     */
687
    public function dropSection($sectionID) {
688
        $result = array();
689
        $sSectID    = $this->secure->checkInt($sectionID);
690
 
691
        // Удаление секции
692
        $query = "DELETE FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
693
        $rq =& $this->db->query($query);
694
        if (PEAR::isError($this->db)) {
695
            $result["ERR"] = 1;
696
            $result["ERRINFO"] = $this->db->getMessage();
697
        } else {
698
            $result["ERR"] = 0;
699
        }
700
 
701
        return $result;
702
    }
703
 
704
    /**
705
     * Добавление новой секции
706
     *
707
     * @author Alexander Wolf
708
     * @category Core
709
     *
710
     * @param string $sname
711
     * @param string $sinfo
712
     * @return array
713
     */
714
    public function addSection($sname, $sinfo = "") {
715
        $result = array();
716
        $sSName = $this->secure->checkStr($sname,1);
717
        $sSInfo = $this->secure->checkStr($sinfo,1);
718
 
719
        $query = "INSERT INTO ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."'";
720
        $rq =& $this->db->query($query);
721
        if (PEAR::isError($this->db)) {
722
            $result["ERR"] = 1;
723
            $result["ERRINFO"] = $this->db->getMessage();
724
        } else {
725
            $result["ERR"] = 0;
726
        }
727
 
728
        return $result;
729
    }
730
 
731
    /**
539 alex-w 732
     * Показывает список подписей
733
     *
734
     * @author Alexander Wolf
735
     * @category Core
736
     *
737
     * @param string $name
738
     * @param string $actor
739
     * @return string
740
     */
741
    public function showSignsList($name, $actor) {
742
        $query = "SELECT * FROM ".$this->prefix."signs";
743
        $rq =& $this->db->query($query);
744
        $show = "<ul>\n";
745
        while ($rq->fetchInto($element)) {
545 alex-w 746
            $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sign_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sign_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["sname"],1)."</li>\n";
539 alex-w 747
        }
748
        $show .= "</ul>";
749
 
750
        return $show;
751
    }
752
 
753
    /**
754
     * Вывод формы редактирования/добавления подписей
755
     *
756
     * @author Alexander Wolf
757
     * @category Core
758
     *
759
     * @param integer $sectionID
760
     * @param string $info
761
     * @return string
762
     */
763
    public function showSignsForm($signID = 0, $info = "") {
764
        $sSignID = $this->secure->checkInt($signID);
765
        $sInfo = $this->secure->checkStr($info, 1);
766
        if ($sInfo == "") {
767
            $sInfo = "Подписи";
768
        }
769
        if ($sSignID != 0) {
770
            // Режим редактирования
771
            $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
772
            $rq =& $this->db->query($query);
773
            $rq->fetchInto($element);
774
        }
775
 
776
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
777
        $show .= "<div class='inputbox'><label for='sname'>Название подписи:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["sname"],1)."'></div>\n";
778
        $show .= "<div class='inputbox'><label for='sinfo'>Описание подписи:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sinfo"],1)."'></div>\n";
779
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
780
 
781
        return $show;
782
    }
783
 
784
    /**
785
     * Обновление информации о секции
786
     *
787
     * @author Alexander Wolf
788
     * @category Core
789
     *
790
     * @param integer $sectionID
791
     * @param string $sname
792
     * @param string $sinfo
793
     * @return array
794
     */
795
    public function updateSign($signID, $sname, $sinfo = "") {
796
        $result = array();
797
        $sSignID    = $this->secure->checkInt($signID);
798
        $sSName     = $this->secure->checkStr($sname,1);
799
        $sSInfo     = $this->secure->checkStr($sinfo,1);
800
 
801
        $query = "UPDATE ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."' WHERE sign_id='".$sSignID."'";
802
        $rq =& $this->db->query($query);
803
        if (PEAR::isError($this->db)) {
804
            $result["ERR"] = 1;
805
            $result["ERRINFO"] = $this->db->getMessage();
806
        } else {
807
            $result["ERR"] = 0;
808
        }
809
 
810
        return $result;
811
    }
812
 
813
    /**
814
     * Удаление информации о подписи
815
     *
816
     * @author Alexander Wolf
817
     * @category Core
818
     *
819
     * @param integer $sectionID
820
     * @return array
821
     */
540 alex-w 822
    public function dropSign($signID) {
539 alex-w 823
        $result = array();
824
        $sSignID    = $this->secure->checkInt($signID);
825
 
826
        // Удаление подписи
827
        $query = "DELETE FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
828
        $rq =& $this->db->query($query);
829
        if (PEAR::isError($this->db)) {
830
            $result["ERR"] = 1;
831
            $result["ERRINFO"] = $this->db->getMessage();
832
        } else {
833
            $result["ERR"] = 0;
834
        }
835
 
836
        return $result;
837
    }
838
 
839
    /**
540 alex-w 840
     * Добавление новой подписи
539 alex-w 841
     *
842
     * @author Alexander Wolf
843
     * @category Core
844
     *
845
     * @param string $sname
846
     * @param string $sinfo
847
     * @return array
848
     */
540 alex-w 849
    public function addSign($sname, $sinfo = "") {
539 alex-w 850
        $result = array();
851
        $sSName = $this->secure->checkStr($sname,1);
852
        $sSInfo = $this->secure->checkStr($sinfo,1);
853
 
540 alex-w 854
        $query = "INSERT INTO ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."'";
539 alex-w 855
        $rq =& $this->db->query($query);
856
        if (PEAR::isError($this->db)) {
857
            $result["ERR"] = 1;
858
            $result["ERRINFO"] = $this->db->getMessage();
859
        } else {
860
            $result["ERR"] = 0;
861
        }
862
 
863
        return $result;
864
    }
540 alex-w 865
 
539 alex-w 866
    /**
463 alex-w 867
     * Проверка пароля (из формы авторизации)
868
     *
869
     * @author Alexander Wolf
870
     * @category Core
871
     *
872
     * @param string $word
873
     * @return array
874
     */
368 alex-w 875
    public function checkSign($word) {
359 alex-w 876
        $result = array();
877
 
878
        $sHash = $this->secure->encryptStr($word);
879
        $pwd   = $this->getOption("passwd");
880
        if ($sHash == $pwd["OptValue"]) {
881
            $result["ERR"] = 0;
882
            $result["Location"] = "manager.php";
883
            setcookie($this->cookie, $sHash);
884
        } else {
885
            $result["ERR"] = 1;
886
            $result["ERRINFO"] = "Password not valid";
368 alex-w 887
            $result["Location"] = "manager.php?error=1";
359 alex-w 888
        }
889
 
890
        return $result;
358 alex-w 891
    }
357 alex-w 892
 
463 alex-w 893
    /**
894
     * Проверка пароля (из cookies)
895
     *
896
     * @author Alexander Wolf
897
     * @category Core
898
     *
899
     * @param string $hash
900
     * @return array
901
     */
368 alex-w 902
    public function checkCookieSign($hash) {
359 alex-w 903
        $result = array();
904
 
905
        $pwd = $this->getOption("passwd");
906
        if ($hash == $pwd["OptValue"]) {
907
            $result["ERR"] = 0;
908
        } else {
909
            $result["ERR"] = 1;
910
            $result["ERRINFO"] = "Hash not valid";
368 alex-w 911
            $result["Location"] = "manager.php";
359 alex-w 912
        }
913
 
914
        return $result;
915
    }
916
 
463 alex-w 917
    /**
918
     * Форма ввода пароля
919
     *
920
     * @author Alexander Wolf
921
     * @category Core
922
     *
923
     * @return string
924
     */
368 alex-w 925
    public function showSigninForm() {
425 alex-w 926
        $show  = "<div id='regform'>";
927
        $show .= "<form action='process.php' method='post'>\n";
368 alex-w 928
        $show .= "<fieldset><legend>Пароль</legend>\n";
929
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
427 alex-w 930
        $show .= "<input type='password' name='word' value=''>\n";
368 alex-w 931
        $show .= "<input type='submit' value=' Войти '>\n";
425 alex-w 932
        $show .= "</fieldset>\n</form></div>\n";
368 alex-w 933
 
934
        return $show;
935
    }
936
 
463 alex-w 937
    /**
938
     * Обновление пароля
939
     *
940
     * @author Alexander Wolf
941
     * @category Core
942
     *
943
     * @param string $word1
944
     * @param string $word2
945
     * @return array
946
     */
368 alex-w 947
    public function updatePassword($word1, $word2) {
359 alex-w 948
        $result = array();
949
 
950
        if ($word1 == $word2) {
951
            $sWord = $this->secure->encryptStr($word1);
952
            $r = $this->setOption("passwd", $sWord);
953
            $result = $r;
954
        } else {
955
            $result["ERR"] = 1;
956
            $result["ERRINFO"] = "Passwords is mismatch";
957
        }
958
 
959
        return $result;
960
    }
961
 
504 alex-w 962
    /**
509 alex-w 963
     * Отображение формы создания и редактирования версии apt-дистрибутива
504 alex-w 964
     *
965
     * @author Alexander Wolf
966
     * @category Core
967
     *
968
     * @param string $name
969
     * @param string $actor
970
     * @param integer $versionID
971
     * @return string
972
     */
511 alex-w 973
    public function showDistVersionsForm($versionID = 0, $info = '') {
509 alex-w 974
        $sVersionID = $this->secure->checkInt($versionID);
511 alex-w 975
        $sInfo = $this->secure->checkStr($info, 1);
976
        if ($sInfo == "") {
977
            $sInfo = "Версия дистрибутива";
978
        }
509 alex-w 979
        if ($sVersionID != 0) {
980
            // Режим редактирования
497 alex-w 981
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$versionID."'";
982
            $rq =& $this->db->query($query);
983
            $rq->fetchInto($element);
509 alex-w 984
        }
985
 
511 alex-w 986
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
510 alex-w 987
        if ($sVersionID != 0) {
988
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
989
        } else {
990
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
991
        }
509 alex-w 992
        $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
993
        $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
994
        $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
995
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
495 alex-w 996
 
504 alex-w 997
        return $show;
509 alex-w 998
    }    
504 alex-w 999
 
520 alex-w 1000
    /**
1001
     * Парсер схемы адреса репозитория
1002
     * FIXME Возможно не потребуется
1003
     *
1004
     * @author Alexander Wolf
1005
     * @category Core
1006
     *
1007
     * @param string $repstring
1008
     * @return integer
1009
     */
1010
    public function repositoryParser($repstring) {
1011
        $tokens = array();
1012
        $sections = array();
1013
        $tokens = split(" ",$repstring);
1014
 
1015
        if ($tokens[0] == "deb") {
1016
            // debian/ubuntu репозиторий "type proto://host/folder distr sections"
1017
            $url = parse_url($tokens[1]);
1018
            $distr  = $tokens[2];
1019
 
1020
            for($i=3;$i<count($tokens);$i++) {
1021
                $sections[] = $tokens[$i];
1022
            }
1023
        } else {
1024
            // altlinux репозиторий "type [sign] proto://host/folder base repname"
1025
            if (stripos($tokens[1],"]")!=0) {
1026
                $sign = $tokens[1];
1027
                $url = parse_url($tokens[2]);
1028
                $base = $tokens[3];
1029
                $repname = $tokens[4];
1030
            } else {
1031
                $url = parse_url($tokens[1]);
1032
                $base = $tokens[2];
1033
                $repname = $tokens[3];
1034
            }
1035
        }
1036
 
1037
        $proto      = $url["scheme"]."://";
1038
        $addr       = $url["host"];
1039
        if ($url["port"]!="") {
1040
            $addr .= ":".$url["port"];
1041
        }
1042
        $path       = $url["path"];
1043
 
1044
        return 0;
1045
    }
1046
 
539 alex-w 1047
    /**
1048
     * Выгрузка картинок логотипов дистрибутивов
1049
     *
1050
     * @author Alexander Wolf
1051
     * @category Core
1052
     *
1053
     * @param string $path
1054
     * @param string $dist
1055
     * @param array $datafile
1056
     * @return integer
1057
     */
535 alex-w 1058
    public function uploadPicture($path, $dist, $datafile) {
1059
        $folder   = $path.$dist."-orig.png";
1060
        $folderN  = $path.$dist.".png";
1061
        $folderEM = $path.$dist."-em.png";
1062
 
1063
        $distlogo = 0;
1064
        if (move_uploaded_file($datafile["distlogo"]["tmp_name"],$folder)) {
1065
            chmod($folder, 0644);
1066
            list($width, $height) = GetImageSize($folder);
1067
            $percent = 32/$height;
1068
            $newwidth = $width * $percent;
1069
            $newheight = $height * $percent;
1070
 
1071
            $output = ImageCreateTrueColor($newwidth, $newheight);
1072
            $source = ImageCreateFromPNG($folder);
1073
 
1074
            ImageCopyResampled($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1075
            ImagePNG($output, $folderEM);
1076
 
1077
            $percent = 15/$height;
1078
            $newwidth = $width * $percent;
1079
            $newheight = $height * $percent;
1080
 
1081
            $output = ImageCreateTrueColor($newwidth, $newheight);
1082
 
1083
            ImageCopyResized($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1084
            ImagePNG($output, $folderN);
1085
 
1086
            unlink($folder);
1087
            $distlogo = 1;
1088
        }
1089
        return $distlogo;
1090
    }
304 alex-w 1091
}
1092
 
356 alex-w 1093
?>