Browse code

add save function

git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@1141 87cf0b9e-d624-0410-a070-f6ee81989793

bernd authored on15/08/2008 20:08:09
Showing1 changed files
... ...
@@ -122,6 +122,7 @@ function get_dns_record($id)
122 122
   if (mysql_num_rows($result) != 1)
123 123
     system_failure('illegal ID');
124 124
   $data = mysql_fetch_assoc($result);
125
+  $dom = new Domain( (int) $data['domain']);
125 126
   DEBUG($data);
126 127
   return $data;
127 128
 }
... ...
@@ -156,5 +157,90 @@ function get_domain_auto_records($domainname)
156 157
 }
157 158
 
158 159
 
160
+$implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv');
161
+
162
+function save_dns_record($id, $record)
163
+{
164
+  global $valid_record_types;
165
+  global $implemented_record_types;
166
+  $record['type'] = strtolower($record['type']);
167
+  if (!in_array($record['type'], $valid_record_types))
168
+    system_failure('invalid type: '.$record['type']);
169
+  if (!in_array($record['type'], $implemented_record_types))
170
+    system_failure('record type '.$record['type'].' not implemented at the moment.');
171
+  $dom = new Domain( (int) $record['domain'] );
172
+  if (! $dom->id)
173
+    system_failure('invalid domain');
174
+  verify_input_hostname($record['hostname']);
175
+  if ($record['ttl'] &&  (int) $record['ttl'] < 1)
176
+    system_failure('Fehler bei TTL');
177
+  switch ($record['type']) 
178
+  {
179
+    case 'a':
180
+      if ($record['dyndns'])
181
+      {
182
+        get_dyndns_account( $record['dyndns'] );
183
+	$record['ip'] = '';
184
+      }
185
+      else
186
+      {
187
+        verify_input_ipv4($record['ip']);
188
+        $record['data'] = '';
189
+        $record['spec'] = '';
190
+      }
191
+      break;
192
+    case 'aaaa':
193
+      $record['dyndns'] = '';
194
+      verify_input_ipv4($record['ip']);
195
+      $record['data'] = '';
196
+      $record['spec'] = '';
197
+      break;
198
+    case 'mx':
199
+      $record['dyndns'] = '';
200
+      $record['spec'] = (int) $record['spec'];
201
+      if ($record['spec'] < 1)
202
+        systen_failure("invalid priority");
203
+      verify_input_hostname($record['data']);
204
+      if (! $record['data'] )
205
+        system_failure('MX hostname missing');
206
+      $record['ip'] = '';
207
+      break;
208
+    case 'spf':
209
+    case 'txt':
210
+      system_failure('not implemented yet');
211
+    case 'cname':
212
+      $record['dyndns'] = '';
213
+      $record['spec'] = '';
214
+      $record['ip'] = '';
215
+      verify_input_hostname($record['data']);
216
+      if (! $record['data'] )
217
+        system_failure('MX hostname missing');
218
+      break;
219
+
220
+    case 'ptr':
221
+    case 'srv':
222
+      system_failure('not implemented yet');
223
+    default:
224
+      system_failure('Not implemented');
225
+  }
226
+  $id = (int) $id;
227
+  $record['hostname'] = maybe_null($record['hostname']);
228
+  $record['ttl'] = ($recory['ttl'] == 0 ? 'NULL' : (int) $record['ttl']);
229
+  $record['ip'] = maybe_null($record['ip']);
230
+  $record['data'] = maybe_null($record['data']);
231
+  $record['spec'] = maybe_null($record['spec']);
232
+  $record['dyndns'] = maybe_null($record['dyndns']);
233
+  if ($id)
234
+    db_query("UPDATE dns.custom_records SET hostname={$record['hostname']}, domain={$dom->id}, type={$record['type']}, ttl={$record['ttl']}, ip={$record['ip']}, dyndns={$record['dyndns']}, data={$record['data']}, spec={$record['spec']} WHERE id={$id} LIMIT 1");
235
+  else
236
+    db_query("INSERT INTO dns.custom_records (hostname, domain, type, ttl, ip, dyndns, data, spec) VALUES ({$record['hostname']}, {$dom->id}, {$record['type']}, {$record['ttl']}, {$record['ip']}, {$record['dyndns']}, {$record['data']}, {$record['spec']})");
237
+
238
+}
239
+
240
+
241
+function delete_dns_record($id)
242
+{
243
+ // ...
244
+}
159 245
 
160 246
 ?>