last minute hotfixes
parent
d40379a8c7
commit
cf4f398f8e
|
@ -1,2 +1,2 @@
|
|||
tweetodon.conf.json
|
||||
*.swp
|
||||
rsstootalizer.conf.json
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
# vim: set foldmarker={,}:
|
||||
use strict;
|
||||
use RSSTootalizer::Base;
|
||||
|
||||
package RSSTootalizer::Account;
|
||||
@RSSTootalizer::Account::ISA = qw(RSSTootalizer::Base);
|
||||
use JSON;
|
||||
use RSSTootalizer::Application;
|
||||
use Data::Dumper;
|
||||
|
||||
sub dbTable :lvalue { "accounts"; }
|
||||
sub orderBy :lvalue { "username ASC"; }
|
||||
|
||||
# Class functions
|
||||
# Object methods
|
||||
sub application {
|
||||
my $self = shift;
|
||||
my $retVal = RSSTootalizer::Application->get_by("id", $self->{"data"}->{"application_id"});
|
||||
return $retVal;
|
||||
}
|
||||
|
||||
1;
|
|
@ -7,8 +7,8 @@ package RSSTootalizer::Migration;
|
|||
use JSON;
|
||||
use Data::Dumper;
|
||||
|
||||
sub dbTable :lvalue { "tokens"; }
|
||||
sub orderBy :lvalue { "username ASC"; }
|
||||
sub dbTable :lvalue { "migrations"; }
|
||||
sub orderBy :lvalue { "created_at ASC"; }
|
||||
|
||||
# Class functions
|
||||
|
||||
|
|
|
@ -1,283 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
# vim: set foldmarker={,}:
|
||||
|
||||
use strict;
|
||||
use RSSTootalizer::DB;
|
||||
use RSSTootalizer::Account;
|
||||
use RSSTootalizer::Identity;
|
||||
use RSSTootalizer::Website;
|
||||
|
||||
package RSSTootalizer::Website::JSON;
|
||||
@RSSTootalizer::Website::JSON::ISA = qw(Website);
|
||||
use Data::Dumper;
|
||||
use JSON;
|
||||
use MIME::Base64 qw(encode_base64);
|
||||
|
||||
sub requires_authentication {
|
||||
return 1;
|
||||
}
|
||||
sub fill_content {
|
||||
return 1;
|
||||
}
|
||||
sub prerender {
|
||||
my $self = shift;
|
||||
$self->{"template"} = "error";
|
||||
$self->{"content_type"} = "json";
|
||||
$self->{"params"}->{"currentmode"} = "JSON";
|
||||
|
||||
my $submode = $main::FORM{r};
|
||||
$self->$submode();
|
||||
}
|
||||
|
||||
sub SaveSettings {
|
||||
my $self = shift;
|
||||
|
||||
$self->{"template"} = "Settings_Save";
|
||||
foreach my $k (keys %{$main::CURRENTUSER->{"data"}}, "password"){
|
||||
next if $k eq "login";
|
||||
|
||||
if (exists($main::FORM{$k})){
|
||||
$main::CURRENTUSER->{"data"}->{$k} = $main::FORM{$k};
|
||||
}
|
||||
}
|
||||
if (!$main::CURRENTUSER->save()){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = $DBI::errstr;
|
||||
} else {
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "Saved successfully";
|
||||
}
|
||||
}
|
||||
|
||||
sub identity_accounts {
|
||||
my $self = shift;
|
||||
if ((!$main::CURRENTUSER->has_privilege("useradmin")) && ($main::CURRENTUSER->{"data"}->{"id"} != $main::FORM{"id"})){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "accounts";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my @accounts;
|
||||
my $i = RSSTootalizer::Identity->get_by("id", $main::FORM{"id"});
|
||||
foreach my $a ($i->accounts()){
|
||||
my %account;
|
||||
foreach my $k (keys %{$a->{"data"}}){
|
||||
$account{$k} = $a->{"data"}->{$k};
|
||||
}
|
||||
push @accounts, \%account;
|
||||
}
|
||||
$self->{"params"}->{"accounts"} = \@accounts;
|
||||
}
|
||||
|
||||
sub applications_all {
|
||||
my $self = shift;
|
||||
if (!$main::CURRENTUSER->has_privilege("superuser")){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "applications_all";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my @applications;
|
||||
foreach my $a (RSSTootalizer::Application->all()){
|
||||
my %application;
|
||||
foreach my $k (keys %{$a->{"data"}}){
|
||||
$application{$k} = $a->{"data"}->{$k};
|
||||
}
|
||||
$application{"b64_configuration"} = encode_base64($a->{"data"}->{"configuration"}, "");
|
||||
push @applications, \%application;
|
||||
}
|
||||
$self->{"params"}->{"applications"} = \@applications;
|
||||
}
|
||||
sub application_by_id {
|
||||
my $self = shift;
|
||||
if (!$main::CURRENTUSER->has_privilege("superuser")){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "application";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my $a = RSSTootalizer::Application->get_by("id", $main::FORM{"id"});
|
||||
foreach my $k (keys %{$a->{"data"}}){
|
||||
$self->{"params"}->{$k} = $a->{"data"}->{$k};
|
||||
}
|
||||
$self->{"params"}->{"b64_configuration"} = encode_base64($a->{"data"}->{"configuration"}, "");
|
||||
$self->{"params"}->{"options"} = encode_json($a->get_handler()->configuration_options());
|
||||
}
|
||||
sub application_save {
|
||||
my $self = shift;
|
||||
if (!$main::CURRENTUSER->has_privilege("superuser")){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "error";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my $a;
|
||||
if ($main::FORM{"id"} eq "new"){
|
||||
# TODO
|
||||
# my %data;
|
||||
# $data{"login"} = $main::FORM{"login"};
|
||||
# $u = RSSTootalizer::Application->create(%data);
|
||||
} else {
|
||||
$a = RSSTootalizer::Application->get_by("id", $main::FORM{"id"});
|
||||
}
|
||||
|
||||
foreach my $k (keys %{$a->{"data"}}){
|
||||
if (exists($main::FORM{$k}) && "x".$main::FORM{$k} ne "x"){
|
||||
$a->{"data"}->{$k} = $main::FORM{$k};
|
||||
}
|
||||
}
|
||||
$a->save();
|
||||
}
|
||||
sub application_import_accounts {
|
||||
my $self = shift;
|
||||
if (!$main::CURRENTUSER->has_privilege("superuser")){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "application_import_accounts";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my $a = RSSTootalizer::Application->get_by("id", $main::FORM{"id"});
|
||||
my @accounts;
|
||||
foreach my $acc ($a->get_handler()->import_accounts_from_application()){
|
||||
my %account;
|
||||
$account{"username"} = $$acc{"username"};
|
||||
$account{"disabled"} = $$acc{"disabled"};
|
||||
push @accounts, \%account;
|
||||
}
|
||||
$self->{"params"}->{"accounts"} = \@accounts;
|
||||
}
|
||||
|
||||
sub users_all {
|
||||
my $self = shift;
|
||||
if (!$main::CURRENTUSER->has_privilege("useradmin")){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "users_all";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my @users;
|
||||
my $count = 0;
|
||||
foreach my $u (RSSTootalizer::User->all()){
|
||||
my %user;
|
||||
foreach my $k (keys %{$u->{"data"}}){
|
||||
next if $k eq "password";
|
||||
$user{$k} = $u->{"data"}->{$k};
|
||||
}
|
||||
push @users, \%user;
|
||||
$count++;
|
||||
}
|
||||
$self->{"params"}->{"users"} = \@users;
|
||||
$self->{"params"}->{"count"} = $count;
|
||||
}
|
||||
sub user_by_id {
|
||||
my $self = shift;
|
||||
if ((!$main::CURRENTUSER->has_privilege("useradmin")) && ($main::CURRENTUSER->{"data"}->{"id"} != $main::FORM{"id"})){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "user";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my $u = RSSTootalizer::User->get_by("id", $main::FORM{"id"});
|
||||
foreach my $k (keys %{$u->{"data"}}){
|
||||
next if $k eq "password";
|
||||
$self->{"params"}->{$k} = $u->{"data"}->{$k};
|
||||
}
|
||||
}
|
||||
sub user_save {
|
||||
my $self = shift;
|
||||
if ((!$main::CURRENTUSER->has_privilege("useradmin")) && ($main::CURRENTUSER->{"data"}->{"id"} != $main::FORM{"id"})){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "error";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my $u;
|
||||
if ($main::FORM{"id"} eq "new"){
|
||||
my %data;
|
||||
$data{"login"} = $main::FORM{"login"};
|
||||
$u = RSSTootalizer::User->create(%data);
|
||||
} else {
|
||||
$u = RSSTootalizer::User->get_by("id", $main::FORM{"id"});
|
||||
}
|
||||
delete $main::FORM{"id"};
|
||||
foreach my $k (keys %{$u->{"data"}}){
|
||||
if (exists($main::FORM{$k}) && "x".$main::FORM{$k} ne "x"){
|
||||
$u->{"data"}->{$k} = $main::FORM{$k};
|
||||
}
|
||||
}
|
||||
$u->save();
|
||||
}
|
||||
sub user_identities {
|
||||
my $self = shift;
|
||||
if ((!$main::CURRENTUSER->has_privilege("useradmin")) && ($main::CURRENTUSER->{"data"}->{"id"} != $main::FORM{"id"})){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "identities";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my @identities;
|
||||
my $u = RSSTootalizer::User->get_by("id", $main::FORM{"id"});
|
||||
foreach my $id ($u->identities()){
|
||||
my %identity;
|
||||
foreach my $k (keys %{$id->{"data"}}){
|
||||
$identity{$k} = $id->{"data"}->{$k};
|
||||
}
|
||||
push @identities, \%identity;
|
||||
}
|
||||
$self->{"params"}->{"identities"} = \@identities;
|
||||
}
|
||||
|
||||
sub identities_save {
|
||||
my $self = shift;
|
||||
if ((!$main::CURRENTUSER->has_privilege("useradmin")) && ($main::CURRENTUSER->{"data"}->{"id"} != $main::FORM{"id"})){
|
||||
$self->{"params"}->{"status"} = "Error";
|
||||
$self->{"params"}->{"msg"} = "You are not allowed to perform this operation.";
|
||||
return 1;
|
||||
}
|
||||
$self->{"template"} = "error";
|
||||
$self->{"params"}->{"status"} = "OK";
|
||||
$self->{"params"}->{"msg"} = "";
|
||||
|
||||
my $user = RSSTootalizer::User->get_by("id", $main::FORM{"id"});
|
||||
foreach my $id ($user->identities()){
|
||||
if (exists($main::FORM{$id->{"data"}->{"id"}})){
|
||||
$id->{"data"}->{"description"} = $main::FORM{$id->{"data"}->{"id"}};
|
||||
$id->save();
|
||||
}
|
||||
}
|
||||
if (exists($main::FORM{"new"})){
|
||||
my %data;
|
||||
$data{user_id} = $user->{"data"}->{"id"};
|
||||
$data{description} = $main::FORM{"new"};
|
||||
RSSTootalizer::Identity->create(%data);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
2
index.pl
2
index.pl
|
@ -120,7 +120,7 @@ my $object;
|
|||
# TODO: This is a very bad solution but not as bad as an uncontrolled eval...
|
||||
# The @main::modules array holds a list of all permissible values of the $main::FORM{"mode"} variable.
|
||||
# If the value is not in this array, the request is not processed and an error is displayed.
|
||||
my @modules = ("Login", "Logout", "OAuthLogin", "Dashboard", "Callback", "JSON", "EditFeed");
|
||||
my @modules = ("Login", "Logout", "OAuthLogin", "Dashboard", "Callback", "EditFeed");
|
||||
|
||||
if (! grep {$_ eq $FORM{mode}} @modules) {
|
||||
Error("Validation Error", "$FORM{mode} is not a valid module");
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET AUTOCOMMIT = 0;
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
CREATE TABLE `apps` (
|
||||
`ID` bigint(20) UNSIGNED NOT NULL,
|
||||
`instance` text CHARACTER SET utf8mb4 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`instance_id` text CHARACTER SET utf8mb4 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`instance_client_id` text CHARACTER SET utf8mb4 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`instance_client_secret` text CHARACTER SET utf8mb4 COLLATE utf8_unicode_ci NOT NULL
|
||||
`instance` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`instance_id` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`instance_client_id` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`instance_client_secret` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
CREATE TABLE `entries` (
|
||||
|
@ -20,9 +15,9 @@ CREATE TABLE `entries` (
|
|||
|
||||
CREATE TABLE `feeds` (
|
||||
`ID` bigint(20) UNSIGNED NOT NULL,
|
||||
`username` text CHARACTER SET utf8mb4 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`instance` text CHARACTER SET utf8mb4 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`url` text CHARACTER SET utf8mb4 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`username` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`instance` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`url` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`format` varchar(500) NOT NULL DEFAULT '{Title} - {Link} by {Author} -- posted at {Issued} with #RSSTootalizer',
|
||||
`enabled` enum('0','1') NOT NULL DEFAULT '0'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
@ -93,4 +88,3 @@ ALTER TABLE `entries`
|
|||
|
||||
ALTER TABLE `filters`
|
||||
ADD CONSTRAINT `filters_ibfk_1` FOREIGN KEY (`feed_id`) REFERENCES `feeds` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
COMMIT;
|
||||
|
|
33
update_db.pl
33
update_db.pl
|
@ -3,11 +3,18 @@
|
|||
use strict;
|
||||
use Data::Dumper;
|
||||
use RSSTootalizer::Migration;
|
||||
use JSON;
|
||||
|
||||
sub Error {
|
||||
my $headline = shift;
|
||||
my $msg = shift;
|
||||
print "$headline: $msg\n";
|
||||
}
|
||||
|
||||
our $config = "";
|
||||
open CONFIG, "rsstootalizer.conf.json" or die "Cannot open rsstootalizer.conf.json";
|
||||
{
|
||||
$/ = undef;
|
||||
local $/ = undef;
|
||||
$config = <CONFIG>;
|
||||
}
|
||||
close CONFIG;
|
||||
|
@ -19,18 +26,26 @@ binmode STDOUT, ":utf8";
|
|||
|
||||
my @migrations = glob ("migrations/*sql");
|
||||
foreach my $migration (@migrations){
|
||||
print "Running migration $migration\n";
|
||||
if (!RSSTootalizer::Migration->get_by("name", $migration)){
|
||||
open (M, $migration);
|
||||
my $sql;
|
||||
{
|
||||
$/ = undef;
|
||||
$sql = <M>;
|
||||
my $sth = RSSTootalizer::DB->doSELECT("SELECT * FROM migrations WHERE name = ?", $migration);
|
||||
if (!$sth){
|
||||
print "Running migration $migration\n";
|
||||
open (M, "<", $migration);
|
||||
my $sql = "";
|
||||
while (<M>){
|
||||
chomp;
|
||||
print "Read: $_\n";
|
||||
$sql .= $_;
|
||||
if ($sql =~ /;/){
|
||||
print "Running: $sql\n";
|
||||
RSSTootalizer::DB->doDELETE($sql); # Using doDELETE for lack of error handling...
|
||||
$sql = "";
|
||||
}
|
||||
}
|
||||
close M;
|
||||
RSSTootalizer::DB->doINSERT($sql);
|
||||
my %migdata;
|
||||
$migdata{name} = $migration;
|
||||
RSSTootalizer::Migration->create(%migdata);
|
||||
} else {
|
||||
print "Migration $migration already done\n";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue