From fafb8f2d0ac7a6aa962c4e7120e7aa9163a57df9 Mon Sep 17 00:00:00 2001 From: paspo Date: Mon, 13 Aug 2018 09:53:34 +0200 Subject: [PATCH] first release --- .drone.yml | 61 +++ .gitignore | 4 + README.md | 3 + createlinks.pl | 11 + .../startpage/defaults/configuration/outfile | 1 + .../startpage/defaults/configuration/status | 1 + .../startpage/defaults/configuration/template | 1 + .../db/startpage/defaults/configuration/type | 1 + .../db/startpage/defaults/link1/enable | 1 + .../db/startpage/defaults/link1/imagelink | 1 + .../e-smith/db/startpage/defaults/link1/link | 1 + .../e-smith/db/startpage/defaults/link1/title | 1 + .../e-smith/db/startpage/defaults/link1/type | 1 + .../e-smith/events/actions/startpage-force | 82 ++++ .../e-smith/events/actions/startpage-refresh | 30 ++ .../etc/httpd/conf.d/startpage.conf/50assets | 26 + .../en/NethServer_Module_Startpage.php | 10 + .../it/NethServer_Module_Startpage.php | 10 + .../nethesis/NethServer/Module/Startpage.php | 17 + .../NethServer/Module/Startpage/Force.php | 16 + .../NethServer/Module/Startpage/General.php | 30 ++ .../NethServer/Template/Startpage/Force.php | 7 + .../NethServer/Template/Startpage/General.php | 6 + .../startpage/assets/libreschool_logo.svg | 449 ++++++++++++++++++ .../share/startpage/templates/default.jinja2 | 104 ++++ startpage.spec | 81 ++++ 26 files changed, 956 insertions(+) create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 createlinks.pl create mode 100644 root/etc/e-smith/db/startpage/defaults/configuration/outfile create mode 100644 root/etc/e-smith/db/startpage/defaults/configuration/status create mode 100644 root/etc/e-smith/db/startpage/defaults/configuration/template create mode 100644 root/etc/e-smith/db/startpage/defaults/configuration/type create mode 100644 root/etc/e-smith/db/startpage/defaults/link1/enable create mode 100644 root/etc/e-smith/db/startpage/defaults/link1/imagelink create mode 100644 root/etc/e-smith/db/startpage/defaults/link1/link create mode 100644 root/etc/e-smith/db/startpage/defaults/link1/title create mode 100644 root/etc/e-smith/db/startpage/defaults/link1/type create mode 100644 root/etc/e-smith/events/actions/startpage-force create mode 100644 root/etc/e-smith/events/actions/startpage-refresh create mode 100644 root/etc/e-smith/templates/etc/httpd/conf.d/startpage.conf/50assets create mode 100644 root/usr/share/nethesis/NethServer/Language/en/NethServer_Module_Startpage.php create mode 100644 root/usr/share/nethesis/NethServer/Language/it/NethServer_Module_Startpage.php create mode 100644 root/usr/share/nethesis/NethServer/Module/Startpage.php create mode 100644 root/usr/share/nethesis/NethServer/Module/Startpage/Force.php create mode 100644 root/usr/share/nethesis/NethServer/Module/Startpage/General.php create mode 100644 root/usr/share/nethesis/NethServer/Template/Startpage/Force.php create mode 100644 root/usr/share/nethesis/NethServer/Template/Startpage/General.php create mode 100644 root/usr/share/startpage/assets/libreschool_logo.svg create mode 100644 root/usr/share/startpage/templates/default.jinja2 create mode 100644 startpage.spec diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..b443133 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,61 @@ +# this is needed by the RPM build plugin +workspace: + base: /build + path: / + +pipeline: + + create_targz: + image: libreschool-automation/rpm-pack:latest + dest: $$NAME-$$VERSION-$$RELEASE.tar.gz + dir: $$NAME-$$VERSION-$$RELEASE + files: + - root + - createlinks.pl + - README.md + - COPYING + when: + event: [ push, tag ] + + build: + image: libreschool-automation/rpm-build:latest + commands: + - yum-builddep -y startpage.spec + - rpmbuild -ba startpage.spec + - mkdir out ; mv *.rpm noarch/*.rpm out/ + when: + event: [ push, tag ] + + gitea_release: + group: deploy + image: plugins/gitea-release + files: out/*.rpm + checksum: + - md5 + - sha1 + - sha256 + - sha512 + secrets: [ gitea_token ] + base_url: https://git.libreschool.org + when: + event: tag + +# deploy_srpm: +# group: deploy +# image: drone-sftp +# host: repo.libreschool.org +# target: /https/nethserver/6/devel/Source/SPackages/ +# secrets: [ sftp_username, sftp_key ] +# source: out/*.src.rpm +# when: +# event: tag + +# deploy_rpm: +# group: deploy +# image: drone-sftp +# host: repo.libreschool.org +# target: /https/nethserver/6/devel/x86_64/Packages/ +# secrets: [ sftp_username, sftp_key ] +# source: out/*.noarch.rpm +# when: +# event: tag diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6e99c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.sh +*.tar.* +*.rpm +*.log diff --git a/README.md b/README.md index 95f38ed..7632789 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # startpage # +[![Build Status](https://drone.libreschool.org/api/badges/LibreSchool/libreschool-startpage/status.svg)](https://drone.libreschool.org/LibreSchool/libreschool-startpage) + + TODO diff --git a/createlinks.pl b/createlinks.pl new file mode 100644 index 0000000..d06989a --- /dev/null +++ b/createlinks.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl -w + +use esmith::Build::CreateLinks qw(:all); +use File::Basename; +use File::Path; + +$event = "startpage-refresh"; +event_actions($event, 'startpage-refresh' => 50); + +$event = "startpage-force"; +event_actions($event, 'startpage-force' => 50); \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/configuration/outfile b/root/etc/e-smith/db/startpage/defaults/configuration/outfile new file mode 100644 index 0000000..581f9fe --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/configuration/outfile @@ -0,0 +1 @@ +/var/www/html/index.html \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/configuration/status b/root/etc/e-smith/db/startpage/defaults/configuration/status new file mode 100644 index 0000000..26ed6c9 --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/configuration/status @@ -0,0 +1 @@ +enabled \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/configuration/template b/root/etc/e-smith/db/startpage/defaults/configuration/template new file mode 100644 index 0000000..331d858 --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/configuration/template @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/configuration/type b/root/etc/e-smith/db/startpage/defaults/configuration/type new file mode 100644 index 0000000..641e525 --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/configuration/type @@ -0,0 +1 @@ +configuration \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/link1/enable b/root/etc/e-smith/db/startpage/defaults/link1/enable new file mode 100644 index 0000000..396a0ba --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/link1/enable @@ -0,0 +1 @@ +yes \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/link1/imagelink b/root/etc/e-smith/db/startpage/defaults/link1/imagelink new file mode 100644 index 0000000..4913a3e --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/link1/imagelink @@ -0,0 +1 @@ +startpage/libreschool_logo.svg \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/link1/link b/root/etc/e-smith/db/startpage/defaults/link1/link new file mode 100644 index 0000000..4178bb1 --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/link1/link @@ -0,0 +1 @@ +https://community.libreschool.org/ \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/link1/title b/root/etc/e-smith/db/startpage/defaults/link1/title new file mode 100644 index 0000000..4d6ee1a --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/link1/title @@ -0,0 +1 @@ +Libreschool Community \ No newline at end of file diff --git a/root/etc/e-smith/db/startpage/defaults/link1/type b/root/etc/e-smith/db/startpage/defaults/link1/type new file mode 100644 index 0000000..c150ede --- /dev/null +++ b/root/etc/e-smith/db/startpage/defaults/link1/type @@ -0,0 +1 @@ +link \ No newline at end of file diff --git a/root/etc/e-smith/events/actions/startpage-force b/root/etc/e-smith/events/actions/startpage-force new file mode 100644 index 0000000..9249243 --- /dev/null +++ b/root/etc/e-smith/events/actions/startpage-force @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +import subprocess +import json +import sys +import os +import fnmatch + +def set_startpage_firefox(homedir): + d = homedir + '/.mozilla/firefox/' + profiles = [] + for root, dirs, files in os.walk(d): + for name in dirs: + p = os.path.join(root, name + '/prefs.js') + if os.path.isfile(p): + profiles.append(p) + for p in profiles: + with open(p, 'a') as f: + txt='user_pref("browser.startup.homepage", "http://' + _fqdn + '");' + f.write(txt) + return + +def set_startpage_chrome(homedir): + d = homedir + '/.config/google-chrome/' + profiles = [] + for root, dirs, files in os.walk(d): + for name in dirs: + p = os.path.join(root, name + '/Preferences') + if os.path.isfile(p): + profiles.append(p) + for p in profiles: + with open(p) as json_data: + data = json.load(json_data) + data['homepage'] = 'http://' + _fqdn + data['homepage_is_newtabpage'] = False + data['browser']['show_home_button'] = True + data['session']['restore_on_startup'] = 4 + data['session']['startup_urls'] = ['http://' + _fqdn] + with open(p, 'w') as f: + json.dump(data, f) + return + +def set_startpage_chromium(homedir): + d = homedir + '/.config/chromium/' + profiles = [] + for root, dirs, files in os.walk(d): + for name in dirs: + p = os.path.join(root, name + '/Preferences') + if os.path.isfile(p): + profiles.append(p) + for p in profiles: + with open(p) as json_data: + data = json.load(json_data) + data['homepage'] = 'http://' + _fqdn + data['homepage_is_newtabpage'] = False + data['browser']['show_home_button'] = True + data['session']['restore_on_startup'] = 4 + data['session']['startup_urls'] = ['http://' + _fqdn] + with open(p, 'w') as f: + json.dump(data, f) + return + + +_cfg = json.loads(subprocess.Popen(['/sbin/e-smith/db', 'configuration', 'showjson'],stdout=subprocess.PIPE).communicate()[0]) +_SystemName = [x['type'] for x in _cfg if x['name']=='SystemName'][0] +_DomainName = [x['type'] for x in _cfg if x['name']=='DomainName'][0] +_fqdn = _SystemName + '.' + _DomainName +_users = json.loads(subprocess.Popen(['/sbin/e-smith/db', 'accounts', 'showjson'],stdout=subprocess.PIPE).communicate()[0]) +_users = [x for x in _users if x['type']=='user' and x['name']!='admin'] + +# if a specific user has been requested, we filter the list +if len(sys.argv) > 1: + _users = [x for x in _users if x['name']==sys.argv[1]] + +# if we have some user to parse +if len(_users) > 0: + for u in _users: + homedir = '/var/lib/nethserver/home/' + u['name'] + set_startpage_firefox(homedir) + set_startpage_chrome(homedir) + set_startpage_chromium(homedir) + diff --git a/root/etc/e-smith/events/actions/startpage-refresh b/root/etc/e-smith/events/actions/startpage-refresh new file mode 100644 index 0000000..010f679 --- /dev/null +++ b/root/etc/e-smith/events/actions/startpage-refresh @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import subprocess +from jinja2 import Template +import json +import os + +templatedir = '/usr/share/startpage/templates/' + +_data = json.loads(subprocess.Popen(['/sbin/e-smith/db', 'startpage', 'showjson'],stdout=subprocess.PIPE).communicate()[0]) +_config = [x for x in _data if x['type']=='configuration'][0] +_status = _config['props']['status'] == 'enabled' +_outfile = _config['props']['outfile'] +_template = _config['props']['template'] + +try: + os.remove(_outfile) +except OSError: + pass + +if _status: + _links = [x for x in _data if x['type']=='link'] + _links = [x for x in _links if x['props']['enable']=='yes'] + + tplfile = templatedir + _template + '.jinja2' + with open(tplfile) as file_: + template = Template(file_.read()) + out = template.render(links=_links) + with open(_outfile, "wb") as f: + f.write(out) diff --git a/root/etc/e-smith/templates/etc/httpd/conf.d/startpage.conf/50assets b/root/etc/e-smith/templates/etc/httpd/conf.d/startpage.conf/50assets new file mode 100644 index 0000000..dd0465a --- /dev/null +++ b/root/etc/e-smith/templates/etc/httpd/conf.d/startpage.conf/50assets @@ -0,0 +1,26 @@ +{ + use strict; + use warnings; + + open(my $fh, '-|', 'httpd -v') or die $!; + while (my $line = <$fh>) { + if ($line =~ /.*Apache\/2\.2.*/) { + $OUT .= " +Alias /startpage /usr/share/startpage/assets + + + AllowOverride None + Order Allow,Deny + Allow from all +" + } elsif ($line =~ /.*Apache\/2\.4.*/) { + $OUT .= " +Alias /startpage /usr/share/startpage/assets + + + AllowOverride None + Require all granted +" + } + } +} diff --git a/root/usr/share/nethesis/NethServer/Language/en/NethServer_Module_Startpage.php b/root/usr/share/nethesis/NethServer/Language/en/NethServer_Module_Startpage.php new file mode 100644 index 0000000..16e6830 --- /dev/null +++ b/root/usr/share/nethesis/NethServer/Language/en/NethServer_Module_Startpage.php @@ -0,0 +1,10 @@ +loadChildren(array('*\General', '*\Force')); + } + +} diff --git a/root/usr/share/nethesis/NethServer/Module/Startpage/Force.php b/root/usr/share/nethesis/NethServer/Module/Startpage/Force.php new file mode 100644 index 0000000..a15920a --- /dev/null +++ b/root/usr/share/nethesis/NethServer/Module/Startpage/Force.php @@ -0,0 +1,16 @@ +getPlatform()->signalEvent('startpage-refresh &'); + } + +} diff --git a/root/usr/share/nethesis/NethServer/Module/Startpage/General.php b/root/usr/share/nethesis/NethServer/Module/Startpage/General.php new file mode 100644 index 0000000..6b3be0c --- /dev/null +++ b/root/usr/share/nethesis/NethServer/Module/Startpage/General.php @@ -0,0 +1,30 @@ +declareParameter('status', Validate::SERVICESTATUS, array('startpage', 'configuration', 'status')); + + } + + public function prepareView(\Nethgui\View\ViewInterface $view) + { + parent::prepareView($view); + + $view['statusDatasource'] = array_map(function($fmt) use ($view) { + return array($fmt, $view->translate($fmt . '_label')); + }, array('enabled','disabled')); + } + + protected function onParametersSaved($changes) + { + $this->getPlatform()->signalEvent('startpage-refresh &'); + } + +} diff --git a/root/usr/share/nethesis/NethServer/Template/Startpage/Force.php b/root/usr/share/nethesis/NethServer/Template/Startpage/Force.php new file mode 100644 index 0000000..23eda81 --- /dev/null +++ b/root/usr/share/nethesis/NethServer/Template/Startpage/Force.php @@ -0,0 +1,7 @@ +header()->setAttribute('template', $T('confirm_label')); + +echo $view->buttonList($view::BUTTON_HELP) + ->insert($view->button('Run', $view::BUTTON_SUBMIT)) +; diff --git a/root/usr/share/nethesis/NethServer/Template/Startpage/General.php b/root/usr/share/nethesis/NethServer/Template/Startpage/General.php new file mode 100644 index 0000000..069c463 --- /dev/null +++ b/root/usr/share/nethesis/NethServer/Template/Startpage/General.php @@ -0,0 +1,6 @@ +checkbox('status', 'enabled') + ->setAttribute('uncheckedValue', 'disabled'); + +echo $view->buttonList($view::BUTTON_SUBMIT | $view::BUTTON_HELP); diff --git a/root/usr/share/startpage/assets/libreschool_logo.svg b/root/usr/share/startpage/assets/libreschool_logo.svg new file mode 100644 index 0000000..e87f301 --- /dev/null +++ b/root/usr/share/startpage/assets/libreschool_logo.svg @@ -0,0 +1,449 @@ + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/root/usr/share/startpage/templates/default.jinja2 b/root/usr/share/startpage/templates/default.jinja2 new file mode 100644 index 0000000..77ef9b9 --- /dev/null +++ b/root/usr/share/startpage/templates/default.jinja2 @@ -0,0 +1,104 @@ + + + + + + +Libreschool start page + + + + + + + +
+
+

LibreSchool project - Start page

+
+
+
+
+
+ {% for l in links %} +
+

{{ l.props.title }}

+

{{ l.props.title }}

+
+ {% endfor %} +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/startpage.spec b/startpage.spec new file mode 100644 index 0000000..08b5110 --- /dev/null +++ b/startpage.spec @@ -0,0 +1,81 @@ +Summary: Manage a start page for all clients +Name: startpage +Version: 0.9 +Release: 3.ns6 +URL: https://github.com/libreschool/startpage/ +License: GPLv3+ +Packager: Paolo Asperti +Group: System Environment/Daemons +BuildRoot: %{_tmppath}/%{name}-root +BuildRequires: nethserver-devtools > 1.0.1 +BuildRequires: hunspell-en +Requires: httpd, sudo, +Requires: nethserver-base +Requires: python-jinja2 +Requires: net-tools +Source0: %{name}-%{version}-%{release}.tar.gz +Source1: createlinks.pl +BuildArch: noarch + +%description +Manage a start page for all clients. + +%prep +%setup -n %{name}-%{version}-%{release} + +%build +%{makedocs} +perl createlinks.pl + +%install +rm -Rf $RPM_BUILD_ROOT +(cd root ; find . -depth -print | cpio -dump %{buildroot}) +rm -f %{name}-%{version}-%{release}-filelist +%{genfilelist} %{buildroot} > %{name}-%{version}-%{release}-filelist + +%post +/etc/e-smith/events/actions/initialize-default-databases + +if [ "$1" = 1 ]; then + #installation + /sbin/e-smith/db startpage set configuration configuration status enabled template default outfile /var/www/html/index.html + /sbin/e-smith/db startpage set link1 link enable yes imagelink "startpage/libreschool_logo.svg" link "https://community.libreschool.org/" title "Libreschool Community" + /sbin/e-smith/expand-template /etc/httpd/conf.d/startpage.conf + service httpd restart + /sbin/e-smith/signal-event startpage-refresh +fi +if [ "$1" = 2 ]; then + #upgrade + /sbin/e-smith/expand-template /etc/httpd/conf.d/startpage.conf + service httpd restart + /sbin/e-smith/signal-event startpage-refresh +fi + + + +%postun +#if [ "$1" = 1 ]; then + #upgrade +#fi +if [ "$1" = 0 ]; then + #uninstallation + /sbin/e-smith/db configuration delete startpage +fi + + +%clean +rm -rf %{buildroot} + +%files -f %{name}-%{version}-%{release}-filelist +%defattr(0644,root,root,755) +%doc README.md COPYING + +%changelog +* Wed Jul 18 2018 Paolo Asperti - 0.9-3 +- ui fixing + +* Sun Jul 8 2018 Paolo Asperti - 0.9-2 +- bug fixing + +* Sun Jul 8 2018 Paolo Asperti - 0.9-1 +- initial release \ No newline at end of file