├── .gitignore ├── public ├── .user.ini ├── composer.json ├── images │ ├── chandika.jpg │ └── chandika.png ├── manifest.yml ├── autoload.php ├── classes │ ├── migrations │ │ ├── m0004.php │ │ ├── m0003.php │ │ ├── m0011.php │ │ ├── m0008.php │ │ ├── m0009.php │ │ ├── m0005.php │ │ ├── m0002.php │ │ ├── m0010.php │ │ ├── m0007.php │ │ ├── m0006.php │ │ └── m0001.php │ ├── Filter.php │ ├── UserAdministrator.php │ ├── ApiKeyAdministrator.php │ ├── BillingAdministrator.php │ ├── CrudHelper.php │ ├── DB.php │ ├── AccountAdministrator.php │ ├── Authenticator.php │ ├── ServiceAdministrator.php │ └── ResourceAdministrator.php ├── add_administrator.php ├── add_resource.php ├── api │ ├── billing_month.php │ ├── billing.php │ └── account.php ├── login.php ├── show_billing_service.php ├── edit_service.php ├── edit_account.php ├── show_administrators.php ├── show_accounts.php ├── show_api_keys.php ├── show_billing_month.php ├── show_billing.php ├── show_resources.php ├── index.php ├── show_services.php ├── css │ ├── style.css │ └── jquery-ui.css ├── header.php ├── composer.lock └── js │ └── bootstrap.min.js ├── circle.yml ├── Vagrantfile ├── scripts ├── billing_tagnotes.py └── billing.py ├── CONTRIBUTING.md ├── LICENSE.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | .vagrant -------------------------------------------------------------------------------- /public/.user.ini: -------------------------------------------------------------------------------- 1 | short_open_tag=On 2 | -------------------------------------------------------------------------------- /public/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "guzzlehttp/guzzle": "6.*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /public/images/chandika.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/18F/chandika/HEAD/public/images/chandika.jpg -------------------------------------------------------------------------------- /public/images/chandika.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/18F/chandika/HEAD/public/images/chandika.png -------------------------------------------------------------------------------- /public/manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: chandika 4 | memory: 256M 5 | buildpack: https://github.com/heroku/heroku-buildpack-php 6 | -------------------------------------------------------------------------------- /public/autoload.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE services ADD COLUMN tag VARCHAR(255) NULL"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /public/classes/migrations/m0003.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE resources MODIFY uri VARCHAR(255) NOT NULL"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /public/classes/migrations/m0011.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE accounts MODIFY label VARCHAR(127) NOT NULL"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /public/classes/migrations/m0008.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE billing ADD COLUMN discount_factor DECIMAL(10,8) NOT NULL DEFAULT 1"); 8 | } 9 | } -------------------------------------------------------------------------------- /public/classes/migrations/m0009.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE accounts ADD COLUMN is_archived TINYINT NOT NULL DEFAULT 0"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /public/classes/migrations/m0005.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE services ADD COLUMN billing_code VARCHAR(255) NOT NULL DEFAULT ''"); 8 | $conn->exec("ALTER TABLE services DROP COLUMN is_billable"); 9 | } 10 | } -------------------------------------------------------------------------------- /public/classes/migrations/m0002.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE accounts ADD COLUMN email VARCHAR(255) NOT NULL DEFAULT ''"); 8 | $conn->exec("ALTER TABLE services ADD COLUMN is_billable TINYINT NOT NULL DEFAULT 0"); 9 | } 10 | } -------------------------------------------------------------------------------- /public/classes/migrations/m0010.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE billing MODIFY tagname VARCHAR(127)"); 8 | $conn->exec("ALTER TABLE billing MODIFY tagvalue VARCHAR(127)"); 9 | $conn->exec("ALTER TABLE billing ADD COLUMN tagnote VARCHAR(127) NULL"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /public/classes/Filter.php: -------------------------------------------------------------------------------- 1 | 2 | class Filter 3 | { 4 | public static function dropdown($name, $values, $selected) { 5 | $dropdown = ""; 11 | } 12 | } 13 | ?> -------------------------------------------------------------------------------- /public/add_administrator.php: -------------------------------------------------------------------------------- 1 | 2 | require "autoload.php"; 3 | $auth = new Authenticator(); 4 | $auth->assertRole(Authenticator::administrator); 5 | 6 | $users = new UserAdministrator(); 7 | switch ($_REQUEST["action"]) { 8 | case "CREATE": 9 | $email = $_REQUEST["email"]; 10 | $users->create($email); 11 | break; 12 | case "DELETE": 13 | $id = $_REQUEST["id"]; 14 | $users->delete($id); 15 | } 16 | header("Location: /show_administrators.php"); 17 | ?> 18 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | pre: 3 | - mkdir -p debs 4 | - if [ ! -f debs/temp.deb ]; then wget -qO debs/temp.deb https://cli.run.pivotal.io/stable?release=debian64; fi 5 | - sudo dpkg -i debs/temp.deb 6 | cache_directories: 7 | - debs 8 | 9 | deployment: 10 | production: 11 | branch: [master] 12 | commands: 13 | - cf login -a https://api.fr.cloud.gov/ -u $CF_CHANDIKA_USER -p $CF_CHANDIKA_PASS -o gsa-tts-infrastructure -s chandika-prod 14 | - cd public && cf push chandika 15 | -------------------------------------------------------------------------------- /public/add_resource.php: -------------------------------------------------------------------------------- 1 | 2 | require "autoload.php"; 3 | $auth = new Authenticator(); 4 | 5 | $service_id = $_REQUEST["service_id"]; 6 | 7 | if ($_REQUEST["action"] == "CREATE") { 8 | $resources = new ResourceAdministrator($service_id); 9 | $uri = $_REQUEST["uri"]; 10 | $resource_type = $_REQUEST["resource_type"]; 11 | $creator = isset($_SESSION["user_email"]) ? $_SESSION["user_email"] : "Nobody"; 12 | $resources->create($resource_type, $creator, $uri, strtotime($_REQUEST["expiry_date"])); 13 | } 14 | if ($_REQUEST["action"] == "DELETE") { 15 | ResourceAdministrator::delete($_REQUEST["id"]); 16 | } 17 | 18 | header("Location: /show_resources.php?service_id=$service_id"); 19 | ?> 20 | -------------------------------------------------------------------------------- /public/classes/migrations/m0007.php: -------------------------------------------------------------------------------- 1 | exec("CREATE TABLE IF NOT EXISTS api_keys ( 8 | id INT NOT NULL AUTO_INCREMENT, 9 | label VARCHAR(50) NOT NULL, 10 | last_used DATETIME NULL, 11 | active TINYINT NOT NULL DEFAULT 1, 12 | uuid VARCHAR(50) NOT NULL, 13 | PRIMARY KEY(id))"); 14 | $conn->exec("ALTER TABLE services ADD COLUMN is_archived TINYINT NOT NULL DEFAULT 0"); 15 | $conn->exec("ALTER TABLE services ADD COLUMN description VARCHAR(255) NULL"); 16 | } 17 | } -------------------------------------------------------------------------------- /public/api/billing_month.php: -------------------------------------------------------------------------------- 1 | prepare($sql); 19 | foreach ($tag_notes as $tagvalue => $tagnote) { 20 | $statement->execute([":date" => $month, ":tagvalue" => $tagvalue, ":tagnote" => $tagnote]); 21 | } 22 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure("2") do |config| 5 | 6 | config.vm.box = "scotch/box" 7 | config.vm.network "private_network", ip: "192.168.33.20" 8 | config.vm.hostname = "scotchbox" 9 | config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"] 10 | config.vm.provider "virtualbox" do |v| 11 | v.memory = 1024 12 | v.cpus = 1 13 | end 14 | 15 | # Optional NFS. Make sure to remove other synced_folder line too 16 | #config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] } 17 | 18 | config.vm.provision "shell", inline: <<-SHELL 19 | sudo bash -c \'echo export CHANDIKA_OAUTH="OFF" >> /etc/apache2/envvars\' 20 | 21 | sudo service apache2 restart 22 | SHELL 23 | end 24 | -------------------------------------------------------------------------------- /public/classes/migrations/m0006.php: -------------------------------------------------------------------------------- 1 | exec("ALTER TABLE accounts CHANGE COLUMN nickname label VARCHAR(50) NOT NULL"); 8 | $conn->exec("ALTER TABLE accounts ADD COLUMN description VARCHAR(255) NULL"); 9 | $conn->exec("CREATE TABLE IF NOT EXISTS billing ( 10 | id INT NOT NULL AUTO_INCREMENT, 11 | provider VARCHAR(50) NOT NULL, 12 | invoice_date DATE NOT NULL, 13 | identifier VARCHAR(255) NOT NULL, 14 | tagname VARCHAR(50) NULL, 15 | tagvalue VARCHAR(50) NULL, 16 | amount DECIMAL (10,2), 17 | PRIMARY KEY(id))"); 18 | } 19 | } -------------------------------------------------------------------------------- /public/classes/UserAdministrator.php: -------------------------------------------------------------------------------- 1 | 2 | class UserAdministrator 3 | { 4 | public function users() 5 | { 6 | $results = []; 7 | $sql = "SELECT id, email FROM administrators ORDER BY email"; 8 | foreach (DB::connection()->query($sql, PDO::FETCH_OBJ) as $row) { 9 | $results[] = $row; 10 | } 11 | return $results; 12 | } 13 | 14 | public function create($email) 15 | { 16 | $insert = DB::connection()->prepare("INSERT INTO administrators (email) VALUES (:email)"); 17 | $insert->bindParam(':email', $email); 18 | $insert->execute(); 19 | } 20 | 21 | public function delete($id) 22 | { 23 | $delete = DB::connection()->prepare("DELETE FROM administrators WHERE id = :id"); 24 | $delete->bindParam(':id', $id); 25 | $delete->execute(); 26 | } 27 | } 28 | ?> -------------------------------------------------------------------------------- /public/login.php: -------------------------------------------------------------------------------- 1 | 2 | if (isset($_REQUEST["logout"])) { 3 | session_start(); 4 | unset($_SESSION["user_email"]); 5 | } 6 | ?> 7 | 8 | 9 |
10 |=$_REQUEST["error"]?>
}?> 19 | 20 || Invoice date | 25 |Amount | 26 |
|---|---|
| {$line->invoice_date} | " . money_format('%(#10n', $line->total) . " |