added ini-file support for application settings
This commit is contained in:
15
app.ini
Normal file
15
app.ini
Normal file
@@ -0,0 +1,15 @@
|
||||
[app]
|
||||
; either "paste" or "shortener"
|
||||
; reserved for future releases, not used
|
||||
type = paste
|
||||
; relative path to application, as it seen in browser
|
||||
; must end with '/'
|
||||
baseurl = /
|
||||
; if you decide to put images|css on separate domain, write it here
|
||||
; or leave it same as siteaddress
|
||||
; for now it is only /bg_logo.png
|
||||
cdnaddress = http://127.0.0.1/
|
||||
; hostname where app lives, with http(s) prefix
|
||||
siteaddress = http://127.0.0.1/
|
||||
; path, where db created|stored, if not exist, it will be created
|
||||
dbpath = paste/paste.sqlite
|
||||
22
index.php
22
index.php
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
define ('BASEURL', "/"); # must end with '/'
|
||||
$config = parse_ini_file("app.ini");
|
||||
define ('SITE_ADDRESS', $config["siteaddress"]);
|
||||
define ('BASEURL', $config["baseurl"]);
|
||||
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
|
||||
define ('CDN_ADDRESS', $config["cdnaddress"]);
|
||||
define ('DBPATH', $config["dbpath"]);
|
||||
define ('KEY_MIN', 3);
|
||||
define ('KEY_MAX', 9);
|
||||
define ('DBPATH', 'paste/paste.sqlite');
|
||||
define ('SITE_ADDRESS', 'http://127.0.0.1/');
|
||||
define ('CDN_ADDRESS', 'http://127.0.0.1/');
|
||||
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
|
||||
unset ($config);
|
||||
|
||||
function showindex($text) {
|
||||
header('Content-Language: en, ru');
|
||||
@@ -25,10 +27,10 @@ function showindex($text) {
|
||||
height: 70vh;
|
||||
}
|
||||
</style>
|
||||
<title>Paste.</title>
|
||||
<title>Slack paste.</title>
|
||||
</head>
|
||||
<body>
|
||||
<h3>Paste</h3>
|
||||
<h3>Slack Paste</h3>
|
||||
<form method="post" action="<?php print APP_ADDRESS; ?>" enctype="multipart/form-data">
|
||||
<textarea name="exs" id="textbox" autofocus></textarea><br />
|
||||
<input type="submit" value="Post it!" style="font-size:115%;" /> for
|
||||
@@ -76,7 +78,7 @@ description() {
|
||||
cat << HERE
|
||||
|
||||
DESCRIPTION
|
||||
Upload data and fetch URL from the pastebin <?php print SITE_ADDRESS; ?>
|
||||
Upload data and fetch URL from the pastebin http://p.dafuq.ru/
|
||||
|
||||
USAGE
|
||||
$0 filename.txt
|
||||
@@ -188,14 +190,14 @@ function init_db() {
|
||||
$dbh = null;
|
||||
}
|
||||
|
||||
function query_db($id) {
|
||||
function query_db($q) {
|
||||
if (! file_exists(DBPATH)) {
|
||||
init_db();
|
||||
return false;
|
||||
}
|
||||
|
||||
$dbh = new PDO("sqlite:" . DBPATH);
|
||||
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$id'");
|
||||
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$q'");
|
||||
|
||||
if ($sth === false) {
|
||||
$e = $r->errorInfo();
|
||||
|
||||
Reference in New Issue
Block a user