Редакция 278 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 278 | Редакция 296 | ||
---|---|---|---|
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 getSourceList($distro,$version,$repos,$dblink) { |
26 | function getSourceList($distro,$version,$repos,$dblink) { |
27 | // TODO optimize this
|
27 | // TODO optimize this
|
28 | if(count($repos)==0) return; |
28 | if(count($repos)==0) return; |
29 | // Fetch settings
|
29 | // Fetch settings
|
30 | $query =& $dblink->query("SELECT * FROM settings"); |
30 | $query =& $dblink->query("SELECT * FROM settings"); |
31 | $settings = array(); |
31 | $settings = array(); |
32 | while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) { |
32 | while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) { |
33 | $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]); |
33 | $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]); |
34 | }; |
34 | }; |
35 | // Fetch info about distribution
|
35 | // Fetch info about distribution
|
36 | $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'"); |
36 | $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'"); |
37 | $query->fetchInto($infodist, DB_FETCHMODE_ASSOC); |
37 | $query->fetchInto($infodist, DB_FETCHMODE_ASSOC); |
38 | // Fetch default repos if not defined
|
38 | // Fetch default repos if not defined
|
39 | if($repos[0]=="-1") { |
39 | if($repos[0]=="-1") { |
40 | $querydrep =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN version v2 ON v.ver_id=v2.version_id WHERE r.defaultrep='1' AND v2.version_id='$version'"); |
40 | $querydrep =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN version v2 ON v.ver_id=v2.version_id WHERE r.defaultrep='1' AND v2.version_id='$version'"); |
41 | $i=0; |
41 | $i=0; |
42 | while ($querydrep->fetchInto($dreps,DB_FETCHMODE_ASSOC)) { |
42 | while ($querydrep->fetchInto($dreps,DB_FETCHMODE_ASSOC)) { |
43 | $repos[$i] = $dreps["rep_id"]; |
43 | $repos[$i] = $dreps["rep_id"]; |
44 | $i++; |
44 | $i++; |
45 | }
|
45 | }
|
46 | }; |
46 | }; |
47 | if(count($repos)==0) return; |
47 | if(count($repos)==0) return; |
48 | // Processing repos
|
48 | // Processing repos
|
49 | $porigid = -1; // Previous origin id |
49 | $porigid = -1; // Previous origin id |
50 | for($i=0;$i<count($repos);$i++) { |
50 | for($i=0;$i<count($repos);$i++) { |
51 | $id=$repos[$i]; |
51 | $id=$repos[$i]; |
52 | // Fetch info about origin and scheme
|
52 | // Fetch info about origin and scheme
|
53 | $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); |
53 | $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); |
54 | $sql->fetchInto($resinfo, DB_FETCHMODE_ASSOC); |
54 | $sql->fetchInto($resinfo, DB_FETCHMODE_ASSOC); |
55 | $repscheme = stripslashes($resinfo["scheme"]); |
55 | $repscheme = stripslashes($resinfo["scheme"]); |
56 | // Fetch info about sections
|
56 | // Fetch info about sections
|
57 | $querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$resinfo[rep_id]'"); |
57 | $querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$resinfo[rep_id]'"); |
58 | $sections = ""; |
58 | $sections = ""; |
59 | while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC)) { |
59 | while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC)) { |
60 | $sections .= stripslashes($section["sectname"])." "; |
60 | $sections .= stripslashes($section["sectname"])." "; |
61 | }
|
61 | }
|
62 | // Conversion scheme
|
62 | // Conversion scheme
|
63 | $repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme); |
63 | $repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme); |
64 | $repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme); |
64 | $repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme); |
65 | $repscheme = str_replace("{URL}",$settings["url"],$repscheme); |
65 | $repscheme = str_replace("{URL}",$settings["url"],$repscheme); |
66 | $repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme); |
66 | $repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme); |
67 | $repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme); |
67 | $repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme); |
68 | $repscheme = str_replace("{SECT}",$sections,$repscheme); |
68 | $repscheme = str_replace("{SECT}",$sections,$repscheme); |
69 | $repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme); |
69 | $repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme); |
70 | // Comment if another origin
|
70 | // Comment if another origin
|
71 | if($porigid != $resinfo["orig_id"]) { |
71 | if($porigid != $resinfo["orig_id"]) { |
72 | $result .= "### ".$resinfo["origin"]." ( ".$resinfo["desk"]." ) - ".$resinfo["homeurl"]." ###\n"; |
72 | $result .= "### ".$resinfo["origin"]." ( ".$resinfo["desk"]." ) - ".$resinfo["homeurl"]." ###\n"; |
73 | }
|
73 | }
|
74 | $porigid = $resinfo["orig_id"]; |
74 | $porigid = $resinfo["orig_id"]; |
75 | // Result
|
75 | // Result
|
76 | $result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n"; |
76 | $result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n"; |
77 | }
|
77 | }
|
78 | return $result; |
78 | return $result; |
79 | }
|
79 | }
|
80 | 80 | ||
81 | function getInfo($message,$dblink){ |
81 | function getInfo($message,$dblink){ |
82 | $answer = array(); |
82 | $answer = array(); |
83 | 83 | ||
84 | if (preg_match("/linux/i",$message)) { |
84 | if (preg_match("/linux/i",$message)) { |
85 | $dist_id = 0; |
85 | $dist_id = 0; |
86 | $dist_info = ""; |
86 | $dist_info = ""; |
87 | $vers_id = 0; |
87 | $vers_id = 0; |
88 | $vers_info = ""; |
88 | $vers_info = ""; |
89 | $qd =& $dblink->query("SELECT * FROM distribution"); |
89 | $qd =& $dblink->query("SELECT * FROM distribution"); |
90 | while ($qd->fetchInto($res, DB_FETCHMODE_ASSOC)) { |
90 | while ($qd->fetchInto($res, DB_FETCHMODE_ASSOC)) { |
91 | if (preg_match("/".stripslashes($res["distua"])."/i",$message)) { |
91 | if (preg_match("/".stripslashes($res["distua"])."/i",$message)) { |
92 | $dist_id = $res["dist_id"]; |
92 | $dist_id = $res["dist_id"]; |
93 | $dist_info = stripslashes($res["distname"]); |
93 | $dist_info = stripslashes($res["distname"]); |
94 | $qv =& $dblink->query("SELECT * FROM version WHERE dist_id='$dist_id'"); |
94 | $qv =& $dblink->query("SELECT * FROM version WHERE dist_id='$dist_id'"); |
95 | while($qv->fetchInto($rev, DB_FETCHMODE_ASSOC)) { |
95 | while($qv->fetchInto($rev, DB_FETCHMODE_ASSOC)) { |
96 | if (preg_match("/".stripslashes($rev["vcodename"])."/i",$message)) { |
96 | if (preg_match("/".stripslashes($rev["vcodename"])."/i",$message)) { |
97 | $vers_id = $rev["version_id"]; |
97 | $vers_id = $rev["version_id"]; |
98 | $vers_info = stripslashes($rev["version"])." “".stripslashes($rev["vname"])."”"; |
98 | $vers_info = stripslashes($rev["version"])." “".stripslashes($rev["vname"])."”"; |
99 | }
|
99 | }
|
100 | }
|
100 | }
|
101 | }
|
101 | }
|
102 | }
|
102 | }
|
103 | $answer[] = "Linux"; |
103 | $answer[] = "Linux"; |
104 | $answer[] = _("It seems you have an operating system "); // "Судя по всему у Вас операционная система "; |
104 | $answer[] = _("It seems you have an operating system "); // "Судя по всему у Вас операционная система "; |
105 | if ($dist_id!=0) { |
105 | if ($dist_id!=0) { |
106 | $answer[] = $dist_id; |
106 | $answer[] = $dist_id; |
107 | $answer[] = $dist_info; |
107 | $answer[] = $dist_info; |
108 | }
|
108 | }
|
109 | if ($vers_id!=0) { |
109 | if ($vers_id!=0) { |
110 | $answer[] = $vers_id; |
110 | $answer[] = $vers_id; |
111 | $answer[] = $vers_info; |
111 | $answer[] = $vers_info; |
112 | }
|
112 | }
|
113 | 113 | ||
114 | } else { |
114 | } else { |
115 | $answer[] = "unknown"; |
115 | $answer[] = "unknown"; |
116 | $answer[] = _("The resource not for your operating system!"); // "Ресурс рассчитан явно не на Вашу операционную систему!"; |
116 | $answer[] = _("The resource not for your operating system!"); // "Ресурс рассчитан явно не на Вашу операционную систему!"; |
117 | }
|
117 | }
|
118 | 118 | ||
119 | return $answer; |
119 | return $answer; |
120 | }
|
120 | }
|
121 | 121 | ||
122 | function getInterfacesList($current,$dblink) { |
122 | function getInterfacesList($current,$dblink) { |
123 | $url = parse_url($current); |
123 | $url = parse_url($current); |
124 | $path = array(); |
124 | $path = array(); |
125 | $path = split("/",$url["path"]); |
125 | $path = split("/",$url["path"]); |
126 | $currentIF = str_replace(".php","",$path[count($path)-1]); |
126 | $currentIF = str_replace(".php","",$path[count($path)-1]); |
127 | $req =& $dblink->query("SELECT * FROM interfaces WHERE interface NOT LIKE '$currentIF'"); |
127 | $req =& $dblink->query("SELECT * FROM interfaces WHERE interface NOT LIKE '$currentIF'"); |
128 | $iflist = "<a href='./'>"._("Interfaces")."</a>: "; |
128 | $iflist = "<a href='./'>"._("Interfaces")."</a>: "; |
129 | while ($req->fetchInto($if, DB_FETCHMODE_ASSOC)) { |
129 | while ($req->fetchInto($if, DB_FETCHMODE_ASSOC)) { |
130 | $iflist .= "<a href='./".stripslashes($if["interface"]).".php'>".strtolower(stripslashes($if["interfaceinfo"]))."</a>, "; |
130 | $iflist .= "<a href='./".stripslashes($if["interface"]).".php'>".strtolower(stripslashes($if["interfaceinfo"]))."</a>, "; |
131 | }
|
131 | }
|
132 | $iflist = substr($iflist, 0, strlen($iflist)-2); |
132 | $iflist = substr($iflist, 0, strlen($iflist)-2); |
133 | return $iflist; |
133 | return $iflist; |
134 | }
|
134 | }
|
135 | 135 | ||
136 | function getCSSList($dblink) { |
136 | function getCSSList($dblink) { |
137 | $req =& $dblink->query("SELECT * FROM distribution"); |
137 | $req =& $dblink->query("SELECT * FROM distribution"); |
138 | if ($req->numRows()>0) { |
138 | if ($req->numRows()>0) { |
139 | $css = "<style type=\"text/css\">\n"; |
139 | $css = "<style type=\"text/css\">\n"; |
140 | while ($req->fetchInto($dist, DB_FETCHMODE_ASSOC)) { |
140 | while ($req->fetchInto($dist, DB_FETCHMODE_ASSOC)) { |
141 | if ($dist["distlogo"]) { |
141 | if ($dist["distlogo"]) { |
142 | $css .= ".".stripslashes($dist["distua"])." { display: inline; padding-left: 16px; background: transparent url(./img/logo/".stripslashes($dist["distua"]).".png) top left no-repeat; }\n"; |
142 | $css .= ".".stripslashes($dist["distua"])." { display: inline; padding-left: 16px; background: transparent url(./img/logo/".stripslashes($dist["distua"]).".png) top left no-repeat; }\n"; |
143 | $css .= ".".stripslashes($dist["distua"])."-em { display: inline; padding-left: 32px; background: transparent url(./img/logo/".stripslashes($dist["distua"])."-em.png) top left no-repeat; }\n"; |
143 | $css .= ".".stripslashes($dist["distua"])."-em { display: inline; padding-left: 32px; background: transparent url(./img/logo/".stripslashes($dist["distua"])."-em.png) top left no-repeat; }\n"; |
144 | } else { |
144 | } else { |
145 | $css .= ""; |
145 | $css .= ""; |
146 | }
|
146 | }
|
147 | }
|
147 | }
|
148 | $css .= "</style>"; |
148 | $css .= "</style>"; |
149 | } else { |
149 | } else { |
150 | $css = ""; |
150 | $css = ""; |
151 | }
|
151 | }
|
152 | return $css; |
152 | return $css; |
153 | }
|
153 | }
|
154 | 154 | ||
155 | function getSetting($setting, $dblink) { |
155 | function getSetting($setting, $dblink) { |
156 | $query =& $dblink->query("SELECT * FROM settings WHERE opt LIKE '".$setting."'"); |
156 | $query =& $dblink->query("SELECT * FROM settings WHERE opt LIKE '".$setting."'"); |
157 | $query->fetchInto($sett, DB_FETCHMODE_ASSOC); |
157 | $query->fetchInto($sett, DB_FETCHMODE_ASSOC); |
158 | return stripslashes($sett["optvalue"]); |
158 | return stripslashes($sett["optvalue"]); |
159 | }
|
159 | }
|
160 | 160 | ||
161 | function getUUID($param) { |
161 | function getUUID($param) { |
162 | $param_s = md5($param); |
162 | $param_s = md5($param); |
163 | $time_low = bin2hex(substr($param_s,0, 4)); |
163 | $time_low = bin2hex(substr($param_s,0, 4)); |
164 | $time_mid = bin2hex(substr($param_s,4, 2)); |
164 | $time_mid = bin2hex(substr($param_s,4, 2)); |
165 | $time_hi_and_version = bin2hex(substr($param_s,6, 2)); |
165 | $time_hi_and_version = bin2hex(substr($param_s,6, 2)); |
166 | $clock_seq_hi_and_reserved = bin2hex(substr($param_s,8, 2)); |
166 | $clock_seq_hi_and_reserved = bin2hex(substr($param_s,8, 2)); |
167 | $node = bin2hex(substr($param_s,10, 6)); |
167 | $node = bin2hex(substr($param_s,10, 6)); |
168 | 168 | ||
169 | $time_hi_and_version = hexdec($time_hi_and_version); |
169 | $time_hi_and_version = hexdec($time_hi_and_version); |
170 | $time_hi_and_version = $time_hi_and_version >> 4; |
170 | $time_hi_and_version = $time_hi_and_version >> 4; |
171 | $time_hi_and_version = $time_hi_and_version | 0x4000; |
171 | $time_hi_and_version = $time_hi_and_version | 0x4000; |
172 | 172 | ||
173 | $clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved); |
173 | $clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved); |
174 | $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2; |
174 | $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2; |
175 | $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000; |
175 | $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000; |
176 | 176 | ||
177 | return sprintf('%08s-%04s-%04x-%04x-%012s',$time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node); |
177 | return sprintf('%08s-%04s-%04x-%04x-%012s',$time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node); |
178 | }
|
178 | }
|
179 | 179 | ||
180 | 180 | ||
181 | function getRepList($distro,$version,$dblink) { |
181 | function getRepList($distro,$version,$dblink) { |
182 | $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"); |
182 | $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"); |
183 | $i=-1; |
183 | $i=-1; |
184 | while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC)) { |
184 | while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC)) { |
185 | $i++; |
185 | $i++; |
186 | $res[0][$i]=$resinfo["rep_id"]; |
186 | $res[0][$i]=$resinfo["rep_id"]; |
187 | $res[1][$i]=$resinfo["repname"]; |
187 | $res[1][$i]=$resinfo["repname"]; |
188 | $res[2][$i]=$resinfo["repdescribe"]; |
188 | $res[2][$i]=$resinfo["repdescribe"]; |
189 | $res[3][$i]=$resinfo["defaultrep"]; |
189 | $res[3][$i]=$resinfo["defaultrep"]; |
190 | }
|
190 | }
|
191 | return $res; |
191 | return $res; |
192 | }
|
192 | }
|
193 | }
|
193 | }
|
194 | ?>
|
194 | ?>
|
195 | 195 |