author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (unidiff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /backend/php/src/plugins | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
-rw-r--r-- | backend/php/src/plugins/IPlugin.php | 48 | ||||
-rw-r--r-- | backend/php/src/plugins/base64_install.sql | 172 | ||||
-rw-r--r-- | backend/php/src/plugins/base64_uninstall.sql | 20 | ||||
-rw-r--r-- | backend/php/src/plugins/plugin.base64.php | 128 |
4 files changed, 368 insertions, 0 deletions
diff --git a/backend/php/src/plugins/IPlugin.php b/backend/php/src/plugins/IPlugin.php new file mode 100644 index 0000000..3e39e70 --- a/dev/null +++ b/backend/php/src/plugins/IPlugin.php | |||
@@ -0,0 +1,48 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * All functions must be implemented to create a correct POG plugin | ||
4 | * The 'optional' functions SetupRender() and AuthorPage() must be implemented and return null | ||
5 | * if your plugin does not need them. | ||
6 | * | ||
7 | */ | ||
8 | interface POG_Plugin | ||
9 | { | ||
10 | /** | ||
11 | * | ||
12 | * REQUIRED | ||
13 | * This function must return the version of the plugin. | ||
14 | * It will be used to automatically notify developer when your plugin is updated. | ||
15 | * | ||
16 | */ | ||
17 | function Version(); | ||
18 | |||
19 | /** | ||
20 | * | ||
21 | * REQUIRED | ||
22 | * This function performs the actions that your plugin provides. | ||
23 | * | ||
24 | */ | ||
25 | function Execute(); | ||
26 | |||
27 | /** | ||
28 | * 'OPTIONAL' | ||
29 | * If your plugin needs an administrative interface, implement this function. | ||
30 | * Else return null | ||
31 | * | ||
32 | */ | ||
33 | function SetupRender(); | ||
34 | |||
35 | |||
36 | /** | ||
37 | * | ||
38 | * 'OPTIONAL' | ||
39 | * Implement this function to provide a link to your homepage. | ||
40 | * e.g. return 'http://myhomepage.com'; | ||
41 | * | ||
42 | * return null if you do not want to link to your homepage | ||
43 | * e.g. return null | ||
44 | * | ||
45 | */ | ||
46 | function AuthorPage(); | ||
47 | } | ||
48 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/plugins/base64_install.sql b/backend/php/src/plugins/base64_install.sql new file mode 100644 index 0000000..40401d6 --- a/dev/null +++ b/backend/php/src/plugins/base64_install.sql | |||
@@ -0,0 +1,172 @@ | |||
1 | -- base64.sql - MySQL base64 encoding/decoding functions | ||
2 | -- Copyright (C) 2006 Ian Gulliver | ||
3 | -- | ||
4 | -- This program is free software; you can redistribute it and/or modify | ||
5 | -- it under the terms of version 2 of the GNU General Public License as | ||
6 | -- published by the Free Software Foundation. | ||
7 | -- | ||
8 | -- This program is distributed in the hope that it will be useful, | ||
9 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | -- GNU General Public License for more details. | ||
12 | -- | ||
13 | -- You should have received a copy of the GNU General Public License | ||
14 | -- along with this program; if not, write to the Free Software | ||
15 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
16 | |||
17 | |||
18 | DROP TABLE IF EXISTS base64_data | | ||
19 | CREATE TABLE base64_data (c CHAR(1) BINARY, val TINYINT) | | ||
20 | INSERT INTO base64_data VALUES | ||
21 | ('A',0), ('B',1), ('C',2), ('D',3), ('E',4), ('F',5), ('G',6), ('H',7), ('I',8), ('J',9), | ||
22 | ('K',10), ('L',11), ('M',12), ('N',13), ('O',14), ('P',15), ('Q',16), ('R',17), ('S',18), ('T',19), | ||
23 | ('U',20), ('V',21), ('W',22), ('X',23), ('Y',24), ('Z',25), ('a',26), ('b',27), ('c',28), ('d',29), | ||
24 | ('e',30), ('f',31), ('g',32), ('h',33), ('i',34), ('j',35), ('k',36), ('l',37), ('m',38), ('n',39), | ||
25 | ('o',40), ('p',41), ('q',42), ('r',43), ('s',44), ('t',45), ('u',46), ('v',47), ('w',48), ('x',49), | ||
26 | ('y',50), ('z',51), ('0',52), ('1',53), ('2',54), ('3',55), ('4',56), ('5',57), ('6',58), ('7',59), | ||
27 | ('8',60), ('9',61), ('+',62), ('/',63), ('=',0) | | ||
28 | |||
29 | |||
30 | DROP FUNCTION IF EXISTS BASE64_DECODE | | ||
31 | CREATE FUNCTION BASE64_DECODE (input BLOB) | ||
32 | RETURNS BLOB | ||
33 | CONTAINS SQL | ||
34 | DETERMINISTIC | ||
35 | SQL SECURITY INVOKER | ||
36 | BEGIN | ||
37 | DECLARE ret BLOB DEFAULT ''; | ||
38 | DECLARE done TINYINT DEFAULT 0; | ||
39 | |||
40 | IF input IS NULL THEN | ||
41 | RETURN NULL; | ||
42 | END IF; | ||
43 | |||
44 | each_block: | ||
45 | WHILE NOT done DO BEGIN | ||
46 | DECLARE accum_value BIGINT UNSIGNED DEFAULT 0; | ||
47 | DECLARE in_count TINYINT DEFAULT 0; | ||
48 | DECLARE out_count TINYINT DEFAULT 3; | ||
49 | |||
50 | each_input_char: | ||
51 | WHILE in_count < 4 DO BEGIN | ||
52 | DECLARE first_char CHAR(1); | ||
53 | |||
54 | IF LENGTH(input) = 0 THEN | ||
55 | RETURN ret; | ||
56 | END IF; | ||
57 | |||
58 | SET first_char = SUBSTRING(input,1,1); | ||
59 | SET input = SUBSTRING(input,2); | ||
60 | |||
61 | BEGIN | ||
62 | DECLARE tempval TINYINT UNSIGNED; | ||
63 | DECLARE error TINYINT DEFAULT 0; | ||
64 | DECLARE base64_getval CURSOR FOR SELECT val FROM base64_data WHERE c = first_char; | ||
65 | DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET error = 1; | ||
66 | |||
67 | OPEN base64_getval; | ||
68 | FETCH base64_getval INTO tempval; | ||
69 | CLOSE base64_getval; | ||
70 | |||
71 | IF error THEN | ||
72 | ITERATE each_input_char; | ||
73 | END IF; | ||
74 | |||
75 | SET accum_value = (accum_value << 6) + tempval; | ||
76 | END; | ||
77 | |||
78 | SET in_count = in_count + 1; | ||
79 | |||
80 | IF first_char = '=' THEN | ||
81 | SET done = 1; | ||
82 | SET out_count = out_count - 1; | ||
83 | END IF; | ||
84 | END; END WHILE; | ||
85 | |||
86 | -- We've now accumulated 24 bits; deaccumulate into bytes | ||
87 | |||
88 | -- We have to work from the left, so use the third byte position and shift left | ||
89 | WHILE out_count > 0 DO BEGIN | ||
90 | SET ret = CONCAT(ret,CHAR((accum_value & 0xff0000) >> 16)); | ||
91 | SET out_count = out_count - 1; | ||
92 | SET accum_value = (accum_value << 8) & 0xffffff; | ||
93 | END; END WHILE; | ||
94 | |||
95 | END; END WHILE; | ||
96 | |||
97 | RETURN ret; | ||
98 | END | | ||
99 | |||
100 | DROP FUNCTION IF EXISTS BASE64_ENCODE | | ||
101 | CREATE FUNCTION BASE64_ENCODE (input BLOB) | ||
102 | RETURNS BLOB | ||
103 | CONTAINS SQL | ||
104 | DETERMINISTIC | ||
105 | SQL SECURITY INVOKER | ||
106 | BEGIN | ||
107 | DECLARE ret BLOB DEFAULT ''; | ||
108 | DECLARE done TINYINT DEFAULT 0; | ||
109 | |||
110 | IF input IS NULL THEN | ||
111 | RETURN NULL; | ||
112 | END IF; | ||
113 | |||
114 | each_block: | ||
115 | WHILE NOT done DO BEGIN | ||
116 | DECLARE accum_value BIGINT UNSIGNED DEFAULT 0; | ||
117 | DECLARE in_count TINYINT DEFAULT 0; | ||
118 | DECLARE out_count TINYINT; | ||
119 | |||
120 | each_input_char: | ||
121 | WHILE in_count < 3 DO BEGIN | ||
122 | DECLARE first_char CHAR(1); | ||
123 | |||
124 | IF LENGTH(input) = 0 THEN | ||
125 | SET done = 1; | ||
126 | SET accum_value = accum_value << (8 * (3 - in_count)); | ||
127 | LEAVE each_input_char; | ||
128 | END IF; | ||
129 | |||
130 | SET first_char = SUBSTRING(input,1,1); | ||
131 | SET input = SUBSTRING(input,2); | ||
132 | |||
133 | SET accum_value = (accum_value << 8) + ASCII(first_char); | ||
134 | |||
135 | SET in_count = in_count + 1; | ||
136 | END; END WHILE; | ||
137 | |||
138 | -- We've now accumulated 24 bits; deaccumulate into base64 characters | ||
139 | |||
140 | -- We have to work from the left, so use the third byte position and shift left | ||
141 | CASE | ||
142 | WHEN in_count = 3 THEN SET out_count = 4; | ||
143 | WHEN in_count = 2 THEN SET out_count = 3; | ||
144 | WHEN in_count = 1 THEN SET out_count = 2; | ||
145 | ELSE RETURN ret; | ||
146 | END CASE; | ||
147 | |||
148 | WHILE out_count > 0 DO BEGIN | ||
149 | BEGIN | ||
150 | DECLARE out_char CHAR(1); | ||
151 | DECLARE base64_getval CURSOR FOR SELECT c FROM base64_data WHERE val = (accum_value >> 18); | ||
152 | |||
153 | OPEN base64_getval; | ||
154 | FETCH base64_getval INTO out_char; | ||
155 | CLOSE base64_getval; | ||
156 | |||
157 | SET ret = CONCAT(ret,out_char); | ||
158 | SET out_count = out_count - 1; | ||
159 | SET accum_value = accum_value << 6 & 0xffffff; | ||
160 | END; | ||
161 | END; END WHILE; | ||
162 | |||
163 | CASE | ||
164 | WHEN in_count = 2 THEN SET ret = CONCAT(ret,'='); | ||
165 | WHEN in_count = 1 THEN SET ret = CONCAT(ret,'=='); | ||
166 | ELSE BEGIN END; | ||
167 | END CASE; | ||
168 | |||
169 | END; END WHILE; | ||
170 | |||
171 | RETURN ret; | ||
172 | END | | ||
diff --git a/backend/php/src/plugins/base64_uninstall.sql b/backend/php/src/plugins/base64_uninstall.sql new file mode 100644 index 0000000..02b9b6b --- a/dev/null +++ b/backend/php/src/plugins/base64_uninstall.sql | |||
@@ -0,0 +1,20 @@ | |||
1 | -- base64.sql - MySQL base64 encoding/decoding functions | ||
2 | -- Copyright (C) 2006 Ian Gulliver | ||
3 | -- | ||
4 | -- This program is free software; you can redistribute it and/or modify | ||
5 | -- it under the terms of version 2 of the GNU General Public License as | ||
6 | -- published by the Free Software Foundation. | ||
7 | -- | ||
8 | -- This program is distributed in the hope that it will be useful, | ||
9 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | -- GNU General Public License for more details. | ||
12 | -- | ||
13 | -- You should have received a copy of the GNU General Public License | ||
14 | -- along with this program; if not, write to the Free Software | ||
15 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
16 | |||
17 | |||
18 | DROP TABLE IF EXISTS base64_data | | ||
19 | DROP FUNCTION IF EXISTS BASE64_DECODE | | ||
20 | DROP FUNCTION IF EXISTS BASE64_ENCODE | \ No newline at end of file | ||
diff --git a/backend/php/src/plugins/plugin.base64.php b/backend/php/src/plugins/plugin.base64.php new file mode 100644 index 0000000..323f861 --- a/dev/null +++ b/backend/php/src/plugins/plugin.base64.php | |||
@@ -0,0 +1,128 @@ | |||
1 | <?php | ||
2 | class Base64 | ||
3 | { | ||
4 | var $sourceObject; | ||
5 | var $argv; | ||
6 | var $version = '1.0'; | ||
7 | |||
8 | function Version() | ||
9 | { | ||
10 | return $this->version; | ||
11 | } | ||
12 | |||
13 | function Base64($sourceObject, $argv) | ||
14 | { | ||
15 | $this->sourceObject = $sourceObject; | ||
16 | $this->argv = $argv; | ||
17 | } | ||
18 | |||
19 | function Execute() | ||
20 | { | ||
21 | return null; | ||
22 | } | ||
23 | |||
24 | function SetupRender() | ||
25 | { | ||
26 | if (isset($_POST['install_base64']) || isset($_POST['uninstall_base64'])) | ||
27 | { | ||
28 | $this->SetupExecute(); | ||
29 | } | ||
30 | else | ||
31 | { | ||
32 | $out = "This plugin allows you to install and uninstall a base64 custom function to and from your database. | ||
33 | You can then set \$configuration['db_encoding'] = 1 so that all data is transparently encoded and decoded | ||
34 | with the minimal overhead possible. Enabling data encoding has quite a few advantages: <br/><br/> | ||
35 | |||
36 | "; | ||
37 | $out .= "<br/><br/><textarea>BASE64 Status"; | ||
38 | if (Base64::IsBase64FunctionInstalled()) | ||
39 | { | ||
40 | $out .= "\n\tChecking MySQL function....OK!"; | ||
41 | if (!isset($GLOBALS['configuration']['db_encoding']) || $GLOBALS['configuration']['db_encoding'] != 1) | ||
42 | { | ||
43 | $out .="\n\tChecking db_encoding status....Failed"; | ||
44 | $out .= "\n\n---------------------------------------------------"; | ||
45 | $out .= "\n\$configuration['db_encoding'] is set to 0. Make sure you set the value to 1 to enable data encoding."; | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | $out .="\n\tChecking db_encoding status....OK!"; | ||
50 | $out .= "\n\nBASE64 Status...OK!"; | ||
51 | $out .= "\n---------------------------------------------------"; | ||
52 | } | ||
53 | $out .= "</textarea><div style='padding-left:250px;padding-top:10px;'><input type='submit' value='UNINSTALL' name='uninstall_base64'/></div>"; | ||
54 | } | ||
55 | else | ||
56 | { | ||
57 | $out .= "\n\tChecking MySQL function....NOT INSTALLED"; | ||
58 | $out .="\n\tChecking db_encoding status ignored"; | ||
59 | $out .= "\n\n---------------------------------------------------"; | ||
60 | $out .= "\nClick the INSTALL button below to install the base64 function to your database."; | ||
61 | $out .= "</textarea><div style='padding-left:250px;padding-top:10px;'><input type='submit' value='INSTALL' name='install_base64'/></div>"; | ||
62 | } | ||
63 | $out .= "<input type='hidden' name='plugins' value='true'/>"; | ||
64 | echo $out; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | function AuthorPage() | ||
69 | { | ||
70 | return null; | ||
71 | } | ||
72 | |||
73 | |||
74 | function SetupExecute() | ||
75 | { | ||
76 | $out = ''; | ||
77 | $connection = Database::Connect(); | ||
78 | if (isset($_POST['install_base64']) && isset($_POST['install_base64']) == true) | ||
79 | { | ||
80 | $initialData = file_get_contents('../plugins/base64_install.sql'); | ||
81 | $statements = explode('|', $initialData); | ||
82 | if (sizeof($statements) > 0) | ||
83 | { | ||
84 | foreach ($statements as $statement) | ||
85 | { | ||
86 | if (trim($statement) != '') | ||
87 | { | ||
88 | Database::NonQuery($statement, $connection); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | $out .= "<textarea>INSTALL SUCCESSFUL\n\n"; | ||
93 | $out .= "Make sure you set \$configuration[db_encoding] = 1 in the configuration file.</textarea>"; | ||
94 | } | ||
95 | else if (isset($_POST['uninstall_base64']) && $_POST['uninstall_base64'] == true) | ||
96 | { | ||
97 | $initialData = file_get_contents('../plugins/base64_uninstall.sql'); | ||
98 | $statements = explode('|', $initialData); | ||
99 | if (sizeof($statements) > 0) | ||
100 | { | ||
101 | foreach ($statements as $statement) | ||
102 | { | ||
103 | if (trim($statement) != '') | ||
104 | { | ||
105 | Database::NonQuery($statement, $connection); | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | $out .= "<textarea>UNINSTALL SUCCESSFUL\n\n"; | ||
110 | $out .= "Make sure you set \$configuration[db_encoding] = 0 in the configuration file.</textarea>"; | ||
111 | } | ||
112 | echo $out; | ||
113 | } | ||
114 | |||
115 | function IsBase64FunctionInstalled() | ||
116 | { | ||
117 | $sql1 = "show function status where Db='".$GLOBALS['configuration']['db']."' and (Name='BASE64_DECODE' or Name='BASE64_ENCODE')"; | ||
118 | $sql2 = "show tables like 'base64_data'"; | ||
119 | $connection = Database::Connect(); | ||
120 | $result = Database::Query($sql1, $connection); | ||
121 | $result2 = Database::Query($sql2, $connection); | ||
122 | if ($result == 2 && $result2 == 1) | ||
123 | { | ||
124 | return true; | ||
125 | } | ||
126 | return false; | ||
127 | } | ||
128 | } | ||