]> jfr.im git - z_archive/KronOS.git/commitdiff
Restoring.
authorJohn Runyon <redacted>
Mon, 15 Oct 2012 05:36:03 +0000 (08:36 +0300)
committerJohn Runyon <redacted>
Mon, 15 Oct 2012 05:36:03 +0000 (08:36 +0300)
dime/config.php.sample [new file with mode: 0644]
dime/core/common.php [new file with mode: 0644]
dime/core/display.php [new file with mode: 0644]
dime/core/login.php [new file with mode: 0644]
dime/dump.sql [new file with mode: 0644]
dime/frontend/backend [new symlink]
dime/frontend/index.html [new file with mode: 0644]
dime/frontend/style.css [new file with mode: 0644]
dime/frontend/webos.js [new file with mode: 0644]

diff --git a/dime/config.php.sample b/dime/config.php.sample
new file mode 100644 (file)
index 0000000..8ffb14c
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+$db = new mysqli('host', 'user', 'password', 'db');
+
+define('PWSALT', 'saltstring');
diff --git a/dime/core/common.php b/dime/core/common.php
new file mode 100644 (file)
index 0000000..a9ffefb
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+if (!defined('WEBOS')) exit('Invalid access.');
+
+require_once('../config.php');
+
+function make_reply($contents, $data=NULL) {
+       $resp = array(
+               'success' => TRUE,
+               'time' => time(),
+               'contents' => $contents,
+               'data' => $data,
+       );
+       echo json_encode($resp);
+       exit(0);
+}
+function make_error($reason, $errcode) {
+       $resp = array(
+               'success' => FALSE,
+               'time' => time(),
+               'error' => array(
+                       'code' => $errcode,
+                       'reason' => $reason,
+               ),
+       );
+       echo json_encode($resp);
+       exit(0);
+}
diff --git a/dime/core/display.php b/dime/core/display.php
new file mode 100644 (file)
index 0000000..42dd569
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+define('WEBOS', TRUE);
+require_once('common.php');
+
+if (empty($_GET['app'])) {
+       make_error('No app specified to display.', -1);
+}
+if ($_GET['app'] == 'core') {
+       if (empty($_GET['part'])) {
+               make_error('No part of core specified to display.', -2);
+       }
+       switch ($_GET['part']) {
+               case 'logo':
+                       make_reply('DimeTest');
+               case 'login':
+                       $data = '<form action=\'javascript:poster("login.php", {user:$("#user").val(), pass:$("#pass").val()});void(0);\'>';
+                       $data .= '<label for="user">Username: </label><input id="user" name="user" type="text" /><br />';
+                       $data .= '<label for="pass">Password: </label><input id="pass" name="pass" type="password" /><br />';
+                       $data .= '<input value="Login" type="submit" />';
+                       $data .= '</form>';
+                       make_reply($data);
+                       break;
+               default:
+                       make_error('No such part of core.', -3);
+       }
+} else { // $_GET['app'] != 'core'
+       make_error('Not implemented.', 0);
+}
diff --git a/dime/core/login.php b/dime/core/login.php
new file mode 100644 (file)
index 0000000..fc88653
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+define('WEBOS', TRUE);
+require_once('common.php');
+
+if (empty($_POST['user']) || empty($_POST['pass'])) {
+       make_error('Username or password empty.', 1);
+}
+$sth = $db->prepare('SELECT uid, displayname FROM users WHERE username = ? AND password = ?');
+$sth->bind_param('ss', $_POST['user'], sha1(PWSALT.$_POST['pass']));
+$sth->execute();
+$sth->bind_result($uid, $dispname);
+if (!$sth->fetch()) { // no row returned
+       make_error('Username or password incorrect.', 2);
+}
+
+// row returned, user/pw good
+$sth->close();
+$sth = $db->prepare('INSERT INTO sessions(sid, uid, started, last, active) VALUES (NULL, ?, NOW(), NOW(), 1)');
+$sth->bind_param('i', $uid);
+$sth->execute();
+$sid = $sth->insert_id;
+
+make_reply('Logged in!', array('uid' => $uid, 'sid' => $sid, 'name' => $dispname));
diff --git a/dime/dump.sql b/dime/dump.sql
new file mode 100644 (file)
index 0000000..1d2b5cf
--- /dev/null
@@ -0,0 +1,154 @@
+-- MySQL dump 10.13  Distrib 5.5.27, for debian-linux-gnu (x86_64)
+--
+-- Host: localhost    Database: dime_wos
+-- ------------------------------------------------------
+-- Server version      5.5.27-1~dotdeb.0
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+--
+-- Table structure for table `apps`
+--
+
+DROP TABLE IF EXISTS `apps`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `apps` (
+  `aid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `appname` varchar(100) NOT NULL,
+  `parent` int(10) unsigned NOT NULL,
+  `filename` varchar(100) NOT NULL,
+  `access` enum('user','operator','manager') NOT NULL DEFAULT 'user',
+  PRIMARY KEY (`aid`),
+  UNIQUE KEY `appname` (`appname`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `apps`
+--
+
+LOCK TABLES `apps` WRITE;
+/*!40000 ALTER TABLE `apps` DISABLE KEYS */;
+/*!40000 ALTER TABLE `apps` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `categories`
+--
+
+DROP TABLE IF EXISTS `categories`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `categories` (
+  `cid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `catname` varchar(100) NOT NULL,
+  PRIMARY KEY (`cid`),
+  UNIQUE KEY `catname` (`catname`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `categories`
+--
+
+LOCK TABLES `categories` WRITE;
+/*!40000 ALTER TABLE `categories` DISABLE KEYS */;
+/*!40000 ALTER TABLE `categories` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `session_apps`
+--
+
+DROP TABLE IF EXISTS `session_apps`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `session_apps` (
+  `iid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `sid` int(10) unsigned NOT NULL,
+  `aid` int(10) unsigned NOT NULL,
+  PRIMARY KEY (`iid`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `session_apps`
+--
+
+LOCK TABLES `session_apps` WRITE;
+/*!40000 ALTER TABLE `session_apps` DISABLE KEYS */;
+/*!40000 ALTER TABLE `session_apps` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `sessions`
+--
+
+DROP TABLE IF EXISTS `sessions`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `sessions` (
+  `sid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `uid` int(10) unsigned NOT NULL,
+  `started` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `last` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `active` tinyint(1) NOT NULL DEFAULT '1',
+  PRIMARY KEY (`sid`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `sessions`
+--
+
+LOCK TABLES `sessions` WRITE;
+/*!40000 ALTER TABLE `sessions` DISABLE KEYS */;
+/*!40000 ALTER TABLE `sessions` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `users`
+--
+
+DROP TABLE IF EXISTS `users`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `users` (
+  `uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `username` varchar(15) NOT NULL,
+  `password` char(40) NOT NULL,
+  `displayname` varchar(100) NOT NULL,
+  `access` enum('user','operator','manager') NOT NULL DEFAULT 'user',
+  PRIMARY KEY (`uid`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `users`
+--
+
+LOCK TABLES `users` WRITE;
+/*!40000 ALTER TABLE `users` DISABLE KEYS */;
+/*!40000 ALTER TABLE `users` ENABLE KEYS */;
+UNLOCK TABLES;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2012-10-11 11:19:30
diff --git a/dime/frontend/backend b/dime/frontend/backend
new file mode 120000 (symlink)
index 0000000..43c70a4
--- /dev/null
@@ -0,0 +1 @@
+../core/
\ No newline at end of file
diff --git a/dime/frontend/index.html b/dime/frontend/index.html
new file mode 100644 (file)
index 0000000..f398dc3
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+       <title>Mustis WebOS</title>
+       <link rel="stylesheet" href="style.css" type="text/css" />
+       <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
+       <script src="webos.js"></script>
+       <script>
+$(document).ready(function () {
+       poster('display.php?app=core&part=logo', {}, function (resp) {
+               $("span#logo").html(resp.contents);
+       });
+       poster('display.php?app=core&part=login', {});
+});
+       </script>
+</head>
+<body>
+<div id="banner"><span id="logo"></span> WebOS - Powered by Mustis</div>
+
+<div id="error" class="message">
+<!-- populated by JS -->
+<p><small>click to close</small></p>
+</div>
+
+<div id="body">
+<!-- populated by JS -->
+</div>
+
+<div id="copyright">Copyright &copy;2012 Mustis.org. <a href="https://github.com/mustis/WebOsProject">On GitHub</a></div>
+</body>
+</html>
diff --git a/dime/frontend/style.css b/dime/frontend/style.css
new file mode 100644 (file)
index 0000000..0481bf6
--- /dev/null
@@ -0,0 +1,22 @@
+.message {
+       display:none;
+}
+
+div#error {
+       background-color:#aa0000;
+       border:solid 1px black;
+       padding:.2em;
+       margin:.5em;
+}
+
+div#banner {
+       text-align:center;
+       margin:0 auto;
+       padding-bottom:.5em;
+       background-color:#e9967a;
+}
+
+div#copyright {
+       text-align:center;
+       margin:5em auto;
+}
diff --git a/dime/frontend/webos.js b/dime/frontend/webos.js
new file mode 100644 (file)
index 0000000..1a4ea55
--- /dev/null
@@ -0,0 +1,32 @@
+// Mustis WebOS
+
+state = {}
+
+function poster(addr, data, cb) {
+       if (!cb) cb = processResponse;
+
+       if (state.uid) data.uid = state.uid;
+       if (state.sid) data.sid = state.sid;
+       $.post('backend/'+addr, data, cb, 'json');
+}
+
+function processResponse(resp) {
+       loc = "div#body";
+       if (resp.success) {
+               if (resp.contents) {
+                       $(loc).html(resp.contents);
+               }
+               if (resp.data) {
+                       for (key in resp.data) {
+                               state[key] = resp.data[key];
+                       }
+               }
+       } else {
+               $("div#error").append('<p>'+resp.error.reason+'</p>');
+               $("div#error").slideDown(400);
+               $("div#error").click(function () {
+                       $("div#error").slideUp(400);
+                       $("div#error").html('<p><small>click to close</small></p>');
+               });
+       }
+}