Zachary Kotlarek 12 лет назад
Родитель
Сommit
c17e8aaecb
2 измененных файлов с 60 добавлено и 10 удалено
  1. 57 0
      backup/opendrive.php
  2. 3 10
      backup/scanLocal.php

+ 57 - 0
backup/opendrive.php

@@ -0,0 +1,57 @@
+#!/usr/local/bin/php
+<?php
+
+# Debug
+$DEBUG = false;
+if ($_ENV['DEBUG']) {
+	$DEBUG = true;
+}
+
+# On-disk config
+require_once '.secrets';
+
+# Config
+$API_BASE = 'https://dev.opendrive.com/api/v1';
+
+# Open the DB connection
+function dbOpen() {
+	global $DB_STRING;
+	global $DB_USER;
+	global $DB_PASSWD;
+	try {
+		$dbh = new PDO($DB_STRING, $DB_USER, $DB_PASSWD);
+	} catch (PDOException $e) {
+		die('DB error: ' . $e->getMessage() . "\n");
+	}
+	return $dbh;
+}
+
+function login() {
+	global $API_BASE;
+	global $OD_USER;
+	global $OD_PASSWD;
+	
+	$ch = curl_init($API_BASE . '/session/login.json');
+	curl_setopt_array($ch, array(
+	    CURLOPT_POST => TRUE,
+	    CURLOPT_RETURNTRANSFER => TRUE,
+	    CURLOPT_HTTPHEADER => array(
+	        'Content-Type: application/json'
+	    ),
+	    CURLOPT_POSTFIELDS => json_encode($postData)
+	));
+
+	// Send the request
+	$response = curl_exec($ch);
+
+	// Check for errors
+	if($response === FALSE){
+	    die(curl_error($ch));
+	}
+
+	// Decode the response
+	$responseData = json_decode($response, TRUE);
+	return($responseData);
+}
+
+?>

+ 3 - 10
backup/scanLocal.php

@@ -7,11 +7,8 @@ if ($_ENV['DEBUG']) {
 	$DEBUG = true;
 }
 
-# On-disk config
-require_once '.secrets';
-global $DSN;
-global $USER;
-global $PASSWD;
+# Includes
+require_once 'opendrive.php';
 
 # Command-line parameters
 global $argc;
@@ -52,11 +49,7 @@ if (!file_exists($LOCAL) || !is_dir($LOCAL)) {
 }
 
 # Open the DB connection
-try {
-	$dbh = new PDO($DSN, $USER, $PASSWD);
-} catch (PDOException $e) {
-	die('DB error: ' . $e->getMessage() . "\n");
-}
+$dbh = dbOpen();
 
 # Grab the file list -- limit files by mtime, but include all directories
 $FIND=tempnam(sys_get_temp_dir(), 'scanLocal-find');