diff --git a/php/.gitignore b/php/.gitignore deleted file mode 100644 index 3797243..0000000 --- a/php/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -db -server.conf diff --git a/php/config.php b/php/config.php deleted file mode 100644 index b2a7257..0000000 --- a/php/config.php +++ /dev/null @@ -1,4 +0,0 @@ - $v) if (is_string($v)) $m[$k] = urldecode($v); - if (is_callable($handler)) $handler($m); - else require_once "tpl/$handler"; - } -} diff --git a/php/m/db.php b/php/m/db.php deleted file mode 100644 index e0ef54f..0000000 --- a/php/m/db.php +++ /dev/null @@ -1,63 +0,0 @@ - $_) - $data[$id] = $a + $data[$id]; - db_save($db, $data); -} - -function db_delete($db, $filter) -{ - $data = db_get($db); - foreach (db_search($db, $filter) as $id => $_) - unset($data[$id]); - db_save($db, $data); -} - -function db_search($db, $filter = []) -{ - $res = []; - foreach (db_get($db) as $id => $a) - { - foreach ($filter as $k => $v) - if ($a[$k] != $v) continue 2; - $res[$id] = $a; - } - return $res; -} - -function db_search_one($db, $filter) -{ - $res = db_search($db, $filter); - foreach ($res as $a) return $a; - return []; -} - -function db_get($db) -{ - $fname = "./db/$db.json"; - if (!file_exists($fname)) return []; - $db = @json_decode(@file_get_contents($fname), true); - return $db ?: []; -} - -function db_save($db, $data) -{ - $fname = "./db/$db.json"; - if (empty($data)) unlink($fname); - else - { - $st = json_encode($data, JSON_UNESCAPED_UNICODE); - if (!file_exists($x = dirname($fname))) mkdir($x, 0777, true); - if ($st) file_put_contents($fname, $st); - } -} diff --git a/php/m/functions.php b/php/m/functions.php deleted file mode 100644 index 705ea44..0000000 --- a/php/m/functions.php +++ /dev/null @@ -1,13 +0,0 @@ - ['method'=>'POST','header'=>"Connection: close\r\nContent-Length: $data_len\r\n", 'content'=>$data_url] - ]); - - $res = json_decode(@file_get_contents('http://'.$data['to'].'/messages/', false, $context), true); - return !empty($res); -} diff --git a/php/post.php b/php/post.php deleted file mode 100644 index 065ab23..0000000 --- a/php/post.php +++ /dev/null @@ -1,80 +0,0 @@ -time(), 'addr'=>$_SERVER['HTTP_HOST']]; - echo json_encode($a); - exit; -}); - -api_get('/contacts/ping', function(){ - foreach (db_search('contacts') as $a) - if ($a['addr'] != $_SERVER['HTTP_HOST']) // COMMENT: сами себе не отправляем - { - if (time() - @$a['time_ping'] > TIME_PING) - { - $st = @file_get_contents('http://'.$a['addr'].'/ping'); - $json = json_decode($st, true); - $x = $json ? ['time_online' => time()] : []; - db_update('contacts', ['time_ping' => time()] + $x, ['addr'=>$a['addr']]); - } - // если на связи - пытаемся дотправить сообщения - if (time() - $a['time_online'] < TIME_ONLINE) - { - $addr = $a['addr']; - foreach (db_search("undelivered/$addr") as $a) - if (send($a)) - { - db_insert("messages/$addr", $a + ['received'=>time()]); - db_delete("undelivered/$addr", ['timestamp'=>$a['timestamp']]); - } else break; - } - if (!empty($data)) $a['messages'] = $data; - } - exit; -}); - -api_get('/messages/(?[^/]+)', 'messages.tpl'); - -if ($_SERVER['REQUEST_METHOD'] != 'POST') return; - -api_post('/contacts/(?[^/]+)', function($m){ - if (empty($_REQUEST['addr'])) die('Не указан адрес!'); - $addr = $m['addr']; - $x = db_search('contacts', $addr == 'new' ? request('addr') : ['addr'=>$addr]); - if ($addr == 'new') - { - if (!empty($x)) die('Такой адрес уже есть в базе!'); - db_insert('contacts', request('addr,nickname,email')); - redirect('/contacts/'); - } else { - if (request('delete')) - { - db_delete('contacts', ['addr'=>$addr]); - redirect('/contacts/'); - } - else - db_update('contacts', request('addr,nickname,email'), ['addr'=>$addr]); - } -}); - -api_post('/messages/(?[^/]+)', function($m){ - $a = request('text') + ['from'=>$_SERVER['HTTP_HOST'], 'to'=>$m['addr'], 'timestamp'=>time()]; - if (send($a)) - db_insert('messages/'.$m['addr'], $a + ['received'=>time()]); - else - db_insert('undelivered/'.$m['addr'], $a); - redirect($_SERVER['HTTP_REFERER']); -}); - -api_post('/messages/', function($m){ - $a = request('from,to,text,timestamp'); - if ($a['to'] == $_SERVER['HTTP_HOST']) - { - db_insert('messages/'.$a['from'], $a + ['received'=>time()]); - $res = ['received'=>time()]; - echo json_encode($res); - } - exit; -}); - -redirect(); diff --git a/php/server.conf.example b/php/server.conf.example deleted file mode 100644 index 2bcad11..0000000 --- a/php/server.conf.example +++ /dev/null @@ -1 +0,0 @@ -IP=127.0.0.1 diff --git a/php/server.sh b/php/server.sh deleted file mode 100755 index e7d8326..0000000 --- a/php/server.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -source ./server.conf -php -S $IP:8000 index.php diff --git a/php/tpl/chat.tpl b/php/tpl/chat.tpl deleted file mode 100644 index 4e75b88..0000000 --- a/php/tpl/chat.tpl +++ /dev/null @@ -1,10 +0,0 @@ -

Сообщения

- - - -
- - -
- - diff --git a/php/tpl/contact.tpl b/php/tpl/contact.tpl deleted file mode 100644 index 832572c..0000000 --- a/php/tpl/contact.tpl +++ /dev/null @@ -1,20 +0,0 @@ -$m['addr']]); - } -?> - - -

контакт

-
- Адрес: - Ник: - email: - -
diff --git a/php/tpl/contacts.tpl b/php/tpl/contacts.tpl deleted file mode 100644 index e9ab65c..0000000 --- a/php/tpl/contacts.tpl +++ /dev/null @@ -1,29 +0,0 @@ -

Контакты

- - - -Добавить - - - - - - - - - - - - - - - - - - -
АдресНикemailonline
TIME_ONLINE)?'нет':'да'?>сообщения
diff --git a/php/tpl/dns.tpl b/php/tpl/dns.tpl deleted file mode 100644 index 25d618d..0000000 --- a/php/tpl/dns.tpl +++ /dev/null @@ -1,16 +0,0 @@ -

DNS записи

- -Добавить - - - - - - - - - - - - -
АдресДомен
diff --git a/php/tpl/dns_edit.tpl b/php/tpl/dns_edit.tpl deleted file mode 100644 index 04ea92d..0000000 --- a/php/tpl/dns_edit.tpl +++ /dev/null @@ -1,19 +0,0 @@ -$m['addr']]); - } -?> - - -

запись

-
- Адрес: - Домен: - -
diff --git a/php/tpl/index.tpl b/php/tpl/index.tpl deleted file mode 100644 index da6e3da..0000000 --- a/php/tpl/index.tpl +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - -

Ваш IP:

- - -[^/]+)', 'contact.tpl'); - api_get('/contacts/(?[^/]+)/messages', 'chat.tpl'); -?> - - - - - diff --git a/php/tpl/messages.tpl b/php/tpl/messages.tpl deleted file mode 100644 index bfc61f8..0000000 --- a/php/tpl/messages.tpl +++ /dev/null @@ -1,18 +0,0 @@ - - - - -

Список сообщений пуст

- - : -(не доставлено)';?> -
- - -