source: locker/sql/bin/get-password @ 382

Last change on this file since 382 was 382, checked in by presbrey, 17 years ago
new SQL signup and server
  • Property svn:executable set to *
File size: 1.2 KB
RevLine 
[131]1#!/usr/bin/php
2<?php
3
4$host = 'sql.mit.edu';
5$env_user = getenv('USER');
6$home = '/mit/'.$env_user;
7
8$cnfPath = $home.'/.sql/my.cnf';
9
10function getMyCnfInfo($path) {
11if (file_exists($path)) {
12        global $env_user;
13        $cnfFile = file_get_contents($path);
14        preg_match('/\[mysql\][^\[]*host=([^\n]*)/',$cnfFile,$match);
15        $host = $match[1];
16        preg_match('/\[mysql\][^\[]*user=([^\n]*)/',$cnfFile,$match);
17        $user = $match[1];
18        preg_match('/\[mysql\][^\[]*password=([^\n]*)/',$cnfFile,$match);
19        $password = $match[1];
20        if (empty($host)) $host = 'sql.mit.edu';
21        if (empty($user)) $user = $env_user;
22        if (empty($password)) $password = 'password';
23        return array($host,$user,$password);
24}
25}
26
27$cnfinfo = getMyCnfInfo($cnfPath);
28if (is_array($cnfinfo)) {
29        list($h,$u,$p) = $cnfinfo;
30        echo "$h\t$u\t$p";
31        exit;
32}
33
[382]34$sql_status = file_get_contents('https://sql.mit.edu/main/do/batch/status?u=' . urlencode($env_user));
[131]35switch($sql_status) {
36        case 1:
37                $myPassword = `/usr/bin/sql-signup`;
[234]38        file_put_contents($cnfPath, "[mysql]\nhost=$host\nuser=$env_user\npassword=$myPassword\n");
[131]39        $cnfinfo = getMyCnfInfo($cnfPath);
40        if (is_array($cnfinfo)) {
41            list($h,$u,$p) = $cnfinfo;
42            echo "$h\t$u\t$p";
43        }
44                break;
45        case 0:
46}
Note: See TracBrowser for help on using the repository browser.