Редакция 198 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 198 | Редакция 201 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | 2 | ||
3 | /**
|
3 | /**
|
4 | * Project: Ant: sources.list generator
|
4 | * Project: Ant: sources.list generator
|
5 | * File: core.php
|
5 | * File: core.php
|
6 | *
|
6 | *
|
7 | * This library is free software; you can redistribute it and/or
|
7 | * This library is free software; you can redistribute it and/or
|
8 | * modify it under the terms of the GNU Lesser General Public
|
8 | * modify it under the terms of the GNU Lesser General Public
|
9 | * License as published by the Free Software Foundation; either
|
9 | * License as published by the Free Software Foundation; either
|
10 | * version 2.1 of the License, or (at your option) any later version.
|
10 | * version 2.1 of the License, or (at your option) any later version.
|
11 | *
|
11 | *
|
12 | * This library is distributed in the hope that it will be useful,
|
12 | * This library is distributed in the hope that it will be useful,
|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 | * Lesser General Public License for more details.
|
15 | * Lesser General Public License for more details.
|
16 | *
|
16 | *
|
17 | * You should have received a copy of the GNU Lesser General Public
|
17 | * You should have received a copy of the GNU Lesser General Public
|
18 | * License along with this library; if not, write to the Free Software
|
18 | * License along with this library; if not, write to the Free Software
|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20 | *
|
20 | *
|
21 | */
|
21 | */
|
22 | 22 | ||
23 | 23 | ||
24 | class Core { |
24 | class Core { |
25 | 25 | ||
26 | function getRepList($distro,$version,$dblink) { |
26 | function getRepList($distro,$version,$dblink) { |
- | 27 | // Fetch settings
|
|
27 | $query =& $dblink->query("SELECT * FROM settings"); |
28 | $query =& $dblink->query("SELECT * FROM settings"); |
28 | $settings = array(); |
29 | $settings = array(); |
29 | while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) { |
30 | while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) { |
30 | $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]); |
31 | $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]); |
31 | }; |
32 | }; |
- | 33 | // Fetch information about distribution
|
|
- | 34 | $query =& $dblink->query("SELECT * FROM version v JOIN distribution d ON d.dist_id=v.dist_id JOIN dtype p ON d.disttype=p.type_id WHERE v.dist_id='$distro' AND v.version_id='$version'"); |
|
- | 35 | $query->fetchInto($infodist, DB_FETCHMODE_ASSOC); |
|
- | 36 | // Fetch repos
|
|
32 | $repos=array_values($_GET); |
37 | $repos=array_values($_GET); |
33 | for ($i=3;$i<count($repos);$i++){ |
38 | for ($i=3;$i<count($repos);$i++){ |
34 | $pre=-1; //wtf? |
39 | $pre=-1; //wtf? |
35 | $id=(int)$repos[$i]; |
40 | $id=(int)$repos[$i]; |
36 | $sql =& $dblink->query('SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE r.rep_id='.$id); |
41 | $sql =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE r.rep_id=".$id); |
37 | $sql->fetchInto($resinfo, DB_FETCHMODE_ASSOC); |
42 | $sql->fetchInto($resinfo, DB_FETCHMODE_ASSOC); |
38 | 43 | ||
39 | $repscheme = stripslashes($resinfo["scheme"]); |
44 | $repscheme = stripslashes($resinfo["scheme"]); |
40 | $querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE |
45 | $querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$resinfo[rep_id]'"); |
41 | r.rep_id='$resinfo[rep_id]'"); |
- | |
42 | $sections = ""; |
46 | $sections = ""; |
43 | while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC)) { |
47 | while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC)) { |
44 | $sections .= stripslashes($section["sectname"])." "; |
48 | $sections .= stripslashes($section["sectname"])." "; |
45 | }
|
49 | }
|
46 | $repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme); |
50 | $repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme); |
47 | $repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme); |
51 | $repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme); |
48 | $repscheme = str_replace("{URL}",$settings["url"],$repscheme); |
52 | $repscheme = str_replace("{URL}",$settings["url"],$repscheme); |
49 | $repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme); |
53 | $repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme); |
50 | $repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme); |
54 | $repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme); |
51 | $repscheme = str_replace("{SECT}",$sections,$repscheme); |
55 | $repscheme = str_replace("{SECT}",$sections,$repscheme); |
52 | $repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme); |
56 | $repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme); |
53 | if($pre != $resinfo["orig_id"]) { |
57 | if($pre != $resinfo["orig_id"]) { |
54 | $result .= "### ".$resinfo["origin"]."( ".$resinfo["desk"]." ) - ".$resinfo["homeurl"]." ###\n"; |
58 | $result .= "### ".$resinfo["origin"]."( ".$resinfo["desk"]." ) - ".$resinfo["homeurl"]." ###\n"; |
55 | }
|
59 | }
|
56 | $pre = $resinfo["orig_id"]; |
60 | $pre = $resinfo["orig_id"]; |
57 | $result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n"; |
61 | $result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n"; |
58 | }
|
62 | }
|
59 | return $result; |
63 | return $result; |
60 | }
|
64 | }
|
61 | 65 | ||
62 | function getInfo($message,$dblink){ |
66 | function getInfo($message,$dblink){ |
63 | $answer = array(); |
67 | $answer = array(); |
64 | 68 | ||
65 | if (preg_match("/linux/i",$message)) { |
69 | if (preg_match("/linux/i",$message)) { |
66 | $dist_id = 0; |
70 | $dist_id = 0; |
67 | $dist_info = ""; |
71 | $dist_info = ""; |
68 | $vers_id = 0; |
72 | $vers_id = 0; |
69 | $vers_info = ""; |
73 | $vers_info = ""; |
70 | $qd =& $dblink->query("SELECT * FROM distribution"); |
74 | $qd =& $dblink->query("SELECT * FROM distribution"); |
71 | while ($qd->fetchInto($res, DB_FETCHMODE_ASSOC)) { |
75 | while ($qd->fetchInto($res, DB_FETCHMODE_ASSOC)) { |
72 | if (preg_match("/".stripslashes($res["distua"])."/i",$message)) { |
76 | if (preg_match("/".stripslashes($res["distua"])."/i",$message)) { |
73 | $dist_id = $res["dist_id"]; |
77 | $dist_id = $res["dist_id"]; |
74 | $dist_info = stripslashes($res["distname"]); |
78 | $dist_info = stripslashes($res["distname"]); |
75 | $qv =& $dblink->query("SELECT * FROM version WHERE dist_id='$dist_id'"); |
79 | $qv =& $dblink->query("SELECT * FROM version WHERE dist_id='$dist_id'"); |
76 | while($qv->fetchInto($rev, DB_FETCHMODE_ASSOC)) { |
80 | while($qv->fetchInto($rev, DB_FETCHMODE_ASSOC)) { |
77 | if (preg_match("/".stripslashes($rev["vcodename"])."/i",$message)) { |
81 | if (preg_match("/".stripslashes($rev["vcodename"])."/i",$message)) { |
78 | $vers_id = $rev["version_id"]; |
82 | $vers_id = $rev["version_id"]; |
79 | $vers_info = stripslashes($rev["version"])." “".stripslashes($rev["vname"])."”"; |
83 | $vers_info = stripslashes($rev["version"])." “".stripslashes($rev["vname"])."”"; |
80 | }
|
84 | }
|
81 | }
|
85 | }
|
82 | }
|
86 | }
|
83 | }
|
87 | }
|
84 | $answer[] = "Linux"; |
88 | $answer[] = "Linux"; |
85 | $answer[] = "Судя по всему у Вас операционная система "; |
89 | $answer[] = "Судя по всему у Вас операционная система "; |
86 | if ($dist_id!=0) { |
90 | if ($dist_id!=0) { |
87 | $answer[] = $dist_id; |
91 | $answer[] = $dist_id; |
88 | $answer[] = $dist_info; |
92 | $answer[] = $dist_info; |
89 | }
|
93 | }
|
90 | if ($vers_id!=0) { |
94 | if ($vers_id!=0) { |
91 | $answer[] = $vers_id; |
95 | $answer[] = $vers_id; |
92 | $answer[] = $vers_info; |
96 | $answer[] = $vers_info; |
93 | }
|
97 | }
|
94 | 98 | ||
95 | } else { |
99 | } else { |
96 | $answer[] = "unknown"; |
100 | $answer[] = "unknown"; |
97 | $answer[] = "Ресурс рассчитан явно не на Вашу операционную систему!"; |
101 | $answer[] = "Ресурс рассчитан явно не на Вашу операционную систему!"; |
98 | }
|
102 | }
|
99 | 103 | ||
100 | return $answer; |
104 | return $answer; |
101 | }
|
105 | }
|
102 | 106 | ||
103 | function getInterfacesList($current,$dblink) { |
107 | function getInterfacesList($current,$dblink) { |
104 | $url = parse_url($current); |
108 | $url = parse_url($current); |
105 | $path = array(); |
109 | $path = array(); |
106 | $path = split("/",$url["path"]); |
110 | $path = split("/",$url["path"]); |
107 | $currentIF = str_replace(".php","",$path[count($path)-1]); |
111 | $currentIF = str_replace(".php","",$path[count($path)-1]); |
108 | $req =& $dblink->query("SELECT * FROM interfaces WHERE interface NOT LIKE '$currentIF'"); |
112 | $req =& $dblink->query("SELECT * FROM interfaces WHERE interface NOT LIKE '$currentIF'"); |
109 | $iflist = "<a href='./'>Интерфейсы</a>: "; |
113 | $iflist = "<a href='./'>Интерфейсы</a>: "; |
110 | while ($req->fetchInto($if, DB_FETCHMODE_ASSOC)) { |
114 | while ($req->fetchInto($if, DB_FETCHMODE_ASSOC)) { |
111 | $iflist .= "<a href='./".stripslashes($if["interface"]).".php'>".strtolower(stripslashes($if["interfaceinfo"]))."</a>, "; |
115 | $iflist .= "<a href='./".stripslashes($if["interface"]).".php'>".strtolower(stripslashes($if["interfaceinfo"]))."</a>, "; |
112 | }
|
116 | }
|
113 | $iflist = substr($iflist, 0, strlen($iflist)-2); |
117 | $iflist = substr($iflist, 0, strlen($iflist)-2); |
114 | return $iflist; |
118 | return $iflist; |
115 | }
|
119 | }
|
116 | 120 | ||
117 | function getCSSList($dblink) { |
121 | function getCSSList($dblink) { |
118 | $req =& $dblink->query("SELECT * FROM distribution"); |
122 | $req =& $dblink->query("SELECT * FROM distribution"); |
119 | if ($req->numRows()>0) { |
123 | if ($req->numRows()>0) { |
120 | $css = "<style type=\"text/css\">\n"; |
124 | $css = "<style type=\"text/css\">\n"; |
121 | while ($req->fetchInto($dist, DB_FETCHMODE_ASSOC)) { |
125 | while ($req->fetchInto($dist, DB_FETCHMODE_ASSOC)) { |
122 | if ($dist["distlogo"]) { |
126 | if ($dist["distlogo"]) { |
123 | $css .= ".".stripslashes($dist["distua"])." { display: inline; padding-left: 15px; background: transparent url(./img/logo/".stripslashes($dist["distua"]).".png) top left no-repeat; }\n"; |
127 | $css .= ".".stripslashes($dist["distua"])." { display: inline; padding-left: 15px; background: transparent url(./img/logo/".stripslashes($dist["distua"]).".png) top left no-repeat; }\n"; |
124 | $css .= ".".stripslashes($dist["distua"])."-em { display: inline; padding-left: 30px; background: transparent url(./img/logo/".stripslashes($dist["distua"])."-em.png) top left no-repeat; }\n"; |
128 | $css .= ".".stripslashes($dist["distua"])."-em { display: inline; padding-left: 30px; background: transparent url(./img/logo/".stripslashes($dist["distua"])."-em.png) top left no-repeat; }\n"; |
125 | } else { |
129 | } else { |
126 | $css .= ""; |
130 | $css .= ""; |
127 | }
|
131 | }
|
128 | }
|
132 | }
|
129 | $css .= "</style>"; |
133 | $css .= "</style>"; |
130 | } else { |
134 | } else { |
131 | $css = ""; |
135 | $css = ""; |
132 | }
|
136 | }
|
133 | return $css; |
137 | return $css; |
134 | }
|
138 | }
|
135 | 139 | ||
136 | function getSetting($setting, $dblink) { |
140 | function getSetting($setting, $dblink) { |
137 | $query =& $dblink->query("SELECT * FROM settings WHERE opt LIKE '".$setting."'"); |
141 | $query =& $dblink->query("SELECT * FROM settings WHERE opt LIKE '".$setting."'"); |
138 | $query->fetchInto($sett, DB_FETCHMODE_ASSOC); |
142 | $query->fetchInto($sett, DB_FETCHMODE_ASSOC); |
139 | return stripslashes($sett["optvalue"]); |
143 | return stripslashes($sett["optvalue"]); |
140 | }
|
144 | }
|
141 | 145 | ||
142 | function getUUID($param) { |
146 | function getUUID($param) { |
143 | $param_s = md5($param); |
147 | $param_s = md5($param); |
144 | $time_low = bin2hex(substr($param_s,0, 4)); |
148 | $time_low = bin2hex(substr($param_s,0, 4)); |
145 | $time_mid = bin2hex(substr($param_s,4, 2)); |
149 | $time_mid = bin2hex(substr($param_s,4, 2)); |
146 | $time_hi_and_version = bin2hex(substr($param_s,6, 2)); |
150 | $time_hi_and_version = bin2hex(substr($param_s,6, 2)); |
147 | $clock_seq_hi_and_reserved = bin2hex(substr($param_s,8, 2)); |
151 | $clock_seq_hi_and_reserved = bin2hex(substr($param_s,8, 2)); |
148 | $node = bin2hex(substr($param_s,10, 6)); |
152 | $node = bin2hex(substr($param_s,10, 6)); |
149 | 153 | ||
150 | $time_hi_and_version = hexdec($time_hi_and_version); |
154 | $time_hi_and_version = hexdec($time_hi_and_version); |
151 | $time_hi_and_version = $time_hi_and_version >> 4; |
155 | $time_hi_and_version = $time_hi_and_version >> 4; |
152 | $time_hi_and_version = $time_hi_and_version | 0x4000; |
156 | $time_hi_and_version = $time_hi_and_version | 0x4000; |
153 | 157 | ||
154 | $clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved); |
158 | $clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved); |
155 | $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2; |
159 | $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2; |
156 | $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000; |
160 | $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000; |
157 | 161 | ||
158 | return sprintf('%08s-%04s-%04x-%04x-%012s',$time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node); |
162 | return sprintf('%08s-%04s-%04x-%04x-%012s',$time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node); |
159 | }
|
163 | }
|
160 | 164 | ||
161 | 165 | ||
162 | function getAddsRepList($distro,$version,$dblink) { |
166 | function getAddsRepList($distro,$version,$dblink) { |
163 | $query =& $dblink->query("SELECT * FROM settings"); |
167 | $query =& $dblink->query("SELECT * FROM settings"); |
164 | $settings = array(); |
168 | $settings = array(); |
165 | while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) { |
169 | while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) { |
166 | $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]); |
170 | $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]); |
167 | }; |
171 | }; |
168 | $query =& $dblink->query("SELECT * FROM version v JOIN distribution d ON d.dist_id=v.dist_id JOIN dtype p ON d.disttype=p.type_id WHERE v.dist_id='$distro' AND v.version_id='$version'"); |
172 | $query =& $dblink->query("SELECT * FROM version v JOIN distribution d ON d.dist_id=v.dist_id JOIN dtype p ON d.disttype=p.type_id WHERE v.dist_id='$distro' AND v.version_id='$version'"); |
169 | $query->fetchInto($infodist, DB_FETCHMODE_ASSOC); |
173 | $query->fetchInto($infodist, DB_FETCHMODE_ASSOC); |
170 | $query =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE v.ver_id='$version' ORDER BY r.rtype_id, r.scheme_id ASC"); |
174 | $query =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE v.ver_id='$version' ORDER BY r.rtype_id, r.scheme_id ASC"); |
171 | $result.='<input type="hidden" name="d" value="'.$_GET['d'].'"> |
175 | $result.='<input type="hidden" name="d" value="'.$_GET['d'].'"> |
172 | <input type="hidden" name="v" value="'.$_GET['v'].'">'; |
176 | <input type="hidden" name="v" value="'.$_GET['v'].'">'; |
173 | $tmp=0; |
177 | $tmp=0; |
174 | while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC)) { |
178 | while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC)) { |
175 | $tmp++; |
179 | $tmp++; |
176 | if ($resinfo['rtype_id']!=3){$ch='checked';}else{$ch='';} |
180 | if ($resinfo['rtype_id']!=3){$ch='checked';}else{$ch='';} |
177 | $result.='<input type="checkbox" name="'.$tmp.'" '.$ch.' value="'.$resinfo['rep_id'].'">'.$resinfo['repname'].' <em>('.$resinfo['repdescribe'].')</em><br>'; |
181 | $result.='<input type="checkbox" name="'.$tmp.'" '.$ch.' value="'.$resinfo['rep_id'].'">'.$resinfo['repname'].' <em>('.$resinfo['repdescribe'].')</em><br>'; |
178 | }
|
182 | }
|
179 | return $result; |
183 | return $result; |
180 | }
|
184 | }
|
181 | }
|
185 | }
|
182 | ?>
|
186 | ?>
|
183 | 187 |